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
13 changes: 12 additions & 1 deletion src/passes/RemoveImports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,19 @@ struct RemoveImports : public WalkerPass<PostWalker<RemoveImports>> {
std::vector<Name> names;
ModuleUtils::iterImportedFunctions(
*curr, [&](Function* func) { names.push_back(func->name); });
// Do not remove names referenced in a table
std::set<Name> indirectNames;
if (curr->table.exists) {
for (auto& segment : curr->table.segments) {
for (auto& name : segment.data) {
indirectNames.insert(name);
}
}
}
for (auto& name : names) {
curr->removeFunction(name);
if (indirectNames.find(name) == indirectNames.end()) {
curr->removeFunction(name);
}
}
}
};
Expand Down
8 changes: 7 additions & 1 deletion test/passes/remove-imports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
(type $FUNCSIG$v (func))
(type $FUNCSIG$i (func (result i32)))
(type $FUNCSIG$d (func (result f64)))
(import "env" "table" (table $0 1 1 funcref))
(elem (i32.const 0) $waka-sneaky)
(import "env" "memBase" (global $import$global0 i32))
(import "somewhere" "waka-sneaky" (func $waka-sneaky))
(memory $0 1024 1024)
(func $nada (; 0 ;) (type $FUNCSIG$v)
(func $nada (; 1 ;) (type $FUNCSIG$v)
(nop)
(drop
(i32.const 0)
)
(drop
(f64.const 0)
)
(call_indirect (type $FUNCSIG$v)
(i32.const 0)
)
)
)
4 changes: 4 additions & 0 deletions test/passes/remove-imports.wast
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
(import $waka "somewhere" "waka")
(import $waka-ret "somewhere" "waka-ret" (result i32))
(import $waka-ret-d "somewhere" "waka-ret-d" (result f64))
(import $waka-sneaky "somewhere" "waka-sneaky")
(import "env" "memBase" (global i32))
(import "env" "table" (table $table 1 1 funcref))
(elem (i32.const 0) $waka-sneaky)
(func $nada (type $FUNCSIG$v)
(call $waka)
(drop
Expand All @@ -15,5 +18,6 @@
(drop
(call $waka-ret-d)
)
(call_indirect (i32.const 0))
)
)