summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-28 14:15:45 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-28 14:15:45 -0800
commitbbefe366f4d585ae1103c59b3c20a3f1dfc9f225 (patch)
tree7951f4e39723bd2c65d1bd4f606e1f1abba39776 /src
parentd98de7569efadb1c654cd53c6404f40b15ad7ae7 (diff)
downloadbinaryen-bbefe366f4d585ae1103c59b3c20a3f1dfc9f225.tar.gz
binaryen-bbefe366f4d585ae1103c59b3c20a3f1dfc9f225.tar.bz2
binaryen-bbefe366f4d585ae1103c59b3c20a3f1dfc9f225.zip
support interpreting wasm from either asm2wasm or wasm-s-parser in wasm.js
Diffstat (limited to 'src')
-rw-r--r--src/js/post.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/js/post.js b/src/js/post.js
index e64774c3c..c4df41865 100644
--- a/src/js/post.js
+++ b/src/js/post.js
@@ -84,10 +84,6 @@ function integrateWasmJS(Module) {
Module['asm'] = function(global, env, providedBuffer) {
assert(providedBuffer === Module['buffer']); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way.
- // Generate a module instance of the asm.js converted into wasm.
- var code = Module['read'](Module['asmjsCodeFile']);
- // TODO: support wasm s-expression loading here
-
// wasm code would create its own buffer, at this time. But static init code might have
// written to the buffer already, and we must copy it over. We could just avoid
// this copy in wasm.js polyfilling, but to be as close as possible to real wasm,
@@ -107,9 +103,17 @@ function integrateWasmJS(Module) {
return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed
};
+ // Prepare to generate wasm, using either asm2wasm or wasm-s-parser
+ var method = Module['wasmJSMethod'] || 'asm2wasm';
+ assert(method == 'asm2wasm' || method == 'wasm-s-parser');
+ var code = Module['read'](method == 'asm2wasm' ? Module['asmjsCodeFile'] : Module['wasmCodeFile']);
var temp = wasmJS['_malloc'](code.length + 1);
wasmJS['writeAsciiToMemory'](code, temp);
- wasmJS['_load_asm2wasm'](temp);
+ if (method == 'asm2wasm') {
+ wasmJS['_load_asm2wasm'](temp);
+ } else {
+ wasmJS['_load_s_expr2wasm'](temp);
+ }
wasmJS['_free'](temp);
wasmJS['_instantiate'](temp);