diff options
Diffstat (limited to 'src/passes/GenerateDynCalls.cpp')
-rw-r--r-- | src/passes/GenerateDynCalls.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/passes/GenerateDynCalls.cpp b/src/passes/GenerateDynCalls.cpp index 818bfa967..6e6e0a717 100644 --- a/src/passes/GenerateDynCalls.cpp +++ b/src/passes/GenerateDynCalls.cpp @@ -140,8 +140,17 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) { } std::vector<NameType> namedParams; std::vector<Type> params; - namedParams.emplace_back("fptr", Type::i32); // function pointer param - params.push_back(Type::i32); + 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"; + table->indexType = wasm->memories[0]->indexType; + } + auto& table = wasm->tables[0]; + namedParams.emplace_back("fptr", table->indexType); // function pointer param + params.push_back(table->indexType); int p = 0; for (const auto& param : sig.params) { namedParams.emplace_back(std::to_string(p++), param); @@ -150,21 +159,13 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) { auto f = builder.makeFunction( name, std::move(namedParams), Signature(Type(params), sig.results), {}); f->hasExplicitName = true; - Expression* fptr = builder.makeLocalGet(0, Type::i32); + Expression* fptr = builder.makeLocalGet(0, table->indexType); std::vector<Expression*> args; Index i = 0; for (const auto& param : sig.params) { args.push_back(builder.makeLocalGet(++i, param)); } - 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, funcType); + f->body = builder.makeCallIndirect(table->name, fptr, args, funcType); wasm->addFunction(std::move(f)); exportFunction(*wasm, name, true); |