diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-08-07 12:55:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-07 12:55:47 -0700 |
commit | 4b9852ad23541c851031398b835d6387b1b51393 (patch) | |
tree | c41ad109e1e54825b4da0c823c62a28a97e0ed99 /src/leb128.cc | |
parent | 05c1aa18e53258fefee9a8aac656280475ccf614 (diff) | |
download | wabt-4b9852ad23541c851031398b835d6387b1b51393.tar.gz wabt-4b9852ad23541c851031398b835d6387b1b51393.tar.bz2 wabt-4b9852ad23541c851031398b835d6387b1b51393.zip |
Added initial "memory64" proposal support (#1500)
Diffstat (limited to 'src/leb128.cc')
-rw-r--r-- | src/leb128.cc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/leb128.cc b/src/leb128.cc index 796c4e29..c3decac5 100644 --- a/src/leb128.cc +++ b/src/leb128.cc @@ -187,6 +187,50 @@ size_t ReadU32Leb128(const uint8_t* p, } } +size_t ReadU64Leb128(const uint8_t* p, + const uint8_t* end, + uint64_t* out_value) { + if (p < end && (p[0] & 0x80) == 0) { + *out_value = LEB128_1(uint64_t); + return 1; + } else if (p + 1 < end && (p[1] & 0x80) == 0) { + *out_value = LEB128_2(uint64_t); + return 2; + } else if (p + 2 < end && (p[2] & 0x80) == 0) { + *out_value = LEB128_3(uint64_t); + return 3; + } else if (p + 3 < end && (p[3] & 0x80) == 0) { + *out_value = LEB128_4(uint64_t); + return 4; + } else if (p + 4 < end && (p[4] & 0x80) == 0) { + *out_value = LEB128_5(uint64_t); + return 5; + } else if (p + 5 < end && (p[5] & 0x80) == 0) { + *out_value = LEB128_6(uint64_t); + return 6; + } else if (p + 6 < end && (p[6] & 0x80) == 0) { + *out_value = LEB128_7(uint64_t); + return 7; + } else if (p + 7 < end && (p[7] & 0x80) == 0) { + *out_value = LEB128_8(uint64_t); + return 8; + } else if (p + 8 < end && (p[8] & 0x80) == 0) { + *out_value = LEB128_9(uint64_t); + return 9; + } else if (p + 9 < end && (p[9] & 0x80) == 0) { + // The top bits set represent values > 32 bits. + if (p[9] & 0xf0) { + return 0; + } + *out_value = LEB128_10(uint64_t); + return 10; + } else { + // past the end. + *out_value = 0; + return 0; + } +} + size_t ReadS32Leb128(const uint8_t* p, const uint8_t* end, uint32_t* out_value) { |