diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/literal.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 11 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 10 | ||||
-rw-r--r-- | src/wasm/wasm-stack.cpp | 3 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 4 |
6 files changed, 54 insertions, 2 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 91fc91e1e..e22088d9c 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -100,6 +100,7 @@ Literal::Literal(const Literal& other) : type(other.type) { i32 = other.i32; return; case HeapType::func: + case HeapType::data: case HeapType::exn: WASM_UNREACHABLE("invalid type"); } @@ -126,6 +127,7 @@ Literal::Literal(const Literal& other) : type(other.type) { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: WASM_UNREACHABLE("invalid type"); } @@ -350,6 +352,7 @@ void Literal::getBits(uint8_t (&buf)[16]) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: WASM_UNREACHABLE("invalid type"); } @@ -393,6 +396,7 @@ bool Literal::operator==(const Literal& other) const { case Type::externref: case Type::exnref: case Type::anyref: + case Type::dataref: case Type::eqref: return compareRef(); case Type::unreachable: @@ -539,8 +543,9 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case HeapType::i31: o << "i31ref(" << literal.geti31() << ")"; break; + case HeapType::data: case HeapType::func: - WASM_UNREACHABLE("invalid type"); + WASM_UNREACHABLE("type should have been handled above"); } } } else if (literal.type.isRtt()) { @@ -576,6 +581,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -804,6 +810,7 @@ Literal Literal::eqz() const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -828,6 +835,7 @@ Literal Literal::neg() const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -852,6 +860,7 @@ Literal Literal::abs() const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -993,6 +1002,7 @@ Literal Literal::add(const Literal& other) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -1017,6 +1027,7 @@ Literal Literal::sub(const Literal& other) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -1112,6 +1123,7 @@ Literal Literal::mul(const Literal& other) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -1348,6 +1360,7 @@ Literal Literal::eq(const Literal& other) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -1372,6 +1385,7 @@ Literal Literal::ne(const Literal& other) const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index eea0a9c21..62c8a6cb3 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1057,6 +1057,9 @@ void WasmBinaryWriter::writeType(Type type) { case Type::i31ref: ret = BinaryConsts::EncodedType::i31ref; break; + case Type::dataref: + ret = BinaryConsts::EncodedType::dataref; + break; default: WASM_UNREACHABLE("unexpected type"); } @@ -1089,6 +1092,9 @@ void WasmBinaryWriter::writeHeapType(HeapType type) { case HeapType::i31: ret = BinaryConsts::EncodedHeapType::i31; break; + case HeapType::data: + ret = BinaryConsts::EncodedHeapType::data; + break; } } else { WASM_UNREACHABLE("TODO: compound GC types"); @@ -1415,6 +1421,9 @@ Type WasmBinaryBuilder::getType(int initial) { case BinaryConsts::EncodedType::nonnullable: // FIXME: for now, force all inputs to be nullable return Type(getHeapType(), Nullable); + case BinaryConsts::EncodedType::dataref: + // FIXME: for now, force all inputs to be nullable + return Type(HeapType::BasicHeapType::data, Nullable); case BinaryConsts::EncodedType::i31ref: // FIXME: for now, force all inputs to be nullable return Type(HeapType::BasicHeapType::i31, Nullable); @@ -1456,6 +1465,8 @@ HeapType WasmBinaryBuilder::getHeapType() { return HeapType::eq; case BinaryConsts::EncodedHeapType::i31: return HeapType::i31; + case BinaryConsts::EncodedHeapType::data: + return HeapType::data; default: throwError("invalid wasm heap type: " + std::to_string(type)); } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 84576fde7..0356db235 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -867,6 +867,10 @@ Type SExpressionWasmBuilder::stringToType(const char* str, if (strncmp(str, "eqref", 5) == 0 && (prefix || str[5] == 0)) { return Type::eqref; } + if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) { + // FIXME: for now, force all inputs to be nullable + return Type(HeapType::BasicHeapType::data, Nullable); + } if (strncmp(str, "i31ref", 6) == 0 && (prefix || str[6] == 0)) { // FIXME: for now, force all inputs to be nullable return Type(HeapType::BasicHeapType::i31, Nullable); @@ -909,6 +913,12 @@ HeapType SExpressionWasmBuilder::stringToHeapType(const char* str, return HeapType::func; } } + if (str[0] == 'd') { + if (str[1] == 'a' && str[2] == 't' && str[3] == 'a' && + (prefix || str[4] == 0)) { + return HeapType::data; + } + } throw ParseException(std::string("invalid wasm heap type: ") + str); } diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index b0e000719..8fc6c02c6 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -196,6 +196,7 @@ void BinaryInstWriter::visitLoad(Load* curr) { case Type::anyref: case Type::eqref: case Type::i31ref: + case Type::dataref: case Type::none: WASM_UNREACHABLE("unexpected type"); } @@ -300,6 +301,7 @@ void BinaryInstWriter::visitStore(Store* curr) { case Type::anyref: case Type::eqref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); @@ -764,6 +766,7 @@ void BinaryInstWriter::visitConst(Const* curr) { case Type::anyref: case Type::eqref: case Type::i31ref: + case Type::dataref: case Type::none: case Type::unreachable: WASM_UNREACHABLE("unexpected type"); diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index d3c4c0fc4..862a95223 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -308,6 +308,7 @@ struct TypeStore : Store<TypeInfo> { return Type::anyref; case HeapType::eq: return Type::eqref; + case HeapType::data: case HeapType::i31: break; } @@ -315,6 +316,9 @@ struct TypeStore : Store<TypeInfo> { if (info.ref.heapType == HeapType::i31) { return Type::i31ref; } + if (info.ref.heapType == HeapType::data) { + return Type::dataref; + } } } return Store<TypeInfo>::canonicalize(info); @@ -451,6 +455,7 @@ unsigned Type::getByteSize() const { case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: case Type::unreachable: @@ -500,6 +505,7 @@ FeatureSet Type::getFeatures() const { return FeatureSet::ReferenceTypes | FeatureSet::ExceptionHandling; case HeapType::BasicHeapType::any: case HeapType::BasicHeapType::eq: + case HeapType::BasicHeapType::data: case HeapType::BasicHeapType::i31: return FeatureSet::ReferenceTypes | FeatureSet::GC; default: {} @@ -554,6 +560,8 @@ HeapType Type::getHeapType() const { return HeapType::any; case Type::eqref: return HeapType::eq; + case Type::dataref: + return HeapType::data; case Type::i31ref: return HeapType::i31; } @@ -892,6 +900,8 @@ std::ostream& operator<<(std::ostream& os, Type type) { return os << "anyref"; case Type::eqref: return os << "eqref"; + case Type::dataref: + return os << "dataref"; case Type::i31ref: return os << "i31ref"; } @@ -984,6 +994,8 @@ std::ostream& operator<<(std::ostream& os, HeapType heapType) { return os << "any"; case HeapType::eq: return os << "eq"; + case HeapType::data: + return os << "data"; case HeapType::i31: return os << "i31"; } diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 1557240bb..cc8a2bb56 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1398,6 +1398,7 @@ void FunctionValidator::validateMemBytes(uint8_t bytes, case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: WASM_UNREACHABLE("unexpected type"); @@ -2447,7 +2448,7 @@ void FunctionValidator::visitFunction(Function* curr) { } for (const auto& var : curr->vars) { features |= var.getFeatures(); - shouldBeTrue(var.isDefaultable(), curr, "vars must be defaultable"); + shouldBeTrue(var.isDefaultable(), var, "vars must be defaultable"); } shouldBeTrue(features <= getModule()->features, curr->name, @@ -2544,6 +2545,7 @@ void FunctionValidator::validateAlignment( case Type::exnref: case Type::anyref: case Type::eqref: + case Type::dataref: case Type::i31ref: case Type::none: WASM_UNREACHABLE("invalid type"); |