summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r--src/wasm-binary.h20
1 files changed, 12 insertions, 8 deletions
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<typename T>
+struct LEB {
+ T value;
- LEB128() {}
- LEB128(uint32_t value) : value(value) {}
+ LEB() {}
+ LEB(T value) : value(value) {}
void write(std::vector<uint8_t>* 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<uint8_t>* 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<uint8_t ()> 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<uint32_t> LEB128;
+typedef LEB<uint64_t> 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