diff options
Diffstat (limited to 'src/wasm-ir-builder.h')
-rw-r--r-- | src/wasm-ir-builder.h | 63 |
1 files changed, 17 insertions, 46 deletions
diff --git a/src/wasm-ir-builder.h b/src/wasm-ir-builder.h index 7c4c4a36d..3b6588e86 100644 --- a/src/wasm-ir-builder.h +++ b/src/wasm-ir-builder.h @@ -76,6 +76,15 @@ public: Name label = {}); [[nodiscard]] Result<> visitEnd(); + // 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); + // 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); + // Binaryen IR uses names to refer to branch targets, but in general there may // be branches to constructs that do not yet have names, so in IRBuilder we // use indices to refer to branch targets instead, just as the binary format @@ -220,49 +229,10 @@ public: // Private functions that must be public for technical reasons. [[nodiscard]] Result<> visitExpression(Expression*); - [[nodiscard]] Result<> - visitDrop(Drop*, std::optional<uint32_t> arity = std::nullopt); - [[nodiscard]] Result<> visitIf(If*); - [[nodiscard]] Result<> visitReturn(Return*); - [[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*); - [[nodiscard]] Result<> visitLocalSet(LocalSet*); - [[nodiscard]] Result<> visitGlobalSet(GlobalSet*); - [[nodiscard]] Result<> visitThrow(Throw*); - [[nodiscard]] Result<> visitStringNew(StringNew*); - [[nodiscard]] Result<> visitStringEncode(StringEncode*); - [[nodiscard]] Result<> visitContBind(ContBind*); - [[nodiscard]] Result<> visitResume(Resume*); - [[nodiscard]] Result<> visitSuspend(Suspend*); - [[nodiscard]] Result<> visitTupleMake(TupleMake*); - [[nodiscard]] Result<> - visitTupleExtract(TupleExtract*, - std::optional<uint32_t> arity = std::nullopt); - [[nodiscard]] Result<> visitPop(Pop*); + + // Do not push pops onto the stack since we generate our own pops as necessary + // when visiting the beginnings of try blocks. + [[nodiscard]] Result<> visitPop(Pop*) { return Ok{}; } private: Module& wasm; @@ -270,6 +240,8 @@ private: Builder builder; std::optional<Function::DebugLocation> debugLoc; + struct ChildPopper; + void applyDebugLoc(Expression* expr); // The context for a single block scope, including the instructions parsed @@ -534,7 +506,6 @@ private: [[nodiscard]] Result<Name> getLabelName(Index label); [[nodiscard]] Result<Name> getDelegateLabelName(Index label); [[nodiscard]] Result<Index> addScratchLocal(Type); - [[nodiscard]] Result<Expression*> pop(size_t size = 1); struct HoistedVal { // The index in the stack of the original value-producing expression. @@ -556,8 +527,8 @@ private: [[nodiscard]] Result<> packageHoistedValue(const HoistedVal&, size_t sizeHint = 1); - [[nodiscard]] Result<Expression*> - getBranchValue(Expression* curr, Name labelName, std::optional<Index> label); + [[nodiscard]] Result<Type> getLabelType(Index label); + [[nodiscard]] Result<Type> getLabelType(Name labelName); void dump(); }; |