summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-16 17:20:15 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-03-16 17:33:36 -0700
commit31e92024ae8859c9387dbdcda1dfebb888f82510 (patch)
tree73f3b6ab9e3a3dee72d787a7148de1da8b6ef872 /src/wasm-binary.h
parent65716c4ec22ad2edb9326920487d804f91ba75b4 (diff)
downloadbinaryen-31e92024ae8859c9387dbdcda1dfebb888f82510.tar.gz
binaryen-31e92024ae8859c9387dbdcda1dfebb888f82510.tar.bz2
binaryen-31e92024ae8859c9387dbdcda1dfebb888f82510.zip
add a 64-bit LEB
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