summaryrefslogtreecommitdiff
path: root/src/binary-reader-interpreter.cc
diff options
context:
space:
mode:
authorBen Smith <binjimin@gmail.com>2017-03-16 14:49:06 -0700
committerGitHub <noreply@github.com>2017-03-16 14:49:06 -0700
commit5b642c3ce487b77102dec4fc4b55538cfbccc5ff (patch)
tree960aebda63374bd6d5660355f836e935b402bdc0 /src/binary-reader-interpreter.cc
parent81a64d68c7ce50617bac025061d8f6db91b00ee9 (diff)
downloadwabt-5b642c3ce487b77102dec4fc4b55538cfbccc5ff.tar.gz
wabt-5b642c3ce487b77102dec4fc4b55538cfbccc5ff.tar.bz2
wabt-5b642c3ce487b77102dec4fc4b55538cfbccc5ff.zip
Use std::unordered_multimap for BindingHash (#357)
This change can't really be done in isolation, since once we add members with constructors to a struct, it is no longer has a trivial constructor. This propagates through all types that use it, etc. There are a number of changes that are ugly, but hopefully reduced the amount of code that needed to change. In particular, I changed some union members to pointers so they would stay trivially constructible. Another tricky change is the handling of duplicate bindings: previously we just relied on the fact that our hash implementation would be consistent. A nicer solution is to display the duplicated bindings in source order. There's probably a nicer way to do this; bikeshedding welcome. :-)
Diffstat (limited to 'src/binary-reader-interpreter.cc')
-rw-r--r--src/binary-reader-interpreter.cc46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc
index 38f0a4b9..e69acd1c 100644
--- a/src/binary-reader-interpreter.cc
+++ b/src/binary-reader-interpreter.cc
@@ -68,32 +68,43 @@ struct Label {
WABT_DEFINE_VECTOR(label, Label);
struct Context {
- BinaryReader* reader;
- BinaryErrorHandler* error_handler;
- InterpreterEnvironment* env;
- DefinedInterpreterModule* module;
- DefinedInterpreterFunc* current_func;
+ Context() {
+ WABT_ZERO_MEMORY(typechecker);
+ WABT_ZERO_MEMORY(label_stack);
+ WABT_ZERO_MEMORY(func_fixups);
+ WABT_ZERO_MEMORY(depth_fixups);
+ WABT_ZERO_MEMORY(istream_writer);
+ WABT_ZERO_MEMORY(sig_index_mapping);
+ WABT_ZERO_MEMORY(func_index_mapping);
+ WABT_ZERO_MEMORY(global_index_mapping);
+ }
+
+ BinaryReader* reader = nullptr;
+ BinaryErrorHandler* error_handler = nullptr;
+ InterpreterEnvironment* env = nullptr;
+ DefinedInterpreterModule* module = nullptr;
+ DefinedInterpreterFunc* current_func = nullptr;
TypeChecker typechecker;
LabelVector label_stack;
Uint32VectorVector func_fixups;
Uint32VectorVector depth_fixups;
MemoryWriter istream_writer;
- uint32_t istream_offset;
+ uint32_t istream_offset = 0;
/* mappings from module index space to env index space; this won't just be a
* translation, because imported values will be resolved as well */
Uint32Vector sig_index_mapping;
Uint32Vector func_index_mapping;
Uint32Vector global_index_mapping;
- uint32_t num_func_imports;
- uint32_t num_global_imports;
+ uint32_t num_func_imports = 0;
+ uint32_t num_global_imports = 0;
/* values cached in the Context so they can be shared between callbacks */
InterpreterTypedValue init_expr_value;
- uint32_t table_offset;
- bool is_host_import;
- HostInterpreterModule* host_import_module;
- uint32_t import_env_index;
+ uint32_t table_offset = 0;
+ bool is_host_import = false;
+ HostInterpreterModule* host_import_module = nullptr;
+ uint32_t import_env_index = 0;
};
} // namespace
@@ -392,8 +403,8 @@ static Result on_import(uint32_t index,
InterpreterImport* import = &ctx->module->imports[index];
import->module_name = dup_string_slice(module_name);
import->field_name = dup_string_slice(field_name);
- int module_index = find_binding_index_by_name(
- &ctx->env->registered_module_bindings, &import->module_name);
+ int module_index =
+ ctx->env->registered_module_bindings.find_index(import->module_name);
if (module_index < 0) {
print_error(ctx, "unknown import module \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG(import->module_name));
@@ -469,7 +480,7 @@ static Result append_export(Context* ctx,
ExternalKind kind,
uint32_t item_index,
StringSlice name) {
- if (find_binding_index_by_name(&module->export_bindings, &name) != -1) {
+ if (module->export_bindings.find_index(name) != -1) {
print_error(ctx, "duplicate export \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG(name));
return Result::Error;
@@ -478,8 +489,8 @@ static Result append_export(Context* ctx,
module->exports.emplace_back(dup_string_slice(name), kind, item_index);
InterpreterExport* export_ = &module->exports.back();
- Binding* binding = insert_binding(&module->export_bindings, &export_->name);
- binding->index = module->exports.size() - 1;
+ module->export_bindings.emplace(string_slice_to_string(export_->name),
+ Binding(module->exports.size() - 1));
return Result::Ok;
}
@@ -1420,7 +1431,6 @@ Result read_binary_interpreter(InterpreterEnvironment* env,
new DefinedInterpreterModule(env->istream.size);
env->modules.emplace_back(module);
- WABT_ZERO_MEMORY(ctx);
WABT_ZERO_MEMORY(reader);
ctx.reader = &reader;