@@ -85,32 +85,26 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
85
85
}
86
86
}
87
87
88
- void visitCall (Call* curr) {
89
- if (reachable.count (
90
- ModuleElement (ModuleElementKind::Function, curr->target )) == 0 ) {
91
- queue.emplace_back (ModuleElementKind::Function, curr->target );
88
+ void maybeAdd (ModuleElement element) {
89
+ if (reachable.count (element) == 0 ) {
90
+ queue.emplace_back (element);
92
91
}
93
92
}
93
+
94
+ void visitCall (Call* curr) {
95
+ maybeAdd (ModuleElement (ModuleElementKind::Function, curr->target ));
96
+ }
94
97
void visitCallIndirect (CallIndirect* curr) {
95
98
assert (!module ->tables .empty () && " call-indirect to undefined table." );
96
99
97
- if (reachable.count (ModuleElement (ModuleElementKind::Table, curr->table )) ==
98
- 0 ) {
99
- queue.emplace_back (ModuleElementKind::Table, curr->table );
100
- }
100
+ maybeAdd (ModuleElement (ModuleElementKind::Table, curr->table ));
101
101
}
102
102
103
103
void visitGlobalGet (GlobalGet* curr) {
104
- if (reachable.count (ModuleElement (ModuleElementKind::Global, curr->name )) ==
105
- 0 ) {
106
- queue.emplace_back (ModuleElementKind::Global, curr->name );
107
- }
104
+ maybeAdd (ModuleElement (ModuleElementKind::Global, curr->name ));
108
105
}
109
106
void visitGlobalSet (GlobalSet* curr) {
110
- if (reachable.count (ModuleElement (ModuleElementKind::Global, curr->name )) ==
111
- 0 ) {
112
- queue.emplace_back (ModuleElementKind::Global, curr->name );
113
- }
107
+ maybeAdd (ModuleElement (ModuleElementKind::Global, curr->name ));
114
108
}
115
109
116
110
void visitLoad (Load* curr) { usesMemory = true ; }
@@ -127,15 +121,14 @@ struct ReachabilityAnalyzer : public PostWalker<ReachabilityAnalyzer> {
127
121
void visitMemorySize (MemorySize* curr) { usesMemory = true ; }
128
122
void visitMemoryGrow (MemoryGrow* curr) { usesMemory = true ; }
129
123
void visitRefFunc (RefFunc* curr) {
130
- if (reachable.count (
131
- ModuleElement (ModuleElementKind::Function, curr->func )) == 0 ) {
132
- queue.emplace_back (ModuleElementKind::Function, curr->func );
133
- }
124
+ maybeAdd (ModuleElement (ModuleElementKind::Function, curr->func ));
134
125
}
135
126
void visitThrow (Throw* curr) {
136
- if (reachable.count (ModuleElement (ModuleElementKind::Event, curr->event )) ==
137
- 0 ) {
138
- queue.emplace_back (ModuleElementKind::Event, curr->event );
127
+ maybeAdd (ModuleElement (ModuleElementKind::Event, curr->event ));
128
+ }
129
+ void visitTry (Try* curr) {
130
+ for (auto event : curr->catchEvents ) {
131
+ maybeAdd (ModuleElement (ModuleElementKind::Event, event));
139
132
}
140
133
}
141
134
};
0 commit comments