diff options
author | Sam Clegg <sbc@chromium.org> | 2018-05-10 22:16:44 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-05-10 22:16:44 +0000 |
commit | 16c16827bc7e21ff628e89562e32960eb3d7ca1d (patch) | |
tree | 5dab905667f9fdc837a4a8f21df3141fafd5ccff /llvm/unittests/MC/Disassembler.cpp | |
parent | 65e9f1f2c9d5a9d4422472184ae9a6bb1e1d7552 (diff) | |
download | bcm5719-llvm-16c16827bc7e21ff628e89562e32960eb3d7ca1d.tar.gz bcm5719-llvm-16c16827bc7e21ff628e89562e32960eb3d7ca1d.zip |
[WebAssembly] Initial Disassembler.
This implements a new table-gen emitter to create tables for
a wasm disassembler, and a dissassembler to use them.
Comes with 2 tests, that tests a few instructions manually. Is also able to
disassemble large .wasm files with objdump reasonably.
Not working so well, to be addressed in followups:
- objdump appears to be passing an incorrect starting point.
- since the disassembler works an instruction at a time, and it is
disassembling stack instruction, it has no idea of pseudo register assignments.
These registers are required for the instruction printing code that follows.
For now, all such registers appear in the output as $0.
Patch by Wouter van Oortmerssen
Differential Revision: https://reviews.llvm.org/D45848
llvm-svn: 332052
Diffstat (limited to 'llvm/unittests/MC/Disassembler.cpp')
-rw-r--r-- | llvm/unittests/MC/Disassembler.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/llvm/unittests/MC/Disassembler.cpp b/llvm/unittests/MC/Disassembler.cpp index dd0f1ef9ace..ef4b57be45c 100644 --- a/llvm/unittests/MC/Disassembler.cpp +++ b/llvm/unittests/MC/Disassembler.cpp @@ -21,7 +21,7 @@ static const char *symbolLookupCallback(void *DisInfo, uint64_t ReferenceValue, return nullptr; } -TEST(Disassembler, Test1) { +TEST(Disassembler, X86Test) { llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); llvm::InitializeAllDisassemblers(); @@ -62,3 +62,46 @@ TEST(Disassembler, Test1) { LLVMDisasmDispose(DCR); } + +TEST(Disassembler, WebAssemblyTest) { + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllDisassemblers(); + + uint8_t Bytes[] = {0x6a, 0x42, 0x7F, 0x35, 0x01, 0x10}; + uint8_t *BytesP = Bytes; + const char OutStringSize = 100; + char OutString[OutStringSize]; + LLVMDisasmContextRef DCR = LLVMCreateDisasm( + "wasm32-unknown-unknown-elf", nullptr, 0, nullptr, symbolLookupCallback); + if (!DCR) + return; + + size_t InstSize; + unsigned NumBytes = sizeof(Bytes); + unsigned PC = 0; + + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString, + OutStringSize); + EXPECT_EQ(InstSize, 1U); + EXPECT_EQ(StringRef(OutString), "\ti32.add \t$0=, $0, $0"); + PC += InstSize; + BytesP += InstSize; + NumBytes -= InstSize; + + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString, + OutStringSize); + EXPECT_EQ(InstSize, 2U); + EXPECT_EQ(StringRef(OutString), "\ti64.const\t$0=, -1"); + + PC += InstSize; + BytesP += InstSize; + NumBytes -= InstSize; + + InstSize = LLVMDisasmInstruction(DCR, BytesP, NumBytes, PC, OutString, + OutStringSize); + EXPECT_EQ(InstSize, 3U); + EXPECT_EQ(StringRef(OutString), "\ti64.load32_u\t$0=, 16($0):p2align=1"); + + LLVMDisasmDispose(DCR); +} |