summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2020-12-07 19:32:48 -0800
committerGitHub <noreply@github.com>2020-12-07 19:32:48 -0800
commit2a0059dec2fe01dcf1358e0120c32aadd2d765b6 (patch)
tree639e392e995c92140a242818663437f00fd2948a /src/wasm/wasm-binary.cpp
parenta84898c11df3d93fb69365fb274a9bb06d60ed47 (diff)
downloadbinaryen-2a0059dec2fe01dcf1358e0120c32aadd2d765b6.tar.gz
binaryen-2a0059dec2fe01dcf1358e0120c32aadd2d765b6.tar.bz2
binaryen-2a0059dec2fe01dcf1358e0120c32aadd2d765b6.zip
Intern HeapTypes and clean up types code (#3428)
Interns HeapTypes using the same patterns and utilities already used to intern Types. This allows HeapTypes to efficiently be compared for equality and hashed, which may be important for very large struct types in the future. This change also has the benefit of increasing symmetry between the APIs of Type and HeapType, which will make the developer experience more consistent. Finally, this change will make TypeBuilder (#3418) much simpler because it will no longer have to introduce TypeInfo variants to refer to HeapTypes indirectly.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index e70dc4a29..25c1eea8c 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1034,29 +1034,29 @@ void WasmBinaryWriter::writeHeapType(HeapType type) {
return;
}
int ret = 0;
- switch (type.kind) {
- case HeapType::FuncKind:
- ret = BinaryConsts::EncodedHeapType::func;
- break;
- case HeapType::ExternKind:
- ret = BinaryConsts::EncodedHeapType::extern_;
- break;
- case HeapType::ExnKind:
- ret = BinaryConsts::EncodedHeapType::exn;
- break;
- case HeapType::AnyKind:
- ret = BinaryConsts::EncodedHeapType::any;
- break;
- case HeapType::EqKind:
- ret = BinaryConsts::EncodedHeapType::eq;
- break;
- case HeapType::I31Kind:
- ret = BinaryConsts::EncodedHeapType::i31;
- break;
- case HeapType::SignatureKind:
- case HeapType::StructKind:
- case HeapType::ArrayKind:
- WASM_UNREACHABLE("TODO: compound GC types");
+ if (type.isBasic()) {
+ switch (type.getBasic()) {
+ case HeapType::func:
+ ret = BinaryConsts::EncodedHeapType::func;
+ break;
+ case HeapType::ext:
+ ret = BinaryConsts::EncodedHeapType::extern_;
+ break;
+ case HeapType::exn:
+ ret = BinaryConsts::EncodedHeapType::exn;
+ break;
+ case HeapType::any:
+ ret = BinaryConsts::EncodedHeapType::any;
+ break;
+ case HeapType::eq:
+ ret = BinaryConsts::EncodedHeapType::eq;
+ break;
+ case HeapType::i31:
+ ret = BinaryConsts::EncodedHeapType::i31;
+ break;
+ }
+ } else {
+ WASM_UNREACHABLE("TODO: compound GC types");
}
o << S64LEB(ret); // TODO: Actually s33
}
@@ -1401,17 +1401,17 @@ HeapType WasmBinaryBuilder::getHeapType() {
}
switch (type) {
case BinaryConsts::EncodedHeapType::func:
- return HeapType::FuncKind;
+ return HeapType::func;
case BinaryConsts::EncodedHeapType::extern_:
- return HeapType::ExternKind;
+ return HeapType::ext;
case BinaryConsts::EncodedHeapType::exn:
- return HeapType::ExnKind;
+ return HeapType::exn;
case BinaryConsts::EncodedHeapType::any:
- return HeapType::AnyKind;
+ return HeapType::any;
case BinaryConsts::EncodedHeapType::eq:
- return HeapType::EqKind;
+ return HeapType::eq;
case BinaryConsts::EncodedHeapType::i31:
- return HeapType::I31Kind;
+ return HeapType::i31;
default:
throwError("invalid wasm heap type: " + std::to_string(type));
}
@@ -5630,7 +5630,8 @@ bool WasmBinaryBuilder::maybeVisitStructGet(Expression*& out, uint32_t code) {
default:
return false;
}
- auto type = getHeapType();
+ // This type annotation is unused. Beware it needing to be used in the future!
+ getHeapType();
curr->index = getU32LEB();
curr->ref = popNonVoidExpression();
curr->finalize();
@@ -5643,7 +5644,8 @@ bool WasmBinaryBuilder::maybeVisitStructSet(Expression*& out, uint32_t code) {
return false;
}
auto* curr = allocator.alloc<StructSet>();
- auto type = getHeapType();
+ // This type annotation is unused. Beware it needing to be used in the future!
+ getHeapType();
curr->index = getU32LEB();
curr->ref = popNonVoidExpression();
curr->value = popNonVoidExpression();