summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-02-21 12:47:09 -0800
committerGitHub <noreply@github.com>2023-02-21 12:47:09 -0800
commita6ae22ca0c5c0f4d5e681d749adc0a2d1bea8861 (patch)
treedf5ea7c1af4cf24cb495f71f6bc9b43759a10166 /src
parentc2f3bbff0d77d3f6ad87a1e47570d4d5d5171284 (diff)
downloadbinaryen-a6ae22ca0c5c0f4d5e681d749adc0a2d1bea8861.tar.gz
binaryen-a6ae22ca0c5c0f4d5e681d749adc0a2d1bea8861.tar.bz2
binaryen-a6ae22ca0c5c0f4d5e681d749adc0a2d1bea8861.zip
[Strings] Add hashing and equality support for strings (#5507)
This is enough to test RSE.
Diffstat (limited to 'src')
-rw-r--r--src/literal.h8
-rw-r--r--src/wasm/literal.cpp3
2 files changed, 11 insertions, 0 deletions
diff --git a/src/literal.h b/src/literal.h
index 317839b72..9d7ac2222 100644
--- a/src/literal.h
+++ b/src/literal.h
@@ -769,6 +769,14 @@ template<> struct hash<wasm::Literal> {
wasm::rehash(digest, a.geti31(true));
return digest;
}
+ if (a.type.isString()) {
+ auto& values = a.getGCData()->values;
+ wasm::rehash(digest, values.size());
+ for (auto c : values) {
+ wasm::rehash(digest, c.getInteger());
+ }
+ return digest;
+ }
// other non-null reference type literals cannot represent concrete
// values, i.e. there is no concrete anyref or eqref other than null.
WASM_UNREACHABLE("unexpected type");
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index 016df2e18..2a7dd1bcf 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -432,6 +432,9 @@ bool Literal::operator==(const Literal& other) const {
assert(func.is() && other.func.is());
return func == other.func;
}
+ if (type.isString()) {
+ return gcData->values == other.gcData->values;
+ }
if (type.isData()) {
return gcData == other.gcData;
}