summaryrefslogtreecommitdiff
path: root/src/wasm.c
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2015-12-11 14:45:02 -0800
committerBen Smith <binji@chromium.org>2015-12-11 14:46:17 -0800
commit68f771eeeea36fd924734d9c2a27a720d2c01fcd (patch)
treeba0f12c212f9806fa7dd5170ea9168beb6e3e794 /src/wasm.c
parent5726defaabe668f390ec56ad9e2da59d71512ab9 (diff)
downloadwabt-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.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/wasm.c b/src/wasm.c
index f7cc412b..b82fc2eb 100644
--- a/src/wasm.c
+++ b/src/wasm.c
@@ -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');
+ }
+}