Skip to content

Commit

Permalink
Add main ISA extension selector
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Dec 28, 2023
1 parent 175a1e4 commit 27bba0b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/isa/isainfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class ISAInfoBase {
*/
virtual QString elfSupportsFlags(unsigned flags) const = 0;

/// The name of the base extension for this ISA
virtual QString baseExtension() const = 0;

/**
* @brief supportedExtensions/enabledExtensions
* An ISA may have a set of (optional) extensions which may be
Expand Down
2 changes: 2 additions & 0 deletions src/isa/mipsisainfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class MIPS_ISAInfoBase : public ISAInfoBase {
return QString();
}

QString baseExtension() const override { return "I"; }

const QStringList &supportedExtensions() const override {
return m_supportedExtensions;
}
Expand Down
2 changes: 2 additions & 0 deletions src/isa/rvisainfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ class RV_ISAInfoBase : public ISAInfoBase {
return QString();
}

QString baseExtension() const override { return "I"; }

const QStringList &supportedExtensions() const override {
return m_supportedExtensions;
}
Expand Down
35 changes: 25 additions & 10 deletions src/sliderulestab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@ SliderulesTab::SliderulesTab(QToolBar *toolbar, QWidget *parent)
}

connect(ProcessorHandler::get(), &ProcessorHandler::processorChanged, this,
&SliderulesTab::isaChanged);
&SliderulesTab::processorChanged);
connect(ui->isaSelector, &QComboBox::currentIndexChanged, this,
&SliderulesTab::updateRegWidthSelector);
connect(ui->regWidthSelector, &QComboBox::currentIndexChanged, this,
&SliderulesTab::isaSelectorChanged);
connect(ui->isaSelector, &QComboBox::currentIndexChanged, this,
&SliderulesTab::isaSelectorChanged);
connect(ui->mainExtensionSelector, &QComboBox::currentIndexChanged, this,
&SliderulesTab::isaSelectorChanged);

updateISASelector(true);
}

void SliderulesTab::isaSelectorChanged() {
ui->encodingTable->updateISA(ui->regWidthSelector->currentText());
auto isa = ui->encodingTable->model->isa;
auto exts = QStringList();
auto text = ui->mainExtensionSelector->currentText();
if (!text.isEmpty() && isa->supportsExtension(text))
exts = QStringList() << text;
ui->encodingTable->updateISA(ui->regWidthSelector->currentText(), exts);
}

void SliderulesTab::isaChanged() { updateISASelector(); }
void SliderulesTab::processorChanged() { updateISASelector(); }

void SliderulesTab::updateISASelector(bool forceUpdate) {
if (auto isaId = ProcessorHandler::currentISA()->isaID();
Expand All @@ -58,6 +65,13 @@ void SliderulesTab::updateRegWidthSelector() {
}
}

auto isa = ui->encodingTable->model->isa;
ui->mainExtensionSelector->clear();
ui->mainExtensionSelector->addItem(isa->baseExtension());
for (const auto &ext : isa->supportedExtensions()) {
ui->mainExtensionSelector->addItem(ext);
}

emit ui->regWidthSelector->currentIndexChanged(
static_cast<int>(m_selectedISA));
}
Expand All @@ -69,7 +83,7 @@ EncodingModel::EncodingModel(
const std::shared_ptr<const InstrVec> instructions,
const std::shared_ptr<const PseudoInstrVec> pseudoInstructions,
QObject *parent)
: QAbstractTableModel(parent), m_isa(isa), m_instructions(instructions),
: QAbstractTableModel(parent), isa(isa), m_instructions(instructions),
m_pseudoInstructions(pseudoInstructions) {
// Map instructions to their row index
size_t row = 0;
Expand Down Expand Up @@ -210,22 +224,23 @@ void EncodingView::processorChanged() {
updateView();
}

void EncodingView::updateISA(const QString &isaName) {
void EncodingView::updateISA(const QString &isaName,
const QStringList &extensions) {
for (const auto &isa : ISANames) {
if (isa.second == isaName) {
updateModel(ISAConstructors.at(isa.first)(QStringList()));
updateModel(ISAConstructors.at(isa.first)(extensions));
updateView();
return;
}
}
}

void EncodingView::updateModel(std::shared_ptr<const ISAInfoBase> isa) {
if (!m_model || !m_model->m_isa->eq(isa.get(), isa->enabledExtensions())) {
m_model = std::make_unique<EncodingModel>(
if (!model || !model->isa->eq(isa.get(), isa->enabledExtensions())) {
model = std::make_unique<EncodingModel>(
isa, std::make_shared<const InstrVec>(isa->instructions()),
std::make_shared<const PseudoInstrVec>(isa->pseudoInstructions()));
setModel(m_model.get());
setModel(model.get());
}
}

Expand All @@ -240,7 +255,7 @@ void EncodingView::updateView() {
horizontalHeader()->setSectionResizeMode(EncodingModel::DESCRIPTION,
QHeaderView::ResizeMode::Stretch);
clearSpans();
for (const auto &pair : m_model->m_rowInstrMap) {
for (const auto &pair : model->m_rowInstrMap) {
int row = static_cast<int>(pair.first);
const auto &instr = pair.second;
size_t fieldIdx = 0;
Expand Down
12 changes: 7 additions & 5 deletions src/sliderulestab.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ class EncodingModel : public QAbstractTableModel {
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const override;

const std::shared_ptr<const ISAInfoBase> isa;

protected:
friend class EncodingView;

size_t m_rows;

const std::shared_ptr<const ISAInfoBase> m_isa;
const std::shared_ptr<const InstrVec> m_instructions;
const std::shared_ptr<const PseudoInstrVec> m_pseudoInstructions;

Expand All @@ -66,16 +67,17 @@ class EncodingView : public QTableView {
public:
EncodingView(QWidget *parent = nullptr);

void updateISA(const QString &isaName);
void updateISA(const QString &isaName,
const QStringList &extensions = QStringList());

std::unique_ptr<EncodingModel> model;

public slots:
void processorChanged();

protected:
void updateModel(std::shared_ptr<const ISAInfoBase> isa);
void updateView();

std::unique_ptr<EncodingModel> m_model;
};

struct DecodingModel : public QAbstractTableModel {
Expand Down Expand Up @@ -109,7 +111,7 @@ class SliderulesTab : public RipesTab {
~SliderulesTab();

public slots:
void isaChanged();
void processorChanged();
void isaSelectorChanged();

private slots:
Expand Down
14 changes: 14 additions & 0 deletions src/sliderulestab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Main Extension</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mainExtensionSelector"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 27bba0b

Please sign in to comment.