diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binary-reader-objdump.c | 44 | ||||
-rw-r--r-- | src/binary-reader-opcnt.c | 6 |
2 files changed, 37 insertions, 13 deletions
diff --git a/src/binary-reader-objdump.c b/src/binary-reader-objdump.c index 084e4e2c..993fbbd6 100644 --- a/src/binary-reader-objdump.c +++ b/src/binary-reader-objdump.c @@ -41,6 +41,7 @@ typedef struct Context { WasmStringSlice import_field_name; int function_index; + int global_index; } Context; @@ -104,6 +105,8 @@ static WasmResult begin_user_section(WasmBinaryReaderContext* ctx, return WASM_ERROR; if (context->options->mode == WASM_DUMP_DETAILS) printf(" - name: \"" PRIstringslice "\"\n", WASM_PRINTF_STRING_SLICE_ARG(section_name)); + else if (context->options->mode == WASM_DUMP_HEADERS) + printf("\"" PRIstringslice "\"\n", WASM_PRINTF_STRING_SLICE_ARG(section_name)); return WASM_OK; } @@ -406,10 +409,10 @@ static WasmResult on_import_func(uint32_t index, void* user_data) { Context* ctx = user_data; print_details(user_data, - " - " PRIstringslice "." PRIstringslice " -> func[%d] sig=%d\n", + " - func[%d] sig=%d <- " PRIstringslice "." PRIstringslice "\n", + ctx->function_index, sig_index, WASM_PRINTF_STRING_SLICE_ARG(ctx->import_module_name), - WASM_PRINTF_STRING_SLICE_ARG(ctx->import_field_name), - ctx->function_index, sig_index); + WASM_PRINTF_STRING_SLICE_ARG(ctx->import_field_name)); ctx->function_index++; return WASM_OK; } @@ -444,11 +447,12 @@ static WasmResult on_import_global(uint32_t index, WasmBool mutable_, void* user_data) { Context* ctx = user_data; - print_details(user_data, " - " PRIstringslice "." PRIstringslice - " -> global %s mutable=%d\n", + print_details(user_data, " - global[%d] %s mutable=%d <- " PRIstringslice + "." PRIstringslice "\n", + ctx->global_index, wasm_get_type_name(type), mutable_, WASM_PRINTF_STRING_SLICE_ARG(ctx->import_module_name), - WASM_PRINTF_STRING_SLICE_ARG(ctx->import_field_name), - wasm_get_type_name(type), mutable_); + WASM_PRINTF_STRING_SLICE_ARG(ctx->import_field_name)); + ctx->global_index++; return WASM_OK; } @@ -477,7 +481,7 @@ static WasmResult on_export(uint32_t index, 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, " - %s[%d] ", wasm_get_kind_name(kind), item_index); print_details(user_data, PRIstringslice, WASM_PRINTF_STRING_SLICE_ARG(name)); print_details(user_data, "\n"); return WASM_OK; @@ -497,17 +501,29 @@ static WasmResult begin_elem_segment(uint32_t index, return WASM_OK; } +static WasmResult begin_global(uint32_t index, WasmType type, WasmBool mutable, void* user_data) { + Context* ctx = user_data; + print_details(user_data, " - global[%d] %s mutable=%d", ctx->global_index, + wasm_get_type_name(type), mutable); + ctx->global_index++; + return WASM_OK; +} + static WasmResult on_init_expr_f32_const_expr(uint32_t index, uint32_t value, void* user_data) { - print_details(user_data, " - init f32=%d\n", value); + char buffer[WASM_MAX_FLOAT_HEX]; + wasm_write_float_hex(buffer, sizeof(buffer), value); + print_details(user_data, " - init f32=%s\n", buffer); return WASM_OK; } static WasmResult on_init_expr_f64_const_expr(uint32_t index, uint64_t value, void* user_data) { - print_details(user_data, " - init f64=%" PRId64 "\n", value); + char buffer[WASM_MAX_DOUBLE_HEX]; + wasm_write_float_hex(buffer, sizeof(buffer), value); + print_details(user_data, " - init f64=%s\n", buffer); return WASM_OK; } @@ -552,7 +568,11 @@ static WasmResult on_local_name(uint32_t func_index, } static void on_error(WasmBinaryReaderContext* ctx, const char* message) { - wasm_default_binary_error_callback(ctx->offset, message, ctx->user_data); + WasmDefaultErrorHandlerInfo info; + info.header = "error reading binary"; + info.out_file = stdout; + info.print_header = WASM_PRINT_ERROR_HEADER_ONCE; + wasm_default_binary_error_callback(ctx->offset, message, &info); } static WasmBinaryReader s_binary_reader = { @@ -596,6 +616,7 @@ static WasmBinaryReader s_binary_reader = { // Globl seciont .begin_global_section = begin_global_section, + .begin_global = begin_global, .on_global_count = on_count, // Export section @@ -623,7 +644,6 @@ static WasmBinaryReader s_binary_reader = { // Known "User" sections: // - Names section - .on_function_names_count = on_count, .on_function_name = on_function_name, .on_local_name = on_local_name, diff --git a/src/binary-reader-opcnt.c b/src/binary-reader-opcnt.c index 5db2cade..8d184e70 100644 --- a/src/binary-reader-opcnt.c +++ b/src/binary-reader-opcnt.c @@ -130,7 +130,11 @@ static WasmResult on_store_expr(WasmOpcode opcode, } static void on_error(WasmBinaryReaderContext* ctx, const char* message) { - wasm_default_binary_error_callback(ctx->offset, message, ctx->user_data); + WasmDefaultErrorHandlerInfo info; + info.header = "error reading binary"; + info.out_file = stdout; + info.print_header = WASM_PRINT_ERROR_HEADER_ONCE; + wasm_default_binary_error_callback(ctx->offset, message, &info); } static WasmBinaryReader s_binary_reader = { |