summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-ir-builder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r--src/wasm/wasm-ir-builder.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index 8d87d0f33..628a257c7 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -619,6 +619,32 @@ Result<> IRBuilder::visitStringEncode(StringEncode* curr) {
WASM_UNREACHABLE("unexpected op");
}
+Result<> IRBuilder::visitContBind(ContBind* curr) {
+ auto cont = pop();
+ CHECK_ERR(cont);
+ curr->cont = *cont;
+
+ size_t paramsBefore =
+ curr->contTypeBefore.getContinuation().type.getSignature().params.size();
+ size_t paramsAfter =
+ curr->contTypeAfter.getContinuation().type.getSignature().params.size();
+ if (paramsBefore < paramsAfter) {
+ return Err{"incompatible continuation types in cont.bind: source type " +
+ curr->contTypeBefore.toString() +
+ " has fewer parameters than destination " +
+ curr->contTypeAfter.toString()};
+ }
+ size_t numArgs = paramsBefore - paramsAfter;
+
+ curr->operands.resize(numArgs);
+ for (size_t i = 0; i < numArgs; ++i) {
+ auto val = pop();
+ CHECK_ERR(val);
+ curr->operands[numArgs - i - 1] = *val;
+ }
+ return Ok{};
+}
+
Result<> IRBuilder::visitResume(Resume* curr) {
auto cont = pop();
CHECK_ERR(cont);
@@ -1833,6 +1859,22 @@ Result<> IRBuilder::makeStringSliceIter() {
return Ok{};
}
+Result<> IRBuilder::makeContBind(HeapType contTypeBefore,
+ HeapType contTypeAfter) {
+ if (!contTypeBefore.isContinuation() || !contTypeAfter.isContinuation()) {
+ return Err{"expected continuation types"};
+ }
+ ContBind curr(wasm.allocator);
+ curr.contTypeBefore = contTypeBefore;
+ curr.contTypeAfter = contTypeAfter;
+ CHECK_ERR(visitContBind(&curr));
+
+ std::vector<Expression*> operands(curr.operands.begin(), curr.operands.end());
+ push(
+ builder.makeContBind(contTypeBefore, contTypeAfter, operands, curr.cont));
+ return Ok{};
+}
+
Result<> IRBuilder::makeContNew(HeapType ct) {
if (!ct.isContinuation()) {
return Err{"expected continuation type"};