summaryrefslogtreecommitdiff
path: root/src/ir/find_all.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/find_all.h')
-rw-r--r--src/ir/find_all.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ir/find_all.h b/src/ir/find_all.h
index 83c751666..44dc7a675 100644
--- a/src/ir/find_all.h
+++ b/src/ir/find_all.h
@@ -42,6 +42,30 @@ struct FindAll {
}
};
+// Find all pointers to instances of a certain node type
+
+struct PointerFinder : public PostWalker<PointerFinder, UnifiedExpressionVisitor<PointerFinder>> {
+ Expression::Id id;
+ std::vector<Expression**>* list;
+ void visitExpression(Expression* curr) {
+ if (curr->_id == id) {
+ (*list).push_back(getCurrentPointer());
+ }
+ }
+};
+
+template<typename T>
+struct FindAllPointers {
+ std::vector<Expression**> list;
+
+ FindAllPointers(Expression* ast) {
+ PointerFinder finder;
+ finder.id = T()._id;
+ finder.list = &list;
+ finder.walk(ast);
+ }
+};
+
} // namespace wasm
#endif // wasm_ir_find_all_h