summaryrefslogtreecommitdiff
path: root/src/wasm2js.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-04-12 15:45:10 -0700
committerGitHub <noreply@github.com>2019-04-12 15:45:10 -0700
commit883d14de7157950063f74b81658d00df0d53be8d (patch)
treece0eb6bd6f8ba344e41861f3280f5248427072e7 /src/wasm2js.h
parent53badfbea40e78eadf652735d247649948e0b9a9 (diff)
downloadbinaryen-883d14de7157950063f74b81658d00df0d53be8d.tar.gz
binaryen-883d14de7157950063f74b81658d00df0d53be8d.tar.bz2
binaryen-883d14de7157950063f74b81658d00df0d53be8d.zip
Wasm2js memory fixes (#2003)
* I64ToI32Lowering - don't assume address 0 is a hardcoded location for scratch memory. Import __tempMemory__ for that. * RemoveNonJSOps - also use __tempMemory__. Oddly here the address was a hardcoded 1024 (perhaps where the rust program put a static global?). * Support imported ints in wasm2js, coercing them as needed. * Add "env" import support in the tests, since now we emit imports from there. * Make wasm2js tests split out multi-module tests using split_wast which is more robust and avoids emitting multiple outputs in one file (which makes no sense for ES6 modules)
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r--src/wasm2js.h42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 19c12a501..fab39267d 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -486,12 +486,16 @@ void Wasm2JSBuilder::addGlobalImport(Ref ast, Global* import) {
Ref theVar = ValueBuilder::makeVar();
ast->push_back(theVar);
Ref module = ValueBuilder::makeName(ENV); // TODO: handle nested module imports
+ Ref value = ValueBuilder::makeDot(
+ module,
+ fromName(import->base, NameScope::Top)
+ );
+ if (import->type == i32) {
+ value = makeAsmCoercion(value, ASM_INT);
+ }
ValueBuilder::appendToVar(theVar,
fromName(import->name, NameScope::Top),
- ValueBuilder::makeDot(
- module,
- fromName(import->base, NameScope::Top)
- )
+ value
);
}
@@ -2053,7 +2057,6 @@ void Wasm2JSGlue::emitPreES6() {
ImportInfo imports(wasm);
ModuleUtils::iterImportedGlobals(wasm, [&](Global* import) {
- Fatal() << "non-function imports aren't supported yet\n";
noteImport(import->module, import->base);
});
ModuleUtils::iterImportedFunctions(wasm, [&](Function* import) {
@@ -2074,23 +2077,20 @@ void Wasm2JSGlue::emitPost() {
void Wasm2JSGlue::emitPostEmscripten() {
emitMemory("wasmMemory.buffer", "writeSegment");
- out << "return asmFunc(\n"
- << " {\n"
- << " 'env': asmLibraryArg,\n"
- << " 'global': {\n"
- << " 'Int8Array': Int8Array,\n"
- << " 'Int16Array': Int16Array,\n"
- << " 'Int32Array': Int32Array,\n"
- << " 'Uint8Array': Uint8Array,\n"
- << " 'Uint16Array': Uint16Array,\n"
- << " 'Uint32Array': Uint32Array,\n"
- << " 'Float32Array': Float32Array,\n"
- << " 'Float64Array': Float64Array,\n"
- << " 'NaN': NaN,\n"
- << " 'Infinity': Infinity,\n"
- << " 'Math': Math\n"
- << " }\n"
+ out << "return asmFunc({\n"
+ << " 'Int8Array': Int8Array,\n"
+ << " 'Int16Array': Int16Array,\n"
+ << " 'Int32Array': Int32Array,\n"
+ << " 'Uint8Array': Uint8Array,\n"
+ << " 'Uint16Array': Uint16Array,\n"
+ << " 'Uint32Array': Uint32Array,\n"
+ << " 'Float32Array': Float32Array,\n"
+ << " 'Float64Array': Float64Array,\n"
+ << " 'NaN': NaN,\n"
+ << " 'Infinity': Infinity,\n"
+ << " 'Math': Math\n"
<< " },\n"
+ << " asmLibraryArg,\n"
<< " wasmMemory.buffer\n"
<< ")"
<< "\n"