diff options
author | Ben Smith <binjimin@gmail.com> | 2017-06-19 10:17:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 10:17:46 -0700 |
commit | c1507f8aafdf6bc7653657e8fc5895bc88777bc5 (patch) | |
tree | f46ff1325992d55fec3b83c01d46ee8f23260def /src/binary-reader-objdump.cc | |
parent | b8ee81f3b6a0d7f677a77703e8217236ccc14ea2 (diff) | |
download | wabt-c1507f8aafdf6bc7653657e8fc5895bc88777bc5.tar.gz wabt-c1507f8aafdf6bc7653657e8fc5895bc88777bc5.tar.bz2 wabt-c1507f8aafdf6bc7653657e8fc5895bc88777bc5.zip |
Rewrite wabt::Opcode as C++ class (#500)
The class stores just one enum, so should be optimized to be passed as a
register. Since it is an object, the get_opcode_* accessors can now be
members:
get_opcode_name(opcode) => opcode.GetName()
One side-effect of this change is that the opcode enumeration does not
match its binary encoding. This is a potential source of errors, but
will allows us to use a contiguous set of values for the enumeration, so
Opcode::GetInfo is an O(1) lookup. It will also be beneficial when
adding operators with prefixed encodings.
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r-- | src/binary-reader-objdump.cc | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 0209e699..1ea6717e 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -191,17 +191,17 @@ class BinaryReaderObjdumpDisassemble : public BinaryReaderObjdumpBase { Result BinaryReaderObjdumpDisassemble::OnOpcode(Opcode opcode) { if (options->debug) { - const char* opcode_name = get_opcode_name(opcode); + const char* opcode_name = opcode.GetName(); printf("on_opcode: %#" PRIzx ": %s\n", state->offset, opcode_name); } if (last_opcode_end) { if (state->offset != last_opcode_end + 1) { - uint8_t missing_opcode = data[last_opcode_end]; - const char* opcode_name = - get_opcode_name(static_cast<Opcode>(missing_opcode)); - fprintf(stderr, "warning: %#" PRIzx " missing opcode callback at %#" PRIzx - " (%#02x=%s)\n", + Opcode missing_opcode = Opcode::FromCode(data[last_opcode_end]); + const char* opcode_name = missing_opcode.GetName(); + fprintf(stderr, + "warning: %#" PRIzx " missing opcode callback at %#" PRIzx + " (%#02x=%s)\n", state->offset, last_opcode_end + 1, data[last_opcode_end], opcode_name); return Result::Error; @@ -222,8 +222,7 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(const uint8_t* data, Offset offset = current_opcode_offset; // Print binary data - printf(" %06" PRIzx ": %02x", offset - 1, - static_cast<unsigned>(current_opcode)); + printf(" %06" PRIzx ": %02x", offset - 1, current_opcode.GetCode()); for (size_t i = 0; i < data_size && i < IMMEDIATE_OCTET_COUNT; i++, offset++) { printf(" %02x", data[offset]); @@ -241,7 +240,7 @@ void BinaryReaderObjdumpDisassemble::LogOpcode(const uint8_t* data, printf(" "); } - const char* opcode_name = get_opcode_name(current_opcode); + const char* opcode_name = current_opcode.GetName(); printf("%s", opcode_name); if (fmt) { printf(" "); |