Create Cachetab <-> RunnerCache connection
MODIFY
src/cachesetupwidget.cpp
src/cachesetupwidget.cpp
#include "cachesetupwidget.h"
+#include "cachebase.h"
#include "ui_cachesetupwidget.h"
+#include "defines.h"
+
CacheSetupWidget::CacheSetupWidget(QWidget *parent)
: QWidget(parent), m_ui(new Ui::CacheSetupWidget) {
m_ui->setupUi(this);
+
+ // set combobox entries
+ m_ui->cachesize->setInsertPolicy(QComboBox::InsertAtBottom);
+ for (const auto &entry : cacheSizes) {
+ m_ui->cachesize->addItem(entry.second);
+ }
+ m_ui->cachetype->setInsertPolicy(QComboBox::InsertAtBottom);
+ for (const auto &entry : cacheTypes) {
+ m_ui->cachetype->addItem(entry.first);
+ }
+
+ // Connect widget to its m_cachePtr
+ // Connect widget
+ connect(m_ui->cachesize, &QComboBox::currentTextChanged, this,
+ &CacheSetupWidget::cacheSizeChanged);
+ connect(m_ui->cachedelay, QOverload<int>::of(&QSpinBox::valueChanged), this,
+ &CacheSetupWidget::cacheDelayChanged);
}
CacheSetupWidget::~CacheSetupWidget() { delete m_ui; }
+void CacheSetupWidget::cacheSizeChanged(const QString &index) {
+ if (m_cachePtr != nullptr) {
+ // bad way!
+ auto size = index.split(" ")[0].toInt();
+ m_cachePtr->resize(size);
+ }
+}
+
+void CacheSetupWidget::cacheDelayChanged(int delay) {
+ if (m_cachePtr != nullptr) {
+ m_cachePtr->setSearchPenalty(delay);
+ }
+}
+
void CacheSetupWidget::on_groupbox_toggled(bool state) {
emit groupBoxToggled(state);
}

MODIFY
src/cachesetupwidget.h
src/cachesetupwidget.h
#include <QWidget>
+class CacheBase;
+
namespace Ui {
class CacheSetupWidget;
}
class CacheSetupWidget : public QWidget {
Q_OBJECT
+ friend class CacheTab;
public:
explicit CacheSetupWidget(QWidget *parent = 0);
~CacheSetupWidget();
void setName(QString name);
+ void setCachePtr(CacheBase *cachePtr) { m_cachePtr = cachePtr; }
signals:
void groupBoxToggled(bool state);
@@ -25,8 +29,12 @@ public slots:
private slots:
void on_groupbox_toggled(bool arg1);
+ void cacheSizeChanged(const QString &index);
+ void cacheDelayChanged(int);
+
private:
Ui::CacheSetupWidget *m_ui;
+ CacheBase *m_cachePtr;
};
#endif // CACHESETUPWIDGET_H

MODIFY
src/cachesetupwidget.ui
src/cachesetupwidget.ui
</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>
+ <widget class="QComboBox" name="cachetype"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
</widget>
</item>
<item row="2" column="1">
- <widget class="QSpinBox" name="spinBox">
+ <widget class="QSpinBox" name="cachedelay">
<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">
+ <widget class="QComboBox" name="cachesize">
<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>
</item>
<item row="4" column="1">
- <widget class="QComboBox" name="comboBox_3"/>
+ <widget class="QComboBox" name="setsize"/>
</item>
</layout>
</item>

MODIFY
src/cachetab.cpp
src/cachetab.cpp
#include "cachetab.h"
#include "cachesetupwidget.h"
+#include "ui_cachesetupwidget.h"
#include "ui_cachetab.h"
-
-#include "QGroupBox"
+#include <QComboBox>
CacheTab::CacheTab(QWidget *parent) : QWidget(parent), m_ui(new Ui::CacheTab) {
m_ui->setupUi(this);
@@ -12,24 +12,48 @@ CacheTab::CacheTab(QWidget *parent) : QWidget(parent), m_ui(new Ui::CacheTab) {
}
void CacheTab::setupWidgets() {
+ // Set names, initial state etc.
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
+void CacheTab::connectWidgets() {
+ // Connect cache selection checkboxes
connect(m_ui->l1, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
connect(m_ui->l2, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
connect(m_ui->l3, &CacheSetupWidget::groupBoxToggled, this,
&CacheTab::cacheCountChanged);
+
+ // connect to RunnerCache
+ connect(m_ui->l1, &CacheSetupWidget::groupBoxToggled,
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(L1, state); });
+ connect(m_ui->l2, &CacheSetupWidget::groupBoxToggled,
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(L2, state); });
+ connect(m_ui->l3, &CacheSetupWidget::groupBoxToggled,
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(L3, state); });
}
-void CacheTab::cacheCountChanged(bool state) {
- // Set cache selection checkboxes based on
+void CacheTab::connectSetupWidget(CacheBase *cachePtr, cacheLevel level) {
+ // Called by RunnerCache when a cache has been initialized and requests
+ // connection to a cache widget
+ switch (level) {
+ case L1:
+ m_ui->l1->setCachePtr(cachePtr);
+ break;
+ case L2:
+ m_ui->l2->setCachePtr(cachePtr);
+ break;
+ case L3:
+ m_ui->l3->setCachePtr(cachePtr);
+ break;
+ }
+}
+void CacheTab::cacheCountChanged(bool state) {
// 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
@@ -52,4 +76,10 @@ void CacheTab::cacheCountChanged(bool state) {
}
}
+void CacheTab::setRunnerCachePtr(RunnerCache *ptr) {
+ // Setup connection between RunnerCache and CacheTab
+ m_runnerCachePtr = const_cast<RunnerCache *>(ptr);
+ m_runnerCachePtr->m_cacheTabPtr = this;
+}
+
CacheTab::~CacheTab() { delete m_ui; }

MODIFY
src/cachetab.h
src/cachetab.h
#ifndef CACHETAB_H
#define CACHETAB_H
+#include "runnercache.h"
#include <QWidget>
namespace Ui {
class CacheTab;
}
+class CacheSetupWidget;
+
class CacheTab : public QWidget {
+ friend class RunnerCache;
Q_OBJECT
public:
explicit CacheTab(QWidget *parent = 0);
~CacheTab();
+ void setRunnerCachePtr(RunnerCache *ptr);
+
private:
Ui::CacheTab *m_ui;
void connectWidgets();
-
void setupWidgets();
+ RunnerCache *m_runnerCachePtr;
+ void connectSetupWidget(CacheBase *cachePtr, cacheLevel level);
signals:
void countChanged();

MODIFY
src/defines.h
src/defines.h
#ifndef DEFINES_H
#define DEFINES_H
+#include <QString>
#include <cstdint>
+#include <map>
#include <vector>
enum instrType {
@@ -19,6 +21,7 @@ enum instrType {
};
enum cacheLevel { L1, L2, L3 };
+
enum cacheType { DM, SA, FA };
typedef std::vector<uint8_t> memory;
@@ -32,6 +35,16 @@ enum instrState {
ERR_ECALL
};
+const static std::map<int, QString> cacheSizes = {
+ {32, QString("32 Bytes")}, {64, QString("64 Bytes")},
+ {128, QString("128 Bytes")}, {256, {QString("256 Bytes")}},
+ {512, QString("512 Bytes")}, {1024, QString("1024 Bytes")}};
+
+const static std::map<QString, int> cacheTypes = {
+ {QString("Direct mapped"), DM},
+ {QString("Set associative"), SA},
+ {QString("Fully associative"), FA}};
+
typedef struct {
instrType type = INVALID;
uint32_t word = 0;

MODIFY
src/dmcache.cpp
src/dmcache.cpp
@@ -34,7 +34,10 @@ uint32_t DMCache::readData(uint32_t address) {
}
}
-void DMCache::resize(int size) {}
+void DMCache::resize(int size) {
+ int a;
+ a++;
+}
void DMCache::writeData(uint32_t address) {}

MODIFY
src/main.cpp
src/main.cpp
@@ -24,7 +24,7 @@ int main(int argc, char **argv) {
Runner runner(&parser);
runner.exec();
QApplication app(argc, argv);
- MainWindow m;
+ MainWindow m(&runner, &parser);
m.show();
// execute runner

MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
#include "programfiletab.h"
#include "registerwidget.h"
+#include "runner.h"
+<<<<<<< HEAD
#include "defines.h"
-MainWindow::MainWindow(QWidget *parent)
+MainWindow::MainWindow(Runner *runnerPtr, Parser *parserPtr, QWidget *parent)
: QMainWindow(parent), m_ui(new Ui::MainWindow) {
m_ui->setupUi(this);
setWindowTitle("RISC-V simulator");
+ m_runnerPtr = runnerPtr;
+ m_parserPtr = parserPtr;
+
+ // Setup tab pointers
+ m_ui->cachetab->setRunnerCachePtr(m_runnerPtr->getRunnerCachePtr());
// setup example projects
setupExamples();

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -7,11 +7,15 @@ namespace Ui {
class MainWindow;
}
+class Runner;
+class Parser;
+
class MainWindow : public QMainWindow {
Q_OBJECT
public:
- explicit MainWindow(QWidget *parent = 0);
+ explicit MainWindow(Runner *runnerPtr, Parser *parserPtr,
+ QWidget *parent = 0);
~MainWindow();
private slots:
@@ -24,8 +28,10 @@ private slots:
private:
Ui::MainWindow *m_ui;
-
void setupExamples();
+
+ Runner *m_runnerPtr;
+ Parser *m_parserPtr;
};
#endif // MAINWINDOW_H

MODIFY
src/mainwindow.ui
src/mainwindow.ui
</size>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
- <widget class="ProcessorTab" name="widget" native="true"/>
+ <widget class="ProcessorTab" name="processortab" native="true"/>
</item>
</layout>
</widget>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
- <widget class="CacheTab" name="widget_2" native="true"/>
+ <widget class="CacheTab" name="cachetab" native="true"/>
</item>
</layout>
</widget>
<x>0</x>
<y>0</y>
<width>689</width>
- <height>20</height>
+ <height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

MODIFY
src/runner.h
src/runner.h
#include <vector>
#include "defines.h"
+#include "runnercache.h"
class Parser;
typedef std::function<std::vector<uint32_t>(uint32_t)> decode_functor;
@@ -18,6 +19,8 @@ public:
int exec();
+ RunnerCache *getRunnerCachePtr() { return &m_cache; }
+
private:
instrState execInstruction(Instruction instr);
void handleError(instrState err) const;
@@ -68,6 +71,9 @@ private:
decode_functor decodeSInstr;
decode_functor decodeRInstr;
decode_functor decodeBInstr;
+
+ // Cache
+ RunnerCache m_cache;
};
#endif // RUNNER_H

MODIFY
src/runnercache.cpp
src/runnercache.cpp
#include "dmcache.h"
#include "facache.h"
+#include "cachetab.h"
+
RunnerCache::RunnerCache() {}
uint32_t RunnerCache::readData(uint32_t address) { return 0; }
void RunnerCache::writeData(uint32_t address) {}
-void RunnerCache::createCacheLevel(cacheLevel level,
+void RunnerCache::setCacheLevel(cacheLevel level, bool enable,
CacheProperties properties) {
// Creates a cache at the requested cache level with the given properties,
// and sets the newly created cache as a childCache of a potential parent
+ if (enable) {
switch (level) {
case L1:
m_L1 = createCache(properties);
+ m_cacheTabPtr->connectSetupWidget(m_L1.get(), L1);
break;
case L2:
m_L2 = createCache(properties);
m_L1->setChildCache(m_L2.get());
+ m_cacheTabPtr->connectSetupWidget(m_L2.get(), L2);
break;
case L3:
m_L3 = createCache(properties);
m_L2->setChildCache(m_L3.get());
+ m_cacheTabPtr->connectSetupWidget(m_L3.get(), L3);
break;
}
+ } else {
+ switch (level) {
+ case L1:
+ m_L1.reset();
+ break;
+ case L2:
+ m_L2.reset();
+ break;
+ case L3:
+ m_L3.reset();
+ break;
+ }
+ }
}
std::unique_ptr<CacheBase>
@@ -39,17 +58,3 @@ RunnerCache::createCache(CacheProperties properties) {
return std::make_unique<FACache>(properties);
}
}
-
-void RunnerCache::deleteCache(cacheLevel level) {
- switch (level) {
- case L1:
- m_L1.reset();
- break;
- case L2:
- m_L2.reset();
- break;
- case L3:
- m_L3.reset();
- break;
- }
-}

MODIFY
src/runnercache.h
src/runnercache.h
#include "cachebase.h"
#include <memory>
+class CacheTab;
// Class for handling cache fetching and structuring, for the runner
+namespace {
+CacheProperties defaultProperties;
+}
class RunnerCache {
+ friend class CacheTab;
+
public:
RunnerCache();
public:
- void createCacheLevel(cacheLevel level, CacheProperties properties);
+ void setCacheLevel(cacheLevel level, bool enable,
+ CacheProperties properties = defaultProperties);
void deleteCache(cacheLevel level);
void modifyCache(cacheLevel level, CacheProperties properties);
uint32_t readData(uint32_t address);
void writeData(uint32_t address);
+ bool isEnabled() const { return m_enabled; }
+ bool setEnabled(bool state) { m_enabled = state; }
+
private:
std::unique_ptr<CacheBase> createCache(CacheProperties properties);
std::unique_ptr<CacheBase> m_L1;
std::unique_ptr<CacheBase> m_L2;
std::unique_ptr<CacheBase> m_L3;
+
+ bool m_enabled = false;
+ CacheTab *m_cacheTabPtr;
};
#endif // RUNNERCACHE_H

Create Cachetab <-> RunnerCache connection