diff options
author | Alon Zakai <azakai@google.com> | 2024-06-10 16:02:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 16:02:00 -0700 |
commit | 0a1a59af573414a20fe457fd77b732729aa92fb2 (patch) | |
tree | 9639e7d7946f6d63737703d5c032ff85d4d2be79 /src/wasm2js.h | |
parent | 76d1ac3e9c5abfe589bcdfc84b89f263bac7c574 (diff) | |
download | binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.tar.gz binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.tar.bz2 binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.zip |
wasm2js: Add basic reference operations (#6648)
This adds ref.eq, ref.null, ref.is_null, ref.func.
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r-- | src/wasm2js.h | 30 |
1 files changed, 15 insertions, 15 deletions
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); |