Skip to content

Commit 74e6965

Browse files
authored
[C API] Split BinaryenCallRef and BinaryenReturnCallRef in c api (#8121)
This splits `BinaryenReturnCallRef` from `BinaryenCallRef` in the c api, to be more inline with both the JS API and the C APIs for `Call` and `CallIndirect`. Closes: #8110
1 parent 58813d2 commit 74e6965

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ full changeset diff at the end of each section.
1414

1515
Current Trunk
1616
-------------
17+
- The c api now has separate functions for `CallRef` and `ReturnCallRef` matching the semantics of `Call` and `ReturnCall`.
1718

1819
v125
1920
----

src/binaryen-c.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,15 +1731,27 @@ BinaryenExpressionRef BinaryenCallRef(BinaryenModuleRef module,
17311731
BinaryenExpressionRef target,
17321732
BinaryenExpressionRef* operands,
17331733
BinaryenIndex numOperands,
1734-
BinaryenType type,
1735-
bool isReturn) {
1734+
BinaryenType type) {
1735+
std::vector<Expression*> args;
1736+
for (BinaryenIndex i = 0; i < numOperands; i++) {
1737+
args.push_back((Expression*)operands[i]);
1738+
}
1739+
return static_cast<Expression*>(
1740+
Builder(*(Module*)module)
1741+
.makeCallRef((Expression*)target, args, Type(type), false));
1742+
}
1743+
BinaryenExpressionRef BinaryenReturnCallRef(BinaryenModuleRef module,
1744+
BinaryenExpressionRef target,
1745+
BinaryenExpressionRef* operands,
1746+
BinaryenIndex numOperands,
1747+
BinaryenType type) {
17361748
std::vector<Expression*> args;
17371749
for (BinaryenIndex i = 0; i < numOperands; i++) {
17381750
args.push_back((Expression*)operands[i]);
17391751
}
17401752
return static_cast<Expression*>(
17411753
Builder(*(Module*)module)
1742-
.makeCallRef((Expression*)target, args, Type(type), isReturn));
1754+
.makeCallRef((Expression*)target, args, Type(type), true));
17431755
}
17441756
BinaryenExpressionRef BinaryenRefTest(BinaryenModuleRef module,
17451757
BinaryenExpressionRef ref,

src/binaryen-c.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,13 @@ BinaryenCallRef(BinaryenModuleRef module,
10161016
BinaryenExpressionRef target,
10171017
BinaryenExpressionRef* operands,
10181018
BinaryenIndex numOperands,
1019-
BinaryenType type,
1020-
bool isReturn);
1019+
BinaryenType type);
1020+
BINARYEN_API BinaryenExpressionRef
1021+
BinaryenReturnCallRef(BinaryenModuleRef module,
1022+
BinaryenExpressionRef target,
1023+
BinaryenExpressionRef* operands,
1024+
BinaryenIndex numOperands,
1025+
BinaryenType type);
10211026
BINARYEN_API BinaryenExpressionRef BinaryenRefTest(BinaryenModuleRef module,
10221027
BinaryenExpressionRef ref,
10231028
BinaryenType castType);

src/js/binaryen.js-post.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,13 +2474,13 @@ function wrapModule(module, self = {}) {
24742474

24752475
self['call_ref'] = function(target, operands, type) {
24762476
return preserveStack(() =>
2477-
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type, false)
2477+
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type)
24782478
);
24792479
};
24802480

24812481
self['return_call_ref'] = function(target, operands, type) {
24822482
return preserveStack(() =>
2483-
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type, true)
2483+
Module['_BinaryenReturnCallRef'](module, target, i32sToStack(operands), operands.length, type)
24842484
);
24852485
}
24862486

test/example/c-api-kitchen-sink.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,8 @@ void test_core() {
10461046
4,
10471047
iIfF,
10481048
BinaryenTypeInt32()),
1049+
BinaryenReturnCallRef(
1050+
module, funcrefExpr, callOperands4b, 4, BinaryenTypeNone()),
10491051
// Reference types
10501052
BinaryenRefIsNull(module, externrefExpr),
10511053
BinaryenRefIsNull(module, funcrefExpr),
@@ -2264,8 +2266,7 @@ void test_callref_and_types() {
22642266
BinaryenRefFunc(module, "tiny", funcType),
22652267
NULL,
22662268
0,
2267-
BinaryenTypeNone(),
2268-
false);
2269+
BinaryenTypeNone());
22692270
BinaryenFunctionSetBody(tiny, callRef);
22702271

22712272
bool didValidate = BinaryenModuleValidate(module);

test/example/c-api-kitchen-sink.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,13 @@ BinaryenFeatureAll: 4194303
21112111
(f64.const 3.7)
21122112
(i32.const 2449)
21132113
)
2114+
(return_call_ref $2
2115+
(i32.const 13)
2116+
(i64.const 37)
2117+
(f32.const 1.2999999523162842)
2118+
(f64.const 3.7)
2119+
(ref.func $"kitchen()sinker")
2120+
)
21142121
(drop
21152122
(ref.is_null
21162123
(ref.null noextern)

0 commit comments

Comments
 (0)