diff options
author | Ben Smith <binjimin@gmail.com> | 2017-03-22 21:14:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-22 21:14:16 -0700 |
commit | 192fbd023a542f2e6d7a737ac5412e392dd0e45e (patch) | |
tree | 7d8e7e84d6a351b175fa6c132493cda3d8be4cd2 /src/binary-reader-objdump.cc | |
parent | f8c3d6027dd64c7c3c962aa1d4bfc50e6ecc4a8c (diff) | |
download | wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.tar.gz wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.tar.bz2 wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.zip |
Replace wabt::*vector with std::vector (#366)
This propagates through a lot of code since std::vector will call
constructors and destructors. In particular, this CL adds many default
constructors and destructors to previously POD types. Many of them are
only there to construct `Var` and `StringSlice` types, so they likely
can be removed when those have their own constructors.
Since unions members cannot contain constructors or destructors
(without additional implementation), this CL changes those members to
pointers instead. (Perhaps in a future CL these will be std::variant
instead of union, so the members can be value types again.)
Diffstat (limited to 'src/binary-reader-objdump.cc')
-rw-r--r-- | src/binary-reader-objdump.cc | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index 95130643..47f05770 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -21,16 +21,16 @@ #include <string.h> #include <stdio.h> +#include <vector> + #include "binary-reader.h" #include "literal.h" -#include "vector.h" namespace wabt { namespace { -typedef uint32_t Uint32; -WABT_DEFINE_VECTOR(uint32, Uint32); +typedef std::vector<uint32_t> Uint32Vector; struct Context { ObjdumpOptions* options; @@ -247,8 +247,8 @@ static void log_opcode(Context* ctx, ctx->last_opcode_end = ctx->current_opcode_offset + data_size; if (ctx->options->relocs) { - if (ctx->next_reloc < ctx->options->code_relocations.size) { - Reloc* reloc = &ctx->options->code_relocations.data[ctx->next_reloc]; + if (ctx->next_reloc < ctx->options->code_relocations.size()) { + Reloc* reloc = &ctx->options->code_relocations[ctx->next_reloc]; size_t code_start = ctx->section_starts[static_cast<size_t>(BinarySection::Code)]; size_t abs_offset = code_start + reloc->offset; @@ -414,11 +414,10 @@ static Result begin_function_body(BinaryReaderContext* context, Context* ctx = static_cast<Context*>(context->user_data); if (ctx->options->mode == ObjdumpMode::Disassemble) { - if (index < ctx->options->function_names.size && - !string_slice_is_empty(&ctx->options->function_names.data[index])) - printf("%06" PRIzx " <" PRIstringslice ">:\n", context->offset, - WABT_PRINTF_STRING_SLICE_ARG( - ctx->options->function_names.data[index])); + if (index < ctx->options->function_names.size() && + !ctx->options->function_names[index].empty()) + printf("%06" PRIzx " <%s>:\n", context->offset, + ctx->options->function_names[index].c_str()); else printf("%06" PRIzx " func[%d]:\n", context->offset, index); } @@ -602,12 +601,11 @@ static Result on_function_name(uint32_t index, print_details(ctx, " - func[%d] " PRIstringslice "\n", index, WABT_PRINTF_STRING_SLICE_ARG(name)); if (ctx->options->mode == ObjdumpMode::Prepass) { - while (ctx->options->function_names.size < index) { - StringSlice empty = empty_string_slice(); - append_string_slice_value(&ctx->options->function_names, &empty); + while (ctx->options->function_names.size() < index) { + ctx->options->function_names.emplace_back(); } - if (ctx->options->function_names.size == index) { - append_string_slice_value(&ctx->options->function_names, &name); + if (ctx->options->function_names.size() == index) { + ctx->options->function_names.push_back(string_slice_to_string(name)); } } return Result::Ok; @@ -647,12 +645,7 @@ Result on_reloc(RelocType type, get_reloc_type_name(type), index, addend, offset, total_offset); if (ctx->options->mode == ObjdumpMode::Prepass && ctx->reloc_section == BinarySection::Code) { - Reloc reloc; - reloc.offset = offset; - reloc.type = type; - reloc.index = index; - reloc.addend = addend; - append_reloc_value(&ctx->options->code_relocations, &reloc); + ctx->options->code_relocations.emplace_back(type, offset, index, addend); } return Result::Ok; } |