summaryrefslogtreecommitdiff
path: root/src/ir/eh-utils.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-06-01 07:01:15 -0700
committerGitHub <noreply@github.com>2022-06-01 07:01:15 -0700
commit49763aa9a7fb0f07588a9d19db6896356e52c5f8 (patch)
tree5ffcabfabb1e30e230e6758bf9fe3ce8332453ea /src/ir/eh-utils.cpp
parent6257a5857a42fec6b86352b03c1e92dcb7a490ea (diff)
downloadbinaryen-49763aa9a7fb0f07588a9d19db6896356e52c5f8.tar.gz
binaryen-49763aa9a7fb0f07588a9d19db6896356e52c5f8.tar.bz2
binaryen-49763aa9a7fb0f07588a9d19db6896356e52c5f8.zip
[NFC] Refactor EHUtils::findPops() method (#4704)
This moves it out of the validator so it can be used elsewhere. It will be used in #4685
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