diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/digitlabeldelegate.cc | 8 | ||||
-rw-r--r-- | gui/gui.cc | 44 | ||||
-rw-r--r-- | gui/gui.h | 2 | ||||
-rw-r--r-- | gui/registerview.cc | 24 | ||||
-rw-r--r-- | gui/registerview.h | 18 | ||||
-rw-r--r-- | gui/storageview.h | 2 | ||||
-rw-r--r-- | gui/worker.cc | 24 | ||||
-rw-r--r-- | gui/worker.h | 21 |
8 files changed, 81 insertions, 62 deletions
diff --git a/gui/digitlabeldelegate.cc b/gui/digitlabeldelegate.cc index 430946c..7a6a1d5 100644 --- a/gui/digitlabeldelegate.cc +++ b/gui/digitlabeldelegate.cc @@ -37,9 +37,13 @@ void DigitLabelDelegate::paint( QString t; QStyleOptionViewItem o; QStyle *s; + QVariant a; + bool e; - v = index.data(Qt::DisplayRole).toInt(); - t = format_toggled_value(v, this->is_hex); + a = index.data(Qt::DisplayRole); + v = a.toInt(); + e = a.isNull(); + t = format_toggled_value(v, this->is_hex, e); o = option; initStyleOption(&o, index); @@ -17,11 +17,11 @@ #include "gui.h" #include "./ui_gui.h" -#include "digitlabeldelegate.h" #include "cachewaysselector.h" +#include "digitlabeldelegate.h" #include "messages.h" -#include "storageview.h" #include "registerview.h" +#include "storageview.h" #include "util.h" #include <QHeaderView> #include <QPixmap> @@ -112,32 +112,6 @@ GUI::~GUI() delete ui; } -void displayArrayHTML(QTextEdit *textEdit, const std::array<int, GPR_NUM> &data) -{ - textEdit->setReadOnly(false); - QString tableText = "<table border='1' cellspacing='0' cellpadding='8' " - "style='border-collapse: collapse; width: 100%; " - "border: 2px solid black;'>"; - - tableText += "<tr>"; - int index = 0; - for (int value : data) { - tableText += QString("<td align='center' style='border: 2px solid " - "black; min-width: 60px; padding: 10px;'>" - "%1 <sup style='font-size: 10px; font-weight: " - "bold; color: black;'>%2</sup>" - "</td>") - .arg(QString::asprintf("%04X", value)) - .arg(index); - index++; - } - tableText += "</tr>"; - tableText += "</table>"; - - textEdit->setHtml(tableText); - textEdit->setReadOnly(true); -} - void GUI::on_worker_refresh_gui(int cycles, int pc) { ui->p_counter->set_value(pc); @@ -224,10 +198,13 @@ void GUI::onWorkerShowStorage(const QVector<QVector<int>> &data, int i) this->tab_boxes.at(i)->set_data(data); } -void GUI::onWorkerShowRegisters(const std::array<int, GPR_NUM> &data) +void GUI::onWorkerShowRegisters( + const QVector<signed int> &gprs, const QVector<QVector<signed int>> &vrs) { - ; - // displayArrayHTML(this->tab_boxes.at(0), data); + RegisterView *rv; + + rv = dynamic_cast<RegisterView *>(this->tab_boxes.at(0)); + rv->set_data(gprs, vrs); } void GUI::on_upload_intructions_btn_clicked() @@ -353,7 +330,7 @@ void GUI::make_tabs(int num) for (i = 0; i < num; ++i) { if (i == 0) { n = "Registers"; - e = new RegisterView(GPR_NUM+V_NUM, V_R_LIMIT, this); + e = new RegisterView(GPR_NUM + V_NUM, V_R_LIMIT, this); } else if (i == num - 1) { n = "DRAM"; e = new StorageView(MEM_LINES, LINE_SIZE, this); @@ -361,8 +338,7 @@ void GUI::make_tabs(int num) n = QString("L%1").arg(i); e = new StorageView( (1 << cache_size_mapper(this->curr_cache_levels - 1, i - 1)), - LINE_SIZE, - this); + LINE_SIZE, this); } t = new QTableView(ui->storage); @@ -72,7 +72,7 @@ class GUI : public QMainWindow void onWorkerShowStorage(const QVector<QVector<int>> &data, int i); - void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data); + void onWorkerShowRegisters(const QVector<signed int> &gprs, const QVector<QVector<signed int>> &vrs); void on_upload_intructions_btn_clicked(); diff --git a/gui/registerview.cc b/gui/registerview.cc index 5320afa..b1a1333 100644 --- a/gui/registerview.cc +++ b/gui/registerview.cc @@ -15,8 +15,8 @@ // 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 "pipe_spec.h" #include "registerview.h" -#include "definitions.h" #include "util.h" #include <QAbstractTableModel> #include <QVector> @@ -29,12 +29,22 @@ QVariant RegisterView::data(const QModelIndex &i, int role) const 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()]; + + if (i.row() < 16) { + if (i.column() < 1) + return this->gprs[i.row()]; + else + return QVariant(); + } + + return this->vrs[i.row() - GPR_NUM][i.column() - GPR_NUM]; } -QVariant RegisterView::headerData(int section, Qt::Orientation o, int role) const +QVariant +RegisterView::headerData(int section, Qt::Orientation o, int role) const { Qt::Alignment a; @@ -47,7 +57,13 @@ QVariant RegisterView::headerData(int section, Qt::Orientation o, int role) cons return QVariant(); if (o == Qt::Vertical) { - return format_toggled_value(section * 4, this->is_hex); + return format_toggled_value(section, this->is_hex); } return QVariant(); } + +void RegisterView::set_data(const QVector<int> &gprs, const QVector<QVector<int>> &vrs) +{ + this->gprs = gprs; + this->vrs = vrs; +} diff --git a/gui/registerview.h b/gui/registerview.h index e4cb940..cc5a1f8 100644 --- a/gui/registerview.h +++ b/gui/registerview.h @@ -18,8 +18,8 @@ #ifndef REGISTERVIEW_H #define REGISTERVIEW_H -#include <QAbstractTableModel> #include "storageview.h" +#include <QAbstractTableModel> #include <QVector> // see https://doc.qt.io/qt-6/qabstracttablemodel.html @@ -43,6 +43,22 @@ class RegisterView : public StorageView int section, Qt::Orientation o, int role = Qt::DisplayRole) const override; + + /** + * @param field to assign to `this->gprs'. + * @param field to assign to `this->vrs'. + */ + void set_data(const QVector<int> &gprs, const QVector<QVector<int>> &vrs); + + private: + /** + * The general purpose registers. + */ + QVector<int> gprs; + /** + * The vector registers. + */ + QVector<QVector<int>> vrs; }; #endif // REGISTERVIEW_H diff --git a/gui/storageview.h b/gui/storageview.h index e8f3473..a0f8dbb 100644 --- a/gui/storageview.h +++ b/gui/storageview.h @@ -88,6 +88,8 @@ class StorageView : public QAbstractTableModel * Whether or not the headers should be displayed in hex. */ bool is_hex = true; + + private: /** * The data this table displays. */ diff --git a/gui/worker.cc b/gui/worker.cc index dd7b637..a48888c 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -78,9 +78,16 @@ void Worker::runSteps(int steps) void Worker::update() { unsigned long i; + std::array<int, GPR_NUM> gprs; + std::array<std::array<signed int, V_R_LIMIT>, V_NUM> vrs; this->ct_mutex.lock(); - emit register_storage(this->ct->get_gprs()); + gprs = this->ct->get_gprs(); + vrs = this->ct->get_vrs(); + std::vector<std::array<signed int, V_R_LIMIT>> v(vrs.begin(), vrs.end()); + + emit register_storage( + QVector<int>(gprs.begin(), gprs.end()), this->data_to_QT(v)); for (i = 0; i < s.size(); ++i) emit storage(this->data_to_QT(this->s.at(i)->get_data()), i + 1); @@ -93,18 +100,3 @@ void Worker::update() emit wb_info(this->wb_stage->get_instr()); this->ct_mutex.unlock(); } - -QVector<QVector<int>> -Worker::data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data) -{ - QVector<QVector<int>> r; - QVector<int> tmp; - - r.reserve(static_cast<int>(data.size())); - - for (const auto &line : data) { - tmp = QVector<int>(line.begin(), line.end()); - r.append(tmp); - } - return r; -} diff --git a/gui/worker.h b/gui/worker.h index 5ffb6ef..2a362a4 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -64,9 +64,9 @@ class Worker : public QObject signals: void clock_cycles(int value, int pc); - void - storage(QVector<QVector<int>> data, int i); - void register_storage(const std::array<int, GPR_NUM> data); + void storage(QVector<QVector<int>> data, int i); + void register_storage( + QVector<signed int> gprs, QVector<QVector<signed int>> vrs); void if_info(const InstrDTO *); void id_info(const InstrDTO *); void ex_info(const InstrDTO *); @@ -81,8 +81,21 @@ class Worker : public QObject * @param the original data * @return a less universal version of the same thing */ + template <size_t N> QVector<QVector<int>> - data_to_QT(std::vector<std::array<signed int, LINE_SIZE>> data); + data_to_QT(const std::vector<std::array<signed int, N>> &data) + { + QVector<QVector<int>> r; + QVector<int> tmp; + + r.reserve(static_cast<int>(data.size())); + + for (const auto &line : data) { + tmp = QVector<int>(line.begin(), line.end()); + r.append(tmp); + } + return r; + } /** * Sets the GUI signals to update the storage, clock cycle, and stage * displays. |