From 342722efd075033d7a7dd211dd0ec0383e0949b5 Mon Sep 17 00:00:00 2001 From: Ryan Cohen Date: Tue, 27 Feb 2024 13:05:26 -0500 Subject: [PATCH] Add first signal and slot for ISAInstructionsModel --- src/sliderulestab.cpp | 41 +++++++++++++++++++++++++++++++++++------ src/sliderulestab.h | 12 ++++++------ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/sliderulestab.cpp b/src/sliderulestab.cpp index b33b8c36..cf619d4c 100644 --- a/src/sliderulestab.cpp +++ b/src/sliderulestab.cpp @@ -23,16 +23,23 @@ InstructionItem *InstructionItem::parent() { return m_parent; } bool InstructionItem::hasParent() const { return m_parent; } ISAInstructionsModel::ISAInstructionsModel(QObject *parent) { - for (const auto &instr : ProcessorHandler::currentISA()->instructions()) { - m_instrItems.push_back(std::make_unique(*instr.get())); - } + changeISAInfo(*ProcessorHandler::currentISA()); } int ISAInstructionsModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) { - return parent.parent().isValid() ? 0 : 1; + if (!parent.isValid()) { + // Number of instruction rows + return m_instrItems.size(); + } + + if (parent.parent().isValid()) { + // Tree is only one layer deep + return 0; } - return m_instrItems.size(); + + // TODO(raccog): Extra rows for 64-bit instructions and immediate formats + // Number of extra rows for a single instruction + return 1; } int ISAInstructionsModel::columnCount(const QModelIndex &) const { return 1; } @@ -89,6 +96,24 @@ QModelIndex ISAInstructionsModel::parent(const QModelIndex &index) const { return parent ? createIndex(0, 0, parent) : QModelIndex{}; } +const ISAInfoBase *ISAInstructionsModel::isaInfo() const { + return m_isaInfo.get(); +} + +void ISAInstructionsModel::changeISAInfo(const ISAInfoBase &isaInfo) { + if (!m_isaInfo || !m_isaInfo->eq(&isaInfo, isaInfo.enabledExtensions())) { + beginResetModel(); + m_isaInfo = + ISAInfoRegistry::getISA(isaInfo.isaID(), isaInfo.enabledExtensions()); + m_instrItems.clear(); + for (const auto &instr : m_isaInfo->instructions()) { + m_instrItems.push_back(std::make_unique(*instr)); + } + endResetModel(); + emit isaInfoChanged(*m_isaInfo); + } +} + SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent) : RipesTab(toolbar, parent), ui(new Ui::SliderulesTab) { ui->setupUi(this); @@ -127,6 +152,10 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent) baseExtCheckBox->setText(isaInfo.baseExtension()); baseExtCheckBox->setChecked(true); baseExtCheckBox->setEnabled(false); + + connect(ProcessorHandler::get(), &ProcessorHandler::processorChanged, + m_isaModel.get(), + [=] { m_isaModel->changeISAInfo(*ProcessorHandler::currentISA()); }); } SliderulesTab::~SliderulesTab() { delete ui; } diff --git a/src/sliderulestab.h b/src/sliderulestab.h index 994dcdb9..f6b51d5c 100644 --- a/src/sliderulestab.h +++ b/src/sliderulestab.h @@ -53,19 +53,19 @@ class ISAInstructionsModel : public QAbstractItemModel { const QModelIndex &parent = {}) const override; virtual QModelIndex parent(const QModelIndex &index) const override; - // const ISAInfoBase *isaInfo() const; + const ISAInfoBase *isaInfo() const; // const ISAInfoBase *prevISAInfo() const; - // signals: - // void isaInfoChanged(const ISAInfoBase &isaInfo); +signals: + void isaInfoChanged(const ISAInfoBase &isaInfo); - // public slots: +public slots: // void changeISAFamily(ISAFamily isaFamily); // void changeISA(ISA isa); - // void changeISAInfo(const ISAInfoBase &isaInfo); + void changeISAInfo(const ISAInfoBase &isaInfo); protected: - // std::shared_ptr m_isaInfo = nullptr; + std::shared_ptr m_isaInfo = nullptr; // std::shared_ptr m_prevIsaInfo = nullptr; std::vector> m_instrItems;