Implement highlighting and view following of MRU register
MODIFY
external/VSRTL
external/VSRTL
-Subproject commit 2aaeef1faa092eff445e610a350186c339977d65
+Subproject commit f9b5156807fd8c7191652898878d3c819356aad8

MODIFY
src/isainfo.h
src/isainfo.h
@@ -10,6 +10,7 @@ class ISAInfoBase {
public:
virtual QString name() const = 0;
+ virtual unsigned regCnt() const = 0;
virtual QString regName(unsigned i) const = 0;
virtual QString regAlias(unsigned i) const = 0;
virtual QString regInfo(unsigned i) const = 0;
@@ -89,6 +90,7 @@ public:
QString name() const { return "RV32IM"; }
+ unsigned int regCnt() const override { return 32; }
QString regName(unsigned i) const { return RVRegNames.at(i); }
QString regAlias(unsigned i) const { return RVRegAliases.at(i); }
QString regInfo(unsigned i) const { return RVRegDescs.at(i); }

MODIFY
src/registermodel.cpp
src/registermodel.cpp
@@ -7,18 +7,37 @@ using namespace vsrtl;
RegisterModel::RegisterModel(ProcessorHandler& handler, QObject* parent)
: QAbstractTableModel(parent), m_handler(handler) {}
+std::vector<uint32_t> RegisterModel::gatherRegisterValues() {
+ std::vector<uint32_t> vals;
+ for (int i = 0; i < rowCount(); i++) {
+ vals.push_back(valueData(i).toUInt());
+ }
+ return vals;
+}
+
int RegisterModel::columnCount(const QModelIndex&) const {
return NColumns;
}
int RegisterModel::rowCount(const QModelIndex&) const {
- return 32;
+ return m_handler.getProcessor()->implementsISA().regCnt();
}
void RegisterModel::processorWasClocked() {
// Reload model
beginResetModel();
endResetModel();
+ const auto newRegValues = gatherRegisterValues();
+ if (m_regValues.size() != 0) {
+ for (unsigned i = 0; i < newRegValues.size(); i++) {
+ if (m_regValues[i] != newRegValues[i]) {
+ m_mostRecentlyModifiedReg = i;
+ emit registerChanged(i);
+ break;
+ }
+ }
+ }
+ m_regValues = newRegValues;
}
bool RegisterModel::setData(const QModelIndex& index, const QVariant& value, int role) {
@@ -53,6 +72,8 @@ QVariant RegisterModel::data(const QModelIndex& index, int role) const {
const unsigned idx = index.row();
if (role == Qt::ToolTipRole) {
return tooltipData(idx);
+ } else if (role == Qt::BackgroundRole && index.row() == m_mostRecentlyModifiedReg) {
+ return QBrush(QColor("#FDB515"));
}
switch (index.column()) {

MODIFY
src/registermodel.h
src/registermodel.h
@@ -31,7 +31,16 @@ public:
public slots:
void processorWasClocked();
+signals:
+ /**
+ * @brief registerChanged
+ * Emitted whenever the value of register @param i changes
+ */
+ void registerChanged(unsigned i) const;
+
private:
+ std::vector<uint32_t> gatherRegisterValues();
+
QVariant nameData(unsigned idx) const;
QVariant aliasData(unsigned idx) const;
QVariant valueData(unsigned idx) const;
@@ -39,4 +48,7 @@ private:
ProcessorHandler& m_handler;
Radix m_radix = Radix::Unsigned;
+
+ int m_mostRecentlyModifiedReg = -1;
+ std::vector<uint32_t> m_regValues;
};

MODIFY
src/registerwidget.cpp
src/registerwidget.cpp
#include "registerwidget.h"
#include "ui_registerwidget.h"
+#include <QScrollBar>
+
RegisterWidget::RegisterWidget(QWidget* parent) : QWidget(parent), m_ui(new Ui::RegisterWidget) {
m_ui->setupUi(this);
setupRadixComboBox();
@@ -43,6 +45,7 @@ void RegisterWidget::updateModel() {
m_registerModel = new RegisterModel(*m_handler, this);
m_ui->registerView->setModel(m_registerModel);
updateRadixComboBoxIndex();
+ connect(m_registerModel, &RegisterModel::registerChanged, this, &RegisterWidget::setRegisterviewCenterIndex);
m_ui->registerView->horizontalHeader()->setSectionResizeMode(RegisterModel::Name, QHeaderView::ResizeToContents);
m_ui->registerView->horizontalHeader()->setSectionResizeMode(RegisterModel::Alias, QHeaderView::ResizeToContents);
@@ -56,3 +59,19 @@ void RegisterWidget::updateModel() {
void RegisterWidget::updateView() {
m_registerModel->processorWasClocked();
}
+
+void RegisterWidget::setRegisterviewCenterIndex(unsigned index) {
+ const auto view = m_ui->registerView;
+ const auto rect = view->rect();
+ int indexTop = view->indexAt(rect.topLeft()).row();
+ int indexBot = view->indexAt(rect.bottomLeft()).row();
+ indexBot = indexBot < 0 ? m_registerModel->rowCount() : indexBot;
+
+ const int nItemsVisible = indexBot - indexTop;
+
+ // move scrollbar if if is not visible
+ if (index <= indexTop || index >= indexBot) {
+ auto scrollbar = view->verticalScrollBar();
+ scrollbar->setValue(index - nItemsVisible / 2);
+ }
+}

MODIFY
src/registerwidget.h
src/registerwidget.h
@@ -24,6 +24,7 @@ public:
public slots:
void updateView();
+ void setRegisterviewCenterIndex(unsigned index);
private:
void setupRadixComboBox();

Implement highlighting and view following of MRU register