Skip to content

Commit 0fab24a

Browse files
committed
wasm2c: implement the tail-call proposal
1 parent ba73887 commit 0fab24a

File tree

19 files changed

+784
-162
lines changed

19 files changed

+784
-162
lines changed

include/wabt/ir.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,13 @@ struct Func {
893893
BindingHash bindings;
894894
ExprList exprs;
895895
Location loc;
896+
897+
// For a subset of features, the BinaryReaderIR tracks whether they are
898+
// actually used by the function. wasm2c (CWriter) uses this information to
899+
// limit its output in some cases.
900+
struct {
901+
bool tailcall = false;
902+
} features_used;
896903
};
897904

898905
struct Global {

src/binary-reader-ir.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,22 @@ Result BinaryReaderIR::OnCallRefExpr() {
892892
}
893893

894894
Result BinaryReaderIR::OnReturnCallExpr(Index func_index) {
895+
if (current_func_) {
896+
// syntactically, a return_call expr can occur in an init expression
897+
// (outside a function)
898+
current_func_->features_used.tailcall = true;
899+
}
895900
return AppendExpr(
896901
std::make_unique<ReturnCallExpr>(Var(func_index, GetLocation())));
897902
}
898903

899904
Result BinaryReaderIR::OnReturnCallIndirectExpr(Index sig_index,
900905
Index table_index) {
906+
if (current_func_) {
907+
// syntactically, a return_call_indirect expr can occur in an init
908+
// expression (outside a function)
909+
current_func_->features_used.tailcall = true;
910+
}
901911
auto expr = std::make_unique<ReturnCallIndirectExpr>();
902912
SetFuncDeclaration(&expr->decl, Var(sig_index, GetLocation()));
903913
expr->table = Var(table_index, GetLocation());

0 commit comments

Comments
 (0)