summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/js/post.js23
-rw-r--r--src/wasm-js.cpp20
2 files changed, 23 insertions, 20 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);
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index fb3d5dd5a..aa163ba3c 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -98,25 +98,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_s_expr2wasm(char *input, char *mappedG
abort();
});
- if (wasmJSDebug) std::cerr << "mapping globals...\n";
- EM_ASM_({
- var mappedGlobals = JSON.parse($0);
- var i32 = $1;
- var f32 = $2;
- var f64 = $3;
- 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 = Module['lookupImport'](global.module, global.base);
- var address = global.address;
- switch (global.type) {
- case i32: Module['info'].parent['HEAP32'][address >> 2] = value; break;
- case f32: Module['info'].parent['HEAPF32'][address >> 2] = value; break;
- case f64: Module['info'].parent['HEAPF64'][address >> 3] = value; break;
- default: abort();
- }
- }
- }, mappedGlobals, i32, f32, f64);
+ // global mapping is done in js in post.js
}
// instantiates the loaded wasm (which might be from asm2wasm, or