diff options
author | Derek Schuff <dschuff@chromium.org> | 2016-10-04 15:03:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 15:03:00 -0700 |
commit | a8386c3d6fcf6bf28f369b85784a89a8f272b59d (patch) | |
tree | a76d283ae9dfb89b4fd24b8d2cf8494aa7b776b7 | |
parent | a78bd60bc68993c746a9f236d01558e04b6765bd (diff) | |
download | binaryen-a8386c3d6fcf6bf28f369b85784a89a8f272b59d.tar.gz binaryen-a8386c3d6fcf6bf28f369b85784a89a8f272b59d.tar.bz2 binaryen-a8386c3d6fcf6bf28f369b85784a89a8f272b59d.zip |
Write global mutability into wasm binary (#739)
For compatibility with 0xc
Also update opcode for get_global
-rw-r--r-- | src/wasm-binary.h | 9 |
1 files changed, 6 insertions, 3 deletions
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); } |