diff options
author | Ben Smith <binji@chromium.org> | 2016-10-24 14:02:18 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2016-11-03 13:05:36 -0700 |
commit | 5a1be55f5a50c1df5cdce6412a589bafa5fab1df (patch) | |
tree | ec4f75ff60d7363331dc45e615eb07d199e0f2da /src/wasm-ast-checker.c | |
parent | fe4f7d4f0d85826f8babbda76607654380cfc050 (diff) | |
download | wabt-5a1be55f5a50c1df5cdce6412a589bafa5fab1df.tar.gz wabt-5a1be55f5a50c1df5cdce6412a589bafa5fab1df.tar.bz2 wabt-5a1be55f5a50c1df5cdce6412a589bafa5fab1df.zip |
Use a new format for the spec JSON writer/parser
The previous spec JSON format was defined around modules. This is
because the previous spec tests would only run assertions on the most
recently read module. In addition, the previous spec writer would write
the assertions as new exported functions in the module, and run those.
The primary reason for doing this was to allow for passing/returning i64
values, which was necessary to test in a JavaScript host.
Now that the primary host for running the spec tests is wasm-interp, we
no longer need do bundle assertions into the module. Also, some of the
new spec tests allow running exported functions on a module that is not
the most-recently-read module.
The new spec test format is now defined around commands. The commands
map directly to the spec format commands, e.g. `module`,
`assert_invalid`, `assert_trap`, etc.
Diffstat (limited to 'src/wasm-ast-checker.c')
-rw-r--r-- | src/wasm-ast-checker.c | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/wasm-ast-checker.c b/src/wasm-ast-checker.c index dec9c5fc..c906df2e 100644 --- a/src/wasm-ast-checker.c +++ b/src/wasm-ast-checker.c @@ -1284,9 +1284,33 @@ static const WasmTypeVector* check_invoke(Context* ctx, return &func->decl.sig.result_types; } -static WasmType check_get(Context* ctx, const WasmAction* action) { - /* TODO */ - return WASM_TYPE_ANY; +static WasmResult check_get(Context* ctx, + const WasmAction* action, + WasmType* out_type) { + const WasmActionGet* get = &action->get; + const WasmModule* module = ctx->current_module; + if (!module) { + print_error(ctx, CHECK_STYLE_FULL, &action->loc, + "get must occur after a module definition"); + return WASM_ERROR; + } + + WasmExport* export = wasm_get_export_by_name(module, &get->name); + if (!export) { + print_error(ctx, CHECK_STYLE_NAME, &action->loc, + "unknown global export \"" PRIstringslice "\"", + WASM_PRINTF_STRING_SLICE_ARG(get->name)); + return WASM_ERROR; + } + + WasmGlobal* global = wasm_get_global_by_var(module, &export->var); + if (!global) { + /* this error will have already been reported, just skip it */ + return WASM_ERROR; + } + + *out_type = global->type; + return WASM_OK; } static ActionResult check_action(Context* ctx, const WasmAction* action) { @@ -1301,8 +1325,10 @@ static ActionResult check_action(Context* ctx, const WasmAction* action) { break; case WASM_ACTION_TYPE_GET: - result.kind = ACTION_RESULT_KIND_TYPE; - result.type = check_get(ctx, action); + if (WASM_SUCCEEDED(check_get(ctx, action, &result.type))) + result.kind = ACTION_RESULT_KIND_TYPE; + else + result.kind = ACTION_RESULT_KIND_ERROR; break; } @@ -1424,16 +1450,6 @@ WasmResult wasm_check_ast(WasmAllocator* allocator, return ctx.result; } -static WasmLocation* get_raw_module_location(WasmRawModule* raw) { - switch (raw->type) { - case WASM_RAW_MODULE_TYPE_BINARY: return &raw->binary.loc; - case WASM_RAW_MODULE_TYPE_TEXT: return &raw->text->loc; - default: - assert(0); - return NULL; - } -} - WasmResult wasm_check_assert_invalid_and_malformed( WasmAllocator* allocator, WasmAstLexer* lexer, @@ -1469,9 +1485,10 @@ WasmResult wasm_check_assert_invalid_and_malformed( check_raw_module(&ctx2, &command->assert_invalid.module); wasm_destroy_context(&ctx2); if (WASM_SUCCEEDED(ctx2.result)) { - print_error(&ctx, CHECK_STYLE_FULL, - get_raw_module_location(&command->assert_invalid.module), - "expected module to be invalid"); + print_error( + &ctx, CHECK_STYLE_FULL, + wasm_get_raw_module_location(&command->assert_invalid.module), + "expected module to be invalid"); } } else if (command->type == WASM_COMMAND_TYPE_ASSERT_MALFORMED) { ctx2.error_handler = assert_malformed_error_handler; @@ -1480,9 +1497,10 @@ WasmResult wasm_check_assert_invalid_and_malformed( destroy_read_module(ctx.allocator, &read_module); wasm_destroy_context(&ctx2); if (WASM_SUCCEEDED(ctx2.result)) { - print_error(&ctx, CHECK_STYLE_FULL, - get_raw_module_location(&command->assert_malformed.module), - "expected module to be malformed"); + print_error( + &ctx, CHECK_STYLE_FULL, + wasm_get_raw_module_location(&command->assert_malformed.module), + "expected module to be malformed"); } } } |