diff options
90 files changed, 3074 insertions, 651 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 046a4192..eec482c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,6 @@ add_library(libwasm STATIC src/wasm-binary-writer.c src/wasm-binary-writer-spec.c src/wasm-binary-reader-ast.c - src/wasm-binary-reader-opcnt.c src/wasm-ast-writer.c src/wasm-binary-reader-interpreter.c src/wasm-interpreter.c @@ -236,10 +235,16 @@ if (NOT EMSCRIPTEN) target_link_libraries(wasm2wast libwasm) # wasmopcodecnt - add_executable(wasmopcodecnt src/wasmopcodecnt.c) + add_executable(wasmopcodecnt src/wasmopcodecnt.c + src/wasm-binary-reader-opcnt.c) add_dependencies(everything wasmopcodecnt) target_link_libraries(wasmopcodecnt libwasm) + # wasmdump + add_executable(wasmdump src/wasmdump.c src/wasm-binary-reader-objdump.c) + add_dependencies(everything wasmdump) + target_link_libraries(wasmdump libwasm) + if (NOT WIN32) add_custom_command( TARGET wast2wasm POST_BUILD @@ -32,7 +32,7 @@ COMPILERS := GCC GCC_I686 GCC_FUZZ CLANG EMSCRIPTEN BUILD_TYPES := DEBUG RELEASE SANITIZERS := ASAN MSAN LSAN UBSAN CONFIGS := NORMAL $(SANITIZERS) NO_RE2C_BISON NO_TESTS -EXECUTABLES := wast2wasm wasm2wast wasm-interp wasmopcodecnt hexfloat_test +EXECUTABLES := wast2wasm wasm2wast wasm-interp wasmopcodecnt hexfloat_test wasmdump # directory names GCC_DIR := gcc/ diff --git a/scripts/travis-common.sh b/scripts/travis-common.sh index 4d482df6..3f0f9baf 100644 --- a/scripts/travis-common.sh +++ b/scripts/travis-common.sh @@ -19,4 +19,4 @@ SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd -P)" ROOT_DIR="$(dirname "${SCRIPT_DIR}")" BUILD_TYPES="debug release" BUILD_TYPES_UPPER="Debug Release" -COMPILER="${CC}" +COMPILER="${CC:=clang}" diff --git a/src/wasm-binary-reader-ast.c b/src/wasm-binary-reader-ast.c index 796f42eb..33b19d7e 100644 --- a/src/wasm-binary-reader-ast.c +++ b/src/wasm-binary-reader-ast.c @@ -128,7 +128,8 @@ static WasmResult append_expr(Context* ctx, WasmExpr* expr) { static void handle_error(Context* ctx, uint32_t offset, const char* message) { if (ctx->error_handler->on_error) { - ctx->error_handler->on_error(offset, message, ctx->error_handler->user_data); + ctx->error_handler->on_error(offset, message, + ctx->error_handler->user_data); } } @@ -535,11 +536,11 @@ static WasmResult on_br_if_expr(uint32_t depth, void* user_data) { return append_expr(ctx, expr); } -static WasmResult on_br_table_expr(uint32_t num_targets, +static WasmResult on_br_table_expr(WasmBinaryReaderContext* context, + uint32_t num_targets, uint32_t* target_depths, - uint32_t default_target_depth, - void* user_data) { - Context* ctx = user_data; + uint32_t default_target_depth) { + Context* ctx = context->user_data; WasmExpr* expr = wasm_new_br_table_expr(ctx->allocator); wasm_reserve_vars(ctx->allocator, &expr->br_table.targets, num_targets); expr->br_table.targets.size = num_targets; @@ -574,7 +575,7 @@ static WasmResult on_call_indirect_expr(uint32_t sig_index, void* user_data) { static WasmResult on_compare_expr(WasmOpcode opcode, void* user_data) { Context* ctx = user_data; - WasmExpr *expr = wasm_new_compare_expr(ctx->allocator); + WasmExpr* expr = wasm_new_compare_expr(ctx->allocator); expr->compare.opcode = opcode; return append_expr(ctx, expr); } diff --git a/src/wasm-binary-reader-interpreter.c b/src/wasm-binary-reader-interpreter.c index bc18030c..3155d98f 100644 --- a/src/wasm-binary-reader-interpreter.c +++ b/src/wasm-binary-reader-interpreter.c @@ -320,8 +320,7 @@ static WasmResult emit_func_offset(Context* ctx, return WASM_OK; } -static void on_error(WasmBinaryReaderContext* ctx, - const char* message) { +static void on_error(WasmBinaryReaderContext* ctx, const char* message) { handle_error(ctx->offset, message, ctx->user_data); } @@ -510,8 +509,7 @@ static WasmResult on_init_expr_get_global_expr(uint32_t index, void* user_data) { Context* ctx = user_data; assert(global_index < ctx->module->globals.size); - WasmInterpreterGlobal* ref_global = - &ctx->module->globals.data[global_index]; + WasmInterpreterGlobal* ref_global = &ctx->module->globals.data[global_index]; ctx->init_expr_value = ref_global->typed_value; return WASM_OK; } @@ -719,8 +717,8 @@ static WasmResult check_n_types(Context* ctx, for (i = 0; i < expected->size; ++i) { WasmType actual = ctx->type_stack.data[ctx->type_stack.size - expected->size + i]; - CHECK_RESULT(check_type(ctx, expected->data[expected->size - i - 1], - actual, desc)); + CHECK_RESULT( + check_type(ctx, expected->data[expected->size - i - 1], actual, desc)); } return WASM_OK; } @@ -1049,11 +1047,11 @@ static WasmResult on_br_if_expr(uint32_t depth, void* user_data) { return WASM_OK; } -static WasmResult on_br_table_expr(uint32_t num_targets, +static WasmResult on_br_table_expr(WasmBinaryReaderContext* context, + uint32_t num_targets, uint32_t* target_depths, - uint32_t default_target_depth, - void* user_data) { - Context* ctx = user_data; + uint32_t default_target_depth) { + Context* ctx = context->user_data; CHECK_RESULT(pop_and_check_1_type(ctx, WASM_TYPE_I32, "br_table")); CHECK_RESULT(emit_opcode(ctx, WASM_OPCODE_BR_TABLE)); CHECK_RESULT(emit_i32(ctx, num_targets)); diff --git a/src/wasm-binary-reader-objdump.c b/src/wasm-binary-reader-objdump.c new file mode 100644 index 00000000..c940b227 --- /dev/null +++ b/src/wasm-binary-reader-objdump.c @@ -0,0 +1,434 @@ +/* + * Copyright 2016 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wasm-binary-reader-objdump.h" + +#include <assert.h> +#include <string.h> +#include <stdio.h> + +#include "wasm-binary-reader.h" + +typedef struct Context { + const WasmObjdumpOptions* options; + WasmStream* out_stream; + const uint8_t* data; + size_t size; + WasmOpcode current_opcode; + size_t current_opcode_offset; + size_t last_opcode_end; + int indent_level; +} Context; + +static void WASM_PRINTF_FORMAT(2, 3) + print_details(Context* ctx, const char* fmt, ...) { + if (!ctx->options->verbose) + return; + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +#define SEGSTART(segname, name) \ + static WasmResult begin_##segname##_section(WasmBinaryReaderContext* ctx, \ + uint32_t size) { \ + return begin_section(ctx->user_data, name, ctx->offset, size); \ + } + +static WasmResult begin_section(Context* ctx, + const char* name, + size_t offset, + size_t size) { + if (ctx->options->headers) { + printf("%-12s start=%#010" PRIzx " end=%#010" PRIzx " (size=%#010" PRIzx + ")\n", + name, offset, offset + size, size); + } + if (ctx->options->raw) { + printf("\n"); + wasm_write_memory_dump(ctx->out_stream, ctx->data + offset, size, offset, + WASM_PRINT_CHARS, NULL); + } + return WASM_OK; +} + +SEGSTART(signature, "TYPE") +SEGSTART(import, "IMPORT") +SEGSTART(function_signatures, "FUNCTION") +SEGSTART(table, "TABLE") +SEGSTART(memory, "MEMORY") +SEGSTART(global, "GLOBAL") +SEGSTART(export, "EXPORT") +SEGSTART(start, "START") +SEGSTART(function_bodies, "CODE") +SEGSTART(elem, "ELEM") +SEGSTART(data, "DATA") +SEGSTART(names, "NAMES") + +static WasmResult on_count(uint32_t count, void* user_data) { + Context* ctx = user_data; + print_details(ctx, " - count: %d\n", count); + return WASM_OK; +} + +static WasmResult on_opcode(WasmBinaryReaderContext* ctx, WasmOpcode opcode) { + Context* context = ctx->user_data; + + if (context->options->debug) { + const char* opcode_name = wasm_get_opcode_name(opcode); + printf("on_opcode: %#" PRIzx ": %s\n", ctx->offset, opcode_name); + } + + if (context->last_opcode_end) { + if (ctx->offset != context->last_opcode_end + 1) { + uint8_t missing_opcode = ctx->data[context->last_opcode_end]; + const char* opcode_name = wasm_get_opcode_name(missing_opcode); + fprintf(stderr, "warning: %#" PRIzx " missing opcode callback at %#" PRIzx + " (%#02x=%s)\n", + ctx->offset, context->last_opcode_end + 1, + ctx->data[context->last_opcode_end], opcode_name); + return WASM_ERROR; + } + } + + context->current_opcode_offset = ctx->offset; + context->current_opcode = opcode; + return WASM_OK; +} + +#define IMMEDIATE_OCTET_COUNT 9 + +static void log_opcode(Context* ctx, + const uint8_t* data, + size_t data_size, + const char* fmt, + ...) { + size_t offset = ctx->current_opcode_offset; + + // Print binary data + printf(" %06zx: %02x", offset - 1, ctx->current_opcode); + size_t i; + for (i = 0; i < data_size && i < IMMEDIATE_OCTET_COUNT; i++, offset++) { + printf(" %02x", data[offset]); + } + for (i = data_size + 1; i < IMMEDIATE_OCTET_COUNT; i++) { + printf(" "); + } + printf(" | "); + + // Print disassemble + int j; + int indent_level = ctx->indent_level; + if (ctx->current_opcode == WASM_OPCODE_ELSE) + indent_level--; + for (j = 0; j < indent_level; j++) { + printf(" "); + } + + const char* opcode_name = wasm_get_opcode_name(ctx->current_opcode); + printf("%s", opcode_name); + if (fmt) { + printf(" "); + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + } + + printf("\n"); + + ctx->last_opcode_end = ctx->current_opcode_offset + data_size; +} + +static WasmResult on_opcode_bare(WasmBinaryReaderContext* ctx) { + Context* context = ctx->user_data; + log_opcode(context, ctx->data, 0, NULL); + return WASM_OK; +} + +static WasmResult on_opcode_uint32(WasmBinaryReaderContext* ctx, + uint32_t value) { + Context* context = ctx->user_data; + size_t immediate_len = ctx->offset - context->current_opcode_offset; + log_opcode(context, ctx->data, immediate_len, "%#x", value); + return WASM_OK; +} + +static WasmResult on_opcode_uint32_uint32(WasmBinaryReaderContext* ctx, + uint32_t value, + uint32_t value2) { + Context* context = ctx->user_data; + size_t immediate_len = ctx->offset - context->current_opcode_offset; + log_opcode(context, ctx->data, immediate_len, "%lu %lu", value, value2); + return WASM_OK; +} + +static WasmResult on_opcode_uint64(WasmBinaryReaderContext* ctx, + uint64_t value) { + Context* context = ctx->user_data; + size_t immediate_len = ctx->offset - context->current_opcode_offset; + log_opcode(context, ctx->data, immediate_len, "%d", value); + return WASM_OK; +} + +WasmResult on_br_table_expr(WasmBinaryReaderContext* ctx, + uint32_t num_targets, + uint32_t* target_depths, + uint32_t default_target_depth) { + Context* context = ctx->user_data; + size_t immediate_len = ctx->offset - context->current_opcode_offset; + /* TODO(sbc): Print targets */ + log_opcode(context, ctx->data, immediate_len, NULL); + return WASM_OK; +} + +static WasmResult on_end_expr(void* user_data) { + Context* context = user_data; + context->indent_level--; + assert(context->indent_level >= 0); + log_opcode(context, NULL, 0, NULL); + return WASM_OK; +} + +static const char* wasm_type_name(WasmType type) { + switch (type) { + case WASM_TYPE_I32: + return "i32"; + + case WASM_TYPE_I64: + return "i64"; + + case WASM_TYPE_F32: + return "f32"; + + case WASM_TYPE_F64: + return "f64"; + + default: + assert(0); + return "INVALID TYPE"; + } +} + +static WasmResult on_opcode_block_sig(WasmBinaryReaderContext* ctx, + uint32_t num_types, + WasmType* sig_types) { + Context* context = ctx->user_data; + if (num_types) + log_opcode(context, ctx->data, 1, "%s", wasm_type_name(*sig_types)); + else + log_opcode(context, ctx->data, 1, NULL); + context->indent_level++; + return WASM_OK; +} + +static WasmResult on_signature(uint32_t index, + uint32_t param_count, + WasmType* param_types, + uint32_t result_count, + WasmType* result_types, + void* user_data) { + Context* ctx = user_data; + + if (!ctx->options->verbose) + return WASM_OK; + printf(" - [%d] (", index); + uint32_t i; + for (i = 0; i < param_count; i++) { + if (i != 0) { + printf(", "); + } + printf("%s", wasm_type_name(param_types[i])); + } + printf(") -> "); + if (result_count) + printf("%s", wasm_type_name(result_types[0])); + else + printf("nil"); + printf("\n"); + return WASM_OK; +} + +static WasmResult on_function_signature(uint32_t index, + uint32_t sig_index, + void* user_data) { + print_details(user_data, " - [%d] sig=%d\n", index, sig_index); + return WASM_OK; +} + +static WasmResult begin_function_body(uint32_t index, void* user_data) { + Context* ctx = user_data; + if (ctx->options->verbose || ctx->options->disassemble) + printf("func %d\n", index); + ctx->last_opcode_end = 0; + return WASM_OK; +} + +static WasmResult on_import_func(uint32_t index, + uint32_t sig_index, + void* user_data) { + print_details(user_data, "- func sig=%d\n", sig_index); + return WASM_OK; +} + +static WasmResult on_import_table(uint32_t index, + uint32_t elem_type, + const WasmLimits* elem_limits, + void* user_data) { + /* TODO(sbc): print more useful information about the table here */ + print_details(user_data, "- table elem_type=%d\n", elem_type); + return WASM_OK; +} + +static WasmResult on_import_memory(uint32_t index, + const WasmLimits* page_limits, + void* user_data) { + print_details(user_data, "- memory\n"); + return WASM_OK; +} + +static WasmResult on_import_global(uint32_t index, + WasmType type, + WasmBool mutable_, + void* user_data) { + print_details(user_data, "- global\n"); + return WASM_OK; +} + +static WasmResult on_memory(uint32_t index, + const WasmLimits* page_limits, + void* user_data) { + print_details(user_data, "- memory %d\n", index); + return WASM_OK; +} + +static WasmResult on_table(uint32_t index, + uint32_t elem_type, + const WasmLimits* elem_limits, + void* user_data) { + print_details(user_data, "- table %d\n", index); + return WASM_OK; +} + +static WasmResult on_export(uint32_t index, + WasmExternalKind kind, + uint32_t item_index, + WasmStringSlice name, + void* user_data) { + print_details(user_data, " - [%d] %s ", item_index, wasm_get_kind_name(kind)); + print_details(user_data, PRIstringslice, WASM_PRINTF_STRING_SLICE_ARG(name)); + print_details(user_data, "\n"); + return WASM_OK; +} + +static void on_error(WasmBinaryReaderContext* ctx, const char* message) { + wasm_default_binary_error_callback(ctx->offset, message, ctx->user_data); +} + +static WasmBinaryReader s_binary_reader = { + .user_data = NULL, + .on_error = on_error, + + // Signature sections + .begin_signature_section = begin_signature_section, + .on_signature_count = on_count, + .on_signature = on_signature, + + // Import section + .begin_import_section = begin_import_section, + .on_import_count = on_count, + .on_import_func = on_import_func, + .on_import_table = on_import_table, + .on_import_memory = on_import_memory, + .on_import_global = on_import_global, + + // Function sigs section + .begin_function_signatures_section = begin_function_signatures_section, + .on_function_signatures_count = on_count, + .on_function_signature = on_function_signature, + + // Table section + .begin_table_section = begin_table_section, + .on_table_count = on_count, + .on_table = on_table, + + // Memory section + .begin_memory_section = begin_memory_section, + .on_memory_count = on_count, + .on_memory = on_memory, + + // Globl seciont + .begin_global_section = begin_global_section, + .on_global_count = on_count, + + // Export section + .begin_export_section = begin_export_section, + .on_export_count = on_count, + .on_export = on_export, + + // Start section + .begin_start_section = begin_start_section, + + // Body section + .begin_function_bodies_section = begin_function_bodies_section, + .on_function_bodies_count = on_count, + .begin_function_body = begin_function_body, + + // Elems section + .begin_elem_section = begin_elem_section, + .on_elem_segment_count = on_count, + + // Data section + .begin_data_section = begin_data_section, + .on_data_segment_count = on_count, + + // Names section + .begin_names_section = begin_names_section, + .on_function_names_count = on_count, +}; + +WasmResult wasm_read_binary_objdump(struct WasmAllocator* allocator, + const uint8_t* data, + size_t size, + const WasmObjdumpOptions* options) { + WasmBinaryReader reader; + WASM_ZERO_MEMORY(reader); + reader = s_binary_reader; + Context context; + WASM_ZERO_MEMORY(context); + context.data = data; + context.size = size; + context.options = options; + context.out_stream = wasm_init_stdout_stream(); + + if (options->disassemble) { + reader.on_opcode = on_opcode; + reader.on_opcode_bare = on_opcode_bare; + reader.on_opcode_uint32 = on_opcode_uint32; + reader.on_opcode_uint32_uint32 = on_opcode_uint32_uint32; + reader.on_opcode_uint64 = on_opcode_uint64; + reader.on_opcode_block_sig = on_opcode_block_sig; + reader.on_end_expr = on_end_expr; + reader.on_br_table_expr = on_br_table_expr; + } + + reader.user_data = &context; + WasmReadBinaryOptions read_options = WASM_READ_BINARY_OPTIONS_DEFAULT; + read_options.read_debug_names = WASM_TRUE; + + return wasm_read_binary(allocator, data, size, &reader, 1, &read_options); +} diff --git a/src/wasm-binary-reader-objdump.h b/src/wasm-binary-reader-objdump.h new file mode 100644 index 00000000..c0318f14 --- /dev/null +++ b/src/wasm-binary-reader-objdump.h @@ -0,0 +1,43 @@ +/* + * Copyright 2016 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WASM_BINARY_READER_OBJDUMP_H_ +#define WASM_BINARY_READER_OBJDUMP_H_ + +#include "wasm-common.h" +#include "wasm-stream.h" + +struct WasmAllocator; +struct WasmModule; +struct WasmReadBinaryOptions; + +typedef struct WasmObjdumpOptions { + WasmBool headers; + WasmBool verbose; + WasmBool raw; + WasmBool disassemble; + WasmBool debug; +} WasmObjdumpOptions; + +WASM_EXTERN_C_BEGIN +WasmResult wasm_read_binary_objdump(struct WasmAllocator* allocator, + const uint8_t* data, + size_t size, + const WasmObjdumpOptions* options); + +WASM_EXTERN_C_END + +#endif /* WASM_BINARY_READER_OBJDUMP_H_ */ diff --git a/src/wasm-binary-reader.c b/src/wasm-binary-reader.c index b9d40262..378f5927 100644 --- a/src/wasm-binary-reader.c +++ b/src/wasm-binary-reader.c @@ -43,19 +43,19 @@ typedef uint32_t Uint32; WASM_DEFINE_VECTOR(type, WasmType) WASM_DEFINE_VECTOR(uint32, Uint32); -#define CALLBACK_CTX(member, ...) \ - RAISE_ERROR_UNLESS( \ - WASM_SUCCEEDED( \ - ctx->reader->member \ - ? ctx->reader->member(get_user_context(ctx), __VA_ARGS__)\ - : WASM_OK), \ +#define CALLBACK_CTX(member, ...) \ + RAISE_ERROR_UNLESS( \ + WASM_SUCCEEDED( \ + ctx->reader->member \ + ? ctx->reader->member(get_user_context(ctx), __VA_ARGS__) \ + : WASM_OK), \ #member " callback failed") -#define CALLBACK_CTX0(member) \ - RAISE_ERROR_UNLESS( \ - WASM_SUCCEEDED(ctx->reader->member \ - ? ctx->reader->member(get_user_context(ctx)) \ - : WASM_OK), \ +#define CALLBACK_CTX0(member) \ + RAISE_ERROR_UNLESS( \ + WASM_SUCCEEDED(ctx->reader->member \ + ? ctx->reader->member(get_user_context(ctx)) \ + : WASM_OK), \ #member " callback failed") #define CALLBACK_SECTION(member) CALLBACK_CTX(member, section_size) @@ -79,16 +79,18 @@ WASM_DEFINE_VECTOR(uint32, Uint32); return ctx->reader->member ? ctx->reader->member(ctx->reader->user_data) \ : WASM_OK -#define FORWARD_CTX0(member) \ - if (!ctx->reader->member) return WASM_OK; \ - WasmBinaryReaderContext new_ctx = *reader_context;\ - new_ctx.user_data = ctx->reader->user_data; \ +#define FORWARD_CTX0(member) \ + if (!ctx->reader->member) \ + return WASM_OK; \ + WasmBinaryReaderContext new_ctx = *context; \ + new_ctx.user_data = ctx->reader->user_data; \ return ctx->reader->member(&new_ctx); -#define FORWARD_CTX(member, ...) \ - if (!ctx->reader->member) return WASM_OK; \ - WasmBinaryReaderContext new_ctx = *reader_context;\ - new_ctx.user_data = ctx->reader->user_data; \ +#define FORWARD_CTX(member, ...) \ + if (!ctx->reader->member) \ + return WASM_OK; \ + WasmBinaryReaderContext new_ctx = *context; \ + new_ctx.user_data = ctx->reader->user_data; \ return ctx->reader->member(&new_ctx, __VA_ARGS__); #define FORWARD(member, ...) \ @@ -110,11 +112,6 @@ WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_type_names) == WASM_NUM_TYPES); static const char* s_section_name[] = {WASM_FOREACH_BINARY_SECTION(V)}; #undef V -static const char* s_external_kind_name[] = {"func", "table", "memory", - "global"}; -WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_external_kind_name) == - WASM_NUM_EXTERNAL_KINDS); - typedef struct Context { const uint8_t* data; size_t size; @@ -400,8 +397,7 @@ static uint32_t num_total_globals(Context* ctx) { static WasmBool handle_unknown_section(Context* ctx, WasmStringSlice* section_name, uint32_t section_size) { - if (ctx->options->read_debug_names && - ctx->name_section_ok && + if (ctx->options->read_debug_names && ctx->name_section_ok && strncmp(section_name->start, WASM_BINARY_SECTION_NAME, section_name->length) == 0) { CALLBACK_SECTION(begin_names_section); @@ -482,7 +478,6 @@ static void destroy_context(WasmAllocator* allocator, Context* ctx) { wasm_destroy_uint32_vector(allocator, &ctx->target_depths); } - /* Logging */ static void indent(LoggingContext* ctx) { @@ -526,20 +521,21 @@ static void logging_on_error(WasmBinaryReaderContext* ctx, } } -#define LOGGING_BEGIN(name) \ - static WasmResult logging_begin_##name(WasmBinaryReaderContext* reader_context, uint32_t size) { \ - LoggingContext* ctx = reader_context->user_data; \ - LOGF("begin_" #name "\n"); \ - indent(ctx); \ - FORWARD_CTX(begin_##name, size); \ +#define LOGGING_BEGIN(name) \ + static WasmResult logging_begin_##name(WasmBinaryReaderContext* context, \ + uint32_t size) { \ + LoggingContext* ctx = context->user_data; \ + LOGF("begin_" #name "\n"); \ + indent(ctx); \ + FORWARD_CTX(begin_##name, size); \ } -#define LOGGING_END(name) \ - static WasmResult logging_end_##name(WasmBinaryReaderContext* reader_context) { \ - LoggingContext* ctx = reader_context->user_data; \ - dedent(ctx); \ - LOGF("end_" #name "\n"); \ - FORWARD_CTX0(end_##name); \ +#define LOGGING_END(name) \ + static WasmResult logging_end_##name(WasmBinaryReaderContext* context) { \ + LoggingContext* ctx = context->user_data; \ + dedent(ctx); \ + LOGF("end_" #name "\n"); \ + FORWARD_CTX0(end_##name); \ } #define LOGGING_UINT32(name) \ @@ -782,7 +778,7 @@ static WasmResult logging_on_export(uint32_t index, LoggingContext* ctx = user_data; LOGF("on_export(index: %u, kind: %s, item_index: %u, name: \"" PRIstringslice "\")\n", - index, s_external_kind_name[kind], item_index, + index, wasm_get_kind_name(kind), item_index, WASM_PRINTF_STRING_SLICE_ARG(name)); FORWARD(on_export, index, kind, item_index, name); } @@ -828,11 +824,11 @@ static WasmResult logging_on_br_if_expr(uint32_t depth, void* user_data) { FORWARD(on_br_if_expr, depth); } -static WasmResult logging_on_br_table_expr(uint32_t num_targets, +static WasmResult logging_on_br_table_expr(WasmBinaryReaderContext* context, + uint32_t num_targets, uint32_t* target_depths, - uint32_t default_target_depth, - void* user_data) { - LoggingContext* ctx = user_data; + uint32_t default_target_depth) { + LoggingContext* ctx = context->user_data; LOGF("on_br_table_expr(num_targets: %u, depths: [", num_targets); uint32_t i; for (i = 0; i < num_targets; ++i) { @@ -841,7 +837,8 @@ static WasmResult logging_on_br_table_expr(uint32_t num_targets, LOGF_NOINDENT(", "); } LOGF_NOINDENT("], default: %u)\n", default_target_depth); - FORWARD(on_br_table_expr, num_targets, target_depths, default_target_depth); + FORWARD_CTX(on_br_table_expr, num_targets, target_depths, + default_target_depth); } static WasmResult logging_on_f32_const_expr(uint32_t value_bits, @@ -1245,6 +1242,7 @@ static void read_function_body(Context* ctx, switch (opcode) { case WASM_OPCODE_UNREACHABLE: CALLBACK0(on_unreachable_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_BLOCK: { @@ -1254,6 +1252,7 @@ static void read_function_body(Context* ctx, "expected valid block signature type"); uint32_t num_types = sig_type == WASM_TYPE_VOID ? 0 : 1; CALLBACK(on_block_expr, num_types, &sig_type); + CALLBACK_CTX(on_opcode_block_sig, num_types, &sig_type); break; } @@ -1264,6 +1263,7 @@ static void read_function_body(Context* ctx, "expected valid block signature type"); uint32_t num_types = sig_type == WASM_TYPE_VOID ? 0 : 1; CALLBACK(on_loop_expr, num_types, &sig_type); + CALLBACK_CTX(on_opcode_block_sig, num_types, &sig_type); break; } @@ -1274,21 +1274,25 @@ static void read_function_body(Context* ctx, "expected valid block signature type"); uint32_t num_types = sig_type == WASM_TYPE_VOID ? 0 : 1; CALLBACK(on_if_expr, num_types, &sig_type); + CALLBACK_CTX(on_opcode_block_sig, num_types, &sig_type); break; } case WASM_OPCODE_ELSE: CALLBACK0(on_else_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_SELECT: CALLBACK0(on_select_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_BR: { uint32_t depth; in_u32_leb128(ctx, &depth, "br depth"); CALLBACK(on_br_expr, depth); + CALLBACK_CTX(on_opcode_uint32, depth); break; } @@ -1296,6 +1300,7 @@ static void read_function_body(Context* ctx, uint32_t depth; in_u32_leb128(ctx, &depth, "br_if depth"); CALLBACK(on_br_if_expr, depth); + CALLBACK_CTX(on_opcode_uint32, depth); break; } @@ -1303,8 +1308,7 @@ static void read_function_body(Context* ctx, uint32_t num_targets; in_u32_leb128(ctx, &num_targets, "br_table target count"); if (num_targets > ctx->target_depths.capacity) { - wasm_reserve_uint32s(allocator, &ctx->target_depths, - num_targets); + wasm_reserve_uint32s(allocator, &ctx->target_depths, num_targets); ctx->target_depths.size = num_targets; } @@ -1319,21 +1323,24 @@ static void read_function_body(Context* ctx, in_u32_leb128(ctx, &default_target_depth, "br_table default target depth"); - CALLBACK(on_br_table_expr, num_targets, ctx->target_depths.data, - default_target_depth); + CALLBACK_CTX(on_br_table_expr, num_targets, ctx->target_depths.data, + default_target_depth); break; } case WASM_OPCODE_RETURN: CALLBACK0(on_return_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_NOP: CALLBACK0(on_nop_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_DROP: CALLBACK0(on_drop_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_END: @@ -1347,6 +1354,7 @@ static void read_function_body(Context* ctx, uint32_t value = 0; in_i32_leb128(ctx, &value, "i32.const value"); CALLBACK(on_i32_const_expr, value); + CALLBACK_CTX(on_opcode_uint32, value); break; } @@ -1354,6 +1362,7 @@ static void read_function_body(Context* ctx, uint64_t value = 0; in_i64_leb128(ctx, &value, "i64.const value"); CALLBACK(on_i64_const_expr, value); + CALLBACK_CTX(on_opcode_uint64, value); break; } @@ -1361,6 +1370,7 @@ static void read_function_body(Context* ctx, uint32_t value_bits = 0; in_f32(ctx, &value_bits, "f32.const value"); CALLBACK(on_f32_const_expr, value_bits); + CALLBACK_CTX(on_opcode_uint32, value_bits); break; } @@ -1368,6 +1378,7 @@ static void read_function_body(Context* ctx, uint64_t value_bits = 0; in_f64(ctx, &value_bits, "f64.const value"); CALLBACK(on_f64_const_expr, value_bits); + CALLBACK_CTX(on_opcode_uint64, value_bits); break; } @@ -1375,6 +1386,7 @@ static void read_function_body(Context* ctx, uint32_t global_index; in_u32_leb128(ctx, &global_index, "get_global global index"); CALLBACK(on_get_global_expr, global_index); + CALLBACK_CTX(on_opcode_uint32, global_index); break; } @@ -1382,6 +1394,7 @@ static void read_function_body(Context* ctx, uint32_t local_index; in_u32_leb128(ctx, &local_index, "get_local local index"); CALLBACK(on_get_local_expr, local_index); + CALLBACK_CTX(on_opcode_uint32, local_index); break; } @@ -1389,6 +1402,7 @@ static void read_function_body(Context* ctx, uint32_t global_index; in_u32_leb128(ctx, &global_index, "set_global global index"); CALLBACK(on_set_global_expr, global_index); + CALLBACK_CTX(on_opcode_uint32, global_index); break; } @@ -1396,6 +1410,7 @@ static void read_function_body(Context* ctx, uint32_t local_index; in_u32_leb128(ctx, &local_index, "set_local local index"); CALLBACK(on_set_local_expr, local_index); + CALLBACK_CTX(on_opcode_uint32, local_index); break; } @@ -1405,6 +1420,7 @@ static void read_function_body(Context* ctx, RAISE_ERROR_UNLESS(func_index < num_total_funcs(ctx), "invalid call_function function index"); CALLBACK(on_call_expr, func_index); + CALLBACK_CTX(on_opcode_uint32, func_index); break; } @@ -1414,6 +1430,7 @@ static void read_function_body(Context* ctx, RAISE_ERROR_UNLESS(sig_index < ctx->num_signatures, "invalid call_indirect signature index"); CALLBACK(on_call_indirect_expr, sig_index); + CALLBACK_CTX(on_opcode_uint32, sig_index); break; } @@ -1421,6 +1438,7 @@ static void read_function_body(Context* ctx, uint32_t local_index; in_u32_leb128(ctx, &local_index, "tee_local local index"); CALLBACK(on_tee_local_expr, local_index); + CALLBACK_CTX(on_opcode_uint32, local_index); break; } @@ -1444,6 +1462,7 @@ static void read_function_body(Context* ctx, in_u32_leb128(ctx, &offset, "load offset"); CALLBACK(on_load_expr, opcode, alignment_log2, offset); + CALLBACK_CTX(on_opcode_uint32_uint32, alignment_log2, offset); break; } @@ -1462,15 +1481,18 @@ static void read_function_body(Context* ctx, in_u32_leb128(ctx, &offset, "store offset"); CALLBACK(on_store_expr, opcode, alignment_log2, offset); + CALLBACK_CTX(on_opcode_uint32_uint32, alignment_log2, offset); break; } case WASM_OPCODE_CURRENT_MEMORY: CALLBACK0(on_current_memory_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_GROW_MEMORY: CALLBACK0(on_grow_memory_expr); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_I32_ADD: @@ -1518,6 +1540,7 @@ static void read_function_body(Context* ctx, case WASM_OPCODE_F64_MAX: case WASM_OPCODE_F64_COPYSIGN: CALLBACK(on_binary_expr, opcode); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_I32_EQ: @@ -1553,6 +1576,7 @@ static void read_function_body(Context* ctx, case WASM_OPCODE_F64_GT: case WASM_OPCODE_F64_GE: CALLBACK(on_compare_expr, opcode); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_I32_CLZ: @@ -1576,6 +1600,7 @@ static void read_function_body(Context* ctx, case WASM_OPCODE_F64_NEAREST: case WASM_OPCODE_F64_SQRT: CALLBACK(on_unary_expr, opcode); + CALLBACK_CTX0(on_opcode_bare); break; case WASM_OPCODE_I32_TRUNC_S_F32: @@ -1606,6 +1631,7 @@ static void read_function_body(Context* ctx, case WASM_OPCODE_I32_EQZ: case WASM_OPCODE_I64_EQZ: CALLBACK(on_convert_expr, opcode); + CALLBACK_CTX0(on_opcode_bare); break; default: @@ -1614,8 +1640,7 @@ static void read_function_body(Context* ctx, } RAISE_ERROR_UNLESS(ctx->offset == end_offset, "function body longer than given size"); - RAISE_ERROR_UNLESS(seen_end_opcode, - "function body must end with END opcode"); + RAISE_ERROR_UNLESS(seen_end_opcode, "function body must end with END opcode"); } WasmResult wasm_read_binary(WasmAllocator* allocator, @@ -1659,8 +1684,8 @@ WasmResult wasm_read_binary(WasmAllocator* allocator, uint32_t version; in_u32(ctx, &version, "version"); RAISE_ERROR_UNLESS(version == WASM_BINARY_VERSION, - "bad wasm file version: %#x (expected %#x)", - version, WASM_BINARY_VERSION); + "bad wasm file version: %#x (expected %#x)", version, + WASM_BINARY_VERSION); /* type */ uint32_t section_size; @@ -1763,7 +1788,6 @@ WasmResult wasm_read_binary(WasmAllocator* allocator, default: RAISE_ERROR("invalid import kind: %d", kind); } - } CALLBACK_CTX0(end_import_section); } @@ -1912,8 +1936,7 @@ WasmResult wasm_read_binary(WasmAllocator* allocator, uint32_t j, num_function_indexes; in_u32_leb128(ctx, &num_function_indexes, "elem segment function index count"); - CALLBACK(on_elem_segment_function_index_count, i, - num_function_indexes); + CALLBACK(on_elem_segment_function_index_count, i, num_function_indexes); for (j = 0; j < num_function_indexes; ++j) { uint32_t func_index; in_u32_leb128(ctx, &func_index, "elem segment function index"); diff --git a/src/wasm-binary-reader.h b/src/wasm-binary-reader.h index 35874386..3dcc576e 100644 --- a/src/wasm-binary-reader.h +++ b/src/wasm-binary-reader.h @@ -51,7 +51,8 @@ typedef struct WasmBinaryReader { /* signatures section */ /* TODO(binji): rename to "type" section */ - WasmResult (*begin_signature_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_signature_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_signature_count)(uint32_t count, void* user_data); WasmResult (*on_signature)(uint32_t index, uint32_t param_count, @@ -62,7 +63,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_signature_section)(WasmBinaryReaderContext* ctx); /* import section */ - WasmResult (*begin_import_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_import_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_import_count)(uint32_t count, void* user_data); WasmResult (*on_import)(uint32_t index, WasmStringSlice module_name, @@ -86,7 +88,8 @@ typedef struct WasmBinaryReader { /* function signatures section */ /* TODO(binji): rename to "function" section */ - WasmResult (*begin_function_signatures_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_function_signatures_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_function_signatures_count)(uint32_t count, void* user_data); WasmResult (*on_function_signature)(uint32_t index, uint32_t sig_index, @@ -94,7 +97,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_function_signatures_section)(WasmBinaryReaderContext* ctx); /* table section */ - WasmResult (*begin_table_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_table_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_table_count)(uint32_t count, void* user_data); WasmResult (*on_table)(uint32_t index, uint32_t elem_type, @@ -103,7 +107,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_table_section)(WasmBinaryReaderContext* ctx); /* memory section */ - WasmResult (*begin_memory_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_memory_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_memory_count)(uint32_t count, void* user_data); WasmResult (*on_memory)(uint32_t index, const WasmLimits* limits, @@ -111,7 +116,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_memory_section)(WasmBinaryReaderContext* ctx); /* global section */ - WasmResult (*begin_global_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_global_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_global_count)(uint32_t count, void* user_data); WasmResult (*begin_global)(uint32_t index, WasmType type, @@ -123,7 +129,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_global_section)(WasmBinaryReaderContext* ctx); /* exports section */ - WasmResult (*begin_export_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_export_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_export_count)(uint32_t count, void* user_data); WasmResult (*on_export)(uint32_t index, WasmExternalKind kind, @@ -133,13 +140,15 @@ typedef struct WasmBinaryReader { WasmResult (*end_export_section)(WasmBinaryReaderContext* ctx); /* start section */ - WasmResult (*begin_start_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_start_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_start_function)(uint32_t func_index, void* user_data); WasmResult (*end_start_section)(WasmBinaryReaderContext* ctx); /* function bodies section */ /* TODO(binji): rename to code section */ - WasmResult (*begin_function_bodies_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_function_bodies_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_function_bodies_count)(uint32_t count, void* user_data); WasmResult (*begin_function_body_pass)(uint32_t index, uint32_t pass, @@ -154,16 +163,25 @@ typedef struct WasmBinaryReader { /* function expressions; called between begin_function_body and end_function_body */ WasmResult (*on_opcode)(WasmBinaryReaderContext* ctx, WasmOpcode Opcode); + WasmResult (*on_opcode_bare)(WasmBinaryReaderContext* ctx); + WasmResult (*on_opcode_uint32)(WasmBinaryReaderContext* ctx, uint32_t value); + WasmResult (*on_opcode_uint32_uint32)(WasmBinaryReaderContext* ctx, + uint32_t value, + uint32_t value2); + WasmResult (*on_opcode_uint64)(WasmBinaryReaderContext* ctx, uint64_t value); + WasmResult (*on_opcode_block_sig)(WasmBinaryReaderContext* ctx, + uint32_t num_types, + WasmType* sig_types); WasmResult (*on_binary_expr)(WasmOpcode opcode, void* user_data); WasmResult (*on_block_expr)(uint32_t num_types, WasmType* sig_types, void* user_data); WasmResult (*on_br_expr)(uint32_t depth, void* user_data); WasmResult (*on_br_if_expr)(uint32_t depth, void* user_data); - WasmResult (*on_br_table_expr)(uint32_t num_targets, + WasmResult (*on_br_table_expr)(WasmBinaryReaderContext* ctx, + uint32_t num_targets, uint32_t* target_depths, - uint32_t default_target_depth, - void* user_data); + uint32_t default_target_depth); WasmResult (*on_call_expr)(uint32_t func_index, void* user_data); WasmResult (*on_call_import_expr)(uint32_t import_index, void* user_data); WasmResult (*on_call_indirect_expr)(uint32_t sig_index, void* user_data); @@ -241,7 +259,8 @@ typedef struct WasmBinaryReader { WasmResult (*end_data_section)(WasmBinaryReaderContext* ctx); /* names section */ - WasmResult (*begin_names_section)(WasmBinaryReaderContext* ctx, uint32_t size); + WasmResult (*begin_names_section)(WasmBinaryReaderContext* ctx, + uint32_t size); WasmResult (*on_function_names_count)(uint32_t count, void* user_data); WasmResult (*on_function_name)(uint32_t index, WasmStringSlice name, diff --git a/src/wasm-common.c b/src/wasm-common.c index 9a70e6f1..1df2e335 100644 --- a/src/wasm-common.c +++ b/src/wasm-common.c @@ -34,10 +34,13 @@ WasmOpcodeInfo g_wasm_opcode_info[] = {WASM_FOREACH_OPCODE(V)}; #undef V +const char* g_wasm_kind_name[] = {"func", "table", "memory", "global"}; +WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(g_wasm_kind_name) == + WASM_NUM_EXTERNAL_KINDS); + WasmBool wasm_is_naturally_aligned(WasmOpcode opcode, uint32_t alignment) { uint32_t opcode_align = wasm_get_opcode_memory_size(opcode); - return alignment == WASM_USE_NATURAL_ALIGNMENT || - alignment == opcode_align; + return alignment == WASM_USE_NATURAL_ALIGNMENT || alignment == opcode_align; } uint32_t wasm_get_opcode_alignment(WasmOpcode opcode, uint32_t alignment) { diff --git a/src/wasm-common.h b/src/wasm-common.h index 71f8a044..365572da 100644 --- a/src/wasm-common.h +++ b/src/wasm-common.h @@ -151,6 +151,13 @@ typedef enum WasmExternalKind { WASM_NUM_EXTERNAL_KINDS, } WasmExternalKind; +extern const char* g_wasm_kind_name[]; + +static WASM_INLINE const char* wasm_get_kind_name(WasmExternalKind kind) { + assert(kind < WASM_NUM_EXTERNAL_KINDS); + return g_wasm_kind_name[kind]; +} + typedef struct WasmLimits { uint64_t initial; uint64_t max; diff --git a/src/wasmdump.c b/src/wasmdump.c new file mode 100644 index 00000000..4a6fa0ca --- /dev/null +++ b/src/wasmdump.c @@ -0,0 +1,137 @@ +/* + * Copyright 2016 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "wasm-allocator.h" +#include "wasm-common.h" +#include "wasm-option-parser.h" +#include "wasm-stream.h" +#include "wasm-writer.h" +#include "wasm-binary-reader.h" +#include "wasm-binary-reader-objdump.h" + +#define PROGRAM_NAME "wasmdump" + +enum { + FLAG_HEADERS, + FLAG_RAW, + FLAG_DISASSEMBLE, + FLAG_VERBOSE, + FLAG_DEBUG, + FLAG_HELP, + NUM_FLAGS +}; + +static const char s_description[] = + " Print information about the contents of a wasm binary file.\n" + "\n" + "examples:\n" + " $ wasmdump test.wasm\n"; + +static WasmOption s_options[] = { + {FLAG_HEADERS, 'h', "headers", NULL, WASM_OPTION_NO_ARGUMENT, + "print headers"}, + {FLAG_RAW, 'r', "raw", NULL, WASM_OPTION_NO_ARGUMENT, + "print raw section contents"}, + {FLAG_DISASSEMBLE, 'd', "disassemble", NULL, WASM_OPTION_NO_ARGUMENT, + "disassemble function bodies"}, + {FLAG_DEBUG, '\0', "debug", NULL, WASM_OPTION_NO_ARGUMENT, + "disassemble function bodies"}, + {FLAG_VERBOSE, 'v', "verbose", NULL, WASM_OPTION_NO_ARGUMENT, + "Verbose output"}, + {FLAG_HELP, 'h', "help", NULL, WASM_OPTION_NO_ARGUMENT, + "print this help message"}, +}; +WASM_STATIC_ASSERT(NUM_FLAGS == WASM_ARRAY_SIZE(s_options)); + +static const char* s_infile; +static WasmObjdumpOptions s_objdump_options; + +static void on_argument(struct WasmOptionParser* parser, const char* argument) { + s_infile = argument; +} + +static void on_option(struct WasmOptionParser* parser, + struct WasmOption* option, + const char* argument) { + switch (option->id) { + case FLAG_HEADERS: + s_objdump_options.headers = WASM_TRUE; + break; + + case FLAG_RAW: + s_objdump_options.raw = WASM_TRUE; + break; + + case FLAG_DEBUG: + s_objdump_options.debug = WASM_TRUE; + + case FLAG_DISASSEMBLE: + s_objdump_options.disassemble = WASM_TRUE; + break; + + case FLAG_VERBOSE: + s_objdump_options.verbose = WASM_TRUE; + break; + + case FLAG_HELP: + wasm_print_help(parser, PROGRAM_NAME); + exit(0); + break; + } +} + +static void on_option_error(struct WasmOptionParser* parser, + const char* message) { + WASM_FATAL("%s\n", message); +} + +static void parse_options(int argc, char** argv) { + WasmOptionParser parser; + WASM_ZERO_MEMORY(parser); + parser.description = s_description; + parser.options = s_options; + parser.num_options = WASM_ARRAY_SIZE(s_options); + parser.on_option = on_option; + parser.on_argument = on_argument; + parser.on_error = on_option_error; + wasm_parse_options(&parser, argc, argv); + + if (!s_infile) { + wasm_print_help(&parser, PROGRAM_NAME); + WASM_FATAL("No filename given.\n"); + } +} + +int main(int argc, char** argv) { + wasm_init_stdio(); + + parse_options(argc, argv); + WasmAllocator* allocator = &g_wasm_libc_allocator; + + void* data; + size_t size; + WasmResult result = wasm_read_file(allocator, s_infile, &data, &size); + if (WASM_FAILED(result)) + return result; + + result = wasm_read_binary_objdump(allocator, data, size, &s_objdump_options); + wasm_free(allocator, data); + return result; +} diff --git a/test/dump/basic.txt b/test/dump/basic.txt index f1425d54..b96c8b69 100644 --- a/test/dump/basic.txt +++ b/test/dump/basic.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory 1) (func $f (param i32 i32) (result i32) @@ -71,9 +72,14 @@ 0000038: 0f ; end 0000024: 14 ; FIXUP func body size 0000022: 16 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0107 0140 0201 0101 -0000010: 0103 0201 0005 0301 0001 0705 0101 6600 -0000020: 000a 1601 1400 1000 1000 2a02 0010 0140 -0000030: 3302 0014 0014 0140 0f +func 0 + 000026: 10 00 | i32.const 0 + 000028: 10 00 | i32.const 0 + 00002a: 2a 02 00 | i32.load 2 0 + 00002d: 10 01 | i32.const 0x1 + 00002f: 40 | i32.add + 000030: 33 02 00 | i32.store 2 0 + 000033: 14 00 | get_local 0 + 000035: 14 01 | get_local 0x1 + 000037: 40 | i32.add ;;; STDOUT ;;) diff --git a/test/dump/basic_dump_only.txt b/test/dump/basic_dump_only.txt index 0e49fb7e..46f888b7 100644 --- a/test/dump/basic_dump_only.txt +++ b/test/dump/basic_dump_only.txt @@ -1,4 +1,4 @@ -;;; FLAGS: -d +;;; TOOL: run-wasmdump (module (memory 1) (func $f (param i32 i32) (result i32) @@ -6,8 +6,14 @@ (i32.add (get_local 0) (get_local 1))) (export "f" (func $f))) (;; STDOUT ;;; -0000000: 0061 736d 0c00 0000 0107 0140 0201 0101 -0000010: 0103 0201 0005 0301 0001 0705 0101 6600 -0000020: 000a 1601 1400 1000 1000 2a02 0010 0140 -0000030: 3302 0014 0014 0140 0f +func 0 + 000026: 10 00 | i32.const 0 + 000028: 10 00 | i32.const 0 + 00002a: 2a 02 00 | i32.load 2 0 + 00002d: 10 01 | i32.const 0x1 + 00002f: 40 | i32.add + 000030: 33 02 00 | i32.store 2 0 + 000033: 14 00 | get_local 0 + 000035: 14 01 | get_local 0x1 + 000037: 40 | i32.add ;;; STDOUT ;;) diff --git a/test/dump/binary.txt b/test/dump/binary.txt index ad1614c7..33005cb0 100644 --- a/test/dump/binary.txt +++ b/test/dump/binary.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop @@ -277,21 +278,101 @@ 0000015: e201 ; FIXUP func body size ; move data: [14, f9) -> [15, fa) 0000013: e501 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0ae5 0101 e201 0010 0010 00b6 1000 -0000020: b710 004c 1000 4b10 004a 1000 4910 0048 -0000030: 1000 4710 0046 1000 4510 0044 1000 4310 -0000040: 0042 1000 4110 0040 0b11 0011 00b8 1100 -0000050: b911 0067 1100 6611 0065 1100 6411 0063 -0000060: 1100 6211 0061 1100 6011 005f 1100 5e11 -0000070: 005d 1100 5c11 005b 0b13 0000 0000 1300 -0000080: 0000 007d 1300 0000 007a 1300 0000 0079 -0000090: 1300 0000 0078 1300 0000 0077 1300 0000 -00000a0: 0076 1300 0000 0075 0b12 0000 0000 0000 -00000b0: 0000 1200 0000 0000 0000 0091 1200 0000 -00000c0: 0000 0000 008e 1200 0000 0000 0000 008d -00000d0: 1200 0000 0000 0000 008c 1200 0000 0000 -00000e0: 0000 008b 1200 0000 0000 0000 008a 1200 -00000f0: 0000 0000 0000 0089 0b0f +func 0 + 000019: 10 00 | i32.const 0 + 00001b: 10 00 | i32.const 0 + 00001d: b6 | i32.rotr + 00001e: 10 00 | i32.const 0 + 000020: b7 | i32.rotl + 000021: 10 00 | i32.const 0 + 000023: 4c | i32.shr_s + 000024: 10 00 | i32.const 0 + 000026: 4b | i32.shr_u + 000027: 10 00 | i32.const 0 + 000029: 4a | i32.shl + 00002a: 10 00 | i32.const 0 + 00002c: 49 | i32.xor + 00002d: 10 00 | i32.const 0 + 00002f: 48 | i32.or + 000030: 10 00 | i32.const 0 + 000032: 47 | i32.and + 000033: 10 00 | i32.const 0 + 000035: 46 | i32.rem_u + 000036: 10 00 | i32.const 0 + 000038: 45 | i32.rem_s + 000039: 10 00 | i32.const 0 + 00003b: 44 | i32.div_u + 00003c: 10 00 | i32.const 0 + 00003e: 43 | i32.div_s + 00003f: 10 00 | i32.const 0 + 000041: 42 | i32.mul + 000042: 10 00 | i32.const 0 + 000044: 41 | i32.sub + 000045: 10 00 | i32.const 0 + 000047: 40 | i32.add + 000048: 0b | drop + 000049: 11 00 | i64.const 0 + 00004b: 11 00 | i64.const 0 + 00004d: b8 | i64.rotr + 00004e: 11 00 | i64.const 0 + 000050: b9 | i64.rotl + 000051: 11 00 | i64.const 0 + 000053: 67 | i64.shr_s + 000054: 11 00 | i64.const 0 + 000056: 66 | i64.shr_u + 000057: 11 00 | i64.const 0 + 000059: 65 | i64.shl + 00005a: 11 00 | i64.const 0 + 00005c: 64 | i64.xor + 00005d: 11 00 | i64.const 0 + 00005f: 63 | i64.or + 000060: 11 00 | i64.const 0 + 000062: 62 | i64.and + 000063: 11 00 | i64.const 0 + 000065: 61 | i64.rem_u + 000066: 11 00 | i64.const 0 + 000068: 60 | i64.rem_s + 000069: 11 00 | i64.const 0 + 00006b: 5f | i64.div_u + 00006c: 11 00 | i64.const 0 + 00006e: 5e | i64.div_s + 00006f: 11 00 | i64.const 0 + 000071: 5d | i64.mul + 000072: 11 00 | i64.const 0 + 000074: 5c | i64.sub + 000075: 11 00 | i64.const 0 + 000077: 5b | i64.add + 000078: 0b | drop + 000079: 13 00 00 00 00 | f32.const 0 + 00007e: 13 00 00 00 00 | f32.const 0 + 000083: 7d | f32.copysign + 000084: 13 00 00 00 00 | f32.const 0 + 000089: 7a | f32.max + 00008a: 13 00 00 00 00 | f32.const 0 + 00008f: 79 | f32.min + 000090: 13 00 00 00 00 | f32.const 0 + 000095: 78 | f32.div + 000096: 13 00 00 00 00 | f32.const 0 + 00009b: 77 | f32.mul + 00009c: 13 00 00 00 00 | f32.const 0 + 0000a1: 76 | f32.sub + 0000a2: 13 00 00 00 00 | f32.const 0 + 0000a7: 75 | f32.add + 0000a8: 0b | drop + 0000a9: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000b2: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000bb: 91 | f64.copysign + 0000bc: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000c5: 8e | f64.max + 0000c6: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000cf: 8d | f64.min + 0000d0: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000d9: 8c | f64.div + 0000da: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000e3: 8b | f64.mul + 0000e4: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000ed: 8a | f64.sub + 0000ee: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000f7: 89 | f64.add + 0000f8: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/block-257-exprs-br.txt b/test/dump/block-257-exprs-br.txt index 8b1b1d79..79624ac5 100644 --- a/test/dump/block-257-exprs-br.txt +++ b/test/dump/block-257-exprs-br.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block $foo @@ -339,24 +340,265 @@ 0000015: 8902 ; FIXUP func body size ; move data: [14, 120) -> [15, 121) 0000013: 8c02 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a8c 0201 8902 0001 000a 0a0a 0a0a -0000020: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000030: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000040: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000050: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000060: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000070: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000080: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000090: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000a0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000b0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000c0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000d0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000e0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000f0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000100: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000110: 0a0a 0a0a 0a0a 0a0a 0a0a 0a06 0006 000f -0000120: 0f +func 0 + 000019: 01 00 | block + 00001b: 0a | nop + 00001c: 0a | nop + 00001d: 0a | nop + 00001e: 0a | nop + 00001f: 0a | nop + 000020: 0a | nop + 000021: 0a | nop + 000022: 0a | nop + 000023: 0a | nop + 000024: 0a | nop + 000025: 0a | nop + 000026: 0a | nop + 000027: 0a | nop + 000028: 0a | nop + 000029: 0a | nop + 00002a: 0a | nop + 00002b: 0a | nop + 00002c: 0a | nop + 00002d: 0a | nop + 00002e: 0a | nop + 00002f: 0a | nop + 000030: 0a | nop + 000031: 0a | nop + 000032: 0a | nop + 000033: 0a | nop + 000034: 0a | nop + 000035: 0a | nop + 000036: 0a | nop + 000037: 0a | nop + 000038: 0a | nop + 000039: 0a | nop + 00003a: 0a | nop + 00003b: 0a | nop + 00003c: 0a | nop + 00003d: 0a | nop + 00003e: 0a | nop + 00003f: 0a | nop + 000040: 0a | nop + 000041: 0a | nop + 000042: 0a | nop + 000043: 0a | nop + 000044: 0a | nop + 000045: 0a | nop + 000046: 0a | nop + 000047: 0a | nop + 000048: 0a | nop + 000049: 0a | nop + 00004a: 0a | nop + 00004b: 0a | nop + 00004c: 0a | nop + 00004d: 0a | nop + 00004e: 0a | nop + 00004f: 0a | nop + 000050: 0a | nop + 000051: 0a | nop + 000052: 0a | nop + 000053: 0a | nop + 000054: 0a | nop + 000055: 0a | nop + 000056: 0a | nop + 000057: 0a | nop + 000058: 0a | nop + 000059: 0a | nop + 00005a: 0a | nop + 00005b: 0a | nop + 00005c: 0a | nop + 00005d: 0a | nop + 00005e: 0a | nop + 00005f: 0a | nop + 000060: 0a | nop + 000061: 0a | nop + 000062: 0a | nop + 000063: 0a | nop + 000064: 0a | nop + 000065: 0a | nop + 000066: 0a | nop + 000067: 0a | nop + 000068: 0a | nop + 000069: 0a | nop + 00006a: 0a | nop + 00006b: 0a | nop + 00006c: 0a | nop + 00006d: 0a | nop + 00006e: 0a | nop + 00006f: 0a | nop + 000070: 0a | nop + 000071: 0a | nop + 000072: 0a | nop + 000073: 0a | nop + 000074: 0a | nop + 000075: 0a | nop + 000076: 0a | nop + 000077: 0a | nop + 000078: 0a | nop + 000079: 0a | nop + 00007a: 0a | nop + 00007b: 0a | nop + 00007c: 0a | nop + 00007d: 0a | nop + 00007e: 0a | nop + 00007f: 0a | nop + 000080: 0a | nop + 000081: 0a | nop + 000082: 0a | nop + 000083: 0a | nop + 000084: 0a | nop + 000085: 0a | nop + 000086: 0a | nop + 000087: 0a | nop + 000088: 0a | nop + 000089: 0a | nop + 00008a: 0a | nop + 00008b: 0a | nop + 00008c: 0a | nop + 00008d: 0a | nop + 00008e: 0a | nop + 00008f: 0a | nop + 000090: 0a | nop + 000091: 0a | nop + 000092: 0a | nop + 000093: 0a | nop + 000094: 0a | nop + 000095: 0a | nop + 000096: 0a | nop + 000097: 0a | nop + 000098: 0a | nop + 000099: 0a | nop + 00009a: 0a | nop + 00009b: 0a | nop + 00009c: 0a | nop + 00009d: 0a | nop + 00009e: 0a | nop + 00009f: 0a | nop + 0000a0: 0a | nop + 0000a1: 0a | nop + 0000a2: 0a | nop + 0000a3: 0a | nop + 0000a4: 0a | nop + 0000a5: 0a | nop + 0000a6: 0a | nop + 0000a7: 0a | nop + 0000a8: 0a | nop + 0000a9: 0a | nop + 0000aa: 0a | nop + 0000ab: 0a | nop + 0000ac: 0a | nop + 0000ad: 0a | nop + 0000ae: 0a | nop + 0000af: 0a | nop + 0000b0: 0a | nop + 0000b1: 0a | nop + 0000b2: 0a | nop + 0000b3: 0a | nop + 0000b4: 0a | nop + 0000b5: 0a | nop + 0000b6: 0a | nop + 0000b7: 0a | nop + 0000b8: 0a | nop + 0000b9: 0a | nop + 0000ba: 0a | nop + 0000bb: 0a | nop + 0000bc: 0a | nop + 0000bd: 0a | nop + 0000be: 0a | nop + 0000bf: 0a | nop + 0000c0: 0a | nop + 0000c1: 0a | nop + 0000c2: 0a | nop + 0000c3: 0a | nop + 0000c4: 0a | nop + 0000c5: 0a | nop + 0000c6: 0a | nop + 0000c7: 0a | nop + 0000c8: 0a | nop + 0000c9: 0a | nop + 0000ca: 0a | nop + 0000cb: 0a | nop + 0000cc: 0a | nop + 0000cd: 0a | nop + 0000ce: 0a | nop + 0000cf: 0a | nop + 0000d0: 0a | nop + 0000d1: 0a | nop + 0000d2: 0a | nop + 0000d3: 0a | nop + 0000d4: 0a | nop + 0000d5: 0a | nop + 0000d6: 0a | nop + 0000d7: 0a | nop + 0000d8: 0a | nop + 0000d9: 0a | nop + 0000da: 0a | nop + 0000db: 0a | nop + 0000dc: 0a | nop + 0000dd: 0a | nop + 0000de: 0a | nop + 0000df: 0a | nop + 0000e0: 0a | nop + 0000e1: 0a | nop + 0000e2: 0a | nop + 0000e3: 0a | nop + 0000e4: 0a | nop + 0000e5: 0a | nop + 0000e6: 0a | nop + 0000e7: 0a | nop + 0000e8: 0a | nop + 0000e9: 0a | nop + 0000ea: 0a | nop + 0000eb: 0a | nop + 0000ec: 0a | nop + 0000ed: 0a | nop + 0000ee: 0a | nop + 0000ef: 0a | nop + 0000f0: 0a | nop + 0000f1: 0a | nop + 0000f2: 0a | nop + 0000f3: 0a | nop + 0000f4: 0a | nop + 0000f5: 0a | nop + 0000f6: 0a | nop + 0000f7: 0a | nop + 0000f8: 0a | nop + 0000f9: 0a | nop + 0000fa: 0a | nop + 0000fb: 0a | nop + 0000fc: 0a | nop + 0000fd: 0a | nop + 0000fe: 0a | nop + 0000ff: 0a | nop + 000100: 0a | nop + 000101: 0a | nop + 000102: 0a | nop + 000103: 0a | nop + 000104: 0a | nop + 000105: 0a | nop + 000106: 0a | nop + 000107: 0a | nop + 000108: 0a | nop + 000109: 0a | nop + 00010a: 0a | nop + 00010b: 0a | nop + 00010c: 0a | nop + 00010d: 0a | nop + 00010e: 0a | nop + 00010f: 0a | nop + 000110: 0a | nop + 000111: 0a | nop + 000112: 0a | nop + 000113: 0a | nop + 000114: 0a | nop + 000115: 0a | nop + 000116: 0a | nop + 000117: 0a | nop + 000118: 0a | nop + 000119: 0a | nop + 00011a: 0a | nop + 00011b: 06 00 | br 0 + 00011d: 06 00 | br 0 + 00011f: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/block-257-exprs.txt b/test/dump/block-257-exprs.txt index 281b7b06..de0289cd 100644 --- a/test/dump/block-257-exprs.txt +++ b/test/dump/block-257-exprs.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block @@ -334,23 +335,264 @@ 0000015: 8602 ; FIXUP func body size ; move data: [14, 11d) -> [15, 11e) 0000013: 8902 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a89 0201 8602 0001 000a 0a0a 0a0a -0000020: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000030: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000040: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000050: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000060: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000070: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000080: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000090: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000a0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000b0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000c0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000d0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000e0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000f0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000100: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000110: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0f0f +func 0 + 000019: 01 00 | block + 00001b: 0a | nop + 00001c: 0a | nop + 00001d: 0a | nop + 00001e: 0a | nop + 00001f: 0a | nop + 000020: 0a | nop + 000021: 0a | nop + 000022: 0a | nop + 000023: 0a | nop + 000024: 0a | nop + 000025: 0a | nop + 000026: 0a | nop + 000027: 0a | nop + 000028: 0a | nop + 000029: 0a | nop + 00002a: 0a | nop + 00002b: 0a | nop + 00002c: 0a | nop + 00002d: 0a | nop + 00002e: 0a | nop + 00002f: 0a | nop + 000030: 0a | nop + 000031: 0a | nop + 000032: 0a | nop + 000033: 0a | nop + 000034: 0a | nop + 000035: 0a | nop + 000036: 0a | nop + 000037: 0a | nop + 000038: 0a | nop + 000039: 0a | nop + 00003a: 0a | nop + 00003b: 0a | nop + 00003c: 0a | nop + 00003d: 0a | nop + 00003e: 0a | nop + 00003f: 0a | nop + 000040: 0a | nop + 000041: 0a | nop + 000042: 0a | nop + 000043: 0a | nop + 000044: 0a | nop + 000045: 0a | nop + 000046: 0a | nop + 000047: 0a | nop + 000048: 0a | nop + 000049: 0a | nop + 00004a: 0a | nop + 00004b: 0a | nop + 00004c: 0a | nop + 00004d: 0a | nop + 00004e: 0a | nop + 00004f: 0a | nop + 000050: 0a | nop + 000051: 0a | nop + 000052: 0a | nop + 000053: 0a | nop + 000054: 0a | nop + 000055: 0a | nop + 000056: 0a | nop + 000057: 0a | nop + 000058: 0a | nop + 000059: 0a | nop + 00005a: 0a | nop + 00005b: 0a | nop + 00005c: 0a | nop + 00005d: 0a | nop + 00005e: 0a | nop + 00005f: 0a | nop + 000060: 0a | nop + 000061: 0a | nop + 000062: 0a | nop + 000063: 0a | nop + 000064: 0a | nop + 000065: 0a | nop + 000066: 0a | nop + 000067: 0a | nop + 000068: 0a | nop + 000069: 0a | nop + 00006a: 0a | nop + 00006b: 0a | nop + 00006c: 0a | nop + 00006d: 0a | nop + 00006e: 0a | nop + 00006f: 0a | nop + 000070: 0a | nop + 000071: 0a | nop + 000072: 0a | nop + 000073: 0a | nop + 000074: 0a | nop + 000075: 0a | nop + 000076: 0a | nop + 000077: 0a | nop + 000078: 0a | nop + 000079: 0a | nop + 00007a: 0a | nop + 00007b: 0a | nop + 00007c: 0a | nop + 00007d: 0a | nop + 00007e: 0a | nop + 00007f: 0a | nop + 000080: 0a | nop + 000081: 0a | nop + 000082: 0a | nop + 000083: 0a | nop + 000084: 0a | nop + 000085: 0a | nop + 000086: 0a | nop + 000087: 0a | nop + 000088: 0a | nop + 000089: 0a | nop + 00008a: 0a | nop + 00008b: 0a | nop + 00008c: 0a | nop + 00008d: 0a | nop + 00008e: 0a | nop + 00008f: 0a | nop + 000090: 0a | nop + 000091: 0a | nop + 000092: 0a | nop + 000093: 0a | nop + 000094: 0a | nop + 000095: 0a | nop + 000096: 0a | nop + 000097: 0a | nop + 000098: 0a | nop + 000099: 0a | nop + 00009a: 0a | nop + 00009b: 0a | nop + 00009c: 0a | nop + 00009d: 0a | nop + 00009e: 0a | nop + 00009f: 0a | nop + 0000a0: 0a | nop + 0000a1: 0a | nop + 0000a2: 0a | nop + 0000a3: 0a | nop + 0000a4: 0a | nop + 0000a5: 0a | nop + 0000a6: 0a | nop + 0000a7: 0a | nop + 0000a8: 0a | nop + 0000a9: 0a | nop + 0000aa: 0a | nop + 0000ab: 0a | nop + 0000ac: 0a | nop + 0000ad: 0a | nop + 0000ae: 0a | nop + 0000af: 0a | nop + 0000b0: 0a | nop + 0000b1: 0a | nop + 0000b2: 0a | nop + 0000b3: 0a | nop + 0000b4: 0a | nop + 0000b5: 0a | nop + 0000b6: 0a | nop + 0000b7: 0a | nop + 0000b8: 0a | nop + 0000b9: 0a | nop + 0000ba: 0a | nop + 0000bb: 0a | nop + 0000bc: 0a | nop + 0000bd: 0a | nop + 0000be: 0a | nop + 0000bf: 0a | nop + 0000c0: 0a | nop + 0000c1: 0a | nop + 0000c2: 0a | nop + 0000c3: 0a | nop + 0000c4: 0a | nop + 0000c5: 0a | nop + 0000c6: 0a | nop + 0000c7: 0a | nop + 0000c8: 0a | nop + 0000c9: 0a | nop + 0000ca: 0a | nop + 0000cb: 0a | nop + 0000cc: 0a | nop + 0000cd: 0a | nop + 0000ce: 0a | nop + 0000cf: 0a | nop + 0000d0: 0a | nop + 0000d1: 0a | nop + 0000d2: 0a | nop + 0000d3: 0a | nop + 0000d4: 0a | nop + 0000d5: 0a | nop + 0000d6: 0a | nop + 0000d7: 0a | nop + 0000d8: 0a | nop + 0000d9: 0a | nop + 0000da: 0a | nop + 0000db: 0a | nop + 0000dc: 0a | nop + 0000dd: 0a | nop + 0000de: 0a | nop + 0000df: 0a | nop + 0000e0: 0a | nop + 0000e1: 0a | nop + 0000e2: 0a | nop + 0000e3: 0a | nop + 0000e4: 0a | nop + 0000e5: 0a | nop + 0000e6: 0a | nop + 0000e7: 0a | nop + 0000e8: 0a | nop + 0000e9: 0a | nop + 0000ea: 0a | nop + 0000eb: 0a | nop + 0000ec: 0a | nop + 0000ed: 0a | nop + 0000ee: 0a | nop + 0000ef: 0a | nop + 0000f0: 0a | nop + 0000f1: 0a | nop + 0000f2: 0a | nop + 0000f3: 0a | nop + 0000f4: 0a | nop + 0000f5: 0a | nop + 0000f6: 0a | nop + 0000f7: 0a | nop + 0000f8: 0a | nop + 0000f9: 0a | nop + 0000fa: 0a | nop + 0000fb: 0a | nop + 0000fc: 0a | nop + 0000fd: 0a | nop + 0000fe: 0a | nop + 0000ff: 0a | nop + 000100: 0a | nop + 000101: 0a | nop + 000102: 0a | nop + 000103: 0a | nop + 000104: 0a | nop + 000105: 0a | nop + 000106: 0a | nop + 000107: 0a | nop + 000108: 0a | nop + 000109: 0a | nop + 00010a: 0a | nop + 00010b: 0a | nop + 00010c: 0a | nop + 00010d: 0a | nop + 00010e: 0a | nop + 00010f: 0a | nop + 000110: 0a | nop + 000111: 0a | nop + 000112: 0a | nop + 000113: 0a | nop + 000114: 0a | nop + 000115: 0a | nop + 000116: 0a | nop + 000117: 0a | nop + 000118: 0a | nop + 000119: 0a | nop + 00011a: 0a | nop + 00011b: 0a | nop + 00011c: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/block.txt b/test/dump/block.txt index d2ab54f7..ba2b5775 100644 --- a/test/dump/block.txt +++ b/test/dump/block.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block @@ -59,8 +60,14 @@ 000002a: 0f ; end 0000023: 07 ; FIXUP func body size 0000018: 12 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0108 0240 0000 4000 -0000010: 0101 0303 0200 010a 1202 0800 0100 0a0a -0000020: 0a0f 0f07 0001 0110 010f 0f +func 0 + 00001c: 01 00 | block + 00001e: 0a | nop + 00001f: 0a | nop + 000020: 0a | nop + 000021: 0f | end +func 1 + 000025: 01 01 | block i32 + 000027: 10 01 | i32.const 0x1 + 000029: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/br-block-named.txt b/test/dump/br-block-named.txt index f76d1b34..93902d32 100644 --- a/test/dump/br-block-named.txt +++ b/test/dump/br-block-named.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block $outer ;; 3 @@ -55,8 +56,17 @@ 000002a: 0f ; end 0000015: 15 ; FIXUP func body size 0000013: 17 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a17 0115 0001 0002 0001 0010 000b -0000020: 0100 0600 0603 0f0f 0f0f 0f +func 0 + 000017: 01 00 | block + 000019: 02 00 | loop + 00001b: 01 00 | block + 00001d: 10 00 | i32.const 0 + 00001f: 0b | drop + 000020: 01 00 | block + 000022: 06 00 | br 0 + 000024: 06 03 | br 0x3 + 000026: 0f | end + 000027: 0f | end + 000028: 0f | end + 000029: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/br-block.txt b/test/dump/br-block.txt index 4e447db2..77665c6b 100644 --- a/test/dump/br-block.txt +++ b/test/dump/br-block.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func ;; depth (block $outer ;; 4 @@ -61,8 +62,19 @@ 000002e: 0f ; end 0000015: 19 ; FIXUP func body size 0000013: 1b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a1b 0119 0001 0002 0001 0010 000b -0000020: 0100 0600 0601 0602 0603 0f0f 0f0f 0f +func 0 + 000017: 01 00 | block + 000019: 02 00 | loop + 00001b: 01 00 | block + 00001d: 10 00 | i32.const 0 + 00001f: 0b | drop + 000020: 01 00 | block + 000022: 06 00 | br 0 + 000024: 06 01 | br 0x1 + 000026: 06 02 | br 0x2 + 000028: 06 03 | br 0x3 + 00002a: 0f | end + 00002b: 0f | end + 00002c: 0f | end + 00002d: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/br-loop-inner-expr.txt b/test/dump/br-loop-inner-expr.txt index 797c2084..7a79c2df 100644 --- a/test/dump/br-loop-inner-expr.txt +++ b/test/dump/br-loop-inner-expr.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (result i32) (block $exit i32 (loop $cont i32 @@ -60,9 +61,19 @@ 0000030: 0f ; end 0000016: 1a ; FIXUP func body size 0000014: 1c ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0001 0103 -0000010: 0201 000a 1c01 1a00 0101 0201 1001 0300 -0000020: 0601 0f10 0303 0010 0406 020f 1005 0f0f -0000030: 0f +func 0 + 000018: 01 01 | block i32 + 00001a: 02 01 | loop i32 + 00001c: 10 01 | i32.const 0x1 + 00001e: 03 00 | if + 000020: 06 01 | br 0x1 + 000022: 0f | end + 000023: 10 03 | i32.const 0x3 + 000025: 03 00 | if + 000027: 10 04 | i32.const 0x4 + 000029: 06 02 | br 0x2 + 00002b: 0f | end + 00002c: 10 05 | i32.const 0x5 + 00002e: 0f | end + 00002f: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/br-loop-inner.txt b/test/dump/br-loop-inner.txt index 8d5301aa..1aacc50e 100644 --- a/test/dump/br-loop-inner.txt +++ b/test/dump/br-loop-inner.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block $exit (loop $cont @@ -54,8 +55,17 @@ 000002b: 0f ; end 0000015: 16 ; FIXUP func body size 0000013: 18 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a18 0116 0001 0002 0010 0103 0006 -0000020: 020f 1002 0300 0601 0f0f 0f0f +func 0 + 000017: 01 00 | block + 000019: 02 00 | loop + 00001b: 10 01 | i32.const 0x1 + 00001d: 03 00 | if + 00001f: 06 02 | br 0x2 + 000021: 0f | end + 000022: 10 02 | i32.const 0x2 + 000024: 03 00 | if + 000026: 06 01 | br 0x1 + 000028: 0f | end + 000029: 0f | end + 00002a: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/br-loop.txt b/test/dump/br-loop.txt index 79bb7897..f2e6e4fd 100644 --- a/test/dump/br-loop.txt +++ b/test/dump/br-loop.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (loop $cont @@ -42,8 +43,11 @@ 0000021: 0f ; end 0000015: 0c ; FIXUP func body size 0000013: 0e ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0e 010c 0002 0010 0103 0006 010f -0000020: 0f0f +func 0 + 000017: 02 00 | loop + 000019: 10 01 | i32.const 0x1 + 00001b: 03 00 | if + 00001d: 06 01 | br 0x1 + 00001f: 0f | end + 000020: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/brif-loop.txt b/test/dump/brif-loop.txt index eb35b46e..616c12aa 100644 --- a/test/dump/brif-loop.txt +++ b/test/dump/brif-loop.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (loop $cont @@ -38,7 +39,9 @@ 000001e: 0f ; end 0000015: 09 ; FIXUP func body size 0000013: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0b 0109 0002 0010 0007 000f 0f +func 0 + 000017: 02 00 | loop + 000019: 10 00 | i32.const 0 + 00001b: 07 00 | br_if 0 + 00001d: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/brif.txt b/test/dump/brif.txt index 47e7db62..833dcfdf 100644 --- a/test/dump/brif.txt +++ b/test/dump/brif.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block $foo @@ -38,7 +39,9 @@ 000001e: 0f ; end 0000015: 09 ; FIXUP func body size 0000013: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0b 0109 0001 0010 0107 000f 0f +func 0 + 000017: 01 00 | block + 000019: 10 01 | i32.const 0x1 + 00001b: 07 00 | br_if 0 + 00001d: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/brtable-empty.txt b/test/dump/brtable-empty.txt index 6427ea94..b9117f98 100644 --- a/test/dump/brtable-empty.txt +++ b/test/dump/brtable-empty.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block @@ -39,7 +40,9 @@ 000001f: 0f ; end 0000015: 0a ; FIXUP func body size 0000013: 0c ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0c 010a 0001 0010 0008 0000 0f0f +func 0 + 000017: 01 00 | block + 000019: 10 00 | i32.const 0 + 00001b: 08 00 00 | br_table + 00001e: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/brtable.txt b/test/dump/brtable.txt index c32fe0e3..b9dd5a8b 100644 --- a/test/dump/brtable.txt +++ b/test/dump/brtable.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block @@ -68,9 +69,20 @@ 0000032: 0f ; end 0000015: 1d ; FIXUP func body size 0000013: 1f ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a1f 011d 0001 0001 0001 0010 0008 -0000020: 0200 0100 0f10 010b 1002 0b06 010f 0f10 -0000030: 030b 0f +func 0 + 000017: 01 00 | block + 000019: 01 00 | block + 00001b: 01 00 | block + 00001d: 10 00 | i32.const 0 + 00001f: 08 02 00 01 00 | br_table + 000024: 0f | end + 000025: 10 01 | i32.const 0x1 + 000027: 0b | drop + 000028: 10 02 | i32.const 0x2 + 00002a: 0b | drop + 00002b: 06 01 | br 0x1 + 00002d: 0f | end + 00002e: 0f | end + 00002f: 10 03 | i32.const 0x3 + 000031: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/call.txt b/test/dump/call.txt index c02c5698..7f5a2c1e 100644 --- a/test/dump/call.txt +++ b/test/dump/call.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (param i32) (call 0 (i32.const 1)))) @@ -35,7 +36,7 @@ 000001c: 0f ; end 0000016: 06 ; FIXUP func body size 0000014: 08 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0101 0003 -0000010: 0201 000a 0801 0600 1001 1600 0f +func 0 + 000018: 10 01 | i32.const 0x1 + 00001a: 16 00 | call 0 ;;; STDOUT ;;) diff --git a/test/dump/callimport.txt b/test/dump/callimport.txt index 28c32f15..51fdf5b7 100644 --- a/test/dump/callimport.txt +++ b/test/dump/callimport.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (import "foo" "bar" (func (param i32 f32) (result i32))) (func (result i32) @@ -63,9 +64,10 @@ 0000037: 0f ; end 0000029: 0e ; FIXUP func body size 0000027: 10 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 010b 0240 0201 0301 -0000010: 0140 0001 0102 0b01 0366 6f6f 0362 6172 -0000020: 0000 0302 0101 0a10 010e 0010 0113 0000 -0000030: 0040 1600 0b16 010f +func 0 + 00002b: 10 01 | i32.const 0x1 + 00002d: 13 00 00 00 40 | f32.const 0x40000000 + 000032: 16 00 | call 0 + 000034: 0b | drop + 000035: 16 01 | call 0x1 ;;; STDOUT ;;) diff --git a/test/dump/callindirect.txt b/test/dump/callindirect.txt index 3d25f561..8f2fbb48 100644 --- a/test/dump/callindirect.txt +++ b/test/dump/callindirect.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (type $t (func (param i32))) (func $f (type $t) @@ -61,8 +62,8 @@ 000002e: 0f ; end 0000026: 08 ; FIXUP func body size 0000024: 0a ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0101 0003 -0000010: 0201 0004 0501 2001 0101 0907 0100 1000 -0000020: 0f01 000a 0a01 0800 1000 1000 1700 0f +func 0 + 000028: 10 00 | i32.const 0 + 00002a: 10 00 | i32.const 0 + 00002c: 17 00 | call_indirect 0 ;;; STDOUT ;;) diff --git a/test/dump/cast.txt b/test/dump/cast.txt index 39a1c8bb..483bb11c 100644 --- a/test/dump/cast.txt +++ b/test/dump/cast.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (f32.reinterpret/i32 (i32.const 0))) @@ -49,9 +50,17 @@ 0000031: 0f ; end 0000015: 1c ; FIXUP func body size 0000013: 1e ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a1e 011c 0010 00ad 0b13 0000 0000 -0000020: b40b 1100 b30b 1200 0000 0000 0000 00b5 -0000030: 0b0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: ad | f32.reinterpret/i32 + 00001a: 0b | drop + 00001b: 13 00 00 00 00 | f32.const 0 + 000020: b4 | i32.reinterpret/f32 + 000021: 0b | drop + 000022: 11 00 | i64.const 0 + 000024: b3 | f64.reinterpret/i64 + 000025: 0b | drop + 000026: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00002f: b5 | i64.reinterpret/f64 + 000030: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/compare.txt b/test/dump/compare.txt index 4565a3d8..09d982c3 100644 --- a/test/dump/compare.txt +++ b/test/dump/compare.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop @@ -245,25 +246,115 @@ 0000015: 9f02 ; FIXUP func body size ; move data: [14, 136) -> [15, 137) 0000013: a202 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0aa2 0201 9f02 0010 0010 0056 1000 -0000020: 5410 0055 1000 5310 0052 1000 5010 0051 -0000030: 1000 4f10 004e 1000 4d0b 1100 1100 680b -0000040: 1100 1100 690b 1100 1100 6a0b 1100 1100 -0000050: 6c0b 1100 1100 6b0b 1100 1100 6d0b 1100 -0000060: 1100 6e0b 1100 1100 700b 1100 1100 6f0b -0000070: 1100 1100 710b 1300 0000 0013 0000 0000 -0000080: 830b 1300 0000 0013 0000 0000 840b 1300 -0000090: 0000 0013 0000 0000 850b 1300 0000 0013 -00000a0: 0000 0000 860b 1300 0000 0013 0000 0000 -00000b0: 870b 1300 0000 0013 0000 0000 880b 1200 -00000c0: 0000 0000 0000 0012 0000 0000 0000 0000 -00000d0: 970b 1200 0000 0000 0000 0012 0000 0000 -00000e0: 0000 0000 980b 1200 0000 0000 0000 0012 -00000f0: 0000 0000 0000 0000 990b 1200 0000 0000 -0000100: 0000 0012 0000 0000 0000 0000 9a0b 1200 -0000110: 0000 0000 0000 0012 0000 0000 0000 0000 -0000120: 9b0b 1200 0000 0000 0000 0012 0000 0000 -0000130: 0000 0000 9c0b 0f +func 0 + 000019: 10 00 | i32.const 0 + 00001b: 10 00 | i32.const 0 + 00001d: 56 | i32.ge_u + 00001e: 10 00 | i32.const 0 + 000020: 54 | i32.ge_s + 000021: 10 00 | i32.const 0 + 000023: 55 | i32.gt_u + 000024: 10 00 | i32.const 0 + 000026: 53 | i32.gt_s + 000027: 10 00 | i32.const 0 + 000029: 52 | i32.le_u + 00002a: 10 00 | i32.const 0 + 00002c: 50 | i32.le_s + 00002d: 10 00 | i32.const 0 + 00002f: 51 | i32.lt_u + 000030: 10 00 | i32.const 0 + 000032: 4f | i32.lt_s + 000033: 10 00 | i32.const 0 + 000035: 4e | i32.ne + 000036: 10 00 | i32.const 0 + 000038: 4d | i32.eq + 000039: 0b | drop + 00003a: 11 00 | i64.const 0 + 00003c: 11 00 | i64.const 0 + 00003e: 68 | i64.eq + 00003f: 0b | drop + 000040: 11 00 | i64.const 0 + 000042: 11 00 | i64.const 0 + 000044: 69 | i64.ne + 000045: 0b | drop + 000046: 11 00 | i64.const 0 + 000048: 11 00 | i64.const 0 + 00004a: 6a | i64.lt_s + 00004b: 0b | drop + 00004c: 11 00 | i64.const 0 + 00004e: 11 00 | i64.const 0 + 000050: 6c | i64.lt_u + 000051: 0b | drop + 000052: 11 00 | i64.const 0 + 000054: 11 00 | i64.const 0 + 000056: 6b | i64.le_s + 000057: 0b | drop + 000058: 11 00 | i64.const 0 + 00005a: 11 00 | i64.const 0 + 00005c: 6d | i64.le_u + 00005d: 0b | drop + 00005e: 11 00 | i64.const 0 + 000060: 11 00 | i64.const 0 + 000062: 6e | i64.gt_s + 000063: 0b | drop + 000064: 11 00 | i64.const 0 + 000066: 11 00 | i64.const 0 + 000068: 70 | i64.gt_u + 000069: 0b | drop + 00006a: 11 00 | i64.const 0 + 00006c: 11 00 | i64.const 0 + 00006e: 6f | i64.ge_s + 00006f: 0b | drop + 000070: 11 00 | i64.const 0 + 000072: 11 00 | i64.const 0 + 000074: 71 | i64.ge_u + 000075: 0b | drop + 000076: 13 00 00 00 00 | f32.const 0 + 00007b: 13 00 00 00 00 | f32.const 0 + 000080: 83 | f32.eq + 000081: 0b | drop + 000082: 13 00 00 00 00 | f32.const 0 + 000087: 13 00 00 00 00 | f32.const 0 + 00008c: 84 | f32.ne + 00008d: 0b | drop + 00008e: 13 00 00 00 00 | f32.const 0 + 000093: 13 00 00 00 00 | f32.const 0 + 000098: 85 | f32.lt + 000099: 0b | drop + 00009a: 13 00 00 00 00 | f32.const 0 + 00009f: 13 00 00 00 00 | f32.const 0 + 0000a4: 86 | f32.le + 0000a5: 0b | drop + 0000a6: 13 00 00 00 00 | f32.const 0 + 0000ab: 13 00 00 00 00 | f32.const 0 + 0000b0: 87 | f32.gt + 0000b1: 0b | drop + 0000b2: 13 00 00 00 00 | f32.const 0 + 0000b7: 13 00 00 00 00 | f32.const 0 + 0000bc: 88 | f32.ge + 0000bd: 0b | drop + 0000be: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000c7: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000d0: 97 | f64.eq + 0000d1: 0b | drop + 0000d2: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000db: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000e4: 98 | f64.ne + 0000e5: 0b | drop + 0000e6: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000ef: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000f8: 99 | f64.lt + 0000f9: 0b | drop + 0000fa: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000103: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00010c: 9a | f64.le + 00010d: 0b | drop + 00010e: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000117: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000120: 9b | f64.gt + 000121: 0b | drop + 000122: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00012b: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000134: 9c | f64.ge + 000135: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/const.txt b/test/dump/const.txt index 1d3af3c7..b58f33d1 100644 --- a/test/dump/const.txt +++ b/test/dump/const.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (i32.const 0)) @@ -186,25 +187,81 @@ 0000015: 9a02 ; FIXUP func body size ; move data: [14, 131) -> [15, 132) 0000013: 9d02 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a9d 0201 9a02 0010 000b 1080 8080 -0000020: 8078 0b10 7f0b 1080 8080 8078 0b10 7f0b -0000030: 1100 0b11 8080 8080 8080 8080 807f 0b11 -0000040: 7f0b 1180 8080 8080 8080 8080 7f0b 117f -0000050: 0b13 0000 0000 0b13 1668 a965 0b13 4020 -0000060: 4f37 0b13 0000 c07f 0b13 0000 c0ff 0b13 -0000070: 0000 c07f 0b13 bc0a 807f 0b13 bc0a 80ff -0000080: 0b13 bc0a 807f 0b13 0000 807f 0b13 0000 -0000090: 80ff 0b13 0000 807f 0b13 0000 00bf 0b13 -00000a0: db0f c940 0b12 0000 0000 0000 0000 0b12 -00000b0: b856 0e3c dd9a efbf 0b12 182d 4454 fb21 -00000c0: 1940 0b12 0000 0000 0000 f87f 0b12 0000 -00000d0: 0000 0000 f8ff 0b12 0000 0000 0000 f87f -00000e0: 0b12 bc0a 0000 0000 f07f 0b12 bc0a 0000 -00000f0: 0000 f0ff 0b12 bc0a 0000 0000 f07f 0b12 -0000100: 0000 0000 0000 f07f 0b12 0000 0000 0000 -0000110: f0ff 0b12 0000 0000 0000 f07f 0b12 0000 -0000120: 0000 0000 e0bf 0b12 182d 4454 fb21 1940 -0000130: 0b0f +func 0 + 000019: 10 00 | i32.const 0 + 00001b: 0b | drop + 00001c: 10 80 80 80 80 78 | i32.const 0x80000000 + 000022: 0b | drop + 000023: 10 7f | i32.const 0xffffffff + 000025: 0b | drop + 000026: 10 80 80 80 80 78 | i32.const 0x80000000 + 00002c: 0b | drop + 00002d: 10 7f | i32.const 0xffffffff + 00002f: 0b | drop + 000030: 11 00 | i64.const 0 + 000032: 0b | drop + 000033: 11 80 80 80 80 80 80 80 80 80 | i64.const 0 + 00003e: 0b | drop + 00003f: 11 7f | i64.const -1 + 000041: 0b | drop + 000042: 11 80 80 80 80 80 80 80 80 80 | i64.const 0 + 00004d: 0b | drop + 00004e: 11 7f | i64.const -1 + 000050: 0b | drop + 000051: 13 00 00 00 00 | f32.const 0 + 000056: 0b | drop + 000057: 13 16 68 a9 65 | f32.const 0x65a96816 + 00005c: 0b | drop + 00005d: 13 40 20 4f 37 | f32.const 0x374f2040 + 000062: 0b | drop + 000063: 13 00 00 c0 7f | f32.const 0x7fc00000 + 000068: 0b | drop + 000069: 13 00 00 c0 ff | f32.const 0xffc00000 + 00006e: 0b | drop + 00006f: 13 00 00 c0 7f | f32.const 0x7fc00000 + 000074: 0b | drop + 000075: 13 bc 0a 80 7f | f32.const 0x7f800abc + 00007a: 0b | drop + 00007b: 13 bc 0a 80 ff | f32.const 0xff800abc + 000080: 0b | drop + 000081: 13 bc 0a 80 7f | f32.const 0x7f800abc + 000086: 0b | drop + 000087: 13 00 00 80 7f | f32.const 0x7f800000 + 00008c: 0b | drop + 00008d: 13 00 00 80 ff | f32.const 0xff800000 + 000092: 0b | drop + 000093: 13 00 00 80 7f | f32.const 0x7f800000 + 000098: 0b | drop + 000099: 13 00 00 00 bf | f32.const 0xbf000000 + 00009e: 0b | drop + 00009f: 13 db 0f c9 40 | f32.const 0x40c90fdb + 0000a4: 0b | drop + 0000a5: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 0000ae: 0b | drop + 0000af: 12 b8 56 0e 3c dd 9a ef bf | f64.const 1007572664 + 0000b8: 0b | drop + 0000b9: 12 18 2d 44 54 fb 21 19 40 | f64.const 1413754136 + 0000c2: 0b | drop + 0000c3: 12 00 00 00 00 00 00 f8 7f | f64.const 0 + 0000cc: 0b | drop + 0000cd: 12 00 00 00 00 00 00 f8 ff | f64.const 0 + 0000d6: 0b | drop + 0000d7: 12 00 00 00 00 00 00 f8 7f | f64.const 0 + 0000e0: 0b | drop + 0000e1: 12 bc 0a 00 00 00 00 f0 7f | f64.const 2748 + 0000ea: 0b | drop + 0000eb: 12 bc 0a 00 00 00 00 f0 ff | f64.const 2748 + 0000f4: 0b | drop + 0000f5: 12 bc 0a 00 00 00 00 f0 7f | f64.const 2748 + 0000fe: 0b | drop + 0000ff: 12 00 00 00 00 00 00 f0 7f | f64.const 0 + 000108: 0b | drop + 000109: 12 00 00 00 00 00 00 f0 ff | f64.const 0 + 000112: 0b | drop + 000113: 12 00 00 00 00 00 00 f0 7f | f64.const 0 + 00011c: 0b | drop + 00011d: 12 00 00 00 00 00 00 e0 bf | f64.const 0 + 000126: 0b | drop + 000127: 12 18 2d 44 54 fb 21 19 40 | f64.const 1413754136 + 000130: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/convert.txt b/test/dump/convert.txt index 759c863c..ec3cd7bd 100644 --- a/test/dump/convert.txt +++ b/test/dump/convert.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop @@ -85,9 +86,32 @@ 0000038: 0f ; end 0000015: 23 ; FIXUP func body size 0000013: 25 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a25 0123 0010 00af a0ae 9ea9 9fa8 -0000020: 9da7 a10b 1000 a6b1 a5b0 a3ab a4aa a20b -0000030: 1300 0000 00b2 ac0b 0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: af | f64.convert_u/i32 + 00001a: a0 | i32.trunc_u/f64 + 00001b: ae | f64.convert_s/i32 + 00001c: 9e | i32.trunc_s/f64 + 00001d: a9 | f32.convert_u/i32 + 00001e: 9f | i32.trunc_u/f32 + 00001f: a8 | f32.convert_s/i32 + 000020: 9d | i32.trunc_s/f32 + 000021: a7 | i64.extend_u/i32 + 000022: a1 | i32.wrap/i64 + 000023: 0b | drop + 000024: 10 00 | i32.const 0 + 000026: a6 | i64.extend_s/i32 + 000027: b1 | f64.convert_u/i64 + 000028: a5 | i64.trunc_u/f64 + 000029: b0 | f64.convert_s/i64 + 00002a: a3 | i64.trunc_s/f64 + 00002b: ab | f32.convert_u/i64 + 00002c: a4 | i64.trunc_u/f32 + 00002d: aa | f32.convert_s/i64 + 00002e: a2 | i64.trunc_s/f32 + 00002f: 0b | drop + 000030: 13 00 00 00 00 | f32.const 0 + 000035: b2 | f64.promote/f32 + 000036: ac | f32.demote/f64 + 000037: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/current-memory.txt b/test/dump/current-memory.txt index 2e17e13f..39a3ab18 100644 --- a/test/dump/current-memory.txt +++ b/test/dump/current-memory.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory 1) (func (result i32) @@ -41,7 +42,6 @@ 000001e: 0f ; end 000001b: 03 ; FIXUP func body size 0000019: 05 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0001 0103 -0000010: 0201 0005 0301 0001 0a05 0103 003b 0f +func 0 + 00001d: 3b | current_memory ;;; STDOUT ;;) diff --git a/test/dump/debug-names.txt b/test/dump/debug-names.txt index af8e960d..7b82d51a 100644 --- a/test/dump/debug-names.txt +++ b/test/dump/debug-names.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv --debug-names +;;; TOOL: run-wasmdump +;;; FLAGS: -v --debug-names (module (func $F1 (param $F1P0 i32) (local $F1L1 f32) @@ -84,12 +85,6 @@ 000005b: 05 ; string length 000005c: 2446 324c 33 $F2L3 ; local name 3 000002a: 36 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0109 0240 0101 0040 -0000010: 0103 0003 0302 0001 0a0f 0206 0201 0302 -0000020: 010f 0602 0104 0202 0f00 3604 6e61 6d65 -0000030: 0203 2446 3104 0524 4631 5030 0524 4631 -0000040: 4c31 0524 4631 4c32 0003 2446 3204 0524 -0000050: 4632 5030 0524 4632 4c31 0005 2446 324c -0000060: 33 +func 0 +func 1 ;;; STDOUT ;;) diff --git a/test/dump/dedupe-sig.txt b/test/dump/dedupe-sig.txt index 3518daaa..5d8004d6 100644 --- a/test/dump/dedupe-sig.txt +++ b/test/dump/dedupe-sig.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (type (func (param i32) (result i64))) (import "foo" "bar" (func (param i32) (result i64))) @@ -47,8 +48,6 @@ 0000028: 0f ; end 0000024: 04 ; FIXUP func body size 0000022: 06 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0106 0140 0101 0102 -0000010: 020b 0103 666f 6f03 6261 7200 0003 0201 -0000020: 000a 0601 0400 1100 0f +func 0 + 000026: 11 00 | i64.const 0 ;;; STDOUT ;;) diff --git a/test/dump/drop.txt b/test/dump/drop.txt index 577f1d08..72f15253 100644 --- a/test/dump/drop.txt +++ b/test/dump/drop.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (i32.const 0)))) @@ -33,7 +34,7 @@ 000001a: 0f ; end 0000015: 05 ; FIXUP func body size 0000013: 07 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a07 0105 0010 000b 0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/export-multi.txt b/test/dump/export-multi.txt index bbc70912..fe04f986 100644 --- a/test/dump/export-multi.txt +++ b/test/dump/export-multi.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (nop)) (export "a" (func 0)) @@ -45,8 +46,6 @@ 0000023: 0f ; end 0000020: 03 ; FIXUP func body size 000001e: 05 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0709 0201 6100 0001 6200 000a 0501 -0000020: 0300 0a0f +func 0 + 000022: 0a | nop ;;; STDOUT ;;) diff --git a/test/dump/expr-br.txt b/test/dump/expr-br.txt index a5943896..7a22f38c 100644 --- a/test/dump/expr-br.txt +++ b/test/dump/expr-br.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (result i32) (block i32 @@ -39,7 +40,9 @@ 000001f: 0f ; end 0000016: 09 ; FIXUP func body size 0000014: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0001 0103 -0000010: 0201 000a 0b01 0900 0101 1001 0600 0f0f +func 0 + 000018: 01 01 | block i32 + 00001a: 10 01 | i32.const 0x1 + 00001c: 06 00 | br 0 + 00001e: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/expr-brif.txt b/test/dump/expr-brif.txt index 1216d350..5fdb5ac3 100644 --- a/test/dump/expr-brif.txt +++ b/test/dump/expr-brif.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (result i32) (block $exit i32 @@ -46,8 +47,12 @@ 0000024: 0f ; end 0000016: 0e ; FIXUP func body size 0000014: 10 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0001 0103 -0000010: 0201 000a 1001 0e00 0101 102a 1000 0700 -0000020: 0b10 1d0f 0f +func 0 + 000018: 01 01 | block i32 + 00001a: 10 2a | i32.const 0x2a + 00001c: 10 00 | i32.const 0 + 00001e: 07 00 | br_if 0 + 000020: 0b | drop + 000021: 10 1d | i32.const 0x1d + 000023: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/func-exported.txt b/test/dump/func-exported.txt index f5253eed..1dcb44e0 100644 --- a/test/dump/func-exported.txt +++ b/test/dump/func-exported.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func) (export "foo" (func 0))) @@ -39,8 +40,5 @@ 0000020: 0f ; end 000001e: 02 ; FIXUP func body size 000001c: 04 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0707 0103 666f 6f00 000a 0401 0200 -0000020: 0f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/func-multi.txt b/test/dump/func-multi.txt index 440a013f..e98ab2f4 100644 --- a/test/dump/func-multi.txt +++ b/test/dump/func-multi.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func) (func) @@ -43,7 +44,7 @@ 000001f: 0f ; end 000001d: 02 ; FIXUP func body size 0000015: 0a ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0304 -0000010: 0300 0000 0a0a 0302 000f 0200 0f02 000f +func 0 +func 1 +func 2 ;;; STDOUT ;;) diff --git a/test/dump/func-named.txt b/test/dump/func-named.txt index 21012c02..bc3f41bf 100644 --- a/test/dump/func-named.txt +++ b/test/dump/func-named.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func $my-func)) (;; STDOUT ;;; @@ -29,7 +30,5 @@ 0000017: 0f ; end 0000015: 02 ; FIXUP func body size 0000013: 04 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a04 0102 000f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/getglobal.txt b/test/dump/getglobal.txt index 112536fb..496b2e15 100644 --- a/test/dump/getglobal.txt +++ b/test/dump/getglobal.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (global i32 (i32.const 0)) (func (result i32) @@ -44,8 +45,6 @@ 0000022: 0f ; end 000001e: 04 ; FIXUP func body size 000001c: 06 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0001 0103 -0000010: 0201 0006 0601 0100 1000 0f0a 0601 0400 -0000020: bb00 0f +func 0 + 000020: bb 00 | get_global 0 ;;; STDOUT ;;) diff --git a/test/dump/getlocal-param.txt b/test/dump/getlocal-param.txt index c0ac87f1..4e0c392c 100644 --- a/test/dump/getlocal-param.txt +++ b/test/dump/getlocal-param.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module ;; parameters are always first ;; 0 1 @@ -71,9 +72,17 @@ 0000033: 0f ; end 0000017: 1c ; FIXUP func body size 0000015: 1e ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0106 0140 0201 0300 -0000010: 0302 0100 0a1e 011c 0401 0201 0301 0101 -0000020: 0314 000b 1401 0b14 020b 1403 0b14 040b -0000030: 1405 0b0f +func 0 + 000021: 14 00 | get_local 0 + 000023: 0b | drop + 000024: 14 01 | get_local 0x1 + 000026: 0b | drop + 000027: 14 02 | get_local 0x2 + 000029: 0b | drop + 00002a: 14 03 | get_local 0x3 + 00002c: 0b | drop + 00002d: 14 04 | get_local 0x4 + 00002f: 0b | drop + 000030: 14 05 | get_local 0x5 + 000032: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/getlocal.txt b/test/dump/getlocal.txt index 60af19e0..1dc2e088 100644 --- a/test/dump/getlocal.txt +++ b/test/dump/getlocal.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func ;; by default, sexpr-wasm will remap locals so all similar types are @@ -82,9 +83,21 @@ 000003d: 0f ; end 0000015: 28 ; FIXUP func body size 0000013: 2a ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a2a 0128 0701 0401 0301 0202 0101 -0000020: 0301 0401 0214 000b 1401 0b14 020b 1403 -0000030: 0b14 040b 1405 0b14 060b 1407 0b0f +func 0 + 000025: 14 00 | get_local 0 + 000027: 0b | drop + 000028: 14 01 | get_local 0x1 + 00002a: 0b | drop + 00002b: 14 02 | get_local 0x2 + 00002d: 0b | drop + 00002e: 14 03 | get_local 0x3 + 000030: 0b | drop + 000031: 14 04 | get_local 0x4 + 000033: 0b | drop + 000034: 14 05 | get_local 0x5 + 000036: 0b | drop + 000037: 14 06 | get_local 0x6 + 000039: 0b | drop + 00003a: 14 07 | get_local 0x7 + 00003c: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/global.txt b/test/dump/global.txt index 713c507e..d9072f15 100644 --- a/test/dump/global.txt +++ b/test/dump/global.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (global i32 (i32.const 1)) (global i64 (i64.const 2)) @@ -57,9 +58,4 @@ 000003b: 03 ; global index 000003c: 0f ; end 0000009: 33 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0633 0801 0010 010f -0000010: 0200 1102 0f03 0013 0000 4040 0f04 0012 -0000020: 0000 0000 0000 1040 0f01 00bb 000f 0200 -0000030: bb01 0f03 00bb 020f 0400 bb03 0f ;;; STDOUT ;;) diff --git a/test/dump/grow-memory.txt b/test/dump/grow-memory.txt index 47eb4cd3..d30f2b14 100644 --- a/test/dump/grow-memory.txt +++ b/test/dump/grow-memory.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory 1 2) (func (param i32) @@ -46,8 +47,8 @@ 0000022: 0f ; end 000001c: 06 ; FIXUP func body size 000001a: 08 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0105 0140 0101 0003 -0000010: 0201 0005 0401 0101 020a 0801 0600 1400 -0000020: 390b 0f +func 0 + 00001e: 14 00 | get_local 0 + 000020: 39 | grow_memory + 000021: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/hexfloat_f32.txt b/test/dump/hexfloat_f32.txt index 42e478e5..cf52355d 100644 --- a/test/dump/hexfloat_f32.txt +++ b/test/dump/hexfloat_f32.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (f32.const 0x0p0)) @@ -99,13 +100,39 @@ 000007d: 0f ; end 0000015: 68 ; FIXUP func body size 0000013: 6a ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a6a 0168 0013 0000 0000 0b13 80a2 -0000020: 9148 0b13 0000 8059 0b13 0000 007f 0b13 -0000030: 0000 807c 0b13 0080 917d 0b13 f0ff ff7e -0000040: 0b13 feff 7f7e 0b13 0000 807f 0b13 c4ff -0000050: 7f7f 0b13 f8ff 7f7f 0b13 faff ff0a 0b13 -0000060: f8ff ff0a 0b13 0000 0004 0b13 0000 883f -0000070: 0b13 0000 8053 0b13 8080 7fc0 0b0f +func 0 + 000017: 13 00 00 00 00 | f32.const 0 + 00001c: 0b | drop + 00001d: 13 80 a2 91 48 | f32.const 0x4891a280 + 000022: 0b | drop + 000023: 13 00 00 80 59 | f32.const 0x59800000 + 000028: 0b | drop + 000029: 13 00 00 00 7f | f32.const 0x7f000000 + 00002e: 0b | drop + 00002f: 13 00 00 80 7c | f32.const 0x7c800000 + 000034: 0b | drop + 000035: 13 00 80 91 7d | f32.const 0x7d918000 + 00003a: 0b | drop + 00003b: 13 f0 ff ff 7e | f32.const 0x7efffff0 + 000040: 0b | drop + 000041: 13 fe ff 7f 7e | f32.const 0x7e7ffffe + 000046: 0b | drop + 000047: 13 00 00 80 7f | f32.const 0x7f800000 + 00004c: 0b | drop + 00004d: 13 c4 ff 7f 7f | f32.const 0x7f7fffc4 + 000052: 0b | drop + 000053: 13 f8 ff 7f 7f | f32.const 0x7f7ffff8 + 000058: 0b | drop + 000059: 13 fa ff ff 0a | f32.const 0xafffffa + 00005e: 0b | drop + 00005f: 13 f8 ff ff 0a | f32.const 0xafffff8 + 000064: 0b | drop + 000065: 13 00 00 00 04 | f32.const 0x4000000 + 00006a: 0b | drop + 00006b: 13 00 00 88 3f | f32.const 0x3f880000 + 000070: 0b | drop + 000071: 13 00 00 80 53 | f32.const 0x53800000 + 000076: 0b | drop + 000077: 13 80 80 7f c0 | f32.const 0xc07f8080 + 00007c: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/hexfloat_f64.txt b/test/dump/hexfloat_f64.txt index 0e6a47ae..53d42ea1 100644 --- a/test/dump/hexfloat_f64.txt +++ b/test/dump/hexfloat_f64.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (f64.const 0x0p0)) @@ -101,18 +102,39 @@ 0000015: ac01 ; FIXUP func body size ; move data: [14, c3) -> [15, c4) 0000013: af01 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0aaf 0101 ac01 0012 0000 0000 0000 -0000020: 0000 0b12 0000 0000 5034 1241 0b12 0000 -0000030: 0000 0000 3045 0b12 0000 0000 0000 e07f -0000040: 0b12 0000 0000 0000 907f 0b12 0000 0000 -0000050: 0030 c27f 0b12 00e0 ffff ffff df7f 0b12 -0000060: c0ff ffff ffff cf7f 0b12 0000 0000 0000 -0000070: f07f 0b12 fcff ffff ffff ef7f 0b12 feff -0000080: ffff ffff ef7f 0b12 f1ff ffff ffff df02 -0000090: 0b12 f3ff ffff ffff df02 0b12 0000 0000 -00000a0: 0000 8001 0b12 0000 0000 0000 f13f 0b12 -00000b0: 0000 0000 0000 7042 0b12 0000 0000 10f0 -00000c0: 0fc0 0b0f +func 0 + 000019: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000022: 0b | drop + 000023: 12 00 00 00 00 50 34 12 41 | f64.const 0 + 00002c: 0b | drop + 00002d: 12 00 00 00 00 00 00 30 45 | f64.const 0 + 000036: 0b | drop + 000037: 12 00 00 00 00 00 00 e0 7f | f64.const 0 + 000040: 0b | drop + 000041: 12 00 00 00 00 00 00 90 7f | f64.const 0 + 00004a: 0b | drop + 00004b: 12 00 00 00 00 00 30 c2 7f | f64.const 0 + 000054: 0b | drop + 000055: 12 00 e0 ff ff ff ff df 7f | f64.const -8192 + 00005e: 0b | drop + 00005f: 12 c0 ff ff ff ff ff cf 7f | f64.const -64 + 000068: 0b | drop + 000069: 12 00 00 00 00 00 00 f0 7f | f64.const 0 + 000072: 0b | drop + 000073: 12 fc ff ff ff ff ff ef 7f | f64.const -4 + 00007c: 0b | drop + 00007d: 12 fe ff ff ff ff ff ef 7f | f64.const -2 + 000086: 0b | drop + 000087: 12 f1 ff ff ff ff ff df 02 | f64.const -15 + 000090: 0b | drop + 000091: 12 f3 ff ff ff ff ff df 02 | f64.const -13 + 00009a: 0b | drop + 00009b: 12 00 00 00 00 00 00 80 01 | f64.const 0 + 0000a4: 0b | drop + 0000a5: 12 00 00 00 00 00 00 f1 3f | f64.const 0 + 0000ae: 0b | drop + 0000af: 12 00 00 00 00 00 00 70 42 | f64.const 0 + 0000b8: 0b | drop + 0000b9: 12 00 00 00 00 10 f0 0f c0 | f64.const 0 + 0000c2: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/if-then-else-list.txt b/test/dump/if-then-else-list.txt index 8d2e9b64..6fce0819 100644 --- a/test/dump/if-then-else-list.txt +++ b/test/dump/if-then-else-list.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (if (i32.const 1) @@ -54,8 +55,17 @@ 0000029: 0f ; end 0000015: 14 ; FIXUP func body size 0000013: 16 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a16 0114 0010 0103 0010 020b 1003 -0000020: 0b04 1004 0b10 050b 0f0f +func 0 + 000017: 10 01 | i32.const 0x1 + 000019: 03 00 | if + 00001b: 10 02 | i32.const 0x2 + 00001d: 0b | drop + 00001e: 10 03 | i32.const 0x3 + 000020: 0b | drop + 000021: 04 | else + 000022: 10 04 | i32.const 0x4 + 000024: 0b | drop + 000025: 10 05 | i32.const 0x5 + 000027: 0b | drop + 000028: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/if-then-list.txt b/test/dump/if-then-list.txt index aeb3a544..1bce7e1f 100644 --- a/test/dump/if-then-list.txt +++ b/test/dump/if-then-list.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (if (i32.const 1) @@ -38,7 +39,10 @@ 000001e: 0f ; end 0000015: 09 ; FIXUP func body size 0000013: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0b 0109 0010 0103 000a 0a0f 0f +func 0 + 000017: 10 01 | i32.const 0x1 + 000019: 03 00 | if + 00001b: 0a | nop + 00001c: 0a | nop + 00001d: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/if.txt b/test/dump/if.txt index be3d62f0..fc316d67 100644 --- a/test/dump/if.txt +++ b/test/dump/if.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (if (i32.const 1) @@ -70,9 +71,23 @@ 000003a: 0f ; end 0000030: 0a ; FIXUP func body size 0000014: 26 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0303 -0000010: 0200 000a 2602 1900 1001 0300 0a0f 1000 -0000020: 0303 1300 0080 3f04 1300 0000 400f 0b0f -0000030: 0a00 1001 0300 0904 090f 0f +func 0 + 000018: 10 01 | i32.const 0x1 + 00001a: 03 00 | if + 00001c: 0a | nop + 00001d: 0f | end + 00001e: 10 00 | i32.const 0 + 000020: 03 03 | if f32 + 000022: 13 00 00 80 3f | f32.const 0x3f800000 + 000027: 04 | else + 000028: 13 00 00 00 40 | f32.const 0x40000000 + 00002d: 0f | end + 00002e: 0b | drop +func 1 + 000032: 10 01 | i32.const 0x1 + 000034: 03 00 | if + 000036: 09 | return + 000037: 04 | else + 000038: 09 | return + 000039: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/import.txt b/test/dump/import.txt index 607472ca..2bfc4561 100644 --- a/test/dump/import.txt +++ b/test/dump/import.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (import "ignored" "test" (func (param i32 i64 f32 f64))) (import "ignored" "test2" (func (param i32) (result i32)))) @@ -43,9 +44,4 @@ 0000037: 00 ; import kind 0000038: 01 ; import signature index 0000018: 20 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 010d 0240 0401 0203 -0000010: 0400 4001 0101 0102 2002 0769 676e 6f72 -0000020: 6564 0474 6573 7400 0007 6967 6e6f 7265 -0000030: 6405 7465 7374 3200 01 ;;; STDOUT ;;) diff --git a/test/dump/load-aligned.txt b/test/dump/load-aligned.txt index 32826182..63f79ce4 100644 --- a/test/dump/load-aligned.txt +++ b/test/dump/load-aligned.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (i32.load8_s align=1 (i32.const 0))) @@ -147,13 +148,53 @@ 0000077: 0f ; end 0000015: 62 ; FIXUP func body size 0000013: 64 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a64 0162 0010 0020 0000 0b10 0022 -0000020: 0000 0b10 0022 0100 0b10 002a 0000 0b10 -0000030: 002a 0100 0b10 002a 0200 0b10 0024 0000 -0000040: 0b10 0026 0000 0b10 0026 0100 0b10 0028 -0000050: 0000 0b10 0028 0100 0b10 0028 0200 0b10 -0000060: 002b 0000 0b10 002b 0100 0b10 002b 0200 -0000070: 0b10 002b 0300 0b0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 20 00 00 | i32.load8_s 0 0 + 00001c: 0b | drop + 00001d: 10 00 | i32.const 0 + 00001f: 22 00 00 | i32.load16_s 0 0 + 000022: 0b | drop + 000023: 10 00 | i32.const 0 + 000025: 22 01 00 | i32.load16_s 1 0 + 000028: 0b | drop + 000029: 10 00 | i32.const 0 + 00002b: 2a 00 00 | i32.load 0 0 + 00002e: 0b | drop + 00002f: 10 00 | i32.const 0 + 000031: 2a 01 00 | i32.load 1 0 + 000034: 0b | drop + 000035: 10 00 | i32.const 0 + 000037: 2a 02 00 | i32.load 2 0 + 00003a: 0b | drop + 00003b: 10 00 | i32.const 0 + 00003d: 24 00 00 | i64.load8_s 0 0 + 000040: 0b | drop + 000041: 10 00 | i32.const 0 + 000043: 26 00 00 | i64.load16_s 0 0 + 000046: 0b | drop + 000047: 10 00 | i32.const 0 + 000049: 26 01 00 | i64.load16_s 1 0 + 00004c: 0b | drop + 00004d: 10 00 | i32.const 0 + 00004f: 28 00 00 | i64.load32_s 0 0 + 000052: 0b | drop + 000053: 10 00 | i32.const 0 + 000055: 28 01 00 | i64.load32_s 1 0 + 000058: 0b | drop + 000059: 10 00 | i32.const 0 + 00005b: 28 02 00 | i64.load32_s 2 0 + 00005e: 0b | drop + 00005f: 10 00 | i32.const 0 + 000061: 2b 00 00 | i64.load 0 0 + 000064: 0b | drop + 000065: 10 00 | i32.const 0 + 000067: 2b 01 00 | i64.load 1 0 + 00006a: 0b | drop + 00006b: 10 00 | i32.const 0 + 00006d: 2b 02 00 | i64.load 2 0 + 000070: 0b | drop + 000071: 10 00 | i32.const 0 + 000073: 2b 03 00 | i64.load 3 0 + 000076: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/load.txt b/test/dump/load.txt index 4122551f..75e37c04 100644 --- a/test/dump/load.txt +++ b/test/dump/load.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (i32.load (i32.const 0))) @@ -127,12 +128,47 @@ 000006b: 0f ; end 0000015: 56 ; FIXUP func body size 0000013: 58 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a58 0156 0010 002a 0200 0b10 0020 -0000020: 0000 0b10 0022 0100 0b10 0021 0000 0b10 -0000030: 0023 0100 0b10 002b 0300 0b10 0024 0000 -0000040: 0b10 0026 0100 0b10 0028 0200 0b10 0025 -0000050: 0000 0b10 0027 0100 0b10 0029 0200 0b10 -0000060: 002c 0200 0b10 002d 0300 0b0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 2a 02 00 | i32.load 2 0 + 00001c: 0b | drop + 00001d: 10 00 | i32.const 0 + 00001f: 20 00 00 | i32.load8_s 0 0 + 000022: 0b | drop + 000023: 10 00 | i32.const 0 + 000025: 22 01 00 | i32.load16_s 1 0 + 000028: 0b | drop + 000029: 10 00 | i32.const 0 + 00002b: 21 00 00 | i32.load8_u 0 0 + 00002e: 0b | drop + 00002f: 10 00 | i32.const 0 + 000031: 23 01 00 | i32.load16_u 1 0 + 000034: 0b | drop + 000035: 10 00 | i32.const 0 + 000037: 2b 03 00 | i64.load 3 0 + 00003a: 0b | drop + 00003b: 10 00 | i32.const 0 + 00003d: 24 00 00 | i64.load8_s 0 0 + 000040: 0b | drop + 000041: 10 00 | i32.const 0 + 000043: 26 01 00 | i64.load16_s 1 0 + 000046: 0b | drop + 000047: 10 00 | i32.const 0 + 000049: 28 02 00 | i64.load32_s 2 0 + 00004c: 0b | drop + 00004d: 10 00 | i32.const 0 + 00004f: 25 00 00 | i64.load8_u 0 0 + 000052: 0b | drop + 000053: 10 00 | i32.const 0 + 000055: 27 01 00 | i64.load16_u 1 0 + 000058: 0b | drop + 000059: 10 00 | i32.const 0 + 00005b: 29 02 00 | i64.load32_u 2 0 + 00005e: 0b | drop + 00005f: 10 00 | i32.const 0 + 000061: 2c 02 00 | f32.load 2 0 + 000064: 0b | drop + 000065: 10 00 | i32.const 0 + 000067: 2d 03 00 | f64.load 3 0 + 00006a: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/locals.txt b/test/dump/locals.txt index 38d726c4..7367bb0b 100644 --- a/test/dump/locals.txt +++ b/test/dump/locals.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (local i32 i64 i64 f32 f32 f32 f64 f64 f64 f64))) (;; STDOUT ;;; @@ -37,7 +38,5 @@ 000001f: 0f ; end 0000015: 0a ; FIXUP func body size 0000013: 0c ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0c 010a 0401 0102 0203 0304 040f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/loop-257-exprs-br.txt b/test/dump/loop-257-exprs-br.txt index 9ef3b896..8df8e9f8 100644 --- a/test/dump/loop-257-exprs-br.txt +++ b/test/dump/loop-257-exprs-br.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (block $outer (loop $inner @@ -348,24 +349,269 @@ 0000015: 9002 ; FIXUP func body size ; move data: [14, 127) -> [15, 128) 0000013: 9302 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a93 0201 9002 0001 0002 000a 0a0a -0000020: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000030: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000040: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000050: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000060: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000070: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000080: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000090: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000a0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000b0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000c0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000d0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000e0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000f0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000100: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000110: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a06 0106 -0000120: 0006 0106 000f 0f0f +func 0 + 000019: 01 00 | block + 00001b: 02 00 | loop + 00001d: 0a | nop + 00001e: 0a | nop + 00001f: 0a | nop + 000020: 0a | nop + 000021: 0a | nop + 000022: 0a | nop + 000023: 0a | nop + 000024: 0a | nop + 000025: 0a | nop + 000026: 0a | nop + 000027: 0a | nop + 000028: 0a | nop + 000029: 0a | nop + 00002a: 0a | nop + 00002b: 0a | nop + 00002c: 0a | nop + 00002d: 0a | nop + 00002e: 0a | nop + 00002f: 0a | nop + 000030: 0a | nop + 000031: 0a | nop + 000032: 0a | nop + 000033: 0a | nop + 000034: 0a | nop + 000035: 0a | nop + 000036: 0a | nop + 000037: 0a | nop + 000038: 0a | nop + 000039: 0a | nop + 00003a: 0a | nop + 00003b: 0a | nop + 00003c: 0a | nop + 00003d: 0a | nop + 00003e: 0a | nop + 00003f: 0a | nop + 000040: 0a | nop + 000041: 0a | nop + 000042: 0a | nop + 000043: 0a | nop + 000044: 0a | nop + 000045: 0a | nop + 000046: 0a | nop + 000047: 0a | nop + 000048: 0a | nop + 000049: 0a | nop + 00004a: 0a | nop + 00004b: 0a | nop + 00004c: 0a | nop + 00004d: 0a | nop + 00004e: 0a | nop + 00004f: 0a | nop + 000050: 0a | nop + 000051: 0a | nop + 000052: 0a | nop + 000053: 0a | nop + 000054: 0a | nop + 000055: 0a | nop + 000056: 0a | nop + 000057: 0a | nop + 000058: 0a | nop + 000059: 0a | nop + 00005a: 0a | nop + 00005b: 0a | nop + 00005c: 0a | nop + 00005d: 0a | nop + 00005e: 0a | nop + 00005f: 0a | nop + 000060: 0a | nop + 000061: 0a | nop + 000062: 0a | nop + 000063: 0a | nop + 000064: 0a | nop + 000065: 0a | nop + 000066: 0a | nop + 000067: 0a | nop + 000068: 0a | nop + 000069: 0a | nop + 00006a: 0a | nop + 00006b: 0a | nop + 00006c: 0a | nop + 00006d: 0a | nop + 00006e: 0a | nop + 00006f: 0a | nop + 000070: 0a | nop + 000071: 0a | nop + 000072: 0a | nop + 000073: 0a | nop + 000074: 0a | nop + 000075: 0a | nop + 000076: 0a | nop + 000077: 0a | nop + 000078: 0a | nop + 000079: 0a | nop + 00007a: 0a | nop + 00007b: 0a | nop + 00007c: 0a | nop + 00007d: 0a | nop + 00007e: 0a | nop + 00007f: 0a | nop + 000080: 0a | nop + 000081: 0a | nop + 000082: 0a | nop + 000083: 0a | nop + 000084: 0a | nop + 000085: 0a | nop + 000086: 0a | nop + 000087: 0a | nop + 000088: 0a | nop + 000089: 0a | nop + 00008a: 0a | nop + 00008b: 0a | nop + 00008c: 0a | nop + 00008d: 0a | nop + 00008e: 0a | nop + 00008f: 0a | nop + 000090: 0a | nop + 000091: 0a | nop + 000092: 0a | nop + 000093: 0a | nop + 000094: 0a | nop + 000095: 0a | nop + 000096: 0a | nop + 000097: 0a | nop + 000098: 0a | nop + 000099: 0a | nop + 00009a: 0a | nop + 00009b: 0a | nop + 00009c: 0a | nop + 00009d: 0a | nop + 00009e: 0a | nop + 00009f: 0a | nop + 0000a0: 0a | nop + 0000a1: 0a | nop + 0000a2: 0a | nop + 0000a3: 0a | nop + 0000a4: 0a | nop + 0000a5: 0a | nop + 0000a6: 0a | nop + 0000a7: 0a | nop + 0000a8: 0a | nop + 0000a9: 0a | nop + 0000aa: 0a | nop + 0000ab: 0a | nop + 0000ac: 0a | nop + 0000ad: 0a | nop + 0000ae: 0a | nop + 0000af: 0a | nop + 0000b0: 0a | nop + 0000b1: 0a | nop + 0000b2: 0a | nop + 0000b3: 0a | nop + 0000b4: 0a | nop + 0000b5: 0a | nop + 0000b6: 0a | nop + 0000b7: 0a | nop + 0000b8: 0a | nop + 0000b9: 0a | nop + 0000ba: 0a | nop + 0000bb: 0a | nop + 0000bc: 0a | nop + 0000bd: 0a | nop + 0000be: 0a | nop + 0000bf: 0a | nop + 0000c0: 0a | nop + 0000c1: 0a | nop + 0000c2: 0a | nop + 0000c3: 0a | nop + 0000c4: 0a | nop + 0000c5: 0a | nop + 0000c6: 0a | nop + 0000c7: 0a | nop + 0000c8: 0a | nop + 0000c9: 0a | nop + 0000ca: 0a | nop + 0000cb: 0a | nop + 0000cc: 0a | nop + 0000cd: 0a | nop + 0000ce: 0a | nop + 0000cf: 0a | nop + 0000d0: 0a | nop + 0000d1: 0a | nop + 0000d2: 0a | nop + 0000d3: 0a | nop + 0000d4: 0a | nop + 0000d5: 0a | nop + 0000d6: 0a | nop + 0000d7: 0a | nop + 0000d8: 0a | nop + 0000d9: 0a | nop + 0000da: 0a | nop + 0000db: 0a | nop + 0000dc: 0a | nop + 0000dd: 0a | nop + 0000de: 0a | nop + 0000df: 0a | nop + 0000e0: 0a | nop + 0000e1: 0a | nop + 0000e2: 0a | nop + 0000e3: 0a | nop + 0000e4: 0a | nop + 0000e5: 0a | nop + 0000e6: 0a | nop + 0000e7: 0a | nop + 0000e8: 0a | nop + 0000e9: 0a | nop + 0000ea: 0a | nop + 0000eb: 0a | nop + 0000ec: 0a | nop + 0000ed: 0a | nop + 0000ee: 0a | nop + 0000ef: 0a | nop + 0000f0: 0a | nop + 0000f1: 0a | nop + 0000f2: 0a | nop + 0000f3: 0a | nop + 0000f4: 0a | nop + 0000f5: 0a | nop + 0000f6: 0a | nop + 0000f7: 0a | nop + 0000f8: 0a | nop + 0000f9: 0a | nop + 0000fa: 0a | nop + 0000fb: 0a | nop + 0000fc: 0a | nop + 0000fd: 0a | nop + 0000fe: 0a | nop + 0000ff: 0a | nop + 000100: 0a | nop + 000101: 0a | nop + 000102: 0a | nop + 000103: 0a | nop + 000104: 0a | nop + 000105: 0a | nop + 000106: 0a | nop + 000107: 0a | nop + 000108: 0a | nop + 000109: 0a | nop + 00010a: 0a | nop + 00010b: 0a | nop + 00010c: 0a | nop + 00010d: 0a | nop + 00010e: 0a | nop + 00010f: 0a | nop + 000110: 0a | nop + 000111: 0a | nop + 000112: 0a | nop + 000113: 0a | nop + 000114: 0a | nop + 000115: 0a | nop + 000116: 0a | nop + 000117: 0a | nop + 000118: 0a | nop + 000119: 0a | nop + 00011a: 0a | nop + 00011b: 0a | nop + 00011c: 0a | nop + 00011d: 06 01 | br 0x1 + 00011f: 06 00 | br 0 + 000121: 06 01 | br 0x1 + 000123: 06 00 | br 0 + 000125: 0f | end + 000126: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/loop-257-exprs.txt b/test/dump/loop-257-exprs.txt index 83848941..81eefbaf 100644 --- a/test/dump/loop-257-exprs.txt +++ b/test/dump/loop-257-exprs.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (loop @@ -334,23 +335,264 @@ 0000015: 8602 ; FIXUP func body size ; move data: [14, 11d) -> [15, 11e) 0000013: 8902 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a89 0201 8602 0002 000a 0a0a 0a0a -0000020: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000030: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000040: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000050: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000060: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000070: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000080: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000090: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000a0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000b0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000c0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000d0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000e0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -00000f0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000100: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a -0000110: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0f0f +func 0 + 000019: 02 00 | loop + 00001b: 0a | nop + 00001c: 0a | nop + 00001d: 0a | nop + 00001e: 0a | nop + 00001f: 0a | nop + 000020: 0a | nop + 000021: 0a | nop + 000022: 0a | nop + 000023: 0a | nop + 000024: 0a | nop + 000025: 0a | nop + 000026: 0a | nop + 000027: 0a | nop + 000028: 0a | nop + 000029: 0a | nop + 00002a: 0a | nop + 00002b: 0a | nop + 00002c: 0a | nop + 00002d: 0a | nop + 00002e: 0a | nop + 00002f: 0a | nop + 000030: 0a | nop + 000031: 0a | nop + 000032: 0a | nop + 000033: 0a | nop + 000034: 0a | nop + 000035: 0a | nop + 000036: 0a | nop + 000037: 0a | nop + 000038: 0a | nop + 000039: 0a | nop + 00003a: 0a | nop + 00003b: 0a | nop + 00003c: 0a | nop + 00003d: 0a | nop + 00003e: 0a | nop + 00003f: 0a | nop + 000040: 0a | nop + 000041: 0a | nop + 000042: 0a | nop + 000043: 0a | nop + 000044: 0a | nop + 000045: 0a | nop + 000046: 0a | nop + 000047: 0a | nop + 000048: 0a | nop + 000049: 0a | nop + 00004a: 0a | nop + 00004b: 0a | nop + 00004c: 0a | nop + 00004d: 0a | nop + 00004e: 0a | nop + 00004f: 0a | nop + 000050: 0a | nop + 000051: 0a | nop + 000052: 0a | nop + 000053: 0a | nop + 000054: 0a | nop + 000055: 0a | nop + 000056: 0a | nop + 000057: 0a | nop + 000058: 0a | nop + 000059: 0a | nop + 00005a: 0a | nop + 00005b: 0a | nop + 00005c: 0a | nop + 00005d: 0a | nop + 00005e: 0a | nop + 00005f: 0a | nop + 000060: 0a | nop + 000061: 0a | nop + 000062: 0a | nop + 000063: 0a | nop + 000064: 0a | nop + 000065: 0a | nop + 000066: 0a | nop + 000067: 0a | nop + 000068: 0a | nop + 000069: 0a | nop + 00006a: 0a | nop + 00006b: 0a | nop + 00006c: 0a | nop + 00006d: 0a | nop + 00006e: 0a | nop + 00006f: 0a | nop + 000070: 0a | nop + 000071: 0a | nop + 000072: 0a | nop + 000073: 0a | nop + 000074: 0a | nop + 000075: 0a | nop + 000076: 0a | nop + 000077: 0a | nop + 000078: 0a | nop + 000079: 0a | nop + 00007a: 0a | nop + 00007b: 0a | nop + 00007c: 0a | nop + 00007d: 0a | nop + 00007e: 0a | nop + 00007f: 0a | nop + 000080: 0a | nop + 000081: 0a | nop + 000082: 0a | nop + 000083: 0a | nop + 000084: 0a | nop + 000085: 0a | nop + 000086: 0a | nop + 000087: 0a | nop + 000088: 0a | nop + 000089: 0a | nop + 00008a: 0a | nop + 00008b: 0a | nop + 00008c: 0a | nop + 00008d: 0a | nop + 00008e: 0a | nop + 00008f: 0a | nop + 000090: 0a | nop + 000091: 0a | nop + 000092: 0a | nop + 000093: 0a | nop + 000094: 0a | nop + 000095: 0a | nop + 000096: 0a | nop + 000097: 0a | nop + 000098: 0a | nop + 000099: 0a | nop + 00009a: 0a | nop + 00009b: 0a | nop + 00009c: 0a | nop + 00009d: 0a | nop + 00009e: 0a | nop + 00009f: 0a | nop + 0000a0: 0a | nop + 0000a1: 0a | nop + 0000a2: 0a | nop + 0000a3: 0a | nop + 0000a4: 0a | nop + 0000a5: 0a | nop + 0000a6: 0a | nop + 0000a7: 0a | nop + 0000a8: 0a | nop + 0000a9: 0a | nop + 0000aa: 0a | nop + 0000ab: 0a | nop + 0000ac: 0a | nop + 0000ad: 0a | nop + 0000ae: 0a | nop + 0000af: 0a | nop + 0000b0: 0a | nop + 0000b1: 0a | nop + 0000b2: 0a | nop + 0000b3: 0a | nop + 0000b4: 0a | nop + 0000b5: 0a | nop + 0000b6: 0a | nop + 0000b7: 0a | nop + 0000b8: 0a | nop + 0000b9: 0a | nop + 0000ba: 0a | nop + 0000bb: 0a | nop + 0000bc: 0a | nop + 0000bd: 0a | nop + 0000be: 0a | nop + 0000bf: 0a | nop + 0000c0: 0a | nop + 0000c1: 0a | nop + 0000c2: 0a | nop + 0000c3: 0a | nop + 0000c4: 0a | nop + 0000c5: 0a | nop + 0000c6: 0a | nop + 0000c7: 0a | nop + 0000c8: 0a | nop + 0000c9: 0a | nop + 0000ca: 0a | nop + 0000cb: 0a | nop + 0000cc: 0a | nop + 0000cd: 0a | nop + 0000ce: 0a | nop + 0000cf: 0a | nop + 0000d0: 0a | nop + 0000d1: 0a | nop + 0000d2: 0a | nop + 0000d3: 0a | nop + 0000d4: 0a | nop + 0000d5: 0a | nop + 0000d6: 0a | nop + 0000d7: 0a | nop + 0000d8: 0a | nop + 0000d9: 0a | nop + 0000da: 0a | nop + 0000db: 0a | nop + 0000dc: 0a | nop + 0000dd: 0a | nop + 0000de: 0a | nop + 0000df: 0a | nop + 0000e0: 0a | nop + 0000e1: 0a | nop + 0000e2: 0a | nop + 0000e3: 0a | nop + 0000e4: 0a | nop + 0000e5: 0a | nop + 0000e6: 0a | nop + 0000e7: 0a | nop + 0000e8: 0a | nop + 0000e9: 0a | nop + 0000ea: 0a | nop + 0000eb: 0a | nop + 0000ec: 0a | nop + 0000ed: 0a | nop + 0000ee: 0a | nop + 0000ef: 0a | nop + 0000f0: 0a | nop + 0000f1: 0a | nop + 0000f2: 0a | nop + 0000f3: 0a | nop + 0000f4: 0a | nop + 0000f5: 0a | nop + 0000f6: 0a | nop + 0000f7: 0a | nop + 0000f8: 0a | nop + 0000f9: 0a | nop + 0000fa: 0a | nop + 0000fb: 0a | nop + 0000fc: 0a | nop + 0000fd: 0a | nop + 0000fe: 0a | nop + 0000ff: 0a | nop + 000100: 0a | nop + 000101: 0a | nop + 000102: 0a | nop + 000103: 0a | nop + 000104: 0a | nop + 000105: 0a | nop + 000106: 0a | nop + 000107: 0a | nop + 000108: 0a | nop + 000109: 0a | nop + 00010a: 0a | nop + 00010b: 0a | nop + 00010c: 0a | nop + 00010d: 0a | nop + 00010e: 0a | nop + 00010f: 0a | nop + 000110: 0a | nop + 000111: 0a | nop + 000112: 0a | nop + 000113: 0a | nop + 000114: 0a | nop + 000115: 0a | nop + 000116: 0a | nop + 000117: 0a | nop + 000118: 0a | nop + 000119: 0a | nop + 00011a: 0a | nop + 00011b: 0a | nop + 00011c: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/loop.txt b/test/dump/loop.txt index ee298ef5..da07c3fe 100644 --- a/test/dump/loop.txt +++ b/test/dump/loop.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (loop @@ -37,7 +38,9 @@ 000001c: 0f ; end 0000015: 07 ; FIXUP func body size 0000013: 09 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a09 0107 0002 000a 0a0f 0f +func 0 + 000017: 02 00 | loop + 000019: 0a | nop + 00001a: 0a | nop + 00001b: 0f | end ;;; STDOUT ;;) diff --git a/test/dump/memory-1-byte.txt b/test/dump/memory-1-byte.txt index d3965ac1..71a74db5 100644 --- a/test/dump/memory-1-byte.txt +++ b/test/dump/memory-1-byte.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory 1)) (;; STDOUT ;;; 0000000: 0061 736d ; WASM_BINARY_MAGIC @@ -11,6 +12,4 @@ 000000b: 00 ; memory flags 000000c: 01 ; memory initial pages 0000009: 03 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0503 0100 01 ;;; STDOUT ;;) diff --git a/test/dump/memory-data-size.txt b/test/dump/memory-data-size.txt index 1a533276..7c719dc3 100644 --- a/test/dump/memory-data-size.txt +++ b/test/dump/memory-data-size.txt @@ -1,3 +1,4 @@ +;;; TOOL: run-wasmdump ;;; FLAGS: -v --spec (module (memory 1)) (module (memory 2)) diff --git a/test/dump/memory-hex.txt b/test/dump/memory-hex.txt index bfce8de5..9237239d 100644 --- a/test/dump/memory-hex.txt +++ b/test/dump/memory-hex.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory (data "\00\01\02\03\04\05\06\07\08\09\0a"))) @@ -27,8 +28,4 @@ ; data segment data 0 0000016: 0001 0203 0405 0607 0809 0a ; data segment data 000000f: 11 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0504 0101 0101 0b11 -0000010: 0100 1000 0f0b 0001 0203 0405 0607 0809 -0000020: 0a ;;; STDOUT ;;) diff --git a/test/dump/memory.txt b/test/dump/memory.txt index 93792721..faa553d2 100644 --- a/test/dump/memory.txt +++ b/test/dump/memory.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (memory 1) (data (i32.const 10) "hello") @@ -35,8 +36,4 @@ ; data segment data 1 000001f: 676f 6f64 6279 65 ; data segment data 000000e: 17 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0503 0100 010b 1702 -0000010: 0010 0a0f 0568 656c 6c6f 0010 140f 0767 -0000020: 6f6f 6462 7965 ;;; STDOUT ;;) diff --git a/test/dump/no-canonicalize.txt b/test/dump/no-canonicalize.txt index bf7ce393..292a0b16 100644 --- a/test/dump/no-canonicalize.txt +++ b/test/dump/no-canonicalize.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv --no-canonicalize-leb128s +;;; TOOL: run-wasmdump +;;; FLAGS: -v --no-canonicalize-leb128s (module (import "stdio" "print" (func (param i32))) (memory 100) @@ -135,15 +136,19 @@ 0000098: 0f ; end 000008c: 8880 8080 00 ; FIXUP func body size 000006b: a980 8080 00 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 018f 8080 8000 0340 -0000010: 0101 0040 0101 0101 4002 0101 0002 8f80 -0000020: 8080 0001 0573 7464 696f 0570 7269 6e74 -0000030: 0000 0384 8080 8000 0302 0000 0485 8080 -0000040: 8000 0120 0102 0205 8380 8080 0001 0064 -0000050: 0786 8080 8000 0102 6631 0001 0988 8080 -0000060: 8000 0100 1000 0f02 0203 0aa9 8080 8000 -0000070: 0389 8080 8000 0014 0014 0117 010b 0f88 -0000080: 8080 8000 0014 0010 0140 0b0f 8880 8080 -0000090: 0000 1400 1002 420b 0f +func 0 + 000077: 14 00 | get_local 0 + 000079: 14 01 | get_local 0x1 + 00007b: 17 01 | call_indirect 0x1 + 00007d: 0b | drop +func 1 + 000085: 14 00 | get_local 0 + 000087: 10 01 | i32.const 0x1 + 000089: 40 | i32.add + 00008a: 0b | drop +func 2 + 000092: 14 00 | get_local 0 + 000094: 10 02 | i32.const 0x2 + 000096: 42 | i32.mul + 000097: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/nocheck.txt b/test/dump/nocheck.txt index 4108f986..867ed645 100644 --- a/test/dump/nocheck.txt +++ b/test/dump/nocheck.txt @@ -1,3 +1,4 @@ +;;; TOOL: run-wasmdump ;;; FLAGS: -v --no-check (module (func (result i64) @@ -48,4 +49,8 @@ 0000030: 0f ; end 000001f: 11 ; FIXUP func body size 000001d: 13 ; FIXUP section size +func 0 + 000021: 13 00 00 80 3f | f32.const 0x3f800000 + 000026: 12 00 00 00 00 00 00 00 40 | f64.const 0 + 00002f: 40 | i32.add ;;; STDOUT ;;) diff --git a/test/dump/nop.txt b/test/dump/nop.txt index e07a859e..48741933 100644 --- a/test/dump/nop.txt +++ b/test/dump/nop.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (nop))) (;; STDOUT ;;; @@ -30,7 +31,6 @@ 0000018: 0f ; end 0000015: 03 ; FIXUP func body size 0000013: 05 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a05 0103 000a 0f +func 0 + 000017: 0a | nop ;;; STDOUT ;;) diff --git a/test/dump/param-multi.txt b/test/dump/param-multi.txt index d015c67c..38d52b54 100644 --- a/test/dump/param-multi.txt +++ b/test/dump/param-multi.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (param i32 i64 f32 f64))) (;; STDOUT ;;; @@ -33,7 +34,5 @@ 000001b: 0f ; end 0000019: 02 ; FIXUP func body size 0000017: 04 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0108 0140 0401 0203 -0000010: 0400 0302 0100 0a04 0102 000f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/result.txt b/test/dump/result.txt index 55c9764e..6fd21450 100644 --- a/test/dump/result.txt +++ b/test/dump/result.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (result i32) (i32.const 0)) (func (result i64) (i64.const 0)) @@ -74,10 +75,12 @@ 0000042: 0f ; end 0000037: 0b ; FIXUP func body size 0000023: 1f ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0111 0440 0001 0140 -0000010: 0001 0240 0001 0340 0001 0403 0504 0001 -0000020: 0203 0a1f 0404 0010 000f 0400 1100 0f07 -0000030: 0013 0000 0000 0f0b 0012 0000 0000 0000 -0000040: 0000 0f +func 0 + 000027: 10 00 | i32.const 0 +func 1 + 00002c: 11 00 | i64.const 0 +func 2 + 000031: 13 00 00 00 00 | f32.const 0 +func 3 + 000039: 12 00 00 00 00 00 00 00 00 | f64.const 0 ;;; STDOUT ;;) diff --git a/test/dump/return.txt b/test/dump/return.txt index 553cbbfa..6fbfd543 100644 --- a/test/dump/return.txt +++ b/test/dump/return.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (result i32) (return (i32.const 42))) @@ -46,8 +47,9 @@ 0000023: 0f ; end 0000020: 03 ; FIXUP func body size 0000018: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0108 0240 0001 0140 -0000010: 0000 0303 0200 010a 0b02 0500 102a 090f -0000020: 0300 090f +func 0 + 00001c: 10 2a | i32.const 0x2a + 00001e: 09 | return +func 1 + 000022: 09 | return ;;; STDOUT ;;) diff --git a/test/dump/select.txt b/test/dump/select.txt index fec07b41..b4af0664 100644 --- a/test/dump/select.txt +++ b/test/dump/select.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop (select (i32.const 2) (i32.const 3) (i32.const 1))) @@ -65,10 +66,25 @@ 000004b: 0f ; end 0000015: 36 ; FIXUP func body size 0000013: 38 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a38 0136 0010 0210 0310 0105 0b11 -0000020: 0211 0310 0105 0b13 0000 0040 1300 0040 -0000030: 4010 0105 0b12 0000 0000 0000 0040 1200 -0000040: 0000 0000 0008 4010 0105 0b0f +func 0 + 000017: 10 02 | i32.const 0x2 + 000019: 10 03 | i32.const 0x3 + 00001b: 10 01 | i32.const 0x1 + 00001d: 05 | select + 00001e: 0b | drop + 00001f: 11 02 | i64.const 2 + 000021: 11 03 | i64.const 3 + 000023: 10 01 | i32.const 0x1 + 000025: 05 | select + 000026: 0b | drop + 000027: 13 00 00 00 40 | f32.const 0x40000000 + 00002c: 13 00 00 40 40 | f32.const 0x40400000 + 000031: 10 01 | i32.const 0x1 + 000033: 05 | select + 000034: 0b | drop + 000035: 12 00 00 00 00 00 00 00 40 | f64.const 0 + 00003e: 12 00 00 00 00 00 00 08 40 | f64.const 0 + 000047: 10 01 | i32.const 0x1 + 000049: 05 | select + 00004a: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/setglobal.txt b/test/dump/setglobal.txt index 86b4eba0..a6fe4f88 100644 --- a/test/dump/setglobal.txt +++ b/test/dump/setglobal.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (global f32 (f32.const 1)) (func @@ -45,8 +46,7 @@ 0000029: 0f ; end 0000020: 09 ; FIXUP func body size 000001e: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0609 0103 0013 0000 803f 0f0a 0b01 -0000020: 0900 1300 0000 40bc 000f +func 0 + 000022: 13 00 00 00 40 | f32.const 0x40000000 + 000027: bc 00 | set_global 0 ;;; STDOUT ;;) diff --git a/test/dump/setlocal-param.txt b/test/dump/setlocal-param.txt index 2f4ceb76..054f0305 100644 --- a/test/dump/setlocal-param.txt +++ b/test/dump/setlocal-param.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module ;; 0 1 (func (param i32 f32) @@ -74,10 +75,17 @@ 0000042: 0f ; end 0000017: 2b ; FIXUP func body size 0000015: 2d ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0106 0140 0201 0300 -0000010: 0302 0100 0a2d 012b 0401 0201 0301 0101 -0000020: 0310 0015 0013 0000 0000 1501 1100 1502 -0000030: 1300 0000 0015 0310 0015 0413 0000 0000 -0000040: 1505 0f +func 0 + 000021: 10 00 | i32.const 0 + 000023: 15 00 | set_local 0 + 000025: 13 00 00 00 00 | f32.const 0 + 00002a: 15 01 | set_local 0x1 + 00002c: 11 00 | i64.const 0 + 00002e: 15 02 | set_local 0x2 + 000030: 13 00 00 00 00 | f32.const 0 + 000035: 15 03 | set_local 0x3 + 000037: 10 00 | i32.const 0 + 000039: 15 04 | set_local 0x4 + 00003b: 13 00 00 00 00 | f32.const 0 + 000040: 15 05 | set_local 0x5 ;;; STDOUT ;;) diff --git a/test/dump/setlocal.txt b/test/dump/setlocal.txt index 6a1e7b3c..b30bc54a 100644 --- a/test/dump/setlocal.txt +++ b/test/dump/setlocal.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func ;; i32 0 1 @@ -88,11 +89,21 @@ 0000059: 0f ; end 0000015: 44 ; FIXUP func body size 0000013: 46 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a46 0144 0701 0401 0301 0202 0101 -0000020: 0301 0401 0212 0000 0000 0000 0000 1500 -0000030: 1300 0000 0015 0111 0015 0210 0015 0310 -0000040: 0015 0413 0000 0000 1505 1200 0000 0000 -0000050: 0000 0015 0611 0015 070f +func 0 + 000025: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00002e: 15 00 | set_local 0 + 000030: 13 00 00 00 00 | f32.const 0 + 000035: 15 01 | set_local 0x1 + 000037: 11 00 | i64.const 0 + 000039: 15 02 | set_local 0x2 + 00003b: 10 00 | i32.const 0 + 00003d: 15 03 | set_local 0x3 + 00003f: 10 00 | i32.const 0 + 000041: 15 04 | set_local 0x4 + 000043: 13 00 00 00 00 | f32.const 0 + 000048: 15 05 | set_local 0x5 + 00004a: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 000053: 15 06 | set_local 0x6 + 000055: 11 00 | i64.const 0 + 000057: 15 07 | set_local 0x7 ;;; STDOUT ;;) diff --git a/test/dump/signatures.txt b/test/dump/signatures.txt index 3ee88088..de3b9fbd 100644 --- a/test/dump/signatures.txt +++ b/test/dump/signatures.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (type (func (param i32))) (type (func (param i64))) @@ -65,8 +66,4 @@ 000002e: 01 ; num results 000002f: 04 ; result type 0000009: 26 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0126 0940 0101 0040 -0000010: 0102 0040 0103 0040 0104 0040 0001 0140 -0000020: 0001 0240 0001 0340 0001 0440 0101 0104 ;;; STDOUT ;;) diff --git a/test/dump/store-aligned.txt b/test/dump/store-aligned.txt index f9208b6b..7c360a91 100644 --- a/test/dump/store-aligned.txt +++ b/test/dump/store-aligned.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (i32.store8 align=1 (i32.const 0) (i32.const 0)) @@ -163,14 +164,53 @@ 0000087: 0f ; end 0000015: 72 ; FIXUP func body size 0000013: 74 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a74 0172 0010 0010 002e 0000 1000 -0000020: 1000 2f00 0010 0010 002f 0100 1000 1000 -0000030: 3300 0010 0010 0033 0100 1000 1000 3302 -0000040: 0010 0011 0030 0000 1000 1100 3100 0010 -0000050: 0011 0031 0100 1000 1100 3200 0010 0011 -0000060: 0032 0100 1000 1100 3202 0010 0011 0034 -0000070: 0000 1000 1100 3401 0010 0011 0034 0200 -0000080: 1000 1100 3403 000f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 10 00 | i32.const 0 + 00001b: 2e 00 00 | i32.store8 0 0 + 00001e: 10 00 | i32.const 0 + 000020: 10 00 | i32.const 0 + 000022: 2f 00 00 | i32.store16 0 0 + 000025: 10 00 | i32.const 0 + 000027: 10 00 | i32.const 0 + 000029: 2f 01 00 | i32.store16 1 0 + 00002c: 10 00 | i32.const 0 + 00002e: 10 00 | i32.const 0 + 000030: 33 00 00 | i32.store 0 0 + 000033: 10 00 | i32.const 0 + 000035: 10 00 | i32.const 0 + 000037: 33 01 00 | i32.store 1 0 + 00003a: 10 00 | i32.const 0 + 00003c: 10 00 | i32.const 0 + 00003e: 33 02 00 | i32.store 2 0 + 000041: 10 00 | i32.const 0 + 000043: 11 00 | i64.const 0 + 000045: 30 00 00 | i64.store8 0 0 + 000048: 10 00 | i32.const 0 + 00004a: 11 00 | i64.const 0 + 00004c: 31 00 00 | i64.store16 0 0 + 00004f: 10 00 | i32.const 0 + 000051: 11 00 | i64.const 0 + 000053: 31 01 00 | i64.store16 1 0 + 000056: 10 00 | i32.const 0 + 000058: 11 00 | i64.const 0 + 00005a: 32 00 00 | i64.store32 0 0 + 00005d: 10 00 | i32.const 0 + 00005f: 11 00 | i64.const 0 + 000061: 32 01 00 | i64.store32 1 0 + 000064: 10 00 | i32.const 0 + 000066: 11 00 | i64.const 0 + 000068: 32 02 00 | i64.store32 2 0 + 00006b: 10 00 | i32.const 0 + 00006d: 11 00 | i64.const 0 + 00006f: 34 00 00 | i64.store 0 0 + 000072: 10 00 | i32.const 0 + 000074: 11 00 | i64.const 0 + 000076: 34 01 00 | i64.store 1 0 + 000079: 10 00 | i32.const 0 + 00007b: 11 00 | i64.const 0 + 00007d: 34 02 00 | i64.store 2 0 + 000080: 10 00 | i32.const 0 + 000082: 11 00 | i64.const 0 + 000084: 34 03 00 | i64.store 3 0 ;;; STDOUT ;;) diff --git a/test/dump/store.txt b/test/dump/store.txt index 07cca682..33df0bca 100644 --- a/test/dump/store.txt +++ b/test/dump/store.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (i32.store8 (i32.const 0) (i32.const 0)) @@ -101,12 +102,32 @@ 0000060: 0f ; end 0000015: 4b ; FIXUP func body size 0000013: 4d ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a4d 014b 0010 0010 002e 0000 1000 -0000020: 1000 2f01 0010 0010 0033 0200 1000 1100 -0000030: 3403 0010 0011 0030 0000 1000 1100 3101 -0000040: 0010 0011 0032 0200 1000 1300 0000 0035 -0000050: 0200 1000 1200 0000 0000 0000 0036 0300 -0000060: 0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 10 00 | i32.const 0 + 00001b: 2e 00 00 | i32.store8 0 0 + 00001e: 10 00 | i32.const 0 + 000020: 10 00 | i32.const 0 + 000022: 2f 01 00 | i32.store16 1 0 + 000025: 10 00 | i32.const 0 + 000027: 10 00 | i32.const 0 + 000029: 33 02 00 | i32.store 2 0 + 00002c: 10 00 | i32.const 0 + 00002e: 11 00 | i64.const 0 + 000030: 34 03 00 | i64.store 3 0 + 000033: 10 00 | i32.const 0 + 000035: 11 00 | i64.const 0 + 000037: 30 00 00 | i64.store8 0 0 + 00003a: 10 00 | i32.const 0 + 00003c: 11 00 | i64.const 0 + 00003e: 31 01 00 | i64.store16 1 0 + 000041: 10 00 | i32.const 0 + 000043: 11 00 | i64.const 0 + 000045: 32 02 00 | i64.store32 2 0 + 000048: 10 00 | i32.const 0 + 00004a: 13 00 00 00 00 | f32.const 0 + 00004f: 35 02 00 | f32.store 2 0 + 000052: 10 00 | i32.const 0 + 000054: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00005d: 36 03 00 | f64.store 3 0 ;;; STDOUT ;;) diff --git a/test/dump/string-escape.txt b/test/dump/string-escape.txt index 7e2d4a8d..6f834cd7 100644 --- a/test/dump/string-escape.txt +++ b/test/dump/string-escape.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func) (export "tab:\t newline:\n slash:\\ quote:\' double:\"" (func 0))) (;; STDOUT ;;; 0000000: 0061 736d ; WASM_BINARY_MAGIC @@ -39,10 +40,5 @@ 0000045: 0f ; end 0000043: 02 ; FIXUP func body size 0000041: 04 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 072c 0128 7461 623a 0920 6e65 776c -0000020: 696e 653a 0a20 736c 6173 683a 5c20 7175 -0000030: 6f74 653a 2720 646f 7562 6c65 3a22 0000 -0000040: 0a04 0102 000f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/string-hex.txt b/test/dump/string-hex.txt index 81c29367..ba01e77e 100644 --- a/test/dump/string-hex.txt +++ b/test/dump/string-hex.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func) (export "foo\ba\dc\0d\ee" (func 0))) (;; STDOUT ;;; 0000000: 0061 736d ; WASM_BINARY_MAGIC @@ -37,8 +38,5 @@ 0000024: 0f ; end 0000022: 02 ; FIXUP func body size 0000020: 04 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 070b 0107 666f 6fba dc0d ee00 000a -0000020: 0401 0200 0f +func 0 ;;; STDOUT ;;) diff --git a/test/dump/table.txt b/test/dump/table.txt index c0a2f853..fab42178 100644 --- a/test/dump/table.txt +++ b/test/dump/table.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (type $t (func (param i32))) (func (type $t)) @@ -84,10 +85,8 @@ 0000045: 0f ; end 000003a: 0b ; FIXUP func body size 0000032: 13 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 010e 0340 0101 0040 -0000010: 0201 0200 4000 0104 0304 0300 0102 0405 -0000020: 0120 0104 0409 0a01 0010 000f 0400 0001 -0000030: 020a 1303 0200 0f02 000f 0b00 1200 0000 -0000040: 0000 0000 000f +func 0 +func 1 +func 2 + 00003c: 12 00 00 00 00 00 00 00 00 | f64.const 0 ;;; STDOUT ;;) diff --git a/test/dump/tee_local.txt b/test/dump/tee_local.txt index 4707291f..62b2c837 100644 --- a/test/dump/tee_local.txt +++ b/test/dump/tee_local.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (local i32) @@ -39,7 +40,8 @@ 000001e: 0f ; end 0000015: 09 ; FIXUP func body size 0000013: 0b ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a0b 0109 0101 0110 0019 000b 0f +func 0 + 000019: 10 00 | i32.const 0 + 00001b: 19 00 | tee_local 0 + 00001d: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/unary.txt b/test/dump/unary.txt index 9c3fc8eb..f1a41b6f 100644 --- a/test/dump/unary.txt +++ b/test/dump/unary.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (drop @@ -90,10 +91,34 @@ 0000042: 0f ; end 0000015: 2d ; FIXUP func body size 0000013: 2f ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a2f 012d 0010 0059 5857 5a0b 1100 -0000020: 7473 720b 1300 0000 0081 807f 7e82 7b7c -0000030: 0b12 0000 0000 0000 0000 9594 9392 968f -0000040: 900b 0f +func 0 + 000017: 10 00 | i32.const 0 + 000019: 59 | i32.popcnt + 00001a: 58 | i32.ctz + 00001b: 57 | i32.clz + 00001c: 5a | i32.eqz + 00001d: 0b | drop + 00001e: 11 00 | i64.const 0 + 000020: 74 | i64.popcnt + 000021: 73 | i64.ctz + 000022: 72 | i64.clz + 000023: 0b | drop + 000024: 13 00 00 00 00 | f32.const 0 + 000029: 81 | f32.nearest + 00002a: 80 | f32.trunc + 00002b: 7f | f32.floor + 00002c: 7e | f32.ceil + 00002d: 82 | f32.sqrt + 00002e: 7b | f32.abs + 00002f: 7c | f32.neg + 000030: 0b | drop + 000031: 12 00 00 00 00 00 00 00 00 | f64.const 0 + 00003a: 95 | f64.nearest + 00003b: 94 | f64.trunc + 00003c: 93 | f64.floor + 00003d: 92 | f64.ceil + 00003e: 96 | f64.sqrt + 00003f: 8f | f64.abs + 000040: 90 | f64.neg + 000041: 0b | drop ;;; STDOUT ;;) diff --git a/test/dump/unreachable.txt b/test/dump/unreachable.txt index d612b11f..16282dfc 100644 --- a/test/dump/unreachable.txt +++ b/test/dump/unreachable.txt @@ -1,4 +1,5 @@ -;;; FLAGS: -dv +;;; TOOL: run-wasmdump +;;; FLAGS: -v (module (func (unreachable))) @@ -31,7 +32,6 @@ 0000018: 0f ; end 0000015: 03 ; FIXUP func body size 0000013: 05 ; FIXUP section size -;; dump -0000000: 0061 736d 0c00 0000 0104 0140 0000 0302 -0000010: 0100 0a05 0103 0000 0f +func 0 + 000017: 00 | unreachable ;;; STDOUT ;;) diff --git a/test/find_exe.py b/test/find_exe.py index 0c3d3e9b..5c0b66eb 100644 --- a/test/find_exe.py +++ b/test/find_exe.py @@ -25,6 +25,7 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) REPO_ROOT_DIR = os.path.dirname(SCRIPT_DIR) DEFAULT_WAST2WASM_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wast2wasm') DEFAULT_WASM2WAST_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasm2wast') +DEFAULT_WASMDUMP_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasmdump') DEFAULT_WASM_INTERP_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasm-interp') DEFAULT_WASMOPCODECNT_EXE = os.path.join(REPO_ROOT_DIR, 'out', 'wasmopcodecnt') @@ -62,6 +63,10 @@ def GetWasm2WastExecutable(override=None): return FindExeWithFallback('wasm2wast', [DEFAULT_WASM2WAST_EXE], override) +def GetWasmdumpExecutable(override=None): + return FindExeWithFallback('wasmdump', [DEFAULT_WASMDUMP_EXE], override) + + def GetWasmInterpExecutable(override=None): return FindExeWithFallback('wasm-interp', [DEFAULT_WASM_INTERP_EXE], override) diff --git a/test/run-gen-wasm.py b/test/run-gen-wasm.py index c6480c66..6e536670 100755 --- a/test/run-gen-wasm.py +++ b/test/run-gen-wasm.py @@ -36,14 +36,14 @@ def main(args): action='store_true') parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') - parser.add_argument('--wasm2wast-executable', metavar='PATH', + parser.add_argument('--wasm2wast', metavar='PATH', help='set the wasm2wast executable to use.') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') - parser.add_argument('--print-cmd', help='print the commands that are run.', - action='store_true') + parser.add_argument('-p', '--print-cmd', action='store_true', + help='print the commands that are run.') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('--debug-names', action='store_true') parser.add_argument('--generate-names', action='store_true') @@ -54,7 +54,7 @@ def main(args): sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline) wasm2wast = utils.Executable( - find_exe.GetWasm2WastExecutable(options.wasm2wast_executable), + find_exe.GetWasm2WastExecutable(options.wasm2wast), error_cmdline=options.error_cmdline) wasm2wast.AppendOptionalArgs({ '--debug-names': options.debug_names, diff --git a/test/run-interp.py b/test/run-interp.py index 651f6788..caae7672 100755 --- a/test/run-interp.py +++ b/test/run-interp.py @@ -16,6 +16,7 @@ # import argparse +import json import os import subprocess import sys @@ -31,9 +32,11 @@ def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') - parser.add_argument('--wast2wasm-executable', metavar='PATH', + parser.add_argument('--wast2wasm', metavar='PATH', help='override wast2wasm executable.') - parser.add_argument('--wasm-interp-executable', metavar='PATH', + parser.add_argument('--wasmdump', metavar='PATH', + help='override wast2wasm executable.') + parser.add_argument('--wasm-interp', metavar='PATH', help='override wasm-interp executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') @@ -50,7 +53,7 @@ def main(args): options = parser.parse_args(args) wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.wast2wasm_executable), + find_exe.GetWast2WasmExecutable(options.wast2wasm), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '-v': options.verbose, @@ -58,8 +61,12 @@ def main(args): '--use-libc-allocator': options.use_libc_allocator }) + wasmdump = utils.Executable( + find_exe.GetWasmdumpExecutable(options.wasmdump), + error_cmdline=options.error_cmdline) + wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable( - options.wasm_interp_executable), + options.wasm_interp), error_cmdline=options.error_cmdline) wasm_interp.AppendOptionalArgs({ '--run-all-exports': options.run_all_exports, @@ -75,6 +82,15 @@ def main(args): new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) wast2wasm.RunWithArgs(options.file, '-o', out_file) + if options.spec: + with open(out_file) as json_file: + json_data = json.load(json_file) + wasm_files = [m['filename'] for m in json_data['modules']] + wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files] + else: + wasm_files = [out_file] + for wasm_file in wasm_files: + wasmdump.RunWithArgs(wasm_file) wasm_interp.RunWithArgs(out_file) return 0 diff --git a/test/run-roundtrip.py b/test/run-roundtrip.py index 21dfdb15..b40eb852 100755 --- a/test/run-roundtrip.py +++ b/test/run-roundtrip.py @@ -78,7 +78,8 @@ def TwoRoundtrips(wast2wasm, wasm2wast, out_dir, filename, verbose): return FilesAreEqual(wasm1_file, wasm3_file, verbose) -def OneRoundtripToStdout(wast2wasm, wasm2wast, out_dir, filename, verbose): +def OneRoundtripToStdout(wast2wasm, wasm2wast, out_dir, filename, + verbose): basename = os.path.basename(filename) basename_noext = os.path.splitext(basename)[0] wasm_file = os.path.join(out_dir, basename_noext + '.wasm') @@ -101,9 +102,9 @@ def main(args): action='store_true') parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') - parser.add_argument('--wast2wasm-executable', metavar='PATH', + parser.add_argument('--wast2wasm', metavar='PATH', help='set the wast2wasm executable to use.') - parser.add_argument('--wasm2wast-executable', metavar='PATH', + parser.add_argument('--wasm2wast', metavar='PATH', help='set the wasm2wast executable to use.') parser.add_argument('--stdout', action='store_true', help='do one roundtrip and write wast output to stdout') @@ -111,7 +112,7 @@ def main(args): help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') - parser.add_argument('--print-cmd', help='print the commands that are run.', + parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('--debug-names', action='store_true') @@ -120,7 +121,7 @@ def main(args): options = parser.parse_args(args) wast2wasm = utils.Executable( - find_exe.GetWast2WasmExecutable(options.wast2wasm_executable), + find_exe.GetWast2WasmExecutable(options.wast2wasm), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '--debug-names': options.debug_names, @@ -128,7 +129,7 @@ def main(args): }) wasm2wast = utils.Executable( - find_exe.GetWasm2WastExecutable(options.wasm2wast_executable), + find_exe.GetWasm2WastExecutable(options.wasm2wast), error_cmdline=options.error_cmdline) wasm2wast.AppendOptionalArgs({ '--debug-names': options.debug_names, @@ -139,8 +140,12 @@ def main(args): wast2wasm.verbose = options.print_cmd wasm2wast.verbose = options.print_cmd + filename = options.file + if not os.path.exists(filename): + sys.stderr.write('File not found: %s\n' % filename) + return ERROR + with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir: - filename = options.file if options.stdout: result, msg = OneRoundtripToStdout(wast2wasm, wasm2wast, out_dir, filename, options.verbose) diff --git a/test/run-tests.py b/test/run-tests.py index 08faaf12..57099280 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -54,12 +54,20 @@ TOOLS = { 'EXE': '%(wast2wasm)s', 'VERBOSE-FLAGS': ['-v'] }, + 'run-wasmdump': { + 'EXE': 'test/run-wasmdump.py', + 'FLAGS': ' '.join([ + '--wast2wasm=%(wast2wasm)s', + '--wasmdump=%(wasmdump)s', + ]), + 'VERBOSE-FLAGS': ['-v'] + }, 'run-roundtrip': { 'EXE': 'test/run-roundtrip.py', 'FLAGS': ' '.join([ '-v', - '--wast2wasm-executable=%(wast2wasm)s', - '--wasm2wast-executable=%(wasm2wast)s', + '--wast2wasm=%(wast2wasm)s', + '--wasm2wast=%(wasm2wast)s', '--no-error-cmdline', '-o', '%(out_dir)s', ]), @@ -73,8 +81,9 @@ TOOLS = { 'run-interp': { 'EXE': 'test/run-interp.py', 'FLAGS': ' '.join([ - '--wast2wasm-executable', '%(wast2wasm)s', - '--wasm-interp-executable=%(wasm-interp)s', + '--wast2wasm=%(wast2wasm)s', + '--wasmdump=%(wasmdump)s', + '--wasm-interp=%(wasm-interp)s', '--run-all-exports', '--no-error-cmdline', '-o', '%(out_dir)s', @@ -89,8 +98,9 @@ TOOLS = { 'run-interp-spec': { 'EXE': 'test/run-interp.py', 'FLAGS': ' '.join([ - '--wast2wasm-executable', '%(wast2wasm)s', - '--wasm-interp-executable=%(wasm-interp)s', + '--wast2wasm=%(wast2wasm)s', + '--wasmdump=%(wasmdump)s', + '--wasm-interp=%(wasm-interp)s', '--spec', '--no-error-cmdline', '-o', '%(out_dir)s', @@ -105,7 +115,7 @@ TOOLS = { 'run-gen-wasm': { 'EXE': 'test/run-gen-wasm.py', 'FLAGS': ' '.join([ - '--wasm2wast-executable=%(wasm2wast)s', + '--wasm2wast=%(wasm2wast)s', '--no-error-cmdline', '-o', '%(out_dir)s', ]), @@ -119,7 +129,7 @@ TOOLS = { 'run-gen-wasm-interp': { 'EXE': 'test/run-gen-wasm-interp.py', 'FLAGS': ' '.join([ - '--wasm-interp-executable=%(wasm-interp)s', + '--wasm-interp=%(wasm-interp)s', '--run-all-exports', '--no-error-cmdline', '-o', '%(out_dir)s', @@ -134,8 +144,8 @@ TOOLS = { 'run-opcodecnt': { 'EXE': 'test/run-opcodecnt.py', 'FLAGS': ' '.join([ - '--wast2wasm-executable=%(wast2wasm)s', - '--wasmopcodecnt-executable=%(wasmopcodecnt)s', + '--wast2wasm=%(wast2wasm)s', + '--wasmopcodecnt=%(wasmopcodecnt)s', '--no-error-cmdline', ]), 'VERBOSE-FLAGS': [ @@ -248,8 +258,8 @@ class TestInfo(object): result.expected_stderr = '' result.tool = 'run-roundtrip' result.exe = ROUNDTRIP_PY - result.flags = ['--wast2wasm', '%(wast2wasm)s', '--wasm2wast', '%(wasm2wast)s', - '-v'] + result.flags = ['--wast2wasm', '%(wast2wasm)s', '--wasm2wast', + '%(wasm2wast)s', '-v'] result.expected_error = 0 result.slow = self.slow result.skip = self.skip @@ -678,13 +688,15 @@ def main(args): help='directory to search for all executables. ' 'This can be overridden by the other executable ' 'flags.') - parser.add_argument('--wast2wasm-executable', metavar='PATH', - help='override executable.') - parser.add_argument('--wasm2wast-executable', metavar='PATH', + parser.add_argument('--wast2wasm', metavar='PATH', + help='override wast2wasm executable.') + parser.add_argument('--wasm2wast', metavar='PATH', help='override wasm2wast executable.') - parser.add_argument('--wasm-interp-executable', metavar='PATH', + parser.add_argument('--wasmdump', metavar='PATH', + help='override wasmdump executable.') + parser.add_argument('--wasm-interp', metavar='PATH', help='override wasm-interp executable.') - parser.add_argument('--wasmopcodecnt-executable', metavar='PATH', + parser.add_argument('--wasmopcodecnt', metavar='PATH', help='override wasmopcodecnt executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') @@ -735,24 +747,23 @@ def main(args): return 1 if options.exe_dir: - if not options.wast2wasm_executable: - options.wast2wasm_executable = os.path.join(options.exe_dir, 'wast2wasm') - if not options.wasm2wast_executable: - options.wasm2wast_executable = os.path.join(options.exe_dir, 'wasm2wast') - if not options.wasm_interp_executable: - options.wasm_interp_executable = os.path.join(options.exe_dir, - 'wasm-interp') - if not options.wasmopcodecnt_executable: - options.wasmopcodecnt_executable = os.path.join(options.exe_dir, - 'wasmopcodecnt') + if not options.wast2wasm: + options.wast2wasm = os.path.join(options.exe_dir, 'wast2wasm') + if not options.wasm2wast: + options.wasm2wast = os.path.join(options.exe_dir, 'wasm2wast') + if not options.wasm_interp: + options.wasm_interp = os.path.join(options.exe_dir, 'wasm-interp') + if not options.wasmopcodecnt: + options.wasmopcodecnt = os.path.join(options.exe_dir, 'wasmopcodecnt') + if not options.wasmdump: + options.wasmdump = os.path.join(options.exe_dir, 'wasmdump') variables = { - 'wast2wasm': find_exe.GetWast2WasmExecutable(options.wast2wasm_executable), - 'wasm2wast': find_exe.GetWasm2WastExecutable(options.wasm2wast_executable), - 'wasm-interp': - find_exe.GetWasmInterpExecutable(options.wasm_interp_executable), - 'wasmopcodecnt': - find_exe.GetWasmOpcodeCntExecutable(options.wasmopcodecnt_executable), + 'wast2wasm': find_exe.GetWast2WasmExecutable(options.wast2wasm), + 'wasm2wast': find_exe.GetWasm2WastExecutable(options.wasm2wast), + 'wasmdump': find_exe.GetWasmdumpExecutable(options.wasmdump), + 'wasm-interp': find_exe.GetWasmInterpExecutable(options.wasm_interp), + 'wasmopcodecnt': find_exe.GetWasmOpcodeCntExecutable(options.wasmopcodecnt), } status = Status(options.verbose) diff --git a/test/run-wasmdump.py b/test/run-wasmdump.py new file mode 100755 index 00000000..ec0628bb --- /dev/null +++ b/test/run-wasmdump.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# +# Copyright 2016 WebAssembly Community Group participants +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import argparse +import json +import os +import sys +import tempfile + +import find_exe +import utils + + +def main(args): + parser = argparse.ArgumentParser() + parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', + action='store_true') + parser.add_argument('-o', '--out-dir', metavar='PATH', + help='output directory for files.') + parser.add_argument('--wast2wasm', metavar='PATH', + help='set the wast2wasm executable to use.') + parser.add_argument('--wasmdump', metavar='PATH', + help='set the wasmdump executable to use.') + parser.add_argument('--no-error-cmdline', + help='don\'t display the subprocess\'s commandline when' + + ' an error occurs', dest='error_cmdline', + action='store_false') + parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', + action='store_true') + parser.add_argument('--no-check', action='store_true') + parser.add_argument('--spec', action='store_true') + parser.add_argument('--no-canonicalize-leb128s', action='store_true') + parser.add_argument('--use-libc-allocator', action='store_true') + parser.add_argument('--debug-names', action='store_true') + parser.add_argument('file', help='test file.') + options = parser.parse_args(args) + + wast2wasm = utils.Executable( + find_exe.GetWast2WasmExecutable(options.wast2wasm), + error_cmdline=options.error_cmdline) + wast2wasm.AppendOptionalArgs({ + '--debug-names': options.debug_names, + '--no-check': options.no_check, + '--no-canonicalize-leb128s': options.no_canonicalize_leb128s, + '--spec': options.spec, + '-v': options.verbose, + '--use-libc-allocator': options.use_libc_allocator + }) + + wasmdump = utils.Executable( + find_exe.GetWasmdumpExecutable(options.wasmdump), + error_cmdline=options.error_cmdline) + + wast2wasm.verbose = options.print_cmd + wasmdump.verbose = options.print_cmd + + filename = options.file + + with utils.TempDirectory(options.out_dir, 'wasmdump-') as out_dir: + basename = os.path.basename(filename) + basename_noext = os.path.splitext(basename)[0] + if options.spec: + out_file = os.path.join(out_dir, basename_noext + '.json') + else: + out_file = os.path.join(out_dir, basename_noext + '.wasm') + wast2wasm.RunWithArgs('-o', out_file, filename) + + if options.spec: + with open(out_file) as json_file: + json_data = json.load(json_file) + wasm_files = [m['filename'] for m in json_data['modules']] + wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files] + else: + wasm_files = [out_file] + + for wasm_file in wasm_files: + wasmdump.RunWithArgs('-d', wasm_file) + + +if __name__ == '__main__': + try: + sys.exit(main(sys.argv[1:])) + except utils.Error as e: + sys.stderr.write(str(e) + '\n') + sys.exit(1) |