diff options
Diffstat (limited to 'src/tools/wasm-interp.cc')
-rw-r--r-- | src/tools/wasm-interp.cc | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index dae791fc..2c667ae4 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -566,7 +566,6 @@ static Result spectest_import_global(InterpreterImport* import, } static void init_environment(InterpreterEnvironment* env) { - init_interpreter_environment(env); HostInterpreterModule* host_module = append_host_module(env, string_slice_from_cstr("spectest")); host_module->import_delegate.import_func = spectest_import_func; @@ -602,6 +601,20 @@ WABT_DEFINE_VECTOR(interpreter_thread, InterpreterThread); /* An extremely simple JSON parser that only knows how to parse the expected * format from wast2wabt. */ struct Context { + Context() + : last_module(nullptr), + json_data(nullptr), + json_data_size(0), + json_offset(0), + has_prev_loc(0), + command_line_number(0), + passed(0), + total(0) { + WABT_ZERO_MEMORY(source_filename); + WABT_ZERO_MEMORY(loc); + WABT_ZERO_MEMORY(prev_loc); + } + InterpreterEnvironment env; InterpreterThread thread; DefinedInterpreterModule* last_module; @@ -627,7 +640,12 @@ enum class ActionType { }; struct Action { - ActionType type; + Action() { + WABT_ZERO_MEMORY(module_name); + WABT_ZERO_MEMORY(field_name); + } + + ActionType type = ActionType::Invoke; StringSlice module_name; StringSlice field_name; std::vector<InterpreterTypedValue> args; @@ -943,7 +961,6 @@ static Result parse_const_vector( } static Result parse_action(Context* ctx, Action* out_action) { - WABT_ZERO_MEMORY(*out_action); EXPECT_KEY("action"); EXPECT("{"); EXPECT_KEY("type"); @@ -1014,11 +1031,8 @@ static Result on_module_command(Context* ctx, if (!string_slice_is_empty(&name)) { ctx->last_module->name = dup_string_slice(name); - - /* The binding also needs its own copy of the name. */ - StringSlice binding_name = dup_string_slice(name); - Binding* binding = insert_binding(&ctx->env.module_bindings, &binding_name); - binding->index = ctx->env.modules.size() - 1; + ctx->env.module_bindings.emplace(string_slice_to_string(name), + Binding(ctx->env.modules.size() - 1)); } return Result::Ok; } @@ -1032,8 +1046,7 @@ static Result run_action(Context* ctx, int module_index; if (!string_slice_is_empty(&action->module_name)) { - module_index = find_binding_index_by_name(&ctx->env.module_bindings, - &action->module_name); + module_index = ctx->env.module_bindings.find_index(action->module_name); } else { module_index = static_cast<int>(ctx->env.modules.size()) - 1; } @@ -1118,7 +1131,6 @@ static Result on_assert_malformed_command(Context* ctx, BinaryErrorHandler* error_handler = new_custom_error_handler(ctx, "assert_malformed"); InterpreterEnvironment env; - WABT_ZERO_MEMORY(env); init_environment(&env); ctx->total++; @@ -1166,10 +1178,8 @@ static Result on_register_command(Context* ctx, return Result::Error; } - StringSlice dup_as = dup_string_slice(as); - Binding* binding = - insert_binding(&ctx->env.registered_module_bindings, &dup_as); - binding->index = module_index; + ctx->env.registered_module_bindings.emplace(string_slice_to_string(as), + Binding(module_index)); return Result::Ok; } @@ -1205,7 +1215,6 @@ static Result on_assert_invalid_command(Context* ctx, BinaryErrorHandler* error_handler = new_custom_error_handler(ctx, "assert_invalid"); InterpreterEnvironment env; - WABT_ZERO_MEMORY(env); init_environment(&env); ctx->total++; @@ -1439,7 +1448,6 @@ static Result parse_command(Context* ctx) { on_module_command(ctx, filename, name); } else if (match(ctx, "\"action\"")) { Action action; - WABT_ZERO_MEMORY(action); EXPECT(","); CHECK_RESULT(parse_line(ctx)); @@ -1510,7 +1518,6 @@ static Result parse_command(Context* ctx) { } else if (match(ctx, "\"assert_return\"")) { Action action; std::vector<InterpreterTypedValue> expected; - WABT_ZERO_MEMORY(action); EXPECT(","); CHECK_RESULT(parse_line(ctx)); @@ -1523,7 +1530,6 @@ static Result parse_command(Context* ctx) { } else if (match(ctx, "\"assert_return_nan\"")) { Action action; TypeVector expected; - WABT_ZERO_MEMORY(action); EXPECT(","); CHECK_RESULT(parse_line(ctx)); @@ -1538,7 +1544,6 @@ static Result parse_command(Context* ctx) { } else if (match(ctx, "\"assert_trap\"")) { Action action; StringSlice text; - WABT_ZERO_MEMORY(action); WABT_ZERO_MEMORY(text); EXPECT(","); @@ -1551,7 +1556,6 @@ static Result parse_command(Context* ctx) { } else if (match(ctx, "\"assert_exhaustion\"")) { Action action; StringSlice text; - WABT_ZERO_MEMORY(action); WABT_ZERO_MEMORY(text); EXPECT(","); @@ -1591,7 +1595,6 @@ static void destroy_context(Context* ctx) { static Result read_and_run_spec_json(const char* spec_json_filename) { Context ctx; - WABT_ZERO_MEMORY(ctx); ctx.loc.filename = spec_json_filename; ctx.loc.line = 1; ctx.loc.first_column = 1; |