summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp21
-rw-r--r--src/wasm/wasm-type.cpp35
2 files changed, 40 insertions, 16 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 7a6d4d35d..54e417b8c 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -31,7 +31,7 @@ namespace wasm {
void WasmBinaryWriter::prepare() {
// Collect function types and their frequencies. Collect information in each
// function in parallel, then merge.
- ModuleUtils::collectSignatures(*wasm, types, typeIndices);
+ ModuleUtils::collectHeapTypes(*wasm, types, typeIndices);
importInfo = wasm::make_unique<ImportInfo>(*wasm);
}
@@ -215,14 +215,19 @@ void WasmBinaryWriter::writeTypes() {
auto start = startSection(BinaryConsts::Section::Type);
o << U32LEB(types.size());
for (Index i = 0; i < types.size(); ++i) {
- Signature& sig = types[i];
- BYN_TRACE("write " << sig.params << " -> " << sig.results << std::endl);
- o << S32LEB(BinaryConsts::EncodedType::Func);
- for (auto& sigType : {sig.params, sig.results}) {
- o << U32LEB(sigType.size());
- for (const auto& type : sigType) {
- writeType(type);
+ auto type = types[i];
+ BYN_TRACE("write " << type << std::endl);
+ if (type.isSignature()) {
+ o << S32LEB(BinaryConsts::EncodedType::Func);
+ auto sig = type.getSignature();
+ for (auto& sigType : {sig.params, sig.results}) {
+ o << U32LEB(sigType.size());
+ for (const auto& type : sigType) {
+ writeType(type);
+ }
}
+ } else {
+ WASM_UNREACHABLE("TODO GC type writing");
}
}
finishSection(start);
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index be017140d..fd49c5b93 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -405,14 +405,7 @@ bool Type::operator<(const Type& other) const {
if (a.isNullable() != b.isNullable()) {
return a.isNullable();
}
- 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 a.getHeapType() < b.getHeapType();
};
return std::lexicographical_compare(
begin(), end(), other.begin(), other.end(), comp);
@@ -738,6 +731,22 @@ bool HeapType::operator==(const HeapType& other) const {
WASM_UNREACHABLE("unexpected kind");
}
+bool HeapType::operator<(const HeapType& other) const {
+ if (kind != other.kind) {
+ return kind < other.kind;
+ }
+ if (isSignature()) {
+ return getSignature() < other.getSignature();
+ }
+ if (isStruct()) {
+ return getStruct() < other.getStruct();
+ }
+ if (isArray()) {
+ return getArray() < other.getArray();
+ }
+ WASM_UNREACHABLE("unimplemented type comparison");
+}
+
HeapType& HeapType::operator=(const HeapType& other) {
if (&other != this) {
this->~HeapType();
@@ -746,6 +755,16 @@ HeapType& HeapType::operator=(const HeapType& other) {
return *this;
}
+bool Field::operator<(const Field& other) const {
+ if (mutable_ != other.mutable_) {
+ return mutable_ < other.mutable_;
+ }
+ if (type == Type::i32) {
+ return packedType < other.packedType;
+ }
+ return type < other.type;
+}
+
namespace {
std::ostream&