summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-11-15 14:42:30 -0800
committerGitHub <noreply@github.com>2020-11-15 14:42:30 -0800
commit6f433967372455aff90a6e0f03a72c403d77fd12 (patch)
tree74b7c565d35bf0a7eb2c98be030062868f8b94ba /src
parentc91c519cbb0a32e39e9a324cae611c5db0b66325 (diff)
downloadbinaryen-6f433967372455aff90a6e0f03a72c403d77fd12.tar.gz
binaryen-6f433967372455aff90a6e0f03a72c403d77fd12.tar.bz2
binaryen-6f433967372455aff90a6e0f03a72c403d77fd12.zip
[Types] Add type sorting for Signatures (#3366)
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-type.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index f98077961..5e4d5e07f 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -383,15 +383,28 @@ bool Type::isRtt() const {
}
bool Type::operator<(const Type& other) const {
- return std::lexicographical_compare(begin(),
- end(),
- other.begin(),
- other.end(),
- [](const Type& a, const Type& b) {
- TODO_SINGLE_COMPOUND(a);
- TODO_SINGLE_COMPOUND(b);
- return a.getBasic() < b.getBasic();
- });
+ auto comp = [](const Type& a, const Type& b) {
+ if (a.isBasic() && b.isBasic()) {
+ return a.getBasic() < b.getBasic();
+ }
+ if (a.isBasic()) {
+ return true;
+ }
+ if (b.isBasic()) {
+ return false;
+ }
+ // Both are compound.
+ auto aHeap = a.getHeapType();
+ auto bHeap = b.getHeapType();
+ if (aHeap.isSignature() && bHeap.isSignature()) {
+ return aHeap.getSignature() < bHeap.getSignature();
+ }
+ TODO_SINGLE_COMPOUND(a);
+ TODO_SINGLE_COMPOUND(b);
+ WASM_UNREACHABLE("unimplemented type comparison");
+ };
+ return std::lexicographical_compare(
+ begin(), end(), other.begin(), other.end(), comp);
}
unsigned Type::getByteSize() const {