aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-08-30 23:29:14 +0200
committerKarel Kočí <cynerd@email.cz>2017-08-30 23:29:14 +0200
commitc975257cef23d254b1fa9290474268a61509e954 (patch)
treed7f219fa9fcb5a54cc9ccfc5aa692643ea968562
parent83e8593d9e36725d2bfb9d450da451e47a93f349 (diff)
downloadqtmips-c975257cef23d254b1fa9290474268a61509e954.tar.gz
qtmips-c975257cef23d254b1fa9290474268a61509e954.tar.bz2
qtmips-c975257cef23d254b1fa9290474268a61509e954.zip
Some to_string_hex cleanups
-rw-r--r--qtmips_machine/instruction.cpp36
-rw-r--r--qtmips_machine/instruction.h2
-rw-r--r--qtmips_machine/programmemory.cpp3
3 files changed, 14 insertions, 27 deletions
diff --git a/qtmips_machine/instruction.cpp b/qtmips_machine/instruction.cpp
index 159d443..c5d5345 100644
--- a/qtmips_machine/instruction.cpp
+++ b/qtmips_machine/instruction.cpp
@@ -1,6 +1,7 @@
#include "instruction.h"
#include <sstream>
#include <iostream>
+#include "utils.h"
InstructionR::InstructionR(std::uint8_t rs, std::uint8_t rd, std::uint8_t rt, std::uint8_t sa) {
this->rs = rs;
@@ -16,22 +17,14 @@ std::vector<std::string> InstructionR::to_strs() {
// Instruction name
str.push_back("unknown"); // unknown instruction, should be replaced by child
- std::stringstream ss;
// Source register
- ss << std::hex << (unsigned) this->rs;
- str.push_back(ss.str());
- ss.str("");
+ str.push_back(to_string_hex((unsigned)this->rs));
// Target register
- ss << std::hex << (unsigned) this->rt;
- str.push_back(ss.str());
- ss.str("");
+ str.push_back(to_string_hex((unsigned)this->rt));
// Destination register
- ss << std::hex << (unsigned) this->rd;
- str.push_back(ss.str());
- ss.str("");
+ str.push_back(to_string_hex((unsigned)this->rd));
// Shift amount
- ss << std::hex << (unsigned) this->sa;
- str.push_back(ss.str());
+ str.push_back(to_string_hex((unsigned)this->sa));
return str;
}
@@ -39,7 +32,7 @@ std::vector<std::string> InstructionR::to_strs() {
InstructionI::InstructionI(std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate) {
this->rs = rs;
this->rt = rt;
- this->immediage = immediate;
+ this->immediate = immediate;
}
std::vector<std::string> InstructionI::to_strs() {
@@ -47,18 +40,12 @@ std::vector<std::string> InstructionI::to_strs() {
// Instruction name
str.push_back("unknown"); // unknown instruction, should be replaced by child
- std::stringstream ss;
// Source register
- ss << std::hex << (unsigned) this->rs;
- str.push_back(ss.str());
- ss.str("");
- // Destination register
- ss << std::hex << (unsigned) this->rt;
- str.push_back(ss.str());
- ss.str("");
+ str.push_back(to_string_hex((unsigned)this->rs));
+ // Target register
+ str.push_back(to_string_hex((unsigned)this->rt));
// Immediate value
- ss << std::hex << (unsigned) this->immediage;
- str.push_back(ss.str());
+ str.push_back(to_string_hex((unsigned)this->immediate));
return str;
}
@@ -74,8 +61,7 @@ std::vector<std::string> InstructionJ::to_strs() {
std::stringstream ss;
// Source register
- ss << std::hex << (unsigned) this->address;
- str.push_back(ss.str());
+ str.push_back(to_string_hex((unsigned)this->address));
return str;
}
diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h
index 6ab7015..d276a83 100644
--- a/qtmips_machine/instruction.h
+++ b/qtmips_machine/instruction.h
@@ -33,7 +33,7 @@ public:
std::vector<std::string> to_strs();
protected:
std::uint8_t rs, rt;
- std::uint16_t immediage;
+ std::uint16_t immediate;
};
class InstructionJ : public Instruction {
diff --git a/qtmips_machine/programmemory.cpp b/qtmips_machine/programmemory.cpp
index c5ef53a..6759842 100644
--- a/qtmips_machine/programmemory.cpp
+++ b/qtmips_machine/programmemory.cpp
@@ -5,6 +5,7 @@
#include "instructions/loadstore.h"
#include "instructions/nop.h"
#include "instructions/shift.h"
+#include "utils.h"
ProgramMemory::ProgramMemory(ProgramLoader *loader, MemoryAccess *memory) {
this->memory = memory;
@@ -40,7 +41,7 @@ Instruction *ProgramMemory::at(std::uint32_t address) {
}
// TODO implement
-#define I_UNKNOWN(DATA) do { std::stringstream ss; ss << std::hex << DATA; throw QTMIPS_EXCEPTION(UnsupportedInstruction, "Unknown instruction, can't decode", ss.str()); } while(false);
+#define I_UNKNOWN(DATA) throw QTMIPS_EXCEPTION(UnsupportedInstruction, "Unknown instruction, can't decode", to_string_hex(DATA))
#define I_UNSUPPORTED(INST) throw QTMIPS_EXCEPTION(UnsupportedInstruction, "Decoded unsupported unstruction", #INST)
Instruction *ProgramMemory::decode_r(std::uint32_t dt) {