summaryrefslogtreecommitdiff
path: root/test/example/hash.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-08-12 09:32:39 -0700
committerGitHub <noreply@github.com>2021-08-12 09:32:39 -0700
commit96d2c946329f26bb742684a70cb48e98aa55083d (patch)
treef8e102ed634485743fff031f553ecc5718207749 /test/example/hash.cpp
parent18022894adb20cec9dc7ef87464180eb26881266 (diff)
downloadbinaryen-96d2c946329f26bb742684a70cb48e98aa55083d.tar.gz
binaryen-96d2c946329f26bb742684a70cb48e98aa55083d.tar.bz2
binaryen-96d2c946329f26bb742684a70cb48e98aa55083d.zip
Add a shallowHash() method (#4077)
This adds and tests the new method. It will be used in a new pass later, where computing shallow hashes allows it to be done in linear time. 99% of the diff is whitespace.
Diffstat (limited to 'test/example/hash.cpp')
-rw-r--r--test/example/hash.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/test/example/hash.cpp b/test/example/hash.cpp
index ba9ca24ea..944cef14c 100644
--- a/test/example/hash.cpp
+++ b/test/example/hash.cpp
@@ -11,6 +11,14 @@ using namespace wasm;
#define assertNotEqual(left, right) \
assert(ExpressionAnalyzer::hash(&left) != ExpressionAnalyzer::hash(&right));
+#define assertShallowEqual(left, right) \
+ assert(ExpressionAnalyzer::shallowHash(&left) == \
+ ExpressionAnalyzer::shallowHash(&right));
+
+#define assertShallowNotEqual(left, right) \
+ assert(ExpressionAnalyzer::shallowHash(&left) != \
+ ExpressionAnalyzer::shallowHash(&right));
+
int main() {
{
Const x, y;
@@ -33,7 +41,7 @@ int main() {
assertNotEqual(x, y);
}
{
- // Nested child.
+ // Nested identical child.
Drop dx, dy;
Const x, y;
x.set(Literal(int32_t(10)));
@@ -43,7 +51,17 @@ int main() {
assertEqual(dx, dy);
}
{
- // Nested child.
+ // Nested identical child, checked shallowly.
+ Drop dx, dy;
+ Const x, y;
+ x.set(Literal(int32_t(10)));
+ y.set(Literal(int32_t(10)));
+ dx.value = &x;
+ dy.value = &y;
+ assertShallowEqual(dx, dy);
+ }
+ {
+ // Nested different child.
Drop dx, dy;
Const x, y;
x.set(Literal(int32_t(10)));
@@ -52,6 +70,17 @@ int main() {
dy.value = &y;
assertNotEqual(dx, dy);
}
+ {
+ // Nested different child, checked shallowly (so we ignore the difference,
+ // and return equal).
+ Drop dx, dy;
+ Const x, y;
+ x.set(Literal(int32_t(10)));
+ y.set(Literal(int32_t(11)));
+ dx.value = &x;
+ dy.value = &y;
+ assertShallowEqual(dx, dy);
+ }
MixedArena arena;
{
// Blocks