summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2024-05-17 17:22:14 -0700
committerGitHub <noreply@github.com>2024-05-18 00:22:14 +0000
commit369cddfb44ddbada2ef7742a9ebef54727d12dd5 (patch)
tree214348667992065c671968553e80a75b6d123808 /src
parent4e9f4953a2e5968c402eb2e950252294cfa02460 (diff)
downloadbinaryen-369cddfb44ddbada2ef7742a9ebef54727d12dd5.tar.gz
binaryen-369cddfb44ddbada2ef7742a9ebef54727d12dd5.tar.bz2
binaryen-369cddfb44ddbada2ef7742a9ebef54727d12dd5.zip
Fix generate-dyncalls and directize passed under table64 (#6604)
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);