Implement proper Init OutputContext
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2021-08-05 16:29:07 +02:00
parent 3868034b6b
commit 875f6588d9
2 changed files with 29 additions and 11 deletions

View file

@ -29,6 +29,7 @@
#include "../Registers.h" #include "../Registers.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include "../OutputContext.h"
void Instruction::Init::fromBytes(uint32_t offset, const std::vector<uint8_t> &bytes) { void Instruction::Init::fromBytes(uint32_t offset, const std::vector<uint8_t> &bytes) {
_address = offset; _address = offset;
@ -69,18 +70,35 @@ std::string Instruction::Init::toString() const {
if (count > 1 && increment) { if (count > 1 && increment) {
op << " UNTIL " << getAddressRegisterName(address + count - 1, addressOffset); op << " UNTIL " << getAddressRegisterName(address + count - 1, addressOffset);
} }
op << " COUNT " << std::hex << std::setw(6) << std::setfill('0') << count;
op << " INCREMENT " << std::dec << (uint32_t) increment; op << " INCREMENT " << std::dec << (uint32_t) increment;
op << " COUNT " << std::hex << std::setw(6) << std::setfill('0') << count;
op << " DATA 0x" << std::hex << std::setw(8) << std::setfill('0') << data; op << " DATA 0x" << std::hex << std::setw(8) << std::setfill('0') << data;
op << " INC 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add; op << " ADD 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add;
return op.str(); return op.str();
} }
std::vector<Instruction::OutputFormat> Instruction::Init::toOutputFormat(const OutputContext &context) const { std::vector<Instruction::OutputFormat> Instruction::Init::toOutputFormat(const OutputContext &context) const {
return std::vector<OutputFormat>{ std::vector<OutputFormat> f{
//TODO OutputFormat{getAddress() + 0 * 4,
dynamic_cast<std::stringstream &>(std::stringstream("") << "INIT" << " "
<< context.getAddressRegisterName(
address, addressOffset)
<< ", INC " << std::dec
<< (uint32_t) increment).str()}
}; };
f.emplace_back(OutputFormat{getAddress() + 1 * 4,
dynamic_cast<std::stringstream &>(std::stringstream("") << " COUNT " << std::dec
<< count).str()});
f.emplace_back(OutputFormat{getAddress() + 2 * 4,
dynamic_cast<std::stringstream &>(std::stringstream("") << " DATA 0x" << std::hex << std::setw(8) << std::setfill('0') << data).str()});
f.emplace_back(OutputFormat{getAddress() + 3 * 4,
dynamic_cast<std::stringstream &>(std::stringstream("") << " ADD 0x" << std::hex << std::setw(8) << std::setfill('0') << data_add).str()});
return f;
} }
std::vector<uint32_t> Instruction::Init::getPossibleBranches() const { std::vector<uint32_t> Instruction::Init::getPossibleBranches() const {
@ -90,7 +108,7 @@ std::vector<uint32_t> Instruction::Init::getPossibleBranches() const {
std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>> std::vector<std::pair<uint32_t, std::unordered_map<uint32_t, uint32_t>>>
Instruction::Init::execute(AnalysisState &state) const { Instruction::Init::execute(AnalysisState &state) const {
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
state.setRegister(address + (increment ? i : 0), data + data_add * i); state.setRegister(address + increment, data + data_add * i);
} }
state.current = _endAddress; state.current = _endAddress;

View file

@ -54,11 +54,11 @@ namespace Instruction {
execute(AnalysisState &state) const override; execute(AnalysisState &state) const override;
uint8_t addressOffset; uint8_t addressOffset{};
uint8_t increment; uint8_t increment{};
uint32_t address; uint32_t address{};
uint32_t count; uint32_t count{};
uint32_t data; uint32_t data{};
uint32_t data_add; uint32_t data_add{};
}; };
} }