Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
// Like visit, but pushes the expression onto the stack as-is without popping
// any children or refinalization.
void push(Expression*, Origin origin = Origin::Binary);
// Push a control flow construct using its declared Wasm stack result type,
// which may differ from its Binaryen IR type when the construct is typed
// unreachable internally.
void pushControlFlow(Expression* expr,
Type wasmStackResult,
Origin origin = Origin::Binary);
void pushSynthetic(Expression* expr) { push(expr, Origin::Synthetic); }

// Set the debug location to be attached to the next visited, created, or
Expand Down Expand Up @@ -309,6 +315,14 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
// when visiting the beginnings of try blocks.
Result<> visitPop(Pop*) { return Ok{}; }

// An entry on the expression stack, tracking both the Binaryen IR node and
// the Wasm operand-stack type it produces. These may differ for unreachable
// control flow (see StackIRGenerator::makeStackInst in wasm-stack.cpp).
struct StackEntry {
Expression* expr;
Type wasmStackType;
};

private:
Module& wasm;
Function* func = nullptr;
Expand All @@ -332,7 +346,11 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {

struct ChildPopper;

Result<> validateTypeAnnotation(Type type, Expression* child);
Result<> validateTypeAnnotation(HeapType type, Expression* child);

void applyDebugLoc(Expression* expr);
void pushStackEntry(Expression* expr, Type wasmStackType, Origin origin);

// The context for a single block scope, including the instructions parsed
// inside that scope so far and the ultimate result type we expect this block
Expand Down Expand Up @@ -418,7 +436,7 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
std::vector<Name> outputLabels;

// The stack of instructions being built in this scope.
std::vector<Expression*> exprStack;
std::vector<StackEntry> exprStack;

// Whether we have seen an unreachable instruction and are in
// stack-polymorphic unreachable mode.
Expand Down
Loading