From 8c46ba4f216aec9f512cd398317f891be9b07e84 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 14:28:45 -0400 Subject: Add mock stage, proper decode tests --- src/sim/dum.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/sim/dum.cc (limited to 'src/sim/dum.cc') diff --git a/src/sim/dum.cc b/src/sim/dum.cc new file mode 100644 index 0000000..f14c89a --- /dev/null +++ b/src/sim/dum.cc @@ -0,0 +1,41 @@ +#include "dum.h" +#include "accessor.h" +#include "instrDTO.h" +#include "response.h" +#include "stage.h" +#include "utils.h" + +static Logger *global_log = Logger::getInstance(); + +DUM::DUM(Stage *stage) : Stage(stage) { this->id = IDLE; } + +InstrDTO *DUM::advance(Response p) +{ + InstrDTO *r = curr_instr; + + this->advance_helper(); + if (this->status == OK && p == OK) { + this->curr_instr->set_time_of(this->id, this->clock_cycle); + r = new InstrDTO(*this->curr_instr); + delete curr_instr; + curr_instr = nullptr; + } + + return r; +} + +void DUM::advance_helper() +{ + if (this->curr_instr) + global_log->log( + DEBUG, string_format( + "Using bits: %i ", this->curr_instr->get_instr_bits())); + else + global_log->log(DEBUG, "curr_instr is null"); +} + +void DUM::set_curr_instr(InstrDTO *d) +{ + this->curr_instr = d; + this->status = OK; +} -- cgit v1.2.3 From 36dabe6183af98b2e3f6d0316436dc3affc3d986 Mon Sep 17 00:00:00 2001 From: bd Date: Sun, 30 Mar 2025 14:35:27 -0400 Subject: Free everything I allocated :) --- src/sim/dum.cc | 12 +----------- tests/id.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/sim/dum.cc') diff --git a/src/sim/dum.cc b/src/sim/dum.cc index f14c89a..dd16660 100644 --- a/src/sim/dum.cc +++ b/src/sim/dum.cc @@ -5,8 +5,6 @@ #include "stage.h" #include "utils.h" -static Logger *global_log = Logger::getInstance(); - DUM::DUM(Stage *stage) : Stage(stage) { this->id = IDLE; } InstrDTO *DUM::advance(Response p) @@ -24,15 +22,7 @@ InstrDTO *DUM::advance(Response p) return r; } -void DUM::advance_helper() -{ - if (this->curr_instr) - global_log->log( - DEBUG, string_format( - "Using bits: %i ", this->curr_instr->get_instr_bits())); - else - global_log->log(DEBUG, "curr_instr is null"); -} +void DUM::advance_helper() {} void DUM::set_curr_instr(InstrDTO *d) { diff --git a/tests/id.cc b/tests/id.cc index 6d6a155..be50ed5 100644 --- a/tests/id.cc +++ b/tests/id.cc @@ -125,6 +125,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary r-type # two", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0x00000000); CHECK(i->get_mnemonic() == SUB); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") @@ -144,6 +146,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # one", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0xF); CHECK(i->get_mnemonic() == SFTLI); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") @@ -163,6 +167,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary i-type # two", "[id]") CHECK(i->get_s2() == 0x00000000); CHECK(i->get_s3() == 0xCC); CHECK(i->get_mnemonic() == STORE); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") @@ -181,6 +187,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # one", "[id]") CHECK(i->get_s1() == 0x00000000); // registers are empty CHECK(i->get_s2() == 0x3456); CHECK(i->get_mnemonic() == BOF); + + delete i; } TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") @@ -199,6 +207,8 @@ TEST_CASE_METHOD(IDFixture, "Parse arbitrary j-type # two", "[id]") CHECK(i->get_s1() == 0x00000000); // registers are empty CHECK(i->get_s2() == 0xBBCCF); CHECK(i->get_mnemonic() == JAL); + + delete i; } TEST_CASE_METHOD(IDFixture, "read does not conflict with read", "[id]") -- cgit v1.2.3