diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asmjs/asm_v_wasm.cpp | 4 | ||||
-rw-r--r-- | src/emscripten-optimizer/optimizer-shared.cpp | 10 | ||||
-rw-r--r-- | src/emscripten-optimizer/optimizer.h | 2 | ||||
-rw-r--r-- | src/wasm2js.h | 30 |
4 files changed, 29 insertions, 17 deletions
diff --git a/src/asmjs/asm_v_wasm.cpp b/src/asmjs/asm_v_wasm.cpp index 314c2494f..bbbaad5bc 100644 --- a/src/asmjs/asm_v_wasm.cpp +++ b/src/asmjs/asm_v_wasm.cpp @@ -21,6 +21,10 @@ namespace wasm { JsType wasmToJsType(Type type) { + if (type.isRef()) { + return JS_REF; + } + TODO_SINGLE_COMPOUND(type); switch (type.getBasic()) { case Type::i32: diff --git a/src/emscripten-optimizer/optimizer-shared.cpp b/src/emscripten-optimizer/optimizer-shared.cpp index 8208f6f47..773c5d9fc 100644 --- a/src/emscripten-optimizer/optimizer-shared.cpp +++ b/src/emscripten-optimizer/optimizer-shared.cpp @@ -104,6 +104,11 @@ Ref makeJsCoercedZero(JsType type) { abort(); } +bool needsJsCoercion(JsType type) { + // References need no coercion, but everything else does. + return type != JS_REF; +} + Ref makeJsCoercion(Ref node, JsType type) { switch (type) { case JS_INT: @@ -122,10 +127,11 @@ Ref makeJsCoercion(Ref node, JsType type) { return ValueBuilder::makeCall(SIMD_INT16X8_CHECK, node); case JS_INT32X4: return ValueBuilder::makeCall(SIMD_INT32X4_CHECK, node); + case JS_REF: case JS_NONE: default: - // non-validating code, emit nothing XXX this is dangerous, we should only - // allow this when we know we are not validating + // No coercion is needed. + // TODO see if JS_NONE is actually used here. return node; } } diff --git a/src/emscripten-optimizer/optimizer.h b/src/emscripten-optimizer/optimizer.h index a27fe25eb..6347c194c 100644 --- a/src/emscripten-optimizer/optimizer.h +++ b/src/emscripten-optimizer/optimizer.h @@ -39,6 +39,7 @@ enum JsType { JS_INT16X8, JS_INT32X4, JS_INT64, + JS_REF, JS_NONE // number of types }; @@ -51,6 +52,7 @@ enum JsSign { }; cashew::Ref makeJsCoercedZero(JsType type); +bool needsJsCoercion(JsType type); cashew::Ref makeJsCoercion(cashew::Ref node, JsType type); cashew::Ref makeSigning(cashew::Ref node, JsSign sign); diff --git a/src/wasm2js.h b/src/wasm2js.h index 7540bd71a..2084c0453 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -921,11 +921,13 @@ Ref Wasm2JSBuilder::processFunction(Module* m, IString name = fromName(func->getLocalNameOrGeneric(i), NameScope::Local); ValueBuilder::appendArgumentToFunction(ret, name); if (needCoercions) { - ret[3]->push_back(ValueBuilder::makeStatement(ValueBuilder::makeBinary( - ValueBuilder::makeName(name), - SET, - makeJsCoercion(ValueBuilder::makeName(name), - wasmToJsType(func->getLocalType(i)))))); + auto jsType = wasmToJsType(func->getLocalType(i)); + if (needsJsCoercion(jsType)) { + ret[3]->push_back(ValueBuilder::makeStatement(ValueBuilder::makeBinary( + ValueBuilder::makeName(name), + SET, + makeJsCoercion(ValueBuilder::makeName(name), jsType)))); + } } } Ref theVar = ValueBuilder::makeVar(); @@ -2219,21 +2221,19 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, visit(curr->value, EXPRESSION_RESULT), visit(curr->size, EXPRESSION_RESULT)); } - Ref visitRefNull(RefNull* curr) { - unimplemented(curr); - WASM_UNREACHABLE("unimp"); - } + Ref visitRefNull(RefNull* curr) { return ValueBuilder::makeName("null"); } Ref visitRefIsNull(RefIsNull* curr) { - unimplemented(curr); - WASM_UNREACHABLE("unimp"); + return ValueBuilder::makeBinary(visit(curr->value, EXPRESSION_RESULT), + EQ, + ValueBuilder::makeName("null")); } Ref visitRefFunc(RefFunc* curr) { - unimplemented(curr); - WASM_UNREACHABLE("unimp"); + return ValueBuilder::makeName(fromName(curr->func, NameScope::Top)); } Ref visitRefEq(RefEq* curr) { - unimplemented(curr); - WASM_UNREACHABLE("unimp"); + return ValueBuilder::makeBinary(visit(curr->left, EXPRESSION_RESULT), + EQ, + visit(curr->right, EXPRESSION_RESULT)); } Ref visitTableGet(TableGet* curr) { unimplemented(curr); |