Update cache tab layout
MODIFY
RISC-V-sim.pro
RISC-V-sim.pro
@@ -11,7 +11,8 @@ SOURCES += src/main.cpp \
src/programfiletab.cpp \
src/processortab.cpp \
src/memorytab.cpp \
- src/cachetab.cpp
+ src/cachetab.cpp \
+ src/cachesetupwidget.cpp
HEADERS += \
src/parser.h \
@@ -25,7 +26,8 @@ HEADERS += \
src/programfiletab.h \
src/processortab.h \
src/memorytab.h \
- src/cachetab.h
+ src/cachetab.h \
+ src/cachesetupwidget.h
FORMS += \
src/mainwindow.ui \
@@ -33,4 +35,5 @@ FORMS += \
src/programfiletab.ui \
src/processortab.ui \
src/memorytab.ui \
- src/cachetab.ui
+ src/cachetab.ui \
+ src/cachesetupwidget.ui

ADD
src/cachesetupwidget.cpp
+#include "cachesetupwidget.h"
+#include "ui_cachesetupwidget.h"
+
+CacheSetupWidget::CacheSetupWidget(QWidget *parent)
+ : QWidget(parent), m_ui(new Ui::CacheSetupWidget) {
+ m_ui->setupUi(this);
+}
+
+CacheSetupWidget::~CacheSetupWidget() { delete m_ui; }
+
+void CacheSetupWidget::on_groupbox_toggled(bool state) {
+ emit groupBoxToggled(state);
+}
+
+void CacheSetupWidget::enable(bool state) {
+ m_ui->groupbox->setEnabled(state);
+ m_ui->groupbox->setChecked(false);
+}
+
+void CacheSetupWidget::setName(QString name) { m_ui->groupbox->setTitle(name); }

ADD
src/cachesetupwidget.h
+#ifndef CACHESETUPWIDGET_H
+#define CACHESETUPWIDGET_H
+
+#include <QWidget>
+
+namespace Ui {
+class CacheSetupWidget;
+}
+
+class CacheSetupWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ explicit CacheSetupWidget(QWidget *parent = 0);
+ ~CacheSetupWidget();
+
+ void setName(QString name);
+
+signals:
+ void groupBoxToggled(bool state);
+
+public slots:
+ void enable(bool state);
+
+private slots:
+ void on_groupbox_toggled(bool arg1);
+
+private:
+ Ui::CacheSetupWidget *m_ui;
+};
+
+#endif // CACHESETUPWIDGET_H

ADD
src/cachesetupwidget.ui
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CacheSetupWidget</class>
+ <widget class="QWidget" name="CacheSetupWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>260</width>
+ <height>394</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>260</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="groupbox">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="title">
+ <string>L# Cache</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="3" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Cache type</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="comboBox">
+ <item>
+ <property name="text">
+ <string>Direct mapped</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Set associative</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Fully associative</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Cache delay (cycles)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Cache size</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="spinBox">
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="comboBox_2">
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <item>
+ <property name="text">
+ <string>32 Bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>64 Bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>128 Bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>256 Bytes</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>512 Bytes</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="4" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Set size</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1">
+ <widget class="QComboBox" name="comboBox_3"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QStackedWidget" name="stackedWidget">
+ <widget class="QWidget" name="page_3"/>
+ <widget class="QWidget" name="page_4"/>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

MODIFY
src/cachetab.cpp
src/cachetab.cpp
#include "cachetab.h"
+#include "cachesetupwidget.h"
#include "ui_cachetab.h"
-#include "QLineEdit"
+#include "QGroupBox"
CacheTab::CacheTab(QWidget *parent) : QWidget(parent), m_ui(new Ui::CacheTab) {
m_ui->setupUi(this);
@@ -11,93 +12,42 @@ CacheTab::CacheTab(QWidget *parent) : QWidget(parent), m_ui(new Ui::CacheTab) {
}
void CacheTab::setupWidgets() {
- // set cache size combobox values
- QStringList cacheSizes = QStringList() << "32 Bytes"
- << "64 Bytes"
- << "128 Bytes"
- << "256 Bytes";
- m_ui->l1size->addItems(cacheSizes);
- m_ui->l2size->addItems(cacheSizes);
- m_ui->l3size->addItems(cacheSizes);
-
- m_ui->l1delay->setSuffix((" cycles"));
- m_ui->l2delay->setSuffix((" cycles"));
- m_ui->l3delay->setSuffix((" cycles"));
+ m_ui->l1->enable(true);
+ m_ui->l1->setName("L1 cache");
+ m_ui->l2->setName("L2 cache");
+ m_ui->l3->setName("L3 cache");
}
void CacheTab::connectWidgets() { // Connect cache selection checkboxes
- connect(m_ui->l1checkbox, &QCheckBox::toggled, this,
+ connect(m_ui->l1, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
- connect(m_ui->l2checkbox, &QCheckBox::toggled, this,
+ connect(m_ui->l2, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
- connect(m_ui->l3checkbox, &QCheckBox::toggled, this,
+ connect(m_ui->l3, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
}
-void CacheTab::disableCacheWidget(int cacheNumber) {
- // Disables all widgets associated with a cache number
- auto disableFct = [=](QCheckBox *checkbox, QComboBox *combobox,
- QSpinBox *lineedit) {
- checkbox->setEnabled(false);
- checkbox->setChecked(false);
- combobox->setEnabled(false);
- lineedit->setEnabled(false);
- };
- switch (cacheNumber) {
- case 1:
- disableFct(m_ui->l1checkbox, m_ui->l1size, m_ui->l1delay);
- break;
- case 2:
- disableFct(m_ui->l2checkbox, m_ui->l2size, m_ui->l2delay);
- break;
- case 3:
- disableFct(m_ui->l3checkbox, m_ui->l3size, m_ui->l3delay);
- break;
- }
-}
-
-void CacheTab::enableCacheWidget(int cacheNumber) {
- // Enables all widgets associated with a cache number
- auto enableFct = [=](QCheckBox *checkbox, QComboBox *combobox,
- QSpinBox *lineedit) {
- checkbox->setEnabled(true);
- combobox->setEnabled(true);
- lineedit->setEnabled(true);
- };
- switch (cacheNumber) {
- case 1:
- enableFct(m_ui->l1checkbox, m_ui->l1size, m_ui->l1delay);
- break;
- case 2:
- enableFct(m_ui->l2checkbox, m_ui->l2size, m_ui->l2delay);
- break;
- case 3:
- enableFct(m_ui->l3checkbox, m_ui->l3size, m_ui->l3delay);
- break;
- }
-}
-
void CacheTab::cacheCountChanged(bool state) {
// Set cache selection checkboxes based on
// CHANGE ALL THIS STUFF TO JUST CONNECT The checkbox::changed signal to
// enable/disable slot of the other widgets.
// and then only do check/uncheck in the below checks
- auto checkbox = dynamic_cast<QCheckBox *>(sender());
- if (checkbox == m_ui->l1checkbox) {
+ auto cachewidget = dynamic_cast<CacheSetupWidget *>(sender());
+ if (cachewidget == m_ui->l1) {
if (state) {
- enableCacheWidget(2);
+ m_ui->l2->enable(true);
} else {
- disableCacheWidget(2);
- disableCacheWidget(3);
+ m_ui->l2->enable(false);
+ m_ui->l3->enable(false);
}
- } else if (checkbox == m_ui->l2checkbox) {
+ } else if (cachewidget == m_ui->l2) {
if (state) {
- enableCacheWidget(3);
+ m_ui->l3->enable(true);
} else {
- disableCacheWidget(3);
+ m_ui->l3->enable(false);
}
- } else if (checkbox == m_ui->l3checkbox) {
+ } else if (cachewidget == m_ui->l3) {
// nothing
}
}

MODIFY
src/cachetab.h
src/cachetab.h
@@ -19,8 +19,6 @@ private:
void connectWidgets();
- void disableCacheWidget(int cacheNumber);
- void enableCacheWidget(int cacheNumber);
void setupWidgets();
signals:

MODIFY
src/cachetab.ui
src/cachetab.ui
</property>
</widget>
</item>
- </layout>
- </item>
- <item row="1" column="0">
- <layout class="QGridLayout" name="gridLayout_3">
- <item row="0" column="1">
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="CacheSetupWidget" name="l1" native="true">
+ <property name="minimumSize">
<size>
- <width>40</width>
- <height>20</height>
+ <width>0</width>
+ <height>0</height>
</size>
</property>
- </spacer>
- </item>
- <item row="0" column="2">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Cache size</string>
- </property>
- </widget>
- </item>
- <item row="1" column="3">
- <widget class="QComboBox" name="l2size">
- <property name="enabled">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QCheckBox" name="l3checkbox">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>L3</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QCheckBox" name="l2checkbox">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="text">
- <string>L2</string>
- </property>
- </widget>
- </item>
- <item row="0" column="3">
- <widget class="QComboBox" name="l1size"/>
- </item>
- <item row="2" column="5">
- <widget class="QLabel" name="label_4">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>Delay (cycles)</string>
- </property>
- </widget>
- </item>
- <item row="0" column="5">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Delay (cycles)</string>
- </property>
- </widget>
- </item>
- <item row="0" column="6">
- <widget class="QSpinBox" name="l1delay">
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
</widget>
</item>
- <item row="1" column="5">
- <widget class="QLabel" name="label_3">
- <property name="enabled">
- <bool>true</bool>
- </property>
- <property name="text">
- <string>Delay (cycles)</string>
- </property>
- </widget>
- </item>
- <item row="1" column="6">
- <widget class="QSpinBox" name="l2delay">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="2" column="6">
- <widget class="QSpinBox" name="l3delay">
- <property name="enabled">
- <bool>false</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QCheckBox" name="l1checkbox">
- <property name="text">
- <string>L1</string>
- </property>
- </widget>
- </item>
- <item row="2" column="3">
- <widget class="QComboBox" name="l3size">
- <property name="enabled">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item row="2" column="2">
- <widget class="QLabel" name="label_7">
- <property name="text">
- <string>Cache size</string>
- </property>
- </widget>
+ <item>
+ <widget class="CacheSetupWidget" name="l2" native="true"/>
</item>
- <item row="1" column="2">
- <widget class="QLabel" name="label_6">
- <property name="text">
- <string>Cache size</string>
- </property>
- </widget>
+ <item>
+ <widget class="CacheSetupWidget" name="l3" native="true"/>
</item>
- <item row="0" column="4">
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
+ </layout>
</item>
</layout>
</item>
- <item row="2" column="0">
+ <item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>CacheSetupWidget</class>
+ <extends>QWidget</extends>
+ <header>cachesetupwidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
<resources/>
<connections/>
</ui>

Update cache tab layout