From a8386c3d6fcf6bf28f369b85784a89a8f272b59d Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 4 Oct 2016 15:03:00 -0700 Subject: Write global mutability into wasm binary (#739) For compatibility with 0xc Also update opcode for get_global --- src/wasm-binary.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index be09f640a..8e9534973 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -457,8 +457,8 @@ enum ASTNodes { CallFunction = 0x16, CallIndirect = 0x17, TeeLocal = 0x19, - GetGlobal = 0x1a, - SetGlobal = 0x1b, + GetGlobal = 0xbb, + SetGlobal = 0xbc, Unreachable = 0x00, Block = 0x01, @@ -758,6 +758,7 @@ public: for (auto& curr : wasm->globals) { if (debug) std::cerr << "write one" << std::endl; o << binaryWasmType(curr->type); + o << U32LEB(curr->mutable_); writeExpression(curr->init); o << int8_t(BinaryConsts::End); } @@ -1771,8 +1772,10 @@ public: if (debug) std::cerr << "read one" << std::endl; auto curr = new Global; curr->type = getWasmType(); + auto mutable_ = getU32LEB(); + if (bool(mutable_) != mutable_) throw ParseException("Global mutability must be 0 or 1"); + curr->mutable_ = mutable_; curr->init = readExpression(); - curr->mutable_ = true; // TODO curr->name = Name("global$" + std::to_string(wasm.globals.size())); wasm.addGlobal(curr); } -- cgit v1.2.3