diff options
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r-- | src/asm2wasm.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index d958c4b6a..c193791f8 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -426,13 +426,16 @@ public: std::map<IString, MappedGlobal> mappedGlobals; private: - void allocateGlobal(IString name, Type type) { + void allocateGlobal(IString name, Type type, Literal value=Literal()) { assert(mappedGlobals.find(name) == mappedGlobals.end()); + if (value.type == none) { + value = Literal::makeZero(type); + } mappedGlobals.emplace(name, MappedGlobal(type)); wasm.addGlobal(builder.makeGlobal( name, type, - LiteralUtils::makeZero(type, wasm), + builder.makeConst(value), Builder::Mutable )); } @@ -986,8 +989,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { Ref value = pair[1]; if (value->isNumber()) { // global int - assert(value->getNumber() == 0); - allocateGlobal(name, Type::i32); + allocateGlobal(name, Type::i32, Literal(int32_t(value->getInteger()))); } else if (value[0] == BINARY) { // int import assert(value[1] == OR && value[3]->isNumber() && value[3]->getNumber() == 0); |