diff options
author | Ben Smith <binji@chromium.org> | 2015-12-11 14:45:02 -0800 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2015-12-11 14:46:17 -0800 |
commit | 68f771eeeea36fd924734d9c2a27a720d2c01fcd (patch) | |
tree | ba0f12c212f9806fa7dd5170ea9168beb6e3e794 /src/wasm.c | |
parent | 5726defaabe668f390ec56ad9e2da59d71512ab9 (diff) | |
download | wabt-68f771eeeea36fd924734d9c2a27a720d2c01fcd.tar.gz wabt-68f771eeeea36fd924734d9c2a27a720d2c01fcd.tar.bz2 wabt-68f771eeeea36fd924734d9c2a27a720d2c01fcd.zip |
fix --dump-module flag
I broke this when I rewrote everything.
Diffstat (limited to 'src/wasm.c')
-rw-r--r-- | src/wasm.c | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -1,9 +1,13 @@ #include "wasm.h" #include <assert.h> +#include <ctype.h> #include <memory.h> #include <stdlib.h> +#define DUMP_OCTETS_PER_LINE 16 +#define DUMP_OCTETS_PER_GROUP 2 + DEFINE_VECTOR(type, WasmType) DEFINE_VECTOR(var, WasmVar); DEFINE_VECTOR(expr_ptr, WasmExprPtr); @@ -422,3 +426,41 @@ void wasm_destroy_command_vector_and_elements(WasmCommandVector* commands) { void wasm_destroy_script(WasmScript* script) { DESTROY_VECTOR_AND_ELEMENTS(script->commands, command); } + +void wasm_print_memory(const void* start, + size_t size, + size_t offset, + int print_chars, + const char* desc) { + /* mimic xxd output */ + const uint8_t* p = start; + const uint8_t* end = p + size; + while (p < end) { + const uint8_t* line = p; + const uint8_t* line_end = p + DUMP_OCTETS_PER_LINE; + printf("%07x: ", (int)((void*)p - start + offset)); + while (p < line_end) { + int i; + for (i = 0; i < DUMP_OCTETS_PER_GROUP; ++i, ++p) { + if (p < end) { + printf("%02x", *p); + } else { + putchar(' '); + putchar(' '); + } + } + putchar(' '); + } + + putchar(' '); + p = line; + int i; + for (i = 0; i < DUMP_OCTETS_PER_LINE && p < end; ++i, ++p) + if (print_chars) + printf("%c", isprint(*p) ? *p : '.'); + /* if there are multiple lines, only print the desc on the last one */ + if (p >= end && desc) + printf(" ; %s", desc); + putchar('\n'); + } +} |