summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/literal.cpp8
-rw-r--r--src/wasm/wasm-binary.cpp36
-rw-r--r--src/wasm/wasm-s-parser.cpp26
-rw-r--r--src/wasm/wasm-type.cpp21
4 files changed, 91 insertions, 0 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp
index 80af9535e..6c7689990 100644
--- a/src/wasm/literal.cpp
+++ b/src/wasm/literal.cpp
@@ -133,6 +133,10 @@ Literal::Literal(const Literal& other) : type(other.type) {
return;
case HeapType::func:
case HeapType::data:
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
WASM_UNREACHABLE("invalid type");
}
}
@@ -536,6 +540,10 @@ std::ostream& operator<<(std::ostream& o, Literal literal) {
break;
case HeapType::func:
case HeapType::data:
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
WASM_UNREACHABLE("type should have been handled above");
}
}
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index b74331aed..87ee00c8a 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1351,6 +1351,18 @@ void WasmBinaryWriter::writeHeapType(HeapType type) {
case HeapType::data:
ret = BinaryConsts::EncodedHeapType::data;
break;
+ case HeapType::string:
+ ret = BinaryConsts::EncodedHeapType::string;
+ break;
+ case HeapType::stringview_wtf8:
+ ret = BinaryConsts::EncodedHeapType::stringview_wtf8_heap;
+ break;
+ case HeapType::stringview_wtf16:
+ ret = BinaryConsts::EncodedHeapType::stringview_wtf16_heap;
+ break;
+ case HeapType::stringview_iter:
+ ret = BinaryConsts::EncodedHeapType::stringview_iter_heap;
+ break;
}
} else {
WASM_UNREACHABLE("TODO: compound GC types");
@@ -1699,6 +1711,18 @@ bool WasmBinaryBuilder::getBasicType(int32_t code, Type& out) {
case BinaryConsts::EncodedType::dataref:
out = Type(HeapType::data, NonNullable);
return true;
+ case BinaryConsts::EncodedType::stringref:
+ out = Type(HeapType::string, Nullable);
+ return true;
+ case BinaryConsts::EncodedType::stringview_wtf8:
+ out = Type(HeapType::stringview_wtf8, Nullable);
+ return true;
+ case BinaryConsts::EncodedType::stringview_wtf16:
+ out = Type(HeapType::stringview_wtf16, Nullable);
+ return true;
+ case BinaryConsts::EncodedType::stringview_iter:
+ out = Type(HeapType::stringview_iter, Nullable);
+ return true;
default:
return false;
}
@@ -1721,6 +1745,18 @@ bool WasmBinaryBuilder::getBasicHeapType(int64_t code, HeapType& out) {
case BinaryConsts::EncodedHeapType::data:
out = HeapType::data;
return true;
+ case BinaryConsts::EncodedHeapType::string:
+ out = HeapType::string;
+ return true;
+ case BinaryConsts::EncodedHeapType::stringview_wtf8_heap:
+ out = HeapType::stringview_wtf8;
+ return true;
+ case BinaryConsts::EncodedHeapType::stringview_wtf16_heap:
+ out = HeapType::stringview_wtf16;
+ return true;
+ case BinaryConsts::EncodedHeapType::stringview_iter_heap:
+ out = HeapType::stringview_iter;
+ return true;
default:
return false;
}
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index b59319be2..22557a06d 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -1184,6 +1184,18 @@ Type SExpressionWasmBuilder::stringToType(const char* str,
if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) {
return Type::dataref;
}
+ if (strncmp(str, "stringref", 9) == 0 && (prefix || str[9] == 0)) {
+ return Type(HeapType::string, Nullable);
+ }
+ if (strncmp(str, "stringview_wtf8", 15) == 0 && (prefix || str[15] == 0)) {
+ return Type(HeapType::stringview_wtf8, Nullable);
+ }
+ if (strncmp(str, "stringview_wtf16", 16) == 0 && (prefix || str[16] == 0)) {
+ return Type(HeapType::stringview_wtf16, Nullable);
+ }
+ if (strncmp(str, "stringview_iter", 15) == 0 && (prefix || str[15] == 0)) {
+ return Type(HeapType::stringview_iter, Nullable);
+ }
if (allowError) {
return Type::none;
}
@@ -1223,6 +1235,20 @@ HeapType SExpressionWasmBuilder::stringToHeapType(const char* str,
return HeapType::data;
}
}
+ if (str[0] == 's') {
+ if (strncmp(str, "string", 6) == 0 && (prefix || str[6] == 0)) {
+ return HeapType::string;
+ }
+ if (strncmp(str, "stringview_wtf8", 15) == 0 && (prefix || str[15] == 0)) {
+ return HeapType::stringview_wtf8;
+ }
+ if (strncmp(str, "stringview_wtf16", 16) == 0 && (prefix || str[16] == 0)) {
+ return HeapType::stringview_wtf16;
+ }
+ if (strncmp(str, "stringview_iter", 15) == 0 && (prefix || str[15] == 0)) {
+ return HeapType::stringview_iter;
+ }
+ }
throw ParseException(std::string("invalid wasm heap type: ") + str);
}
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 0092f933d..b79080121 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -621,6 +621,10 @@ HeapType getBasicHeapTypeLUB(HeapType::BasicHeapType a,
}
return HeapType::any;
case HeapType::data:
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
return HeapType::any;
}
WASM_UNREACHABLE("unexpected basic type");
@@ -679,6 +683,10 @@ std::optional<Type> TypeInfo::getCanonical() const {
return Type::eqref;
case HeapType::i31:
case HeapType::data:
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
break;
}
} else {
@@ -1739,6 +1747,11 @@ bool SubTyper::isSubType(HeapType a, HeapType b) {
return false;
case HeapType::data:
return a.isData();
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
+ return false;
}
}
if (a.isBasic()) {
@@ -2117,6 +2130,14 @@ std::ostream& TypePrinter::print(HeapType type) {
return os << "i31";
case HeapType::data:
return os << "data";
+ case HeapType::string:
+ return os << "string";
+ case HeapType::stringview_wtf8:
+ return os << "stringview_wtf8";
+ case HeapType::stringview_wtf16:
+ return os << "stringview_wtf16";
+ case HeapType::stringview_iter:
+ return os << "stringview_iter";
}
}