Create main exec function for Runner
MODIFY
src/defines.h
src/defines.h
@@ -15,6 +15,8 @@ enum instrType {
INVALID = 0b0
};
+enum error { INV_IMM, ALLGOOD };
+
typedef struct {
instrType type = INVALID;
uint32_t word = 0;

MODIFY
src/main.cpp
src/main.cpp
#include <iostream>
#include "parser.h"
+#include "runner.h"
using namespace std;
@@ -8,8 +9,9 @@ int main(/*argv, argc*/) {
cout << "Hello World!" << endl;
- Parser myParser(char *fileName);
- // risc5sim test.bin
+ char *ex;
+ Parser parser(ex);
+ Runner runner(&parser);
- return 0;
+ return runner.exec();
}

MODIFY
src/parser.cpp
src/parser.cpp
#include "parser.h"
Parser::Parser(char *fileName) {}
+Parser::~Parser() {}
+
+bool Parser::parseInstruction(int byteOffset) { return true; }
instrType Parser::getOpType(uint32_t word) { return INVALID; }

MODIFY
src/runner.cpp
src/runner.cpp
#include "runner.h"
-Runner::Runner() {}
+#include "parser.h"
+
+Runner::Runner(Parser *parser) { m_parser = parser; }
Runner::~Runner() {}
+
+int Runner::exec() {
+ // Main simulator loop
+ error err;
+ while (m_parser->parseInstruction()) {
+ if ((err = execInstruction(m_parser->getInstruction())) != error::ALLGOOD) {
+ handleError(err);
+ }
+ }
+ return 0;
+}
+
+error Runner::execInstruction(Instruction instr) { return error::ALLGOOD; }
+
+void Runner::handleError(error err) {}

MODIFY
src/runner.h
src/runner.h
#include "defines.h"
+class Parser;
+
class Runner {
public:
- Runner();
+ Runner(Parser *parser);
~Runner();
+ int exec();
+
private:
+ error execInstruction(Instruction instr);
+ void handleError(error err);
+
int m_pc; // program counter
uint32_t m_reg[32]; // Internal registers
uint32_t *m_mem; // Data memory
+
+ Parser *m_parser;
};
#endif // RUNNER_H

Create main exec function for Runner