diff --git a/tests/print_info.cpp b/tests/print_info.cpp index ac8cbef9..9e2064d4 100644 --- a/tests/print_info.cpp +++ b/tests/print_info.cpp @@ -7,10 +7,15 @@ #include #include +#include #include #include "common/common_types.h" #include "common/llvm_disassemble.h" +#include "frontend/A32/decoder/arm.h" +#include "frontend/A32/location_descriptor.h" +#include "frontend/A32/translate/impl/translate_arm.h" +#include "frontend/A32/translate/translate.h" #include "frontend/A64/decoder/a64.h" #include "frontend/A64/location_descriptor.h" #include "frontend/A64/translate/impl/impl.h" @@ -19,27 +24,35 @@ using namespace Dynarmic; -const char* GetNameOfInstruction(u32 instruction) { +const char* GetNameOfA32Instruction(u32 instruction) { + if (auto decoder = A32::DecodeArm(instruction)) { + return decoder->get().GetName(); + } + return ""; +} + +const char* GetNameOfA64Instruction(u32 instruction) { if (auto decoder = A64::Decode(instruction)) { return decoder->get().GetName(); } return ""; } -int main(int argc, char** argv) { - if (argc != 2) { - fmt::print("usage: {} \n", argv[0]); - return 1; - } +void PrintA32Instruction(u32 instruction) { + fmt::print("{:08x} {}\n", instruction, A32::DisassembleArm(instruction)); + fmt::print("Name: {}\n", GetNameOfA32Instruction(instruction)); - if (strlen(argv[1]) > 8) { - fmt::print("hex string too long\n"); - return 1; - } + const A32::LocationDescriptor location{0, {}, {}}; + IR::Block block{location}; + const bool should_continue = A32::TranslateSingleInstruction(block, location, instruction); + fmt::print("should_continue: {}\n", should_continue); + fmt::print("IR:\n"); + fmt::print("{}\n", IR::DumpBlock(block)); +} - const u32 instruction = strtol(argv[1], nullptr, 16); +void PrintA64Instruction(u32 instruction) { fmt::print("{:08x} {}\n", instruction, Common::DisassembleAArch64(instruction)); - fmt::print("Name: {}\n", GetNameOfInstruction(instruction)); + fmt::print("Name: {}\n", GetNameOfA64Instruction(instruction)); const A64::LocationDescriptor location{0, {}}; IR::Block block{location}; @@ -47,6 +60,28 @@ int main(int argc, char** argv) { fmt::print("should_continue: {}\n", should_continue); fmt::print("IR:\n"); fmt::print("{}\n", IR::DumpBlock(block)); +} + +int main(int argc, char** argv) { + if (argc != 3) { + fmt::print("usage: {} \n", argv[0]); + return 1; + } + + if (strlen(argv[2]) > 8) { + fmt::print("hex string too long\n"); + return 1; + } + + const u32 instruction = strtol(argv[2], nullptr, 16); + + if (strcmp(argv[1], "a32") == 0) { + PrintA32Instruction(instruction); + } else if (strcmp(argv[1], "a64") == 0) { + PrintA64Instruction(instruction); + } else { + fmt::print("Invalid mode: {}\nValid values: a32, a64\n", argv[1]); + } return 0; }