summaryrefslogtreecommitdiff
path: root/src/wasm-binary.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-01-29 17:06:49 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-01-29 17:06:49 -0800
commit1cf76c3293fdf8e0326384c39696df844d8d6aed (patch)
tree95d080f3abe3fb84414e8623e93a260cdfcc7453 /src/wasm-binary.h
parent6c52601dde6699e0655c9a61dc2df3089e0a0204 (diff)
downloadbinaryen-1cf76c3293fdf8e0326384c39696df844d8d6aed.tar.gz
binaryen-1cf76c3293fdf8e0326384c39696df844d8d6aed.tar.bz2
binaryen-1cf76c3293fdf8e0326384c39696df844d8d6aed.zip
allow memory size 0 in binary format
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r--src/wasm-binary.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 757551c12..c448f73f4 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -392,9 +392,18 @@ public:
void writeMemory() {
if (wasm->memory.max == 0) return;
if (debug) std::cerr << "== writeMemory" << std::endl;
- o << int8_t(BinaryConsts::Memory) << int8_t(ceil(log2(wasm->memory.initial)))
- << int8_t(ceil(log2(wasm->memory.max)))
- << int8_t(1); // export memory
+ o << int8_t(BinaryConsts::Memory);
+ if (wasm->memory.initial == 0) { // XXX diverge from v8, 0 means 0, 1 and above are powers of 2 starting at 0
+ o << int8_t(0);
+ } else {
+ o << int8_t(ceil(log2(wasm->memory.initial)) + 1);
+ }
+ if (wasm->memory.max == 0) {
+ o << int8_t(0);
+ } else {
+ o << int8_t(ceil(log2(wasm->memory.max)) + 1);
+ }
+ o << int8_t(1); // export memory
}
void writeSignatures() {
@@ -1058,8 +1067,10 @@ public:
void readMemory() {
if (debug) std::cerr << "== readMemory" << std::endl;
- wasm.memory.initial = std::pow<size_t>(2, getInt8());
- wasm.memory.max = std::pow<size_t>(2, getInt8());
+ size_t initial = getInt8();
+ wasm.memory.initial = initial == 0 ? 0 : std::pow<size_t>(2, initial - 1);
+ size_t max = getInt8();
+ wasm.memory.max = max == 0 ? 0 : std::pow<size_t>(2, max - 1);
verifyInt8(1); // export memory
}