From ad0557059bb83da52e1a5bd7ea608a29a4ab6346 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 27 Apr 2025 13:53:21 -0400 Subject: Use spinboxes to select cache levels --- gui/cachewaysselector.cc | 59 +++++++++++++++++++++++++ gui/cachewaysselector.h | 50 +++++++++++++++++++++ gui/dynamicwaysentry.cc | 99 ------------------------------------------ gui/dynamicwaysentry.h | 51 ---------------------- gui/gui.cc | 18 +++----- gui/gui.ui | 110 ++++++++--------------------------------------- gui/messages.h | 3 -- 7 files changed, 134 insertions(+), 256 deletions(-) create mode 100644 gui/cachewaysselector.cc create mode 100644 gui/cachewaysselector.h delete mode 100644 gui/dynamicwaysentry.cc delete mode 100644 gui/dynamicwaysentry.h diff --git a/gui/cachewaysselector.cc b/gui/cachewaysselector.cc new file mode 100644 index 0000000..f0314e5 --- /dev/null +++ b/gui/cachewaysselector.cc @@ -0,0 +1,59 @@ +// 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 . + +#include "cachewaysselector.h" +#include +#include +#include +#include + +CacheWaysSelector::CacheWaysSelector(QWidget *parent) : QWidget(parent) +{ + QVBoxLayout *v; + QHBoxLayout *l; + QSpinBox *sb; + QLabel *b; + int i; + + v = new QVBoxLayout(this); + + for (i = 1; i <= 6; ++i) { + l = new QHBoxLayout(this); + + b = new QLabel(QString("L%1 2^").arg(i), this); + + sb = new QSpinBox; + sb->setRange(-1, 4); + sb->setValue(-1); + + l->addWidget(b); + l->addWidget(sb); + + v->addLayout(l); + this->sbs.append(sb); + } + v->addStretch(); +} + +QList CacheWaysSelector::values() const +{ + QList r; + for (const QSpinBox *sb : this->sbs) { + r.append(sb->value()); + } + return r; +} diff --git a/gui/cachewaysselector.h b/gui/cachewaysselector.h new file mode 100644 index 0000000..4612b0c --- /dev/null +++ b/gui/cachewaysselector.h @@ -0,0 +1,50 @@ +// 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 . + +#ifndef CACHEWAYSSELECTOR_H +#define CACHEWAYSSELECTOR_H + +#include +#include + +class CacheWaysSelector : public QWidget +{ + Q_OBJECT + + public: + /** + * Constructor. + * This class provides a simple group of labeled spinboxs meant for + * selecting cache ways. + * @param The parent widget. + * @param a newly allocated CacheWaysSelector + */ + explicit CacheWaysSelector(QWidget *parent = nullptr); + + /** + * @return the values in the spinboxes. + */ + QList values() const; + + private: + /** + * A list of spinboxes. + */ + QList sbs; +}; + +#endif // CACHEWAYSSELECTOR_H diff --git a/gui/dynamicwaysentry.cc b/gui/dynamicwaysentry.cc deleted file mode 100644 index cbd5342..0000000 --- a/gui/dynamicwaysentry.cc +++ /dev/null @@ -1,99 +0,0 @@ -// 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 . - -#include "dynamicwaysentry.h" -#include -#include -#include -#include -#include -#include - -DynamicWaysEntry::DynamicWaysEntry(QWidget *parent) : QWidget(parent) -{ - this->l = new QVBoxLayout(this); - this->l->setAlignment(Qt::AlignTop); - this->l->setSpacing(6); - this->l->setContentsMargins(0, 0, 0, 0); - this->setLayout(l); - this->add_field(); -} - -QStringList DynamicWaysEntry::get_entries() const { return this->entries; } - -int DynamicWaysEntry::parse_valid_way(QString t) -{ - bool s; - int i; - i = t.toInt(&s); - return (s && i >= 0 && 5 > i) ? i : -1; -} - -// TODO if you enter something valid and then make it invalid, -// the next box still shows -void DynamicWaysEntry::on_number_enter(const QString &t) -{ - int i; - QLineEdit *sender_field; - - sender_field = qobject_cast(sender()); - i = fields.indexOf(sender_field); - entries[i] = t; - - if (i == this->fields.size() - 1 && !t.isEmpty() && - (this->parse_valid_way(t) >= 0) && fields.size() < 4) - add_field(); - - // TODO, unlink, don't trash everything after - if (t.isEmpty()) { - while (this->fields.size() > i + 1) { - remove_last_field(); - } - while (entries.size() > fields.size()) { - entries.removeLast(); - } - } -} - -void DynamicWaysEntry::add_field() -{ - QLineEdit *f; - - f = new QLineEdit(this); - f->setPlaceholderText("# ways (a power of 2)"); - - this->l->addWidget(f);; - this->fields.append(f); - this->entries.append(QString()); - connect( - f, &QLineEdit::textChanged, this, &DynamicWaysEntry::on_number_enter); -} - -void DynamicWaysEntry::remove_last_field() -{ - QLineEdit *f; - - if (this->fields.isEmpty()) - return; - - f = this->fields.takeLast(); - this->l->removeWidget(f); - f->deleteLater(); - - if (!this->entries.isEmpty()) - entries.removeLast(); -} diff --git a/gui/dynamicwaysentry.h b/gui/dynamicwaysentry.h deleted file mode 100644 index 26b8b3e..0000000 --- a/gui/dynamicwaysentry.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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 . - -#ifndef DYNAMICWAYSENTRY_H -#define DYNAMICWAYSENTRY_H - - -#include -#include -#include -#include -#include - -class DynamicWaysEntry : public QWidget -{ - public: - DynamicWaysEntry(QWidget *parent = nullptr); - QStringList get_entries() const; - /** - * Parses a string from this entry field, if it is valid. - * @param a string - * @param -1 if the string is not suitable as a way, an integer compatible - * with the cache constructor otherwise. - */ - int parse_valid_way(QString t); - private slots: - void on_number_enter(const QString &t); - - private: - QVBoxLayout *l; - QVector fields; - QStringList entries; - void add_field(); - void remove_last_field(); -}; - -#endif // DYNAMICWAYSENTRY_H diff --git a/gui/gui.cc b/gui/gui.cc index 28876ba..2581c4c 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -18,7 +18,7 @@ #include "gui.h" #include "./ui_gui.h" #include "digitlabeldelegate.h" -#include "dynamicwaysentry.h" +#include "cachewaysselector.h" #include "messages.h" #include "storageview.h" #include "util.h" @@ -304,21 +304,15 @@ void GUI::on_config_clicked() { std::vector ways; QStringList entries; - signed int i; - DynamicWaysEntry *dwe = ui->cache_way_selector; + CacheWaysSelector *cws = ui->cache_ways_selector; - for (const QString &s : dwe->get_entries()) { + for (int i : cws->values()) { - if (s.isEmpty()) + // invalid + if (i == -1) continue; - i = dwe->parse_valid_way(s); - if (i >= 0) { - ways.push_back((unsigned int)i); - } else { - this->set_status(get_bad_cache, "angry"); - return; - } + ways.push_back((unsigned int)i); } if (this->p.empty()) { diff --git a/gui/gui.ui b/gui/gui.ui index 67cca60..c20b3f6 100644 --- a/gui/gui.ui +++ b/gui/gui.ui @@ -6,7 +6,7 @@ 0 0 - 1499 + 1522 621 @@ -25,7 +25,7 @@ - 700 + 800 0 @@ -45,7 +45,7 @@ - + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop @@ -380,90 +380,18 @@ QLayout::SizeConstraint::SetMinimumSize - - - - Qt::Orientation::Vertical - - - - - - - QLayout::SizeConstraint::SetMinimumSize - - - - - - 16777215 - 16777215 - - - - C1 2^ - - - - - - - - 16777215 - 16777215 - - - - C2 2^ - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - C3 2^ - - - - - - - - 16777215 - 16777215 - - - - C4 2^ - - - - - - - - - - 0 - 0 - - - - + + + + Ways Selector (powers of 2) + + + + + + @@ -674,17 +602,17 @@ - - DynamicWaysEntry - QWidget -
dynamicwaysentry.h
- 1 -
DigitLabel QLabel
digitlabel.h
+ + CacheWaysSelector + QWidget +
cachewaysselector.h
+ 1 +
diff --git a/gui/messages.h b/gui/messages.h index 461c461..0c38751 100644 --- a/gui/messages.h +++ b/gui/messages.h @@ -35,8 +35,6 @@ const std::vector load_file = { const std::vector no_instructions = { "NO PROGRAM PROVIDED", "NOTHING TO DO, GIVING UP", "INSTRUCTIONS MISSING", "404 INSTRUCTIONS NOT FOUND"}; -const std::vector bad_cache = { - "WAYS CANNOT BE BELOW 0 OR ABOVE 4"}; const std::vector no_pipeline = { "SIMULATION READY: NO PIPE", "PIPE OFF, SIMULATION READY"}; const std::vector no_cache = { @@ -59,7 +57,6 @@ 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 -- cgit v1.2.3