Skip to content

Commit

Permalink
Add first signal and slot for ISAInstructionsModel
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Feb 27, 2024
1 parent acb054b commit 342722e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
41 changes: 35 additions & 6 deletions src/sliderulestab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstructionItem>(*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; }
Expand Down Expand Up @@ -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<InstructionItem>(*instr));
}
endResetModel();
emit isaInfoChanged(*m_isaInfo);
}
}

SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
: RipesTab(toolbar, parent), ui(new Ui::SliderulesTab) {
ui->setupUi(this);
Expand Down Expand Up @@ -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; }
Expand Down
12 changes: 6 additions & 6 deletions src/sliderulestab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const ISAInfoBase> m_isaInfo = nullptr;
std::shared_ptr<const ISAInfoBase> m_isaInfo = nullptr;
// std::shared_ptr<const ISAInfoBase> m_prevIsaInfo = nullptr;

std::vector<std::unique_ptr<InstructionItem>> m_instrItems;
Expand Down

0 comments on commit 342722e

Please sign in to comment.