diff options
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index aad142d44..b67a79c3d 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -706,7 +706,8 @@ public: o << U32LEB(num); for (auto& segment : wasm->memory.segments) { if (segment.data.size() == 0) continue; - o << U32LEB(segment.offset); + writeExpression(segment.offset); + o << int8_t(BinaryConsts::End); writeInlineBuffer(&segment.data[0], segment.data.size()); } finishSection(start); @@ -1572,6 +1573,15 @@ public: } } + Expression* readExpression() { + assert(depth == 0); + processExpressions(); + assert(expressionStack.size() == 1); + auto* ret = popExpression(); + assert(depth == 0); + return ret; + } + void readGlobals() { if (debug) std::cerr << "== readGlobals" << std::endl; size_t num = getU32LEB(); @@ -1580,11 +1590,7 @@ public: if (debug) std::cerr << "read one" << std::endl; auto curr = new Global; curr->type = getWasmType(); - assert(depth == 0); - processExpressions(); - assert(expressionStack.size() == 1); - curr->init = popExpression(); - assert(depth == 0); + curr->init = readExpression(); wasm.addGlobal(curr); } } @@ -1649,7 +1655,7 @@ public: auto num = getU32LEB(); for (size_t i = 0; i < num; i++) { Memory::Segment curr; - auto offset = getU32LEB(); + auto offset = readExpression(); auto size = getU32LEB(); std::vector<char> buffer; buffer.resize(size); |