Skip to content

Add RefIsGetOp/SetOp in C and JS API #3605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,16 @@ void BinaryenMemoryFillSetSize(BinaryenExpressionRef expr,
static_cast<MemoryFill*>(expression)->size = (Expression*)sizeExpr;
}
// RefIs
BinaryenOp BinaryenRefIsGetOp(BinaryenExpressionRef expr) {
auto* expression = (Expression*)expr;
assert(expression->is<RefIs>());
return static_cast<RefIs*>(expression)->op;
}
void BinaryenRefIsSetOp(BinaryenExpressionRef expr, BinaryenOp op) {
auto* expression = (Expression*)expr;
assert(expression->is<RefIs>());
static_cast<RefIs*>(expression)->op = RefIsOp(op);
}
BinaryenExpressionRef BinaryenRefIsGetValue(BinaryenExpressionRef expr) {
auto* expression = (Expression*)expr;
assert(expression->is<RefIs>());
Expand Down
10 changes: 7 additions & 3 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1688,12 +1688,16 @@ BinaryenMemoryFillGetSize(BinaryenExpressionRef expr);
BINARYEN_API void BinaryenMemoryFillSetSize(BinaryenExpressionRef expr,
BinaryenExpressionRef sizeExpr);

// RefIsNull
// RefIs

// Gets the value expression tested to be null of a `ref.is_null` expression.
// Gets the operation performed by a `ref.is_*` expression.
BINARYEN_API BinaryenOp BinaryenRefIsGetOp(BinaryenExpressionRef expr);
// Sets the operation performed by a `ref.is_*` expression.
BINARYEN_API void BinaryenRefIsSetOp(BinaryenExpressionRef expr, BinaryenOp op);
// Gets the value expression tested by a `ref.is_*` expression.
BINARYEN_API BinaryenExpressionRef
BinaryenRefIsGetValue(BinaryenExpressionRef expr);
// Sets the value expression tested to be null of a `ref.is_null` expression.
// Sets the value expression tested by a `ref.is_*` expression.
BINARYEN_API void BinaryenRefIsSetValue(BinaryenExpressionRef expr,
BinaryenExpressionRef valueExpr);

Expand Down
6 changes: 6 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,12 @@ Module['MemoryFill'] = makeExpressionWrapper({
});

Module['RefIs'] = makeExpressionWrapper({
'getOp'(expr) {
return Module['_BinaryenRefIsGetOp'](expr);
},
'setOp'(expr, op) {
Module['_BinaryenRefIsSetOp'](expr, op);
},
'getValue'(expr) {
return Module['_BinaryenRefIsGetValue'](expr);
},
Expand Down
5 changes: 5 additions & 0 deletions test/binaryen.js/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,18 @@ console.log("# RefIs");
(function testRefIs() {
const module = new binaryen.Module();

var op = binaryen.Operations.RefIsNull;
var value = module.local.get(1, binaryen.externref);
const theRefIs = binaryen.RefIs(module.ref.is_null(value));
assert(theRefIs instanceof binaryen.RefIs);
assert(theRefIs instanceof binaryen.Expression);
assert(theRefIs.op === op);
assert(theRefIs.value === value);
assert(theRefIs.type === binaryen.i32);

theRefIs.op = op = binaryen.Operations.RefIsFunc;
assert(theRefIs.op === op);
theRefIs.op = op = binaryen.Operations.RefIsNull;
theRefIs.value = value = module.local.get(2, binaryen.externref);
assert(theRefIs.value === value);
theRefIs.type = binaryen.f64;
Expand Down