summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-reader-objdump.c44
-rw-r--r--src/binary-reader-opcnt.c6
-rw-r--r--test/dump/debug-import-names.txt2
-rw-r--r--test/dump/global.txt13
-rw-r--r--test/dump/import.txt4
5 files changed, 52 insertions, 17 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 = {
diff --git a/test/dump/debug-import-names.txt b/test/dump/debug-import-names.txt
index c47eb3ad..af0aead7 100644
--- a/test/dump/debug-import-names.txt
+++ b/test/dump/debug-import-names.txt
@@ -41,7 +41,7 @@ debug-import-names.wasm: file format wasm 0x00000d
Sections:
TYPE start=0x0000000a end=0x0000000e (size=0x00000004) count: 1
IMPORT start=0x00000010 end=0x0000001b (size=0x0000000b) count: 1
- USER start=0x00000022 end=0x0000002e (size=0x0000000c) count: 1
+ USER start=0x00000022 end=0x0000002e (size=0x0000000c) "name"
Code Disassembly:
;;; STDOUT ;;)
diff --git a/test/dump/global.txt b/test/dump/global.txt
index 18e22e6f..fe438097 100644
--- a/test/dump/global.txt
+++ b/test/dump/global.txt
@@ -1,5 +1,5 @@
;;; TOOL: run-wasmdump
-;;; FLAGS: -v
+;;; FLAGS: -v --dump-verbose
(module
(global i32 (i32.const 1))
(global i64 (i64.const 2))
@@ -60,5 +60,16 @@
0000009: 33 ; FIXUP section size
global.wasm: file format wasm 0x00000d
+Section Details:
+GLOBAL:
+ - global[0] i32 mutable=0 - init i32=1
+ - global[1] i64 mutable=0 - init i64=2
+ - global[2] f32 mutable=0 - init f32=0x1.8p+1
+ - global[3] f64 mutable=0 - init f64=0x0p+0
+ - global[4] i32 mutable=0 - init global=0
+ - global[5] i64 mutable=0 - init global=1
+ - global[6] f32 mutable=0 - init global=2
+ - global[7] f64 mutable=0 - init global=3
+
Code Disassembly:
;;; STDOUT ;;)
diff --git a/test/dump/import.txt b/test/dump/import.txt
index 6db268d5..4d5093aa 100644
--- a/test/dump/import.txt
+++ b/test/dump/import.txt
@@ -51,8 +51,8 @@ TYPE:
- [0] (i32, i64, f32, f64) -> nil
- [1] (i32) -> i32
IMPORT:
- - ignored.test -> func[0] sig=0
- - ignored.test2 -> func[1] sig=1
+ - func[0] sig=0 <- ignored.test
+ - func[1] sig=1 <- ignored.test2
Code Disassembly:
;;; STDOUT ;;)