summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-07-25 17:15:08 -0700
committerGitHub <noreply@github.com>2022-07-25 17:15:08 -0700
commita1464d9e004a43ef6d3f2fa83444e7906d9b620f (patch)
treee1d10f402a1fd77847118e32e56b4199a54059cf /src
parentc40b402aaffa24c641cbb0e8efd0019c5c4a68b6 (diff)
downloadbinaryen-a1464d9e004a43ef6d3f2fa83444e7906d9b620f.tar.gz
binaryen-a1464d9e004a43ef6d3f2fa83444e7906d9b620f.tar.bz2
binaryen-a1464d9e004a43ef6d3f2fa83444e7906d9b620f.zip
Update reference type shorthands in binary output (#4828)
Add support for emitting the string type reference shorthands, which had previously been omitted accidentally due to the `default` case in that switch. Also avoid emitting shorthands for non-nullable reference types as a first step towards transitioning the shorthands to represent nullable types instead. Not emitting these shorthands at all will give V8 the flexibility it needs to change its interpretation of the shorthands without breaking any workflows using Binaryen.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-binary.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index edcf5f7bf..9f28c00bb 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1342,32 +1342,37 @@ void WasmBinaryWriter::writeInlineBuffer(const char* data, size_t size) {
void WasmBinaryWriter::writeType(Type type) {
if (type.isRef()) {
auto heapType = type.getHeapType();
- if (heapType.isBasic()) {
- if (type.isNullable()) {
- switch (heapType.getBasic()) {
- case HeapType::any:
- o << S32LEB(BinaryConsts::EncodedType::anyref);
- return;
- case HeapType::func:
- o << S32LEB(BinaryConsts::EncodedType::funcref);
- return;
- case HeapType::eq:
- o << S32LEB(BinaryConsts::EncodedType::eqref);
- return;
- default:
- break;
- }
- } else {
- switch (heapType.getBasic()) {
- case HeapType::i31:
- o << S32LEB(BinaryConsts::EncodedType::i31ref);
- return;
- case HeapType::data:
- o << S32LEB(BinaryConsts::EncodedType::dataref);
- return;
- default:
- break;
- }
+ if (heapType.isBasic() && type.isNullable()) {
+ switch (heapType.getBasic()) {
+ case HeapType::any:
+ o << S32LEB(BinaryConsts::EncodedType::anyref);
+ return;
+ case HeapType::func:
+ o << S32LEB(BinaryConsts::EncodedType::funcref);
+ return;
+ case HeapType::eq:
+ o << S32LEB(BinaryConsts::EncodedType::eqref);
+ return;
+ case HeapType::i31:
+ // TODO: Emit i31ref once V8 (and Binaryen itself) treats it as
+ // nullable.
+ break;
+ case HeapType::data:
+ // TODO: Emit dataref once V8 (and Binaryen itself) treats it as
+ // nullable.
+ break;
+ case HeapType::string:
+ o << S32LEB(BinaryConsts::EncodedType::stringref);
+ return;
+ case HeapType::stringview_wtf8:
+ o << S32LEB(BinaryConsts::EncodedType::stringview_wtf8);
+ return;
+ case HeapType::stringview_wtf16:
+ o << S32LEB(BinaryConsts::EncodedType::stringview_wtf16);
+ return;
+ case HeapType::stringview_iter:
+ o << S32LEB(BinaryConsts::EncodedType::stringview_iter);
+ return;
}
}
if (type.isNullable()) {