diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-19 17:18:59 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-19 18:49:42 -0700 |
commit | ba0a6541885d324b9562a79a8977ed8733191b7f (patch) | |
tree | 98fbbbd23421b75c9e47870f828161aec0d6494d /src/asm2wasm.h | |
parent | 38dc263c303be13bec2fcee713bdb18fa89057c8 (diff) | |
download | binaryen-ba0a6541885d324b9562a79a8977ed8733191b7f.tar.gz binaryen-ba0a6541885d324b9562a79a8977ed8733191b7f.tar.bz2 binaryen-ba0a6541885d324b9562a79a8977ed8733191b7f.zip |
globals mutability fixes
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r-- | src/asm2wasm.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index bce67a582..1c528d7f3 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -177,6 +177,7 @@ private: else if (type == f64) value = Literal(double(0)); else WASM_UNREACHABLE(); global->init = wasm.allocator.alloc<Const>()->set(value); + global->mutable_ = true; wasm.addGlobal(global); } @@ -502,9 +503,20 @@ void Asm2WasmBuilder::processAsm(Ref ast) { type = WasmType::f64; } if (type != WasmType::none) { + // we need imported globals to be mutable, but wasm doesn't support that yet, so we must + // import an immutable and create a mutable global initialized to its value + import->name = Name(std::string(import->name.str) + "$asm2wasm$import"); import->kind = Import::Global; import->globalType = type; mappedGlobals.emplace(name, type); + { + auto global = new Global(); + global->name = name; + global->type = type; + global->init = builder.makeGetGlobal(import->name, type); + global->mutable_ = true; + wasm.addGlobal(global); + } } else { import->kind = Import::Function; } |