From 31e92024ae8859c9387dbdcda1dfebb888f82510 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 16 Mar 2016 17:20:15 -0700 Subject: add a 64-bit LEB --- src/wasm-binary.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 1e6c48c3b..da397399f 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -30,14 +30,15 @@ namespace wasm { -struct LEB128 { - uint32_t value; +template +struct LEB { + T value; - LEB128() {} - LEB128(uint32_t value) : value(value) {} + LEB() {} + LEB(T value) : value(value) {} void write(std::vector* out) { - uint32_t temp = value; + T temp = value; do { uint8_t byte = temp & 127; temp >>= 7; @@ -49,7 +50,7 @@ struct LEB128 { } void writeAt(std::vector* out, size_t at, size_t minimum = 0) { - uint32_t temp = value; + T temp = value; size_t offset = 0; bool more; do { @@ -66,16 +67,19 @@ struct LEB128 { void read(std::function get) { value = 0; - uint32_t shift = 0; + T shift = 0; while (1) { uint8_t byte = get(); - value |= ((byte & 127) << shift); + value |= ((T(byte & 127)) << shift); if (!(byte & 128)) break; shift += 7; } } }; +typedef LEB LEB128; +typedef LEB LEB256; + // // We mostly stream into a buffer as we create the binary format, however, // sometimes we need to backtrack and write to a location behind us - wasm -- cgit v1.2.3