diff options
author | Thomas Lively <tlively@google.com> | 2023-11-08 02:04:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 17:04:41 -0800 |
commit | 3640f9c992746867c5cf4cead11077e36a51eb7c (patch) | |
tree | 5dd299ab8a2a64f18e0bb6cf651a9c96f1cac1eb /src/wasm/wasm-ir-builder.cpp | |
parent | 0167c65132dd41fde2df6b76149ffc91305abe30 (diff) | |
download | binaryen-3640f9c992746867c5cf4cead11077e36a51eb7c.tar.gz binaryen-3640f9c992746867c5cf4cead11077e36a51eb7c.tar.bz2 binaryen-3640f9c992746867c5cf4cead11077e36a51eb7c.zip |
[Parser] Parse `call` and `return_call` (#6086)
To support parsing calls, add support for parsing function indices and building
calls with IRBuilder.
Diffstat (limited to 'src/wasm/wasm-ir-builder.cpp')
-rw-r--r-- | src/wasm/wasm-ir-builder.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp index 4d1c3353d..255683fbc 100644 --- a/src/wasm/wasm-ir-builder.cpp +++ b/src/wasm/wasm-ir-builder.cpp @@ -313,6 +313,17 @@ Result<> IRBuilder::visitBreak(Break* curr, std::optional<Index> label) { return Ok{}; } +Result<> IRBuilder::visitCall(Call* curr) { + auto numArgs = wasm.getFunction(curr->target)->getNumParams(); + curr->operands.resize(numArgs); + for (size_t i = 0; i < numArgs; ++i) { + auto arg = pop(); + CHECK_ERR(arg); + curr->operands[numArgs - 1 - i] = *arg; + } + return Ok{}; +} + Result<> IRBuilder::visitFunctionStart(Function* func) { if (!scopeStack.empty()) { return Err{"unexpected start of function"}; @@ -546,7 +557,14 @@ Result<> IRBuilder::makeBreak(Index label) { // Result<> IRBuilder::makeSwitch() {} -// Result<> IRBuilder::makeCall() {} +Result<> IRBuilder::makeCall(Name func, bool isReturn) { + Call curr(wasm.allocator); + curr.target = func; + CHECK_ERR(visitCall(&curr)); + auto type = wasm.getFunction(func)->getResults(); + push(builder.makeCall(curr.target, curr.operands, type, isReturn)); + return Ok{}; +} // Result<> IRBuilder::makeCallIndirect() {} |