summaryrefslogtreecommitdiff
path: root/src/wasm-ir-builder.h
diff options
context:
space:
mode:
authorAshley Nelson <nashley@google.com>2024-02-27 17:09:30 -0800
committerGitHub <noreply@github.com>2024-02-27 17:09:30 -0800
commit1ef95ae7b9e2c765abbbc6af6dff6c29c1fa4d13 (patch)
tree06a51c0fc5d395260a728362373e346bdbf5cc25 /src/wasm-ir-builder.h
parentc62a0c97168e88f97bca4bd96298a5ffc041844d (diff)
downloadbinaryen-1ef95ae7b9e2c765abbbc6af6dff6c29c1fa4d13.tar.gz
binaryen-1ef95ae7b9e2c765abbbc6af6dff6c29c1fa4d13.tar.bz2
binaryen-1ef95ae7b9e2c765abbbc6af6dff6c29c1fa4d13.zip
[Outlining] Fixes break reconstruction (#6352)
Adds new visitBreakWithType and visitSwitchWithType functions to the IRBuilder API. These functions work around an assumption in IRBuilder that the module is being traversed in the fully nested format, i.e., that the destination scope of a break or switch has been visited before visiting the break or switch. Instead, the type of the destination scope is passed to IRBuilder.
Diffstat (limited to 'src/wasm-ir-builder.h')
-rw-r--r--src/wasm-ir-builder.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h
index b37b352e3..d31a532a7 100644
--- a/src/wasm-ir-builder.h
+++ b/src/wasm-ir-builder.h
@@ -224,10 +224,26 @@ public:
[[nodiscard]] Result<> visitStructNew(StructNew*);
[[nodiscard]] Result<> visitArrayNew(ArrayNew*);
[[nodiscard]] Result<> visitArrayNewFixed(ArrayNewFixed*);
+ // Used to visit break exprs when traversing the module in the fully nested
+ // format. Break label destinations are assumed to have already been visited,
+ // with a corresponding push onto the scope stack. As a result, an error will
+ // return if a corresponding scope is not found for the break.
[[nodiscard]] Result<> visitBreak(Break*,
std::optional<Index> label = std::nullopt);
+ // Used to visit break nodes when traversing a single block without its
+ // context. The type indicates how many values the break carries to its
+ // destination.
+ [[nodiscard]] Result<> visitBreakWithType(Break*, Type);
[[nodiscard]] Result<>
+ // Used to visit switch exprs when traversing the module in the fully nested
+ // format. Switch label destinations are assumed to have already been visited,
+ // with a corresponding push onto the scope stack. As a result, an error will
+ // return if a corresponding scope is not found for the switch.
visitSwitch(Switch*, std::optional<Index> defaultLabel = std::nullopt);
+ // Used to visit switch nodes when traversing a single block without its
+ // context. The type indicates how many values the switch carries to its
+ // destination.
+ [[nodiscard]] Result<> visitSwitchWithType(Switch*, Type);
[[nodiscard]] Result<> visitCall(Call*);
[[nodiscard]] Result<> visitCallIndirect(CallIndirect*);
[[nodiscard]] Result<> visitCallRef(CallRef*);
@@ -535,8 +551,8 @@ private:
[[nodiscard]] Result<> packageHoistedValue(const HoistedVal&,
size_t sizeHint = 1);
- [[nodiscard]] Result<Expression*> getBranchValue(Name labelName,
- std::optional<Index> label);
+ [[nodiscard]] Result<Expression*>
+ getBranchValue(Expression* curr, Name labelName, std::optional<Index> label);
void dump();
};