diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binaryen-c.cpp | 73 | ||||
-rw-r--r-- | src/binaryen-c.h | 12 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 10 |
3 files changed, 78 insertions, 17 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index c22ab4411..fd0ac889a 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -977,11 +977,12 @@ BinaryenExpressionRef BinaryenSwitch(BinaryenModuleRef module, ret->finalize(); return static_cast<Expression*>(ret); } -BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, - const char* target, - BinaryenExpressionRef* operands, - BinaryenIndex numOperands, - BinaryenType returnType) { +static BinaryenExpressionRef makeBinaryenCall(BinaryenModuleRef module, + const char* target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + BinaryenType returnType, + bool isReturn) { auto* ret = ((Module*)module)->allocator.alloc<Call>(); if (tracing) { @@ -999,7 +1000,7 @@ BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, } std::cout << " };\n "; traceExpression(ret, - "BinaryenCall", + (isReturn ? "BinaryenReturnCall" : "BinaryenCall"), StringLit(target), "operands", numOperands, @@ -1012,14 +1013,33 @@ BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, ret->operands.push_back((Expression*)operands[i]); } ret->type = Type(returnType); + ret->isReturn = isReturn; ret->finalize(); return static_cast<Expression*>(ret); } -BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, - BinaryenExpressionRef target, - BinaryenExpressionRef* operands, - BinaryenIndex numOperands, - const char* type) { +BinaryenExpressionRef BinaryenCall(BinaryenModuleRef module, + const char* target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + BinaryenType returnType) { + return makeBinaryenCall( + module, target, operands, numOperands, returnType, false); +} +BinaryenExpressionRef BinaryenReturnCall(BinaryenModuleRef module, + const char* target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + BinaryenType returnType) { + return makeBinaryenCall( + module, target, operands, numOperands, returnType, true); +} +static BinaryenExpressionRef +makeBinaryenCallIndirect(BinaryenModuleRef module, + BinaryenExpressionRef target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + const char* type, + bool isReturn) { auto* wasm = (Module*)module; auto* ret = wasm->allocator.alloc<CallIndirect>(); @@ -1037,12 +1057,13 @@ BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, std::cout << "0"; } std::cout << " };\n "; - traceExpression(ret, - "BinaryenCallIndirect", - target, - "operands", - numOperands, - StringLit(type)); + traceExpression( + ret, + (isReturn ? "BinaryenReturnCallIndirect" : "BinaryenCallIndirect"), + target, + "operands", + numOperands, + StringLit(type)); std::cout << " }\n"; } @@ -1052,9 +1073,27 @@ BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, } ret->fullType = type; ret->type = wasm->getFunctionType(ret->fullType)->result; + ret->isReturn = isReturn; ret->finalize(); return static_cast<Expression*>(ret); } +BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, + BinaryenExpressionRef target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + const char* type) { + return makeBinaryenCallIndirect( + module, target, operands, numOperands, type, false); +} +BinaryenExpressionRef +BinaryenReturnCallIndirect(BinaryenModuleRef module, + BinaryenExpressionRef target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + const char* type) { + return makeBinaryenCallIndirect( + module, target, operands, numOperands, type, true); +} BinaryenExpressionRef BinaryenLocalGet(BinaryenModuleRef module, BinaryenIndex index, BinaryenType type) { diff --git a/src/binaryen-c.h b/src/binaryen-c.h index b186032f5..db49c45c9 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -545,6 +545,18 @@ BinaryenExpressionRef BinaryenCallIndirect(BinaryenModuleRef module, BinaryenExpressionRef* operands, BinaryenIndex numOperands, const char* type); +BinaryenExpressionRef BinaryenReturnCall(BinaryenModuleRef module, + const char* target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + BinaryenType returnType); +BinaryenExpressionRef +BinaryenReturnCallIndirect(BinaryenModuleRef module, + BinaryenExpressionRef target, + BinaryenExpressionRef* operands, + BinaryenIndex numOperands, + const char* type); + // LocalGet: Note the 'type' parameter. It might seem redundant, since the // local at that index must have a type. However, this API lets you // build code "top-down": create a node, then its parents, and so diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 1760f6359..5b24f3a8f 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -450,6 +450,16 @@ function wrapModule(module, self) { return Module['_BinaryenCallIndirect'](module, target, i32sToStack(operands), operands.length, strToStack(type)); }); }; + self['returnCall'] = function(name, operands, type) { + return preserveStack(function() { + return Module['_BinaryenReturnCall'](module, strToStack(name), i32sToStack(operands), operands.length, type); + }); + }; + self['returnCallIndirect'] = function(target, operands, type) { + return preserveStack(function() { + return Module['_BinaryenReturnCallIndirect'](module, target, i32sToStack(operands), operands.length, strToStack(type)); + }); + }; self['local'] = { 'get': function(index, type) { |