summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-12-30 13:41:02 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-12-30 14:02:14 -0800
commit585fd8af473354b9dfa7e57c5c6af396fa60945e (patch)
treec84871881aec6f957c9e3da32191b7c66859705b /src
parentc25d24447aeede9df0e76aac5176cf525522343b (diff)
downloadbinaryen-585fd8af473354b9dfa7e57c5c6af396fa60945e.tar.gz
binaryen-585fd8af473354b9dfa7e57c5c6af396fa60945e.tar.bz2
binaryen-585fd8af473354b9dfa7e57c5c6af396fa60945e.zip
memoryBase and tableBase should not be mutable, as we need to use them in segment/element offsets
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 6ed13b79a..fab74189e 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -649,19 +649,24 @@ 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");
+ // this is a global
import->kind = ExternalKind::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);
+ // tableBase and memoryBase are used as segment/element offsets, and must be constant;
+ // otherwise, an asm.js import of a constant is mutable, e.g. STACKTOP
+ if (name != "tableBase" && name != "memoryBase") {
+ // 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");
+ {
+ 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 = ExternalKind::Function;