summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index e2588422c..5427deea1 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -693,6 +693,7 @@ void WasmBinaryWriter::writeElementSegments() {
auto start = startSection(BinaryConsts::Section::Element);
o << U32LEB(elemCount);
+ Type funcref = Type(HeapType::func, Nullable);
for (auto& segment : wasm->elementSegments) {
Index tableIdx = 0;
@@ -708,7 +709,7 @@ void WasmBinaryWriter::writeElementSegments() {
if (!isPassive) {
tableIdx = getTableIndex(segment->table);
hasTableIndex =
- tableIdx > 0 || wasm->getTable(segment->table)->type != Type::funcref;
+ tableIdx > 0 || wasm->getTable(segment->table)->type != funcref;
}
uint32_t flags = 0;
@@ -1339,7 +1340,36 @@ void WasmBinaryWriter::writeInlineBuffer(const char* data, size_t size) {
}
void WasmBinaryWriter::writeType(Type type) {
- if (type.isRef() && !type.isBasic()) {
+ 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 (type.isNullable()) {
o << S32LEB(BinaryConsts::EncodedType::nullable);
} else {
@@ -1381,21 +1411,6 @@ void WasmBinaryWriter::writeType(Type type) {
case Type::v128:
ret = BinaryConsts::EncodedType::v128;
break;
- case Type::funcref:
- ret = BinaryConsts::EncodedType::funcref;
- break;
- case Type::anyref:
- ret = BinaryConsts::EncodedType::anyref;
- break;
- case Type::eqref:
- ret = BinaryConsts::EncodedType::eqref;
- break;
- case Type::i31ref:
- ret = BinaryConsts::EncodedType::i31ref;
- break;
- case Type::dataref:
- ret = BinaryConsts::EncodedType::dataref;
- break;
default:
WASM_UNREACHABLE("unexpected type");
}
@@ -1774,13 +1789,13 @@ bool WasmBinaryBuilder::getBasicType(int32_t code, Type& out) {
out = Type::v128;
return true;
case BinaryConsts::EncodedType::funcref:
- out = Type::funcref;
+ out = Type(HeapType::func, Nullable);
return true;
case BinaryConsts::EncodedType::anyref:
- out = Type::anyref;
+ out = Type(HeapType::any, Nullable);
return true;
case BinaryConsts::EncodedType::eqref:
- out = Type::eqref;
+ out = Type(HeapType::eq, Nullable);
return true;
case BinaryConsts::EncodedType::i31ref:
out = Type(HeapType::i31, NonNullable);