diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-03-30 14:02:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-30 14:02:23 -0400 |
commit | eedf9686eb60f2008e7766cc9a5d3e037b9dae64 (patch) | |
tree | 0cfa9009fe483b72940727f3b5a4236f779fe6e7 /src | |
parent | d20623d031cf909d8892c2db38cf2e2e02bc6a9b (diff) | |
parent | 8e56373a5436852fe9c7934e03d7b57493625003 (diff) |
Merge pull request #40 from bdunahu/bdunahu
Minor simplification to API between pipeline components
-- Fixed memory leaks
Diffstat (limited to 'src')
-rw-r--r-- | src/sim/controller.cc | 9 | ||||
-rw-r--r-- | src/sim/ex.cc | 2 | ||||
-rw-r--r-- | src/sim/id.cc | 11 | ||||
-rw-r--r-- | src/sim/if.cc | 12 | ||||
-rw-r--r-- | src/sim/mm.cc | 4 | ||||
-rw-r--r-- | src/sim/wb.cc | 2 |
6 files changed, 23 insertions, 17 deletions
diff --git a/src/sim/controller.cc b/src/sim/controller.cc index 17937eb..622f1dc 100644 --- a/src/sim/controller.cc +++ b/src/sim/controller.cc @@ -16,10 +16,9 @@ Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined) void Controller::run_for(int number) { - InstrDTO instr; int i; for (i = 0; i < number; ++i) { - this->advance(instr, OK); + this->advance(OK); } } @@ -29,11 +28,11 @@ std::array<int, GPR_NUM> Controller::get_gprs() { return this->gprs; } int Controller::get_pc() { return this->pc; } -Response Controller::advance(InstrDTO &next_instr, Response p) +InstrDTO *Controller::advance(Response p) { - Response r; + InstrDTO *r; - r = this->next->advance(next_instr, p); + r = this->next->advance(p); ++this->clock_cycle; return r; } diff --git a/src/sim/ex.cc b/src/sim/ex.cc index 5b561f8..3a1e92c 100644 --- a/src/sim/ex.cc +++ b/src/sim/ex.cc @@ -6,4 +6,4 @@ EX::EX(Stage *stage) : Stage(stage) { this->id = EXEC; } -Response EX::advance(InstrDTO &next_instr, Response p) { return OK; } +InstrDTO *EX::advance(Response p) { return nullptr; } diff --git a/src/sim/id.cc b/src/sim/id.cc index e18ef14..969cb9d 100644 --- a/src/sim/id.cc +++ b/src/sim/id.cc @@ -8,21 +8,24 @@ ID::ID(Stage *stage) : Stage(stage) { this->id = DCDE; } -Response ID::advance(InstrDTO &next_instr, Response p) +InstrDTO *ID::advance(Response p) { + InstrDTO *r = nullptr; Response n; this->advance_helper(); if (this->status == OK && p == OK) { - // mutual consent + // mutual consent this->curr_instr->set_time_of(this->id, this->clock_cycle); - next_instr = *this->curr_instr; + r = new InstrDTO(*this->curr_instr); + delete curr_instr; curr_instr = nullptr; } n = (p != OK || this->status != OK) ? BLOCKED : OK; // the power of consent - n = this->next->advance(curr_instr, n); + this->curr_instr = this->next->advance(n); + return r; } void ID::get_instr_fields( diff --git a/src/sim/if.cc b/src/sim/if.cc index 7d3291b..43132ed 100644 --- a/src/sim/if.cc +++ b/src/sim/if.cc @@ -6,17 +6,21 @@ IF::IF(Stage *stage) : Stage(stage) { this->id = FETCH; } -Response IF::advance(InstrDTO &next_instr, Response p) +InstrDTO *IF::advance(Response p) { + InstrDTO *r = nullptr; + this->advance_helper(); if (this->status == OK && p == OK) { // mutual consent ++this->pc; this->curr_instr->set_time_of(this->id, this->clock_cycle); - next_instr = *this->curr_instr; + r = new InstrDTO(*this->curr_instr); + delete curr_instr; curr_instr = nullptr; } - return this->status; + + return r; } void IF::advance_helper() @@ -28,7 +32,7 @@ void IF::advance_helper() r = this->storage->read_word(this->id, this->pc, bits); if (r == OK) { this->status = r; - this->curr_instr = std::make_unique<InstrDTO>(); + this->curr_instr = new InstrDTO(); this->curr_instr->set_instr_bits(bits); } else this->status = STALLED; diff --git a/src/sim/mm.cc b/src/sim/mm.cc index f394420..5bc5836 100644 --- a/src/sim/mm.cc +++ b/src/sim/mm.cc @@ -6,7 +6,7 @@ MM::MM(Stage *stage) : Stage(stage) { this->id = MEM; } -Response MM::advance(InstrDTO &next_instr, Response p) +InstrDTO *MM::advance(Response p) { - return OK; + return nullptr; } diff --git a/src/sim/wb.cc b/src/sim/wb.cc index bdea65a..7a8d64c 100644 --- a/src/sim/wb.cc +++ b/src/sim/wb.cc @@ -6,4 +6,4 @@ WB::WB(Stage *stage) : Stage(stage) { this->id = WRITE; } -Response WB::advance(InstrDTO &next_instr, Response p) { return OK; } +InstrDTO *WB::advance(Response p) { return nullptr; } |