diff options
author | Ben Smith <binjimin@gmail.com> | 2017-01-26 13:17:37 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 13:17:37 -0800 |
commit | 3556e8f9fb1f4dff4bd506fa4c2b764ac4e6aea0 (patch) | |
tree | bc89d4c5c5bb5c3f63dcbde14df80c95139d30e7 /src/binary-writer-spec.c | |
parent | 27e054f1fe4db13e02eaef649bb4bfe71b0efc68 (diff) | |
download | wabt-3556e8f9fb1f4dff4bd506fa4c2b764ac4e6aea0.tar.gz wabt-3556e8f9fb1f4dff4bd506fa4c2b764ac4e6aea0.tar.bz2 wabt-3556e8f9fb1f4dff4bd506fa4c2b764ac4e6aea0.zip |
Resolve names in assert_invalid modules (#293)
Names should be resolved in assert_invalid modules, even when running
wast2wasm with --no-check-assert-invalid-and-malformed.
* Add wasm_find_duplicate_bindings; this is a generic version of
check_duplicate_bindings, which was in resolve-names.c. The reason is
that in general, duplicated bindings will prevent name resolution, but
duplicated exports won't. So checking for duplicated exports belongs
in validator.c, not resolve-names.c.
* Add a new command type: ASSERT_INVALID_NON_BINARY. This is set if name
resolution cannot succeed, because that is the only case where a binary
module cannot be generated.
* When writing spec modules, always write the binary format to a memory
buffer even if the user specifies no output file. This way we can test
module writing errors more easily.
This fixes issue #292.
Diffstat (limited to 'src/binary-writer-spec.c')
-rw-r--r-- | src/binary-writer-spec.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/binary-writer-spec.c b/src/binary-writer-spec.c index 909b709b..7bd0f29d 100644 --- a/src/binary-writer-spec.c +++ b/src/binary-writer-spec.c @@ -139,6 +139,7 @@ static void write_command_type(Context* ctx, const WasmCommand* command) { "register", "assert_malformed", "assert_invalid", + NULL, /* ASSERT_INVALID_NON_BINARY, this command will never be written */ "assert_unlinkable", "assert_uninstantiable", "assert_return", @@ -150,6 +151,7 @@ static void write_command_type(Context* ctx, const WasmCommand* command) { WASM_NUM_COMMAND_TYPES); write_key(ctx, "type"); + assert(s_command_names[command->type] != NULL); write_string(ctx, s_command_names[command->type]); } @@ -292,16 +294,13 @@ static void write_action_result_type(Context* ctx, static void write_module(Context* ctx, char* filename, const WasmModule* module) { - if (!ctx->write_modules) - return; - WasmMemoryWriter writer; WasmResult result = wasm_init_mem_writer(ctx->allocator, &writer); if (WASM_SUCCEEDED(result)) { WasmWriteBinaryOptions options = ctx->spec_options->write_binary_options; result = wasm_write_binary_module(ctx->allocator, &writer.base, module, &options); - if (WASM_SUCCEEDED(result)) + if (WASM_SUCCEEDED(result) && ctx->write_modules) result = wasm_write_output_buffer_to_file(&writer.buf, filename); wasm_close_mem_writer(&writer); } @@ -312,12 +311,9 @@ static void write_module(Context* ctx, static void write_raw_module(Context* ctx, char* filename, const WasmRawModule* raw_module) { - if (!ctx->write_modules) - return; - if (raw_module->type == WASM_RAW_MODULE_TYPE_TEXT) { write_module(ctx, filename, raw_module->text); - } else { + } else if (ctx->write_modules) { WasmFileStream stream; WasmResult result = wasm_init_file_writer(&stream.writer, filename); if (WASM_SUCCEEDED(result)) { @@ -354,6 +350,13 @@ static void write_commands(Context* ctx, WasmScript* script) { for (i = 0; i < script->commands.size; ++i) { WasmCommand* command = &script->commands.data[i]; + if (command->type == WASM_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY) + continue; + + if (i != 0) + write_separator(ctx); + wasm_writef(&ctx->json_stream, "\n"); + wasm_writef(&ctx->json_stream, " {"); write_command_type(ctx, command); write_separator(ctx); @@ -459,15 +462,13 @@ static void write_commands(Context* ctx, WasmScript* script) { write_action(ctx, &command->assert_trap.action); break; + case WASM_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY: case WASM_NUM_COMMAND_TYPES: assert(0); break; } wasm_writef(&ctx->json_stream, "}"); - if (i != script->commands.size - 1) - write_separator(ctx); - wasm_writef(&ctx->json_stream, "\n"); } wasm_writef(&ctx->json_stream, "]}\n"); } |