2021-05-23 20:59:09 +00:00
|
|
|
#include "VuInstruction.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2022-02-09 00:02:47 +00:00
|
|
|
#include "common/util/Assert.h"
|
2021-05-23 20:59:09 +00:00
|
|
|
|
2024-03-06 03:11:52 +00:00
|
|
|
#include "fmt/core.h"
|
2022-06-23 03:37:46 +00:00
|
|
|
|
2021-05-23 20:59:09 +00:00
|
|
|
namespace decompiler {
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_vf(int idx) {
|
2022-02-09 00:02:47 +00:00
|
|
|
ASSERT(idx >= 0 && idx <= 31);
|
2021-05-23 20:59:09 +00:00
|
|
|
return {Kind::VF, idx};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_vi(int idx) {
|
2022-02-09 00:02:47 +00:00
|
|
|
ASSERT(idx >= 0 && idx <= 15);
|
2021-05-23 20:59:09 +00:00
|
|
|
return {Kind::VI, idx};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_label(int idx) {
|
|
|
|
return {Kind::LABEL, idx};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_q() {
|
|
|
|
return {Kind::Q};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_acc() {
|
|
|
|
return {Kind::ACC};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_imm(u64 value) {
|
|
|
|
return {Kind::IMM, (s64)value};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_load_store_imm(s64 value) {
|
|
|
|
return {Kind::LOAD_STORE_IMM, value};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_i() {
|
|
|
|
return {Kind::I};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_p() {
|
|
|
|
return {Kind::P};
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstructionAtom VuInstructionAtom::make_r() {
|
|
|
|
return {Kind::R};
|
|
|
|
}
|
|
|
|
|
2022-02-04 03:45:41 +00:00
|
|
|
bool VuInstructionAtom::is_int_reg(int idx) const {
|
|
|
|
return m_kind == Kind::VI && m_value == idx;
|
|
|
|
}
|
|
|
|
|
2021-05-23 20:59:09 +00:00
|
|
|
std::string VuInstructionAtom::to_string(const std::vector<std::string>& labels) const {
|
|
|
|
switch (m_kind) {
|
|
|
|
case Kind::VF:
|
|
|
|
return fmt::format("vf{:02d}", m_value);
|
|
|
|
case Kind::Q:
|
|
|
|
return "Q";
|
|
|
|
case Kind::ACC:
|
|
|
|
return "ACC";
|
|
|
|
case Kind::IMM:
|
|
|
|
if (m_value < 0) {
|
|
|
|
return fmt::format("-0x{:x}", -m_value);
|
|
|
|
} else {
|
|
|
|
return fmt::format("0x{:x}", m_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Kind::I:
|
|
|
|
return "I";
|
|
|
|
case Kind::P:
|
|
|
|
return "P";
|
|
|
|
case Kind::R:
|
|
|
|
return "R";
|
|
|
|
case Kind::LABEL:
|
|
|
|
if (m_value < (int)labels.size()) {
|
|
|
|
return labels.at(m_value);
|
|
|
|
} else {
|
|
|
|
return "BAD-LABEL";
|
|
|
|
}
|
|
|
|
case Kind::LOAD_STORE_IMM:
|
|
|
|
return fmt::format("{}", m_value);
|
|
|
|
case Kind::VI:
|
|
|
|
return fmt::format("vi{:02d}", m_value);
|
|
|
|
case Kind::INVALID:
|
|
|
|
default:
|
2022-02-09 00:02:47 +00:00
|
|
|
ASSERT(false);
|
2021-05-23 20:59:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VuInstruction VuInstruction::make_fp_constant(u32 value) {
|
|
|
|
VuInstruction result;
|
|
|
|
memcpy(&result.fp, &value, sizeof(float));
|
|
|
|
result.kind = VuInstrK::FP_CONSTANT;
|
|
|
|
return result;
|
|
|
|
}
|
2022-01-02 23:02:10 +00:00
|
|
|
} // namespace decompiler
|