summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index f7e10d39b..ceb230f73 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1823,14 +1823,16 @@ void WasmBinaryBuilder::readGlobals() {
if (debug) std::cerr << "num: " << num << std::endl;
for (size_t i = 0; i < num; i++) {
if (debug) std::cerr << "read one" << std::endl;
- auto curr = new Global;
- curr->type = getWasmType();
+ auto 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->name = Name("global$" + std::to_string(wasm.globals.size()));
- wasm.addGlobal(curr);
+ auto* init = readExpression();
+ wasm.addGlobal(Builder::makeGlobal(
+ "global$" + std::to_string(wasm.globals.size()),
+ type,
+ init,
+ mutable_ ? Builder::Mutable : Builder::Immutable
+ ));
}
}