summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-22 23:39:14 -0400
committerbd <bdunahu@operationnull.com>2025-04-22 23:39:14 -0400
commit302bbdc7ac18cd355f9f081cae202f5434427262 (patch)
treea80693956999a39deece3130bbdee9a553babbb1 /src
parent74b24d15eb1fe48a8e221a0bc061107d6b85d659 (diff)
Use a struct for InstrDTO
Diffstat (limited to 'src')
-rw-r--r--src/ex.cc14
-rw-r--r--src/id.cc20
-rw-r--r--src/if.cc14
-rw-r--r--src/instrDTO.cc70
-rw-r--r--src/mm.cc14
-rw-r--r--src/stage.cc14
-rw-r--r--src/wb.cc24
7 files changed, 53 insertions, 117 deletions
diff --git a/src/ex.cc b/src/ex.cc
index 117002c..eac24ff 100644
--- a/src/ex.cc
+++ b/src/ex.cc
@@ -422,15 +422,15 @@ void EX::advance_helper()
unsigned int pc;
Mnemonic m;
- m = this->curr_instr->get_mnemonic();
- s1 = this->curr_instr->get_s1();
- s2 = this->curr_instr->get_s2();
- s3 = this->curr_instr->get_s3();
- pc = this->curr_instr->get_pc();
+ m = this->curr_instr->mnemonic;
+ s1 = this->curr_instr->operands.integer.slot_one;
+ s2 = this->curr_instr->operands.integer.slot_two;
+ s3 = this->curr_instr->operands.integer.slot_three;
+ pc = this->curr_instr->slot_B;
this->instr_map[m](s1, s2, s3, pc);
- this->curr_instr->set_s1(s1);
+ this->curr_instr->operands.integer.slot_one = s1;
this->status = OK;
}
@@ -440,7 +440,7 @@ void EX::handle_divide(signed int &s1, signed int s2, bool is_mod)
this->set_condition(UF, false);
if (s2 == 0) {
// handle everything here
- this->curr_instr->set_s1(MAX_INT);
+ this->curr_instr->operands.integer.slot_one = MAX_INT;
this->status = OK;
throw HaltException();
} else if ((s1 == -(MAX_INT)-1) && s2 == -1) {
diff --git a/src/id.cc b/src/id.cc
index 97bd844..14fe595 100644
--- a/src/id.cc
+++ b/src/id.cc
@@ -57,7 +57,7 @@ void ID::write_guard(signed int &v)
// keep track in the instrDTO for displaying to user and writeback
// keep track in checked_out so we can still access this information!
this->checked_out.push_back(v);
- this->curr_instr->set_checked_out(v);
+ this->curr_instr->checked_out = v;
}
v = this->dereference_register(v);
}
@@ -68,17 +68,17 @@ void ID::advance_helper()
Mnemonic m;
Type t;
- if (curr_instr->get_mnemonic() == NOP)
+ if (curr_instr->mnemonic == NOP)
this->status = OK;
else {
- s1 = curr_instr->get_instr_bits();
+ s1 = curr_instr->slot_A;
get_instr_fields(s1, s2, s3, m, t);
if (this->status == OK) {
- curr_instr->set_s1(s1);
- curr_instr->set_s2(s2);
- curr_instr->set_s3(s3);
- curr_instr->set_mnemonic(m);
- curr_instr->set_type(t);
+ curr_instr->operands.integer.slot_one = s1;
+ curr_instr->operands.integer.slot_two = s2;
+ curr_instr->operands.integer.slot_three = s3;
+ curr_instr->mnemonic = m;
+ curr_instr->type = t;
}
}
}
@@ -221,8 +221,8 @@ std::vector<int> ID::stage_info()
{
std::vector<int> info;
if (this->curr_instr) {
- info.push_back(this->curr_instr->is_squashed());
- info.push_back(this->curr_instr->get_instr_bits());
+ info.push_back(this->curr_instr->is_squashed);
+ info.push_back(this->curr_instr->slot_A);
}
return info;
}
diff --git a/src/if.cc b/src/if.cc
index 054c77c..fd795c7 100644
--- a/src/if.cc
+++ b/src/if.cc
@@ -27,7 +27,7 @@ InstrDTO *IF::advance(Response p)
this->advance_helper();
if (this->curr_instr != nullptr && p == WAIT) {
// don't increment PC if the PC was just set by wb
- if (this->curr_instr->is_squashed() != 1)
+ if (this->curr_instr->is_squashed != 1)
++this->pc;
r = new InstrDTO(*this->curr_instr);
delete curr_instr;
@@ -40,8 +40,8 @@ InstrDTO *IF::advance(Response p)
std::vector<int> IF::stage_info() {
std::vector<int> info;
if(this->curr_instr){
- info.push_back(this->curr_instr->is_squashed());
- info.push_back(this->curr_instr->get_instr_bits());
+ info.push_back(this->curr_instr->is_squashed);
+ info.push_back(this->curr_instr->slot_A);
}
return info;
}
@@ -57,8 +57,12 @@ void IF::advance_helper()
r = i ? OK : STALLED;
if (r == OK) {
this->curr_instr = new InstrDTO();
- this->curr_instr->set_instr_bits(bits);
- this->curr_instr->set_pc(this->pc);
+ this->curr_instr->slot_A = bits;
+ this->curr_instr->slot_B = this->pc;
+ this->curr_instr->type = INV;
+ this->curr_instr->is_squashed = 0;
+ this->curr_instr->checked_out = -1;
+ this->curr_instr->mnemonic = ADD;
this->is_empty = false;
}
}
diff --git a/src/instrDTO.cc b/src/instrDTO.cc
deleted file mode 100644
index cb093bb..0000000
--- a/src/instrDTO.cc
+++ /dev/null
@@ -1,70 +0,0 @@
-// Simulator for the RISC-V[ECTOR] mini-ISA
-// Copyright (C) 2025 Siddarth Suresh
-// Copyright (C) 2025 bdunahu
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <https://www.gnu.org/licenses/>.
-
-#include "instrDTO.h"
-
-InstrDTO::InstrDTO()
-{
- this->instr_bits = 0;
- this->checked_out = -1;
- this->s1 = 0;
- this->s2 = 0;
- this->s3 = 0;
- this->mnemonic = ADD;
- this->type = INV;
- this->pc = 0;
- this->squashed = 0;
-}
-
-signed int InstrDTO::get_instr_bits() { return this->instr_bits; }
-
-signed int InstrDTO::get_checked_out() { return this->checked_out; }
-
-signed int InstrDTO::get_s1() { return this->s1; }
-
-signed int InstrDTO::get_s2() { return this->s2; }
-
-signed int InstrDTO::get_s3() { return this->s3; }
-
-Mnemonic InstrDTO::get_mnemonic() { return this->mnemonic; }
-
-Type InstrDTO::get_type() { return this->type; }
-
-unsigned int InstrDTO::get_pc() { return this->pc; }
-
-int InstrDTO::is_squashed() { return this->squashed; }
-
-void InstrDTO::set_instr_bits(signed int instr) { this->instr_bits = instr; }
-
-void InstrDTO::set_checked_out(signed int checked_out)
-{
- this->checked_out = checked_out;
-}
-
-void InstrDTO::set_s1(signed int s) { this->s1 = s; }
-
-void InstrDTO::set_s2(signed int s) { this->s2 = s; }
-
-void InstrDTO::set_s3(signed int s) { this->s3 = s; }
-
-void InstrDTO::set_mnemonic(Mnemonic m) { this->mnemonic = m; }
-
-void InstrDTO::set_type(Type t) { this->type = t; }
-
-void InstrDTO::set_pc(unsigned int pc) { this->pc = pc; }
-
-void InstrDTO::squash() { this->squashed = 1; }
diff --git a/src/mm.cc b/src/mm.cc
index 3df1578..ac77433 100644
--- a/src/mm.cc
+++ b/src/mm.cc
@@ -25,12 +25,13 @@ void MM::advance_helper()
signed int data;
int i;
- switch (this->curr_instr->get_mnemonic()) {
+ switch (this->curr_instr->mnemonic) {
case LOAD:
- i = this->storage->read_word(this, this->curr_instr->get_s1(), data);
+ i = this->storage->read_word(
+ this, this->curr_instr->operands.integer.slot_one, data);
this->status = i ? OK : STALLED;
if (this->status == OK) {
- this->curr_instr->set_s1(data);
+ this->curr_instr->operands.integer.slot_one = data;
} else
this->status = STALLED;
break;
@@ -38,7 +39,8 @@ void MM::advance_helper()
case PUSH:
case STORE:
i = this->storage->write_word(
- this, this->curr_instr->get_s2(), this->curr_instr->get_s1());
+ this, this->curr_instr->operands.integer.slot_two,
+ this->curr_instr->operands.integer.slot_one);
this->status = i ? OK : STALLED;
if (this->status != OK) {
this->status = STALLED;
@@ -46,10 +48,10 @@ void MM::advance_helper()
break;
case POP:
- i = this->storage->read_word(this, this->curr_instr->get_s3(), data);
+ i = this->storage->read_word(this, this->curr_instr->operands.integer.slot_three, data);
this->status = i ? OK : STALLED;
if (this->status == OK) {
- this->curr_instr->set_s3(data);
+ this->curr_instr->operands.integer.slot_three = data;
} else
this->status = STALLED;
break;
diff --git a/src/stage.cc b/src/stage.cc
index b7be595..e5a4333 100644
--- a/src/stage.cc
+++ b/src/stage.cc
@@ -45,7 +45,7 @@ InstrDTO *Stage::advance(Response p)
InstrDTO *s = nullptr;
Response n;
- if (this->curr_instr && this->curr_instr->is_squashed() == 1)
+ if (this->curr_instr && this->curr_instr->is_squashed == 1)
this->status = OK;
if (this->curr_instr && this->status != OK) {
this->advance_helper();
@@ -69,11 +69,11 @@ std::vector<int> Stage::stage_info()
{
std::vector<int> info;
if (this->curr_instr) {
- info.push_back(this->curr_instr->get_mnemonic());
- info.push_back(this->curr_instr->is_squashed());
- info.push_back(this->curr_instr->get_s1());
- info.push_back(this->curr_instr->get_s2());
- info.push_back(this->curr_instr->get_s3());
+ info.push_back(this->curr_instr->mnemonic);
+ info.push_back(this->curr_instr->is_squashed);
+ info.push_back(this->curr_instr->operands.integer.slot_one);
+ info.push_back(this->curr_instr->operands.integer.slot_two);
+ info.push_back(this->curr_instr->operands.integer.slot_three);
}
return info;
}
@@ -121,7 +121,7 @@ bool Stage::is_checked_out(signed int r)
void Stage::squash()
{
if (curr_instr) {
- this->curr_instr->squash();
+ this->curr_instr->is_squashed = 1;
this->status = OK;
}
if (this->next) {
diff --git a/src/wb.cc b/src/wb.cc
index 55591b6..08d512b 100644
--- a/src/wb.cc
+++ b/src/wb.cc
@@ -24,9 +24,9 @@
void WB::advance_helper()
{
- if (this->curr_instr->get_mnemonic() != NOP &&
- this->curr_instr->get_type() != INV) {
- if (this->curr_instr->get_checked_out() > 0)
+ if (this->curr_instr->mnemonic != NOP &&
+ this->curr_instr->type != INV) {
+ if (this->curr_instr->checked_out > 0)
this->write_handler();
else if (this->should_jump())
this->jump_handler();
@@ -42,25 +42,25 @@ void WB::write_handler()
throw std::runtime_error("instruction tried to pop a register out of "
"an empty queue during writeback.");
- if (this->curr_instr->get_mnemonic() == POP) {
+ if (this->curr_instr->mnemonic == POP) {
// POP performs a second register write
reg = this->checked_out.front();
this->checked_out.pop_front();
- this->store_register(reg, this->curr_instr->get_s3());
+ this->store_register(reg, this->curr_instr->operands.integer.slot_three);
}
this->checked_out.pop_front();
- reg = this->curr_instr->get_checked_out();
- this->store_register(reg, this->curr_instr->get_s1());
+ reg = this->curr_instr->checked_out;
+ this->store_register(reg, this->curr_instr->operands.integer.slot_one);
}
void WB::jump_handler()
{
- if (this->curr_instr->get_s1() > 0) {
- if (this->curr_instr->get_mnemonic() == JAL)
- this->gprs[1] = this->curr_instr->get_pc() + 1;;
- this->pc = this->curr_instr->get_s1();
+ if (this->curr_instr->operands.integer.slot_one > 0) {
+ if (this->curr_instr->mnemonic == JAL)
+ this->gprs[1] = this->curr_instr->slot_B + 1;;
+ this->pc = this->curr_instr->operands.integer.slot_one;
this->checked_out = {};
this->next->squash();
}
@@ -70,6 +70,6 @@ bool WB::should_jump()
{
Type t;
- t = this->curr_instr->get_type();
+ t = this->curr_instr->type;
return t == J;
}