diff options
author | Alon Zakai <azakai@google.com> | 2022-06-01 07:01:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-01 07:01:15 -0700 |
commit | 49763aa9a7fb0f07588a9d19db6896356e52c5f8 (patch) | |
tree | 5ffcabfabb1e30e230e6758bf9fe3ce8332453ea /src/wasm/wasm-validator.cpp | |
parent | 6257a5857a42fec6b86352b03c1e92dcb7a490ea (diff) | |
download | binaryen-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/wasm/wasm-validator.cpp')
-rw-r--r-- | src/wasm/wasm-validator.cpp | 27 |
1 files changed, 2 insertions, 25 deletions
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 9845da72c..57b52e182 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2165,29 +2165,6 @@ void FunctionValidator::visitTry(Try* curr) { curr, "try cannot have both catch and delegate at the same time"); - // Given a catch body, find pops corresponding to the catch - auto 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; - }; - for (Index i = 0; i < curr->catchTags.size(); i++) { Name tagName = curr->catchTags[i]; auto* tag = getModule()->getTagOrNull(tagName); @@ -2196,7 +2173,7 @@ void FunctionValidator::visitTry(Try* curr) { } auto* catchBody = curr->catchBodies[i]; - SmallVector<Pop*, 1> pops = findPops(catchBody); + auto pops = EHUtils::findPops(catchBody); if (tag->sig.params == Type::none) { if (!shouldBeTrue(pops.empty(), curr, "")) { getStream() << "catch's tag (" << tagName @@ -2225,7 +2202,7 @@ void FunctionValidator::visitTry(Try* curr) { if (curr->hasCatchAll()) { auto* catchAllBody = curr->catchBodies.back(); - shouldBeTrue(findPops(catchAllBody).empty(), + shouldBeTrue(EHUtils::findPops(catchAllBody).empty(), curr, "catch_all's body should not have pops"); } |