summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Directize.cpp2
-rw-r--r--src/passes/GenerateDynCalls.cpp25
2 files changed, 14 insertions, 13 deletions
diff --git a/src/passes/Directize.cpp b/src/passes/Directize.cpp
index 78294d59d..66b42d386 100644
--- a/src/passes/Directize.cpp
+++ b/src/passes/Directize.cpp
@@ -130,7 +130,7 @@ private:
return CallUtils::Unknown{};
}
- Index index = c->value.geti32();
+ Index index = c->value.getInteger();
// Check if index is invalid, or the type is wrong.
auto& flatTable = *table.flatTable;
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);