summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/hash-stringify-walker.cpp21
-rw-r--r--src/passes/stringify-walker.h13
2 files changed, 30 insertions, 4 deletions
diff --git a/src/passes/hash-stringify-walker.cpp b/src/passes/hash-stringify-walker.cpp
index beae3bf44..abcd07162 100644
--- a/src/passes/hash-stringify-walker.cpp
+++ b/src/passes/hash-stringify-walker.cpp
@@ -82,7 +82,7 @@ void HashStringifyWalker::visitExpression(Expression* curr) {
// repeats come first and 2) these are more worthwhile to keep than subsequent
// substrings of substrings, even if they appear more times.
std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::dedupe(
- const std::vector<SuffixTree::RepeatedSubstring>&& substrings) {
+ const std::vector<SuffixTree::RepeatedSubstring>& substrings) {
std::unordered_set<uint32_t> seen;
std::vector<SuffixTree::RepeatedSubstring> result;
for (auto substring : substrings) {
@@ -111,7 +111,7 @@ std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::dedupe(
}
std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::filter(
- const std::vector<SuffixTree::RepeatedSubstring>&& substrings,
+ const std::vector<SuffixTree::RepeatedSubstring>& substrings,
const std::vector<Expression*> exprs,
std::function<bool(const Expression*)> condition) {
@@ -166,4 +166,21 @@ std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::filter(
return result;
}
+std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::filterLocalSets(
+ const std::vector<SuffixTree::RepeatedSubstring>& substrings,
+ const std::vector<Expression*> exprs) {
+ return StringifyProcessor::filter(
+ substrings, exprs, [](const Expression* curr) {
+ return curr->is<LocalSet>();
+ });
+}
+
+std::vector<SuffixTree::RepeatedSubstring> StringifyProcessor::filterBranches(
+ const std::vector<SuffixTree::RepeatedSubstring>& substrings,
+ const std::vector<Expression*> exprs) {
+ return StringifyProcessor::filter(
+ substrings, exprs, [](const Expression* curr) {
+ return Properties::isBranch(curr) || curr->is<Return>();
+ });
+}
} // namespace wasm
diff --git a/src/passes/stringify-walker.h b/src/passes/stringify-walker.h
index 55aa26940..6095eb7ad 100644
--- a/src/passes/stringify-walker.h
+++ b/src/passes/stringify-walker.h
@@ -234,11 +234,20 @@ struct HashStringifyWalker : public StringifyWalker<HashStringifyWalker> {
// Functions that filter vectors of SuffixTree::RepeatedSubstring
struct StringifyProcessor {
static std::vector<SuffixTree::RepeatedSubstring>
- dedupe(const std::vector<SuffixTree::RepeatedSubstring>&& substrings);
+ dedupe(const std::vector<SuffixTree::RepeatedSubstring>& substrings);
+ // Filter is the general purpose function backing subsequent filter functions.
+ // It can be used directly, but generally prefer a wrapper function
+ // to encapsulate your condition and make it available for tests
static std::vector<SuffixTree::RepeatedSubstring>
- filter(const std::vector<SuffixTree::RepeatedSubstring>&& substrings,
+ filter(const std::vector<SuffixTree::RepeatedSubstring>& substrings,
const std::vector<Expression*> exprs,
std::function<bool(const Expression*)> condition);
+ static std::vector<SuffixTree::RepeatedSubstring>
+ filterLocalSets(const std::vector<SuffixTree::RepeatedSubstring>& substrings,
+ const std::vector<Expression*> exprs);
+ static std::vector<SuffixTree::RepeatedSubstring>
+ filterBranches(const std::vector<SuffixTree::RepeatedSubstring>& substrings,
+ const std::vector<Expression*> exprs);
};
} // namespace wasm