From 4ed8f1e4d41fbe0c925c5ccdd32cc3f64cc68af7 Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Mon, 18 Dec 2023 08:20:05 -0500 Subject: [PATCH] Get main extensions selector working --- src/sliderulestab.cpp | 36 +++++++++++++++++++++++++++++------- src/sliderulestab.h | 3 +-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/sliderulestab.cpp b/src/sliderulestab.cpp index 1d01aa63..b19abe18 100644 --- a/src/sliderulestab.cpp +++ b/src/sliderulestab.cpp @@ -34,8 +34,30 @@ void SliderulesTab::isaSelectorChanged() { auto isa = ui->encodingTable->model->isa; auto exts = QStringList(); auto text = ui->mainExtensionSelector->currentText(); - if (!text.isEmpty() && isa->supportsExtension(text)) - exts = QStringList() << text; + if (!text.isEmpty()) { + bool hideRows = true; + if (isa->supportsExtension(text)) { + exts = QStringList() << text; + } else { + hideRows = false; + } + // Hide base extension + for (const auto &instr : ui->encodingTable->model->rowInstrMap) { + if (instr.second->extensionOrigin() == isa->baseExtension()) { + ui->encodingTable->setRowHidden(instr.first, hideRows); + bool hasImmediate = false; + for (const auto &field : instr.second->getFields()) { + if (field->fieldType() == "imm") { + hasImmediate = true; + break; + } + } + if (hasImmediate) { + ui->encodingTable->setRowHidden(instr.first + 1, hideRows); + } + } + } + } ui->encodingTable->updateISA(ui->regWidthSelector->currentText(), exts); } @@ -88,7 +110,7 @@ EncodingModel::EncodingModel( // Map instructions to their row index size_t row = 0; for (const auto &instr : *m_instructions) { - m_rowInstrMap[row] = instr.get(); + rowInstrMap[row] = instr.get(); ++row; bool hasImmediate = false; for (const auto &field : instr->getFields()) { @@ -148,13 +170,13 @@ QVariant EncodingModel::data(const QModelIndex &index, int role) const { } bool isImmediateRow = false; - if (m_rowInstrMap.count(row) == 0) { - assert(m_rowInstrMap.count(row - 1) == 1 && + if (rowInstrMap.count(row) == 0) { + assert(rowInstrMap.count(row - 1) == 1 && "No matching instruction for row in encoding table"); isImmediateRow = true; } auto col = index.column(); - auto &instr = m_rowInstrMap.at(isImmediateRow ? row - 1 : row); + auto &instr = rowInstrMap.at(isImmediateRow ? row - 1 : row); auto fields = instr->getFields(); if (isImmediateRow) { @@ -255,7 +277,7 @@ void EncodingView::updateView() { horizontalHeader()->setSectionResizeMode(EncodingModel::DESCRIPTION, QHeaderView::ResizeMode::Stretch); clearSpans(); - for (const auto &pair : model->m_rowInstrMap) { + for (const auto &pair : model->rowInstrMap) { int row = static_cast(pair.first); const auto &instr = pair.second; size_t fieldIdx = 0; diff --git a/src/sliderulestab.h b/src/sliderulestab.h index 11a550e7..be80435f 100644 --- a/src/sliderulestab.h +++ b/src/sliderulestab.h @@ -50,6 +50,7 @@ class EncodingModel : public QAbstractTableModel { int role = Qt::DisplayRole) const override; const std::shared_ptr isa; + std::map rowInstrMap; protected: friend class EncodingView; @@ -58,8 +59,6 @@ class EncodingModel : public QAbstractTableModel { const std::shared_ptr m_instructions; const std::shared_ptr m_pseudoInstructions; - - std::map m_rowInstrMap; }; class EncodingView : public QTableView {