diff options
Diffstat (limited to 'src/passes/RemoveUnusedModuleElements.cpp')
-rw-r--r-- | src/passes/RemoveUnusedModuleElements.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp index 2b460a0fd..7436676ef 100644 --- a/src/passes/RemoveUnusedModuleElements.cpp +++ b/src/passes/RemoveUnusedModuleElements.cpp @@ -92,18 +92,18 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> { } } + // Add a reference to a table and all its segments and elements. + void maybeAddTable(Name name) { + maybeAdd(ModuleElement(ModuleElementKind::Table, name)); + ModuleUtils::iterTableSegments(*module, name, [&](ElementSegment* segment) { + maybeAdd(ModuleElement(ModuleElementKind::ElementSegment, segment->name)); + }); + } + void visitCall(Call* curr) { maybeAdd(ModuleElement(ModuleElementKind::Function, curr->target)); } - void visitCallIndirect(CallIndirect* curr) { - assert(!module->tables.empty() && "call-indirect to undefined table."); - maybeAdd(ModuleElement(ModuleElementKind::Table, curr->table)); - ModuleUtils::iterTableSegments( - *module, curr->table, [&](ElementSegment* segment) { - maybeAdd( - ModuleElement(ModuleElementKind::ElementSegment, segment->name)); - }); - } + void visitCallIndirect(CallIndirect* curr) { maybeAddTable(curr->table); } void visitGlobalGet(GlobalGet* curr) { maybeAdd(ModuleElement(ModuleElementKind::Global, curr->name)); @@ -128,6 +128,7 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> { void visitRefFunc(RefFunc* curr) { maybeAdd(ModuleElement(ModuleElementKind::Function, curr->func)); } + void visitTableGet(TableGet* curr) { maybeAddTable(curr->table); } void visitThrow(Throw* curr) { maybeAdd(ModuleElement(ModuleElementKind::Tag, curr->tag)); } |