diff options
author | bd <bdunahu@operationnull.com> | 2025-04-19 03:37:43 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-19 03:37:43 -0400 |
commit | bb3d940fb4ce0dd3efc56b934a7b4ea8ffab4b13 (patch) | |
tree | 857e9ee14530e4492c6e6f612bce227a3197fd48 | |
parent | 327ba8b631436cf21866c05c6c7cae239fe54a5c (diff) |
GUI validate program
-rw-r--r-- | gui/dynamicwaysentry.h | 6 | ||||
-rw-r--r-- | gui/gui.cc | 54 | ||||
-rw-r--r-- | gui/gui.h | 27 | ||||
-rw-r--r-- | gui/messages.h | 19 | ||||
-rw-r--r-- | gui/worker.cc | 27 | ||||
-rw-r--r-- | gui/worker.h | 1 | ||||
-rw-r--r-- | inc/pipe_spec.h | 10 |
7 files changed, 132 insertions, 12 deletions
diff --git a/gui/dynamicwaysentry.h b/gui/dynamicwaysentry.h index be42696..de001ee 100644 --- a/gui/dynamicwaysentry.h +++ b/gui/dynamicwaysentry.h @@ -1,3 +1,7 @@ +#ifndef DYNAMICWAYSENTRY_H +#define DYNAMICWAYSENTRY_H + + #include <QLineEdit> #include <QStringList> #include <QVBoxLayout> @@ -26,3 +30,5 @@ class DynamicWaysEntry : public QWidget void add_field(); void remove_last_field(); }; + +#endif // DYNAMICWAYSENTRY_H @@ -1,5 +1,6 @@ #include "gui.h" #include "./ui_gui.h" +#include "dynamicwaysentry.h" #include "messages.h" GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) @@ -43,6 +44,11 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) connect( worker, &Worker::register_storage, this, &GUI::onWorkerShowRegisters); + // Configure pipeline + connect( + this, &GUI::sendConfigure, worker, &Worker::configure, + Qt::QueuedConnection); + // // Refresh DRAM from worker thread // connect(this, &GUI::sendRefreshDram, worker, &Worker::refreshDram, // Qt::QueuedConnection); @@ -56,7 +62,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent), ui(new Ui::GUI) this, &GUI::sendRefreshRegisters, worker, &Worker::refreshRegisters, Qt::QueuedConnection); - // Advance controller by somes steps + // Advance controller by some steps connect( this, &GUI::sendRunSteps, worker, &Worker::runSteps, Qt::QueuedConnection); @@ -269,7 +275,7 @@ void GUI::on_upload_intructions_btn_clicked() } if (this->p.empty()) - this->set_status(get_no_instructions); + this->set_status(get_no_instructions); else this->set_status(get_load_file); @@ -297,6 +303,8 @@ void GUI::on_enable_pipeline_checkbox_checkStateChanged( void GUI::on_step_btn_clicked() { qDebug() << "Run step button clicked."; + if (!this->ready) + return this->on_config_clicked(); int steps = step_values[ui->step_slider->value()]; emit sendRunSteps(steps); } @@ -307,7 +315,47 @@ void GUI::on_save_program_state_btn_clicked() qDebug() << "save program state button is clicked."; } +void GUI::on_config_clicked() +{ + std::vector<unsigned int> ways; + QStringList entries; + signed int i; + DynamicWaysEntry *dwe = ui->cache_way_selector; + + for (const QString &s : dwe->get_entries()) { + + if (s.isEmpty()) + continue; + + i = dwe->parse_valid_way(s); + if (i != -1) { + ways.push_back((unsigned int)i); + } else { + this->set_status(get_bad_cache); + return; + } + } + + if (this->p.empty()) { + this->set_status(get_no_instructions); + return; + } + + this->ready = true; + + // say something snarky + if (!is_pipelined) + this->set_status(get_no_pipeline); + else if (ways.size() == 0) + this->set_status(get_no_cache); + else + this->set_status(get_initialize); + + emit sendConfigure(ways, is_pipelined); +} + void GUI::set_status(const std::function<std::string()> &func) { - this->status_label->setText("COMPUTER SAYS: \"" + QString::fromStdString(func()) + "\""); + this->status_label->setText( + "COMPUTER SAYS: \"" + QString::fromStdString(func()) + "\""); } @@ -5,8 +5,8 @@ #include <QFile> #include <QFileDialog> #include <QInputDialog> +#include <QLabel> #include <QMainWindow> -#include <QMessageBox> #include <QTextEdit> #include <QTextStream> #include <QThread> @@ -42,6 +42,7 @@ class GUI : public QMainWindow void sendRefreshCache(); void sendRefreshRegisters(); void sendRunSteps(int steps); + void sendConfigure(std::vector<unsigned int> ways, bool is_pipelined); private slots: void onWorkerClockCycles(int value, int pc); @@ -77,10 +78,23 @@ class GUI : public QMainWindow 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; + + /** * The message displayed on the status bar. */ QLabel *status_label; @@ -91,21 +105,19 @@ class GUI : public QMainWindow std::vector<signed int> p; /** - * The current cache configurations. + * If this stage is pipelined or not. */ - std::vector<unsigned int> c; + bool is_pipelined = false; /** - * If this stage is pipelined or not. + * The possible step slider values. */ - bool is_pipelined = false; + QVector<int> step_values = {1, 5, 20, 50, 250, 1000, 10000}; QThread workerThread; Worker *worker; - QVector<int> step_values = {1, 5, 20, 50, 250, 1000, 10000}; - const std::map<Mnemonic, QString> mnemonicNameMap = { {Mnemonic::ADD, "ADD"}, {Mnemonic::SUB, "SUB"}, {Mnemonic::MUL, "MUL"}, {Mnemonic::QUOT, "QUOT"}, @@ -132,6 +144,5 @@ class GUI : public QMainWindow auto it = mnemonicNameMap.find(mnemonic); return (it != mnemonicNameMap.end()) ? it->second : "Unknown"; } - }; #endif // GUI_H diff --git a/gui/messages.h b/gui/messages.h index 2af8e6b..c2a86b9 100644 --- a/gui/messages.h +++ b/gui/messages.h @@ -13,8 +13,17 @@ const std::vector<std::string> waiting = { const std::vector<std::string> load_file = { "FILE LOADED", "FINISHED READING DATA. EAGERLY WAITING"}; const std::vector<std::string> no_instructions = { - "NO PROGRAM PROVIDED", "RISC V[ECTOR]: INSTRUCTIONS NOT INCLUDED", + "NO PROGRAM PROVIDED", "INSTRUCTIONS NOT INCLUDED", "NOTHING TO DO, GIVING UP"}; +const std::vector<std::string> bad_cache = { + "INVALID NUMBER OF WAYS", "WAYS CANNOT BE BELOW 0 OR ABOVE 5"}; +const std::vector<std::string> no_pipeline = { + "PIPELINE--HUMANS PROBABLY WORKED HARD ON THAT", + "I WOULD PREFER YOU LEAVE THE PIPE ON", "SLOW MODE ENABLED", + "SIMULATION READY"}; +const std::vector<std::string> no_cache = { + "NO CACHE HAS NO WAY TO GO", "SLOW MODE ENABLED", "SIMULATION READY"}; +const std::vector<std::string> initialize = {"SIMULATION READY"}; /** * @return an unsolicited waiting message @@ -30,5 +39,13 @@ std::string get_load_file() { return RANDOM_MESSAGE(load_file); } * @return a friendly reminder that the simulation is not configured yet */ std::string get_no_instructions() { return RANDOM_MESSAGE(no_instructions); } +std::string get_bad_cache() { return RANDOM_MESSAGE(bad_cache); } + +/** + * @return unsolicited complaints for successful initialization + */ +std::string get_no_pipeline() { return RANDOM_MESSAGE(no_pipeline); } +std::string get_no_cache() { return RANDOM_MESSAGE(no_cache); } +std::string get_initialize() { return RANDOM_MESSAGE(initialize); } #endif // MESSAGES_H diff --git a/gui/worker.cc b/gui/worker.cc index 1d87fd3..558552f 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -10,6 +10,33 @@ Worker::~Worker() delete this->ct; } +void Worker::configure(std::vector<unsigned int> ways, bool is_pipelined) +{ + // this->d = new Dram(DRAM_DELAY); + // setWays(ways); + // setSize(size); + // this->cache_enabled = is_cache_enabled; + // if (!is_cache_enabled || ways.size() == 0) { + // this->ct = new Controller(wb_stage, this->d, is_pipelined); + // } else { + // // 0th index cache has largest delay + // for (int i = 0; i < ways.size(); i++) { + // if (i == 0) { + // Cache *cache = + // new Cache(this->d, size[i], ways[i], ways.size()); + // this->c.push_back(cache); + // } else { + // Cache *cache = new Cache( + // this->c[i - 1], size[i], ways[i], ways.size() - i); + // this->c.push_back(cache); + // } + // } + // this->ct = + // new Controller(wb_stage, this->c.at(ways.size() - 1), is_pipelined); + // } + emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); +} + void Worker::refreshDram() { qDebug() << "Refreshing Dram"; diff --git a/gui/worker.h b/gui/worker.h index 53e4851..df7d9cc 100644 --- a/gui/worker.h +++ b/gui/worker.h @@ -31,6 +31,7 @@ public slots: void refreshCache(); void refreshRegisters(); void runSteps(int steps); + void configure(std::vector<unsigned int> ways, bool is_pipelined); signals: void clock_cycles(int value, int pc); diff --git a/inc/pipe_spec.h b/inc/pipe_spec.h index d211b72..4f5bc46 100644 --- a/inc/pipe_spec.h +++ b/inc/pipe_spec.h @@ -49,6 +49,16 @@ #define MAX_INT 2147483647 /** + * The delay on DRAM objects. + */ +#define DRAM_DELAY 10 + +/** + * The (base) on cache objects. + */ +#define CACHE_DELAY 1 + +/** * Return the N least-significant bits from integer K using a bit mask * @param the integer to be parsed * @param the number of bits to be parsed |