summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-s-parser.cpp
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-09-09 03:40:09 +0200
committerGitHub <noreply@github.com>2020-09-09 03:40:09 +0200
commit916ce6f1a9f7c85102a8c69f593b301c8df5d19d (patch)
tree93b22be9f2c0718248528d140b05221cb6878600 /src/wasm/wasm-s-parser.cpp
parent0fdcf5b51a0c8c379b2d3ad8262aa22bb234f0e9 (diff)
downloadbinaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.tar.gz
binaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.tar.bz2
binaryen-916ce6f1a9f7c85102a8c69f593b301c8df5d19d.zip
Update reference types (#3084)
Align with the current state of the reference types proposal: * Remove `nullref` * Remove `externref` and `funcref` subtyping * A `Literal` of a nullable reference type can now represent `null` (previously was type `nullref`) * Update the tests and temporarily comment out those tests relying on subtyping
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r--src/wasm/wasm-s-parser.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 931cd1bf0..0e4202a24 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -869,9 +869,6 @@ Type SExpressionWasmBuilder::stringToType(const char* str,
if (strncmp(str, "externref", 9) == 0 && (prefix || str[9] == 0)) {
return Type::externref;
}
- if (strncmp(str, "nullref", 7) == 0 && (prefix || str[7] == 0)) {
- return Type::nullref;
- }
if (strncmp(str, "exnref", 6) == 0 && (prefix || str[6] == 0)) {
return Type::exnref;
}
@@ -881,6 +878,41 @@ Type SExpressionWasmBuilder::stringToType(const char* str,
throw ParseException(std::string("invalid wasm type: ") + str);
}
+HeapType SExpressionWasmBuilder::stringToHeapType(const char* str,
+ bool prefix) {
+ if (str[0] == 'a') {
+ if (str[1] == 'n' && str[2] == 'y' && (prefix || str[3] == 0)) {
+ return HeapType::AnyKind;
+ }
+ }
+ if (str[0] == 'e') {
+ if (str[1] == 'q' && (prefix || str[2] == 0)) {
+ return HeapType::EqKind;
+ }
+ if (str[1] == 'x') {
+ if (str[2] == 'n' && (prefix || str[3] == 0)) {
+ return HeapType::ExnKind;
+ }
+ if (str[2] == 't' && str[3] == 'e' && str[4] == 'r' && str[5] == 'n' &&
+ (prefix || str[6] == 0)) {
+ return HeapType::ExternKind;
+ }
+ }
+ }
+ if (str[0] == 'i') {
+ if (str[1] == '3' && str[2] == '1' && (prefix || str[3] == 0)) {
+ return HeapType::I31Kind;
+ }
+ }
+ if (str[0] == 'f') {
+ if (str[1] == 'u' && str[2] == 'n' && str[3] == 'c' &&
+ (prefix || str[4] == 0)) {
+ return HeapType::FuncKind;
+ }
+ }
+ throw ParseException(std::string("invalid wasm heap type: ") + str);
+}
+
Type SExpressionWasmBuilder::elementToType(Element& s) {
if (s.isStr()) {
return stringToType(s.str(), false, false);
@@ -1779,8 +1811,12 @@ Expression* SExpressionWasmBuilder::makeReturn(Element& s) {
}
Expression* SExpressionWasmBuilder::makeRefNull(Element& s) {
+ if (s.size() != 2) {
+ throw ParseException("invalid heap type reference", s.line, s.col);
+ }
+ auto heapType = stringToHeapType(s[1]->str());
auto ret = allocator.alloc<RefNull>();
- ret->finalize();
+ ret->finalize(heapType);
return ret;
}