summaryrefslogtreecommitdiff
path: root/src/passes/GenerateDynCalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/GenerateDynCalls.cpp')
-rw-r--r--src/passes/GenerateDynCalls.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/passes/GenerateDynCalls.cpp b/src/passes/GenerateDynCalls.cpp
index 9669dcdb8..827dccea0 100644
--- a/src/passes/GenerateDynCalls.cpp
+++ b/src/passes/GenerateDynCalls.cpp
@@ -127,9 +127,13 @@ void GenerateDynCalls::generateDynCallThunk(Signature sig) {
for (const auto& param : sig.params) {
args.push_back(builder.makeLocalGet(++i, param));
}
- // FIXME: Should the existence of a table be ensured here? i.e. create one if
- // there is none?
- assert(wasm->tables.size() > 0);
+ if (wasm->tables.empty()) {
+ // Add an imported table in exactly the same manner as the LLVM wasm backend
+ // would add one.
+ auto* table = wasm->addTable(Builder::makeTable(Name::fromInt(0)));
+ table->module = ENV;
+ table->base = "__indirect_function_table";
+ }
f->body = builder.makeCallIndirect(wasm->tables[0]->name, fptr, args, sig);
wasm->addFunction(std::move(f));