summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-27 16:00:06 -0400
committerbd <bdunahu@operationnull.com>2025-04-27 16:00:06 -0400
commit07c618096daec422c42ee1a379200101d0d349cc (patch)
tree3b4ee4e3d946620ff1fddb4f218c3ef3f07a2ecd /gui
parent64efd868deec8921eac16b181f3a2e6d29f90b99 (diff)
Add files for new RegisterView class
Diffstat (limited to 'gui')
-rw-r--r--gui/gui.cc6
-rw-r--r--gui/registerview.cc53
-rw-r--r--gui/registerview.h48
-rw-r--r--gui/storageview.cc5
-rw-r--r--gui/storageview.h12
5 files changed, 116 insertions, 8 deletions
diff --git a/gui/gui.cc b/gui/gui.cc
index b4feda6..4d558d4 100644
--- a/gui/gui.cc
+++ b/gui/gui.cc
@@ -21,6 +21,7 @@
#include "dynamicwaysentry.h"
#include "messages.h"
#include "storageview.h"
+#include "registerview.h"
#include "util.h"
#include <QHeaderView>
#include <QPixmap>
@@ -355,14 +356,15 @@ void GUI::make_tabs(int num)
for (i = 0; i < num; ++i) {
if (i == 0) {
n = "Registers";
- e = new StorageView(0, this);
+ e = new RegisterView(GPR_NUM+V_NUM, V_R_LIMIT, this);
} else if (i == num - 1) {
n = "DRAM";
- e = new StorageView(MEM_LINES, this);
+ e = new StorageView(MEM_LINES, LINE_SIZE, this);
} else {
n = QString("L%1").arg(i);
e = new StorageView(
(1 << cache_size_mapper(this->curr_cache_levels - 1, i - 1)),
+ LINE_SIZE,
this);
}
diff --git a/gui/registerview.cc b/gui/registerview.cc
new file mode 100644
index 0000000..5320afa
--- /dev/null
+++ b/gui/registerview.cc
@@ -0,0 +1,53 @@
+// Simulator for the RISC-V[ECTOR] mini-ISA
+// Copyright (C) 2025 Siddarth Suresh
+// Copyright (C) 2025 bdunahu
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#include "registerview.h"
+#include "definitions.h"
+#include "util.h"
+#include <QAbstractTableModel>
+#include <QVector>
+
+QVariant RegisterView::data(const QModelIndex &i, int role) const
+{
+ Qt::Alignment a;
+
+ if (role == Qt::TextAlignmentRole) {
+ a = Qt::AlignRight | Qt::AlignVCenter;
+ return QVariant(static_cast<int>(a));
+ }
+ if (!i.isValid() || role != Qt::DisplayRole)
+ return QVariant();
+ return this->d[i.row()][i.column()];
+}
+
+QVariant RegisterView::headerData(int section, Qt::Orientation o, int role) const
+{
+ Qt::Alignment a;
+
+ if (role == Qt::TextAlignmentRole) {
+ a = Qt::AlignRight | Qt::AlignVCenter;
+ return QVariant(static_cast<int>(a));
+ }
+
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (o == Qt::Vertical) {
+ return format_toggled_value(section * 4, this->is_hex);
+ }
+ return QVariant();
+}
diff --git a/gui/registerview.h b/gui/registerview.h
new file mode 100644
index 0000000..e4cb940
--- /dev/null
+++ b/gui/registerview.h
@@ -0,0 +1,48 @@
+// Simulator for the RISC-V[ECTOR] mini-ISA
+// Copyright (C) 2025 Siddarth Suresh
+// Copyright (C) 2025 bdunahu
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#ifndef REGISTERVIEW_H
+#define REGISTERVIEW_H
+
+#include <QAbstractTableModel>
+#include "storageview.h"
+#include <QVector>
+
+// see https://doc.qt.io/qt-6/qabstracttablemodel.html
+class RegisterView : public StorageView
+{
+ Q_OBJECT
+ public:
+ using StorageView::StorageView;
+
+ /**
+ * Returns a properly formatted cell, including alignment.This function is
+ * specific to the implementation details of QAbstractTableModel.
+ */
+ QVariant
+ data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+
+ /**
+ * Adds custom formatting options for row and column headers.
+ */
+ QVariant headerData(
+ int section,
+ Qt::Orientation o,
+ int role = Qt::DisplayRole) const override;
+};
+
+#endif // REGISTERVIEW_H
diff --git a/gui/storageview.cc b/gui/storageview.cc
index 2f444a9..60391f9 100644
--- a/gui/storageview.cc
+++ b/gui/storageview.cc
@@ -21,10 +21,11 @@
#include <QAbstractTableModel>
#include <QVector>
-StorageView::StorageView(int rows, QObject *parent)
+StorageView::StorageView(int rows, int columns, QObject *parent)
: QAbstractTableModel(parent)
{
this->r = rows;
+ this->c = columns;
this->d.resize(rows);
for (auto &row : this->d)
row.resize(LINE_SIZE, 0);
@@ -32,7 +33,7 @@ StorageView::StorageView(int rows, QObject *parent)
int StorageView::rowCount(const QModelIndex &) const { return this->r; }
-int StorageView::columnCount(const QModelIndex &) const { return LINE_SIZE; }
+int StorageView::columnCount(const QModelIndex &) const { return this->c; }
QVariant StorageView::data(const QModelIndex &i, int role) const
{
diff --git a/gui/storageview.h b/gui/storageview.h
index 0518d8f..e8f3473 100644
--- a/gui/storageview.h
+++ b/gui/storageview.h
@@ -31,7 +31,7 @@ class StorageView : public QAbstractTableModel
* `rows' rows.
* @param the number of rows
*/
- StorageView(int rows, QObject *parent = nullptr);
+ StorageView(int rows, int columns, QObject *parent = nullptr);
/**
* Returns the number of rows in this table.
@@ -51,13 +51,13 @@ class StorageView : public QAbstractTableModel
* Returns a properly formatted cell, including alignment.This function is
* specific to the implementation details of QAbstractTableModel.
*/
- QVariant
+ virtual QVariant
data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
/**
* Adds custom formatting options for row and column headers.
*/
- QVariant headerData(
+ virtual QVariant headerData(
int section,
Qt::Orientation o,
int role = Qt::DisplayRole) const override;
@@ -75,12 +75,16 @@ class StorageView : public QAbstractTableModel
public slots:
void set_hex_display(bool hex);
- private:
+ protected:
/**
* The number of rows in this table.
*/
int r;
/**
+ * The number of columns in this table.
+ */
+ int c;
+ /**
* Whether or not the headers should be displayed in hex.
*/
bool is_hex = true;