Skip to content

Commit

Permalink
Get main extensions selector working
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Dec 28, 2023
1 parent 27bba0b commit 4ed8f1e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
36 changes: 29 additions & 7 deletions src/sliderulestab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<int>(pair.first);
const auto &instr = pair.second;
size_t fieldIdx = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/sliderulestab.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EncodingModel : public QAbstractTableModel {
int role = Qt::DisplayRole) const override;

const std::shared_ptr<const ISAInfoBase> isa;
std::map<size_t, const InstructionBase *> rowInstrMap;

protected:
friend class EncodingView;
Expand All @@ -58,8 +59,6 @@ class EncodingModel : public QAbstractTableModel {

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

std::map<size_t, const InstructionBase *> m_rowInstrMap;
};

class EncodingView : public QTableView {
Expand Down

0 comments on commit 4ed8f1e

Please sign in to comment.