DSPTool: make existing tests pass

Disassemble code without the additional text for humans, like the
current PC and opcode hex values, so that it can be reassembled.

I'm not updating any commented-out tests here.
This commit is contained in:
Michael Maltese 2017-05-19 17:07:26 -07:00
parent b9b3b1dc19
commit 1580b6e627
2 changed files with 214 additions and 197 deletions

View File

@ -6,6 +6,7 @@
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/DSP/DSPCodeUtil.h" #include "Core/DSP/DSPCodeUtil.h"
#include "Core/DSP/DSPDisassembler.h"
#include "Core/DSP/DSPHost.h" #include "Core/DSP/DSPHost.h"
#include "Core/DSP/DSPTables.h" #include "Core/DSP/DSPTables.h"
@ -38,13 +39,27 @@ void DSP::Host::UpdateDebugger()
{ {
} }
static bool RoundTrippableDissassemble(const std::vector<u16>& code, std::string& text)
{
DSP::AssemblerSettings settings;
settings.ext_separator = '\'';
settings.decode_names = true;
settings.decode_registers = true;
// These two prevent roundtripping.
settings.show_hex = false;
settings.show_pc = false;
DSP::DSPDisassembler disasm(settings);
return disasm.Disassemble(0x0000, code, 0x0000, text);
}
// This test goes from text ASM to binary to text ASM and once again back to binary. // This test goes from text ASM to binary to text ASM and once again back to binary.
// Then the two binaries are compared. // Then the two binaries are compared.
static bool RoundTrip(const std::vector<u16>& code1) static bool RoundTrip(const std::vector<u16>& code1)
{ {
std::vector<u16> code2; std::vector<u16> code2;
std::string text; std::string text;
if (!DSP::Disassemble(code1, false, text)) if (!RoundTrippableDissassemble(code1, text))
{ {
printf("RoundTrip: Disassembly failed.\n"); printf("RoundTrip: Disassembly failed.\n");
return false; return false;
@ -74,7 +89,8 @@ static bool SuperTrip(const char* asm_code)
return false; return false;
} }
printf("First assembly: %i words\n", (int)code1.size()); printf("First assembly: %i words\n", (int)code1.size());
if (!DSP::Disassemble(code1, false, text))
if (!RoundTrippableDissassemble(code1, text))
{ {
printf("SuperTrip: Disassembly failed\n"); printf("SuperTrip: Disassembly failed\n");
return false; return false;
@ -84,6 +100,7 @@ static bool SuperTrip(const char* asm_code)
printf("Disass:\n"); printf("Disass:\n");
printf("%s", text.c_str()); printf("%s", text.c_str());
} }
if (!DSP::Assemble(text, code2)) if (!DSP::Assemble(text, code2))
{ {
printf("SuperTrip: Second assembly failed\n"); printf("SuperTrip: Second assembly failed\n");

View File

@ -240,7 +240,7 @@ main:
cw 0x8600 cw 0x8600
call send_back call send_back
JNS g_0c4d JGE g_0c4d
; cw 0x0290 ; cw 0x0290
; cw 0x0c4d ; cw 0x0c4d
; call send_back JX0 ; call send_back JX0
@ -630,7 +630,7 @@ dump_memory:
mrr $r02, $r00 mrr $r02, $r00
mrr $r00, $r1f mrr $r00, $r1f
addis $acc0, #0x1 addis $AC0.M, #0x1
_fill_loop2: _fill_loop2:
nop nop