summaryrefslogtreecommitdiff
path: root/src/wasm2js.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-06-10 16:02:00 -0700
committerGitHub <noreply@github.com>2024-06-10 16:02:00 -0700
commit0a1a59af573414a20fe457fd77b732729aa92fb2 (patch)
tree9639e7d7946f6d63737703d5c032ff85d4d2be79 /src/wasm2js.h
parent76d1ac3e9c5abfe589bcdfc84b89f263bac7c574 (diff)
downloadbinaryen-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.h30
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);