summaryrefslogtreecommitdiff
path: root/src/binary-reader-objdump.c
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2016-12-02 11:25:06 -0800
committerGitHub <noreply@github.com>2016-12-02 11:25:06 -0800
commit4ee278d04664ebdb84ff5a6c7d37515fe1857ea3 (patch)
tree73d88d2bf56f1a6ba56452fd8757599c86e740dd /src/binary-reader-objdump.c
parent07b6eda70b70e630e65b4d6fcf1263beeaf187c0 (diff)
downloadwabt-4ee278d04664ebdb84ff5a6c7d37515fe1857ea3.tar.gz
wabt-4ee278d04664ebdb84ff5a6c7d37515fe1857ea3.tar.bz2
wabt-4ee278d04664ebdb84ff5a6c7d37515fe1857ea3.zip
Improve handling of globals in wasmdump (#230)
* Improve handling of globals in wasmdump Also, fix bug in on_error handling.
Diffstat (limited to 'src/binary-reader-objdump.c')
-rw-r--r--src/binary-reader-objdump.c44
1 files changed, 32 insertions, 12 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,