Skip to content

Commit

Permalink
wasm2c: implement the tail-call proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Aug 25, 2023
1 parent ba73887 commit 94bcf25
Show file tree
Hide file tree
Showing 19 changed files with 784 additions and 162 deletions.
7 changes: 7 additions & 0 deletions include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,13 @@ struct Func {
BindingHash bindings;
ExprList exprs;
Location loc;

// For a subset of features, the BinaryReaderIR tracks whether they are
// actually used by the function. wasm2c (CWriter) uses this information to
// limit its output in some cases.
struct {
bool tailcall = false;
} features_used;
};

struct Global {
Expand Down
10 changes: 10 additions & 0 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,22 @@ Result BinaryReaderIR::OnCallRefExpr() {
}

Result BinaryReaderIR::OnReturnCallExpr(Index func_index) {
if (current_func_) {
// syntactically, a return_call expr can occur in an init expression
// (outside a function)
current_func_->features_used.tailcall = true;
}
return AppendExpr(
std::make_unique<ReturnCallExpr>(Var(func_index, GetLocation())));
}

Result BinaryReaderIR::OnReturnCallIndirectExpr(Index sig_index,
Index table_index) {
if (current_func_) {
// syntactically, a return_call_indirect expr can occur in an init
// expression (outside a function)
current_func_->features_used.tailcall = true;
}
auto expr = std::make_unique<ReturnCallIndirectExpr>();
SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
expr->table = Var(table_index, GetLocation());
Expand Down
Loading

0 comments on commit 94bcf25

Please sign in to comment.