summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-28 20:50:16 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-28 20:50:16 -0800
commitb7967131b07daca8826945828c3fd155e3889ba6 (patch)
tree78ab9033e451e4e87f5c134d66228ae590334e0a /src/js
parentd8f258e8e74b17d06ee7d94fc7c4dd3165819f0d (diff)
downloadbinaryen-b7967131b07daca8826945828c3fd155e3889ba6.tar.gz
binaryen-b7967131b07daca8826945828c3fd155e3889ba6.tar.bz2
binaryen-b7967131b07daca8826945828c3fd155e3889ba6.zip
fix wasm.js/s-expression-parsing global mapping
Diffstat (limited to 'src/js')
-rw-r--r--src/js/post.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/js/post.js b/src/js/post.js
index 2ef25e30c..0a45df680 100644
--- a/src/js/post.js
+++ b/src/js/post.js
@@ -39,6 +39,14 @@ function integrateWasmJS(Module) {
return;
}
+ var WasmTypes = {
+ none: 0,
+ i32: 1,
+ i64: 2,
+ f32: 3,
+ f64: 4
+ };
+
// Use wasm.js to polyfill and execute code in a wasm interpreter.
var wasmJS = WasmJS({});
@@ -115,7 +123,20 @@ function integrateWasmJS(Module) {
if (method == 'asm2wasm') {
wasmJS['_load_asm2wasm'](temp);
} else {
- wasmJS['_load_s_expr2wasm'](temp, Module['read'](Module['wasmCodeFile'] + '.mappedGlobals'));
+ wasmJS['_load_s_expr2wasm'](temp);
+ var mappedGlobals = JSON.parse(Module['read'](Module['wasmCodeFile'] + '.mappedGlobals'));
+ for (var name in mappedGlobals) {
+ var global = mappedGlobals[name];
+ if (!global.import) continue; // non-imports are initialized to zero in the typed array anyhow, so nothing to do here
+ var value = wasmJS['lookupImport'](global.module, global.base);
+ var address = global.address;
+ switch (global.type) {
+ case WasmTypes.i32: Module['HEAP32'][address >> 2] = value; break;
+ case WasmTypes.f32: Module['HEAPF32'][address >> 2] = value; break;
+ case WasmTypes.f64: Module['HEAPF64'][address >> 3] = value; break;
+ default: abort();
+ }
+ }
}
wasmJS['_free'](temp);