Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Wabt has been compiled to JavaScript via emscripten. Some of the functionality i
| [simd][] | `--disable-simd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [threads][] | `--enable-threads` | | ✓ | ✓ | ✓ | ✓ | |
| [multi-value][] | `--disable-multi-value` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [tail-call][] | `--enable-tail-call` | | ✓ | ✓ | ✓ | ✓ | |
| [tail-call][] | `--enable-tail-call` | | ✓ | ✓ | ✓ | ✓ | |
| [bulk memory][] | `--disable-bulk-memory` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [reference types][] | `--disable-reference-types` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [annotations][] | `--enable-annotations` | | | ✓ | | | |
Expand Down
1 change: 1 addition & 0 deletions include/wabt/c-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Stream;

struct WriteCOptions {
std::string_view module_name;
Features features;
/*
* name_to_output_file_index takes const iterators to begin and end of a list
* of all functions in the module, number of imported functions, and number of
Expand Down
14 changes: 14 additions & 0 deletions include/wabt/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ class FuncType : public TypeEntry {
Type GetResultType(Index index) const { return sig.GetResultType(index); }

FuncSignature sig;

// The BinaryReaderIR tracks whether a FuncType is the target of a tailcall
// (via a return_call_indirect). wasm2c (CWriter) uses this information to
// limit its output in some cases.
struct {
bool tailcall = false;
} features_used;
};

struct Field {
Expand Down Expand Up @@ -893,6 +900,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
14 changes: 14 additions & 0 deletions src/binary-reader-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,15 +895,29 @@ 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());
FuncType* type = module_->GetFuncType(Var(sig_index, GetLocation()));
if (type) {
type->features_used.tailcall = true;
}
return AppendExpr(std::move(expr));
}

Expand Down
Loading