tests: Add print_info program

Eases debugging by printing out dynarmic IR for a given A64 instruction, along with
information about what instruction dynarmic thinks it is.

Also prints an LLVM disassembly of the instruction.
This commit is contained in:
MerryMage 2018-06-27 15:07:28 +01:00
parent be354dbfd0
commit eb3ca7f65b
2 changed files with 61 additions and 0 deletions

View file

@ -44,11 +44,20 @@ if (DYNARMIC_TESTS_USE_UNICORN)
target_link_libraries(dynarmic_tests PRIVATE Unicorn::Unicorn) target_link_libraries(dynarmic_tests PRIVATE Unicorn::Unicorn)
endif() endif()
add_executable(dynarmic_print_info
print_info.cpp
)
include(CreateDirectoryGroups) include(CreateDirectoryGroups)
create_target_directory_groups(dynarmic_tests) create_target_directory_groups(dynarmic_tests)
create_target_directory_groups(dynarmic_print_info)
target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch fmt) target_link_libraries(dynarmic_tests PRIVATE dynarmic boost catch fmt)
target_include_directories(dynarmic_tests PRIVATE . ../src) target_include_directories(dynarmic_tests PRIVATE . ../src)
target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS}) target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS})
target_link_libraries(dynarmic_print_info PRIVATE dynarmic boost catch fmt)
target_include_directories(dynarmic_print_info PRIVATE . ../src)
target_compile_options(dynarmic_print_info PRIVATE ${DYNARMIC_CXX_FLAGS})
add_test(dynarmic_tests dynarmic_tests) add_test(dynarmic_tests dynarmic_tests)

52
tests/print_info.cpp Normal file
View file

@ -0,0 +1,52 @@
/* This file is part of the dynarmic project.
* Copyright (c) 2018 MerryMage
* This software may be used and distributed according to the terms of the GNU
* General Public License version 2 or any later version.
*/
#include <cstring>
#include <cstdlib>
#include <fmt/format.h>
#include "common/common_types.h"
#include "common/llvm_disassemble.h"
#include "frontend/A64/decoder/a64.h"
#include "frontend/A64/location_descriptor.h"
#include "frontend/A64/translate/impl/impl.h"
#include "frontend/A64/translate/translate.h"
#include "frontend/ir/basic_block.h"
using namespace Dynarmic;
const char* GetNameOfInstruction(u32 instruction) {
if (auto decoder = A64::Decode<A64::TranslatorVisitor>(instruction)) {
return decoder->GetName();
}
return "<null>";
}
int main(int argc, char** argv) {
if (argc != 2) {
fmt::print("usage: {} <instruction_in_hex>\n", argv[0]);
return 1;
}
if (strlen(argv[1]) > 8) {
fmt::print("hex string too long\n");
return 1;
}
const u32 instruction = strtol(argv[1], nullptr, 16);
fmt::print("{:08x} {}\n", instruction, Common::DisassembleAArch64(instruction));
fmt::print("Name: {}\n", GetNameOfInstruction(instruction));
const A64::LocationDescriptor location{0, {}};
IR::Block block{location};
const bool should_continue = A64::TranslateSingleInstruction(block, location, instruction);
fmt::print("should_continue: {}\n", should_continue);
fmt::print("IR:\n");
fmt::print("{}\n", IR::DumpBlock(block));
return 0;
}