Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ full changeset diff at the end of each section.

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

v125
----
Expand Down
18 changes: 15 additions & 3 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,15 +1731,27 @@ BinaryenExpressionRef BinaryenCallRef(BinaryenModuleRef module,
BinaryenExpressionRef target,
BinaryenExpressionRef* operands,
BinaryenIndex numOperands,
BinaryenType type,
bool isReturn) {
BinaryenType type) {
std::vector<Expression*> args;
for (BinaryenIndex i = 0; i < numOperands; i++) {
args.push_back((Expression*)operands[i]);
}
return static_cast<Expression*>(
Builder(*(Module*)module)
.makeCallRef((Expression*)target, args, Type(type), false));
}
BinaryenExpressionRef BinaryenReturnCallRef(BinaryenModuleRef module,
BinaryenExpressionRef target,
BinaryenExpressionRef* operands,
BinaryenIndex numOperands,
BinaryenType type) {
std::vector<Expression*> args;
for (BinaryenIndex i = 0; i < numOperands; i++) {
args.push_back((Expression*)operands[i]);
}
return static_cast<Expression*>(
Builder(*(Module*)module)
.makeCallRef((Expression*)target, args, Type(type), isReturn));
.makeCallRef((Expression*)target, args, Type(type), true));
}
BinaryenExpressionRef BinaryenRefTest(BinaryenModuleRef module,
BinaryenExpressionRef ref,
Expand Down
9 changes: 7 additions & 2 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,13 @@ BinaryenCallRef(BinaryenModuleRef module,
BinaryenExpressionRef target,
BinaryenExpressionRef* operands,
BinaryenIndex numOperands,
BinaryenType type,
bool isReturn);
BinaryenType type);
BINARYEN_API BinaryenExpressionRef
BinaryenReturnCallRef(BinaryenModuleRef module,
BinaryenExpressionRef target,
BinaryenExpressionRef* operands,
BinaryenIndex numOperands,
BinaryenType type);
BINARYEN_API BinaryenExpressionRef BinaryenRefTest(BinaryenModuleRef module,
BinaryenExpressionRef ref,
BinaryenType castType);
Expand Down
4 changes: 2 additions & 2 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2474,13 +2474,13 @@ function wrapModule(module, self = {}) {

self['call_ref'] = function(target, operands, type) {
return preserveStack(() =>
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type, false)
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type)
);
};

self['return_call_ref'] = function(target, operands, type) {
return preserveStack(() =>
Module['_BinaryenCallRef'](module, target, i32sToStack(operands), operands.length, type, true)
Module['_BinaryenReturnCallRef'](module, target, i32sToStack(operands), operands.length, type)
);
}

Expand Down
5 changes: 3 additions & 2 deletions test/example/c-api-kitchen-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,8 @@ void test_core() {
4,
iIfF,
BinaryenTypeInt32()),
BinaryenReturnCallRef(
module, funcrefExpr, callOperands4b, 4, BinaryenTypeNone()),
// Reference types
BinaryenRefIsNull(module, externrefExpr),
BinaryenRefIsNull(module, funcrefExpr),
Expand Down Expand Up @@ -2264,8 +2266,7 @@ void test_callref_and_types() {
BinaryenRefFunc(module, "tiny", funcType),
NULL,
0,
BinaryenTypeNone(),
false);
BinaryenTypeNone());
BinaryenFunctionSetBody(tiny, callRef);

bool didValidate = BinaryenModuleValidate(module);
Expand Down
7 changes: 7 additions & 0 deletions test/example/c-api-kitchen-sink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,13 @@ BinaryenFeatureAll: 4194303
(f64.const 3.7)
(i32.const 2449)
)
(return_call_ref $2
(i32.const 13)
(i64.const 37)
(f32.const 1.2999999523162842)
(f64.const 3.7)
(ref.func $"kitchen()sinker")
)
(drop
(ref.is_null
(ref.null noextern)
Expand Down
Loading