diff options
author | bd <bdunaisky@umass.edu> | 2025-04-21 20:00:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-21 20:00:58 +0000 |
commit | d933a0405b7a7dff3cf05839ac99d120cafa4d75 (patch) | |
tree | 43238110a03ce678f1a68b0b4175ae023527b070 /gui/gui.h | |
parent | cdc9d9c6195cf51e2d1ff10ff4f29797d3e51691 (diff) | |
parent | 7cad6f05ebed25557fe6a31bfdf6290c72506868 (diff) |
Merge pull request #57 from bdunahu/bdunahu
Initialize all pipe objects at once, thread safety,
Diffstat (limited to 'gui/gui.h')
-rw-r--r-- | gui/gui.h | 281 |
1 files changed, 165 insertions, 116 deletions
@@ -1,131 +1,180 @@ +// 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 GUI_H #define GUI_H -#include <QMainWindow> -#include <QThread> -#include <QFileDialog> +#include "worker.h" #include <QFile> -#include <QTextStream> -#include <QTextEdit> -#include <QMessageBox> +#include <QFileDialog> #include <QInputDialog> -#include "worker.h" +#include <QLabel> +#include <QMainWindow> +#include <QTextEdit> +#include <QTextStream> +#include <QThread> +#include <functional> QT_BEGIN_NAMESPACE -namespace Ui { +namespace Ui +{ class GUI; } QT_END_NAMESPACE class GUI : public QMainWindow { - Q_OBJECT - -public: - GUI(QWidget *parent = nullptr); - ~GUI(); - bool is_pipelined = false; - bool is_cache_enabled = false; - int cache_levels = 0; - std::vector<int> ways; - std::vector<int> size; - -signals: - void sendRefreshDram(); - void sendRefreshCache(); - void sendRefreshRegisters(); - void sendRunSteps(int steps); - void sendRunStep(); - void sendLoadProgram(std::vector<signed int> program); - void sendConfigure(std::vector<int> ways, std::vector<int> size, bool is_pipelined, bool is_cache_enabled); - -private slots: - void onWorkerClockCycles(int value, int pc); - - void onWorkerFetchInfo(const std::vector<int> info); - - void onWorkerDecodeInfo(const std::vector<int> info); - - void onWorkerExecuteInfo(const std::vector<int> info); - - void onWorkerMemoryInfo(const std::vector<int> info); - - void onWorkerWriteBackInfo(const std::vector<int> info); - - void onWorkerShowDram(const std::vector<std::array<signed int, LINE_SIZE>> data); - - void onWorkerShowCache(const std::vector<std::array<signed int, LINE_SIZE>> data); - - void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data); - - void onWorkerFinished(); - - void on_upload_intructions_btn_clicked(); - - void on_upload_program_state_btn_clicked(); - - void on_Configure_Btn_clicked(); - - void on_set_levels_btn_clicked(); - - void on_set_cache_btn_clicked(); - - void on_enable_pipeline_checkbox_checkStateChanged(const Qt::CheckState &arg1); - - void on_enabl_cache_checkbox_checkStateChanged(const Qt::CheckState &arg1); - - void on_run_steps_btn_clicked(); - - void on_step_btn_clicked(); - - void on_save_program_state_btn_clicked(); - -private: - Ui::GUI *ui; - QThread workerThread; - Worker *worker; - const std::map<Mnemonic, QString> mnemonicNameMap = { - {Mnemonic::ADD, "ADD"}, - {Mnemonic::SUB, "SUB"}, - {Mnemonic::MUL, "MUL"}, - {Mnemonic::QUOT, "QUOT"}, - {Mnemonic::SFTR, "SFTR"}, - {Mnemonic::SFTL, "SFTL"}, - {Mnemonic::AND, "AND"}, - {Mnemonic::OR, "OR"}, - {Mnemonic::NOT, "NOT"}, - {Mnemonic::XOR, "XOR"}, - {Mnemonic::ADDV, "ADDV"}, - {Mnemonic::SUBV, "SUBV"}, - {Mnemonic::MULV, "MULV"}, - {Mnemonic::DIVV, "DIVV"}, - {Mnemonic::CMP, "CMP"}, - {Mnemonic::CEV, "CEV"}, - {Mnemonic::LOAD, "LOAD"}, - {Mnemonic::LOADV, "LOADV"}, - {Mnemonic::ADDI, "ADDI"}, - {Mnemonic::SUBI, "SUBI"}, - {Mnemonic::SFTRI, "SFTRI"}, - {Mnemonic::SFTLI, "SFTLI"}, - {Mnemonic::ANDI, "ANDI"}, - {Mnemonic::ORI, "ORI"}, - {Mnemonic::XORI, "XORI"}, - {Mnemonic::STORE, "STORE"}, - {Mnemonic::STOREV, "STOREV"}, - {Mnemonic::JMP, "JMP"}, - {Mnemonic::JRL, "JRL"}, - {Mnemonic::JAL, "JAL"}, - {Mnemonic::BEQ, "BEQ"}, - {Mnemonic::BGT, "BGT"}, - {Mnemonic::BUF, "BUF"}, - {Mnemonic::BOF, "BOF"}, - {Mnemonic::PUSH, "PUSH"}, - {Mnemonic::POP, "POP"}, - {Mnemonic::NOP, "NOP"}, - }; - QString mnemonicToString(Mnemonic mnemonic) { - auto it = mnemonicNameMap.find(mnemonic); - return (it != mnemonicNameMap.end()) ? it->second : "Unknown"; - } + Q_OBJECT + + public: + /** + * Constructor. + * @return A newly allocated GUI object. + */ + GUI(QWidget *parent = nullptr); + ~GUI(); + + /** + * Uses `func' to set the current status. + * @param a function which returns a string. + * @param a path to the desired avatar + */ + void set_status( + const std::function<std::string()> &func, + const QString &img = "idle.png"); + + signals: + void hex_toggled(bool is_hex); + void sendRunSteps(int steps); + void sendConfigure( + std::vector<unsigned int> ways, vector<int> program, bool is_pipelined); + + private slots: + void on_worker_refresh_gui(int value, int pc); + + void onWorkerFetchInfo(const std::vector<int> info); + + void onWorkerDecodeInfo(const std::vector<int> info); + + void onWorkerExecuteInfo(const std::vector<int> info); + + void onWorkerMemoryInfo(const std::vector<int> info); + + void onWorkerWriteBackInfo(const std::vector<int> info); + + void + onWorkerShowDram(const std::vector<std::array<signed int, LINE_SIZE>> data); + + void onWorkerShowCache( + const std::vector<std::array<signed int, LINE_SIZE>> data); + + void onWorkerShowRegisters(const std::array<int, GPR_NUM> &data); + + void onWorkerFinished(); + + void on_upload_intructions_btn_clicked(); + + void on_upload_program_state_btn_clicked(); + + void + on_enable_pipeline_checkbox_checkStateChanged(const Qt::CheckState &arg1); + + void + on_base_toggle_checkbox_checkStateChanged(const Qt::CheckState &state); + + void on_step_btn_clicked(); + + void on_save_program_state_btn_clicked(); + + /** + * Validates that the user has provided a valid program and cache. + * If so, `this->ready' is set and the user options are passed to the + * worker. + * If not, rudely complains. + */ + void on_config_clicked(); + + private: + Ui::GUI *ui; + + /** + * Indicates if the program has been initialized. + */ + bool ready; + + /** + * Whether or not numerical values are currently displaying in hex. + */ + bool is_hex = true; + + /** + * The message displayed on the status bar. + */ + QLabel *status_label; + + /** + * The robot image displayed on the status bar. + */ + QLabel *avatar; + + /** + * The currently loaded program. + */ + std::vector<signed int> p; + + /** + * If this stage is pipelined or not. + */ + bool is_pipelined = true; + + /** + * The possible step slider values. + */ + QVector<int> step_values = {1, 5, 20, 50, 250, 1000, 10000}; + + QThread workerThread; + + Worker *worker; + + const std::map<Mnemonic, QString> mnemonicNameMap = { + {Mnemonic::ADD, "ADD"}, {Mnemonic::SUB, "SUB"}, + {Mnemonic::MUL, "MUL"}, {Mnemonic::QUOT, "QUOT"}, + {Mnemonic::SFTR, "SFTR"}, {Mnemonic::SFTL, "SFTL"}, + {Mnemonic::AND, "AND"}, {Mnemonic::OR, "OR"}, + {Mnemonic::NOT, "NOT"}, {Mnemonic::XOR, "XOR"}, + {Mnemonic::ADDV, "ADDV"}, {Mnemonic::SUBV, "SUBV"}, + {Mnemonic::MULV, "MULV"}, {Mnemonic::DIVV, "DIVV"}, + {Mnemonic::CMP, "CMP"}, {Mnemonic::CEV, "CEV"}, + {Mnemonic::LOAD, "LOAD"}, {Mnemonic::LOADV, "LOADV"}, + {Mnemonic::ADDI, "ADDI"}, {Mnemonic::SUBI, "SUBI"}, + {Mnemonic::SFTRI, "SFTRI"}, {Mnemonic::SFTLI, "SFTLI"}, + {Mnemonic::ANDI, "ANDI"}, {Mnemonic::ORI, "ORI"}, + {Mnemonic::XORI, "XORI"}, {Mnemonic::STORE, "STORE"}, + {Mnemonic::STOREV, "STOREV"}, {Mnemonic::JMP, "JMP"}, + {Mnemonic::JRL, "JRL"}, {Mnemonic::JAL, "JAL"}, + {Mnemonic::BEQ, "BEQ"}, {Mnemonic::BGT, "BGT"}, + {Mnemonic::BUF, "BUF"}, {Mnemonic::BOF, "BOF"}, + {Mnemonic::PUSH, "PUSH"}, {Mnemonic::POP, "POP"}, + {Mnemonic::NOP, "NOP"}, + }; + QString mnemonicToString(Mnemonic mnemonic) + { + auto it = mnemonicNameMap.find(mnemonic); + return (it != mnemonicNameMap.end()) ? it->second : "Unknown"; + } }; #endif // GUI_H |