Change some enums to enum classes
MODIFY
src/cacheinspector.h
src/cacheinspector.h
#include "defines.h"
#include "qcustomplot.h"
-enum dataRole { hit, miss };
+enum class dataRole { hit, miss };
namespace Ui {
class CacheInspector;

MODIFY
src/cachetab.cpp
src/cachetab.cpp
@@ -27,24 +27,24 @@ void CacheTab::connectWidgets() {
// connect to RunnerCache
connect(m_ui->l1, &CacheSetupWidget::groupBoxToggled,
- [=](bool state) { m_runnerCachePtr->setCacheLevel(L1, state); });
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(cacheLevel::L1, state); });
connect(m_ui->l2, &CacheSetupWidget::groupBoxToggled,
- [=](bool state) { m_runnerCachePtr->setCacheLevel(L2, state); });
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(cacheLevel::L2, state); });
connect(m_ui->l3, &CacheSetupWidget::groupBoxToggled,
- [=](bool state) { m_runnerCachePtr->setCacheLevel(L3, state); });
+ [=](bool state) { m_runnerCachePtr->setCacheLevel(cacheLevel::L3, state); });
}
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:
+ case cacheLevel::L1:
m_ui->l1->setCachePtr(cachePtr);
break;
- case L2:
+ case cacheLevel::L2:
m_ui->l2->setCachePtr(cachePtr);
break;
- case L3:
+ case cacheLevel::L3:
m_ui->l3->setCachePtr(cachePtr);
break;
}

MODIFY
src/defines.h
src/defines.h
@@ -58,13 +58,13 @@ enum instrType {
INVALID = 0b0
};
-enum cacheLevel { L1 = 0, L2 = 1, L3 = 2 };
+enum class cacheLevel { L1, L2, L3 };
-enum cacheType { DM, SA, FA };
+enum class cacheType { DM, SA, FA };
typedef std::unordered_map<uint32_t, uint8_t> memory;
-enum runnerState { ERR_BFUNCT3, ERR_NULLLOAD, EXEC_ERR, SUCCESS, DONE, ERR_ECALL, BREAKPOINT };
+enum class runnerState { ERR_BFUNCT3, ERR_NULLLOAD, EXEC_ERR, SUCCESS, DONE, ERR_ECALL, BREAKPOINT };
const static QStringList ABInames = QStringList() << "zero"
<< "ra"
@@ -103,9 +103,9 @@ const static std::map<int, QString> cacheSizes = {{32, QString("32 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}};
+const static std::map<QString, cacheType> cacheTypes = {{QString("Direct mapped"), cacheType::DM},
+ {QString("Set associative"), cacheType::SA},
+ {QString("Fully associative"), cacheType::FA}};
typedef struct {
instrType type = INVALID;

MODIFY
src/processortab.cpp
src/processortab.cpp
@@ -79,7 +79,7 @@ void ProcessorTab::on_displayValues_toggled(bool checked) {
void ProcessorTab::on_run_clicked() {
auto runner = Runner::getRunner();
if (runner->isReady()) {
- if (runner->exec() == DONE) {
+ if (runner->exec() == runnerState::DONE) {
m_instrModel->update();
m_ui->instructionView->update();
m_ui->registerContainer->update();
@@ -107,7 +107,7 @@ void ProcessorTab::on_step_clicked() {
m_ui->instructionView->update();
m_ui->registerContainer->update();
- if (state == DONE) {
+ if (state == runnerState::DONE) {
m_ui->step->setEnabled(false);
m_ui->start->setEnabled(false);
m_ui->run->setEnabled(false);

MODIFY
src/runner.cpp
src/runner.cpp
@@ -21,20 +21,20 @@ runnerState Runner::exec() {
// Make parser parse an instruction based on the current program counter, and,
// if successfull, execute the read instruction. Loop until parser
// unsuccesfully parses an instruction.
- runnerState err;
+ runnerState state;
while (getInstruction(m_pc)) {
setStageInstructions();
- switch ((err = execInstruction(m_currentInstruction))) {
- case SUCCESS:
+ switch ((state = execInstruction(m_currentInstruction))) {
+ case runnerState::SUCCESS:
break;
- case DONE:
- return DONE;
+ case runnerState::DONE:
+ return runnerState::DONE;
default:
- handleError(err);
- return err;
+ handleError(state);
+ return state;
}
}
- return EXEC_ERR;
+ return runnerState::EXEC_ERR;
}
void Runner::setStageInstructions() {
@@ -94,14 +94,14 @@ runnerState Runner::execLuiInstr(Instruction instr) {
std::vector<uint32_t> fields = m_parser->decodeUInstr(instr.word);
m_reg[fields[1]] = fields[0] << 12;
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execAuipcInstr(Instruction instr) {
std::vector<uint32_t> fields = m_parser->decodeUInstr(instr.word);
m_reg[fields[1]] = (fields[0] << 12) + m_pc;
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execJalInstr(Instruction instr) {
@@ -112,9 +112,9 @@ runnerState Runner::execJalInstr(Instruction instr) {
m_pc += signextend<int32_t, 21>(fields[0] << 20 | fields[1] << 1 | fields[2] << 11 | fields[3] << 12);
// Check for misaligned four-byte boundary
if ((m_pc & 0b11) != 0) {
- return EXEC_ERR;
+ return runnerState::EXEC_ERR;
} else {
- return SUCCESS;
+ return runnerState::SUCCESS;
}
}
@@ -131,9 +131,9 @@ runnerState Runner::execJalrInstr(Instruction instr) {
// Check for misaligned four-byte boundary
if ((m_pc & 0b11) != 0) {
- return EXEC_ERR;
+ return runnerState::EXEC_ERR;
} else {
- return SUCCESS;
+ return runnerState::SUCCESS;
}
}
@@ -163,15 +163,15 @@ runnerState Runner::execBranchInstr(Instruction instr) {
m_pc = m_reg[fields[3]] >= m_reg[fields[2]] ? target : m_pc + 4;
break;
default:
- return ERR_BFUNCT3;
+ return runnerState::ERR_BFUNCT3;
}
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execLoadInstr(Instruction instr) {
std::vector<uint32_t> fields = m_parser->decodeIInstr(instr.word);
if (fields[3] == 0) {
- return ERR_NULLLOAD;
+ return runnerState::ERR_NULLLOAD;
}
uint32_t target = signextend<int32_t, 12>(fields[0]) + m_reg[fields[1]];
@@ -195,7 +195,7 @@ runnerState Runner::execLoadInstr(Instruction instr) {
break;
}
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
void Runner::memWrite(uint32_t address, uint32_t value, int size) {
@@ -231,16 +231,16 @@ runnerState Runner::execStoreInstr(Instruction instr) {
memWrite(target, m_reg[fields[1]], 4);
break;
default:
- return ERR_BFUNCT3;
+ return runnerState::ERR_BFUNCT3;
}
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execOpImmInstr(Instruction instr) {
std::vector<uint32_t> fields = m_parser->decodeIInstr(instr.word);
if (fields[3] == 0) {
- return ERR_NULLLOAD;
+ return runnerState::ERR_NULLLOAD;
}
switch (fields[2]) {
@@ -267,7 +267,7 @@ runnerState Runner::execOpImmInstr(Instruction instr) {
m_reg[fields[3]] = (int32_t)m_reg[fields[1]] >> (fields[0] & 0b11111);
break;
} else {
- return EXEC_ERR;
+ return runnerState::EXEC_ERR;
}
case 0b110: // ORI
m_reg[fields[3]] = m_reg[fields[1]] | fields[0];
@@ -277,7 +277,7 @@ runnerState Runner::execOpImmInstr(Instruction instr) {
break;
}
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execOpInstr(Instruction instr) {
@@ -374,7 +374,7 @@ runnerState Runner::execOpInstr(Instruction instr) {
break;
}
} else {
- return EXEC_ERR;
+ return runnerState::EXEC_ERR;
}
case 0b110:
if (fields[0] == 0b1) {
@@ -415,16 +415,16 @@ runnerState Runner::execOpInstr(Instruction instr) {
}
m_pc += 4;
- return SUCCESS;
+ return runnerState::SUCCESS;
}
runnerState Runner::execEcallInstr() {
switch (m_reg[10]) // a0
{
case 10:
- return DONE;
+ return runnerState::DONE;
default:
- return DONE;
+ return runnerState::DONE;
}
}

MODIFY
src/runnercache.cpp
src/runnercache.cpp
@@ -18,30 +18,30 @@ void RunnerCache::setCacheLevel(cacheLevel level, bool enable, CacheProperties p
// and sets the newly created cache as a childCache of a potential parent
if (enable) {
switch (level) {
- case L1:
+ case cacheLevel::L1:
m_L1 = createCache(properties);
- m_cacheTabPtr->connectSetupWidget(m_L1.get(), L1);
+ m_cacheTabPtr->connectSetupWidget(m_L1.get(), cacheLevel::L1);
break;
- case L2:
+ case cacheLevel::L2:
m_L2 = createCache(properties);
m_L1->setChildCache(m_L2.get());
- m_cacheTabPtr->connectSetupWidget(m_L2.get(), L2);
+ m_cacheTabPtr->connectSetupWidget(m_L2.get(), cacheLevel::L2);
break;
- case L3:
+ case cacheLevel::L3:
m_L3 = createCache(properties);
m_L2->setChildCache(m_L3.get());
- m_cacheTabPtr->connectSetupWidget(m_L3.get(), L3);
+ m_cacheTabPtr->connectSetupWidget(m_L3.get(), cacheLevel::L3);
break;
}
} else {
switch (level) {
- case L1:
+ case cacheLevel::L1:
m_L1.reset();
break;
- case L2:
+ case cacheLevel::L2:
m_L2.reset();
break;
- case L3:
+ case cacheLevel::L3:
m_L3.reset();
break;
}
@@ -50,11 +50,11 @@ void RunnerCache::setCacheLevel(cacheLevel level, bool enable, CacheProperties p
std::unique_ptr<CacheBase> RunnerCache::createCache(CacheProperties properties) {
switch (properties.type) {
- case DM:
+ case cacheType::DM:
return std::make_unique<DMCache>(properties);
- case SA:
+ case cacheType::SA:
// return std::make_unique<>(properties);
- case FA:
+ case cacheType::FA:
return std::make_unique<FACache>(properties);
default:
return std::make_unique<DMCache>(properties);

Change some enums to enum classes