diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 13:29:45 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-31 13:29:45 -0700 |
commit | 81e35a5fdf894232e4167a9d66c7b93ecf31ea41 (patch) | |
tree | 4207dbfdd8649951735da8f5741690b2d588a8d9 /src/js | |
parent | dcdf2e222f0b42c71ca41f7e37bc77decfef37f7 (diff) | |
download | binaryen-81e35a5fdf894232e4167a9d66c7b93ecf31ea41.tar.gz binaryen-81e35a5fdf894232e4167a9d66c7b93ecf31ea41.tar.bz2 binaryen-81e35a5fdf894232e4167a9d66c7b93ecf31ea41.zip |
progress on wasm.js communication
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/post.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/js/post.js b/src/js/post.js new file mode 100644 index 000000000..571fca101 --- /dev/null +++ b/src/js/post.js @@ -0,0 +1,30 @@ + +(function() { + // XXX don't be confused. Module here is in the outside program. WasmJS is the inner wasm-js.cpp. + + // Generate a module instance of the asm.js converted into wasm. + var code = read(Module['asmjsCodeFile']); + var temp = WasmJS._malloc(code.length + 1); + WasmJS.writeAsciiToMemory(code, temp); + var instance = WasmJS.load_asm(temp); + WasmJS._free(temp); + + // Generate memory XXX TODO get the right size + var theBuffer = Module['buffer'] = new ArrayBuffer(16*1024*1024); + + // Information for the instance of the module. + var instance = WasmJS['instance'] = { + global: null, + env: null, + parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program. + }; + + // The asm.js function, called to "link" the asm.js module. + Module['asm'] = function(global, env, buffer) { + assert(buffer === theBuffer); // we should not even need to pass it as a 3rd arg for wasm, but that's the asm.js way. + // write the provided data to a location the wasm instance can get at it. + instance.global = global; + instance.env = env; + }; +})(); + |