diff options
author | Ben Smith <binjimin@gmail.com> | 2018-03-15 14:20:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-15 14:20:43 -0700 |
commit | 3510ced20ab6242d11a7d1ab9a1b9f23dae9fb5d (patch) | |
tree | 6ea6f1cb44e9f702cb0eb89738d5c5eba511a6ae /src/binary-reader-objdump.cc | |
parent | 32e89690fa59500602ebf6e787b7667e78b666a2 (diff) | |
download | wabt-3510ced20ab6242d11a7d1ab9a1b9f23dae9fb5d.tar.gz wabt-3510ced20ab6242d11a7d1ab9a1b9f23dae9fb5d.tar.bz2 wabt-3510ced20ab6242d11a7d1ab9a1b9f23dae9fb5d.zip |
Print locals in objdump disassembly (#808)
Fixes issue #807.
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r-- | src/binary-reader-objdump.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index f4c6b7ca..a320b93d 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -288,6 +288,9 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase { Result BeginFunctionBody(Index index) override; + Result OnLocalDeclCount(Index count) override; + Result OnLocalDecl(Index decl_index, Index count, Type type) override; + Result OnOpcode(Opcode Opcode) override; Result OnOpcodeBare() override; Result OnOpcodeIndex(Index value) override; @@ -315,6 +318,7 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase { Offset last_opcode_end = 0; int indent_level = 0; Index next_reloc = 0; + Index local_index_ = 0; }; Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) { @@ -343,6 +347,41 @@ Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) { #define IMMEDIATE_OCTET_COUNT 9 +Result BinaryReaderObjdumpDisassemble::OnLocalDeclCount(Index count) { + local_index_ = 0; + current_opcode_offset = state->offset; + return Result::Ok; +} + +Result BinaryReaderObjdumpDisassemble::OnLocalDecl(Index decl_index, + Index count, + Type type) { + Offset offset = current_opcode_offset; + size_t data_size = state->offset - offset; + + printf(" %06" PRIzx ":", offset); + for (size_t i = 0; i < data_size && i < IMMEDIATE_OCTET_COUNT; + i++, offset++) { + printf(" %02x", data_[offset]); + } + for (size_t i = data_size; i < IMMEDIATE_OCTET_COUNT; i++) { + printf(" "); + } + printf(" | local[%" PRIindex, local_index_); + + if (count != 1) { + printf("..%" PRIindex "", local_index_ + count - 1); + } + local_index_ += count; + + printf("] type=%s\n", GetTypeName(type)); + + last_opcode_end = current_opcode_offset + data_size; + current_opcode_offset = last_opcode_end; + + return Result::Ok; +} + void BinaryReaderObjdumpDisassemble::LogOpcode(const uint8_t* data, size_t data_size, const char* fmt, |