summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-06-24 13:18:05 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-06-26 10:00:32 -0700
commit5f6b81a8c75eab046eb38b41f501cb604a5aab52 (patch)
treea54b5dae27994f2ec933c02724db3cc6849a318d /src
parent0da770d9660919b03553374d36ce1d5ca93cf78f (diff)
downloadbinaryen-5f6b81a8c75eab046eb38b41f501cb604a5aab52.tar.gz
binaryen-5f6b81a8c75eab046eb38b41f501cb604a5aab52.tar.bz2
binaryen-5f6b81a8c75eab046eb38b41f501cb604a5aab52.zip
add ExpressionAnalyzer::flexibleEquals
Diffstat (limited to 'src')
-rw-r--r--src/ast_utils.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 8952114bc..3d4d57b77 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -242,7 +242,8 @@ struct ExpressionAnalyzer {
return func->result != none;
}
- static bool equal(Expression* left, Expression* right) {
+ template<typename T>
+ static bool flexibleEqual(Expression* left, Expression* right, T& comparer) {
std::vector<Name> nameStack;
std::map<Name, std::vector<Name>> rightNames; // for each name on the left, the stack of names on the right (a stack, since names are scoped and can nest duplicatively
Nop popNameMarker;
@@ -284,6 +285,8 @@ struct ExpressionAnalyzer {
popName();
continue;
}
+ if (comparer.compare(left, right)) continue; // comparison hook, before all the rest
+ // continue with normal structural comparison
if (left->_id != right->_id) return false;
#define PUSH(clazz, what) \
leftStack.push_back(left->cast<clazz>()->what); \
@@ -426,6 +429,15 @@ struct ExpressionAnalyzer {
return true;
}
+ static bool equal(Expression* left, Expression* right) {
+ struct Comparer {
+ bool compare(Expression* left, Expression* right) {
+ return false;
+ }
+ } comparer;
+ return flexibleEqual(left, right, comparer);
+ }
+
// hash an expression, ignoring superficial details like specific internal names
static uint32_t hash(Expression* curr) {
uint32_t digest = 0;