summaryrefslogtreecommitdiff
path: root/src/ir/eh-utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/eh-utils.cpp')
-rw-r--r--src/ir/eh-utils.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/ir/eh-utils.cpp b/src/ir/eh-utils.cpp
index 3d369573d..fe33b09c2 100644
--- a/src/ir/eh-utils.cpp
+++ b/src/ir/eh-utils.cpp
@@ -162,6 +162,37 @@ void handleBlockNestedPops(Function* func, Module& wasm) {
TypeUpdating::handleNonDefaultableLocals(func, wasm);
}
+Pop* findPop(Expression* expr) {
+ auto pops = findPops(expr);
+ if (pops.size() == 0) {
+ return nullptr;
+ }
+ assert(pops.size() == 1);
+ return pops[0];
+}
+
+SmallVector<Pop*, 1> findPops(Expression* expr) {
+ SmallVector<Pop*, 1> pops;
+ SmallVector<Expression*, 8> work;
+ work.push_back(expr);
+ while (!work.empty()) {
+ auto* curr = work.back();
+ work.pop_back();
+ if (auto* pop = curr->dynCast<Pop>()) {
+ pops.push_back(pop);
+ } else if (auto* try_ = curr->dynCast<Try>()) {
+ // We don't go into inner catch bodies; pops in inner catch bodies
+ // belong to the inner catches
+ work.push_back(try_->body);
+ } else {
+ for (auto* child : ChildIterator(curr)) {
+ work.push_back(child);
+ }
+ }
+ }
+ return pops;
+};
+
} // namespace EHUtils
} // namespace wasm