summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp24
-rw-r--r--src/wasm/wasm-s-parser.cpp11
-rw-r--r--src/wasm/wasm-type.cpp8
-rw-r--r--src/wasm/wasm.cpp8
4 files changed, 30 insertions, 21 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 796ba4b4e..66715686e 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1411,10 +1411,10 @@ Type WasmBinaryBuilder::getType(int initial) {
case BinaryConsts::EncodedType::eqref:
return Type::eqref;
case BinaryConsts::EncodedType::nullable:
- return Type(getHeapType(), /* nullable = */ true);
+ return Type(getHeapType(), Nullable);
case BinaryConsts::EncodedType::nonnullable:
// FIXME: for now, force all inputs to be nullable
- return Type(getHeapType(), /* nullable = */ true);
+ return Type(getHeapType(), Nullable);
case BinaryConsts::EncodedType::i31ref:
return Type::i31ref;
case BinaryConsts::EncodedType::rtt_n: {
@@ -1461,21 +1461,32 @@ HeapType WasmBinaryBuilder::getHeapType() {
WASM_UNREACHABLE("unexpected type");
}
+Mutability WasmBinaryBuilder::getMutability() {
+ switch (getU32LEB()) {
+ case 0:
+ return Immutable;
+ case 1:
+ return Mutable;
+ default:
+ throw ParseException("Expected 0 or 1 for mutability");
+ }
+}
+
Field WasmBinaryBuilder::getField() {
// The value may be a general wasm type, or one of the types only possible in
// a field.
auto initial = getS32LEB();
if (initial == BinaryConsts::EncodedType::i8) {
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(Field::i8, mutable_);
}
if (initial == BinaryConsts::EncodedType::i16) {
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(Field::i16, mutable_);
}
// It's a regular wasm value.
auto type = getType(initial);
- auto mutable_ = getU32LEB();
+ auto mutable_ = getMutability();
return Field(type, mutable_);
}
@@ -5433,8 +5444,7 @@ void WasmBinaryBuilder::visitRefFunc(RefFunc* curr) {
// To support typed function refs, we give the reference not just a general
// funcref, but a specific subtype with the actual signature.
// FIXME: for now, emit a nullable type here
- curr->finalize(Type(HeapType(getSignatureByFunctionIndex(index)),
- /* nullable = */ true));
+ curr->finalize(Type(HeapType(getSignatureByFunctionIndex(index)), Nullable));
}
void WasmBinaryBuilder::visitRefEq(RefEq* curr) {
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 85bc2aba9..c1c227d21 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -932,10 +932,10 @@ Type SExpressionWasmBuilder::elementToType(Element& s) {
std::string("invalid reference type qualifier"), s.line, s.col);
}
// FIXME: for now, force all inputs to be nullable
- bool nullable = true;
+ Nullability nullable = Nullable;
size_t i = 1;
if (size == 3) {
- nullable = true;
+ nullable = Nullable;
i++;
}
return Type(parseHeapType(*s[i]), nullable);
@@ -1925,8 +1925,7 @@ Expression* SExpressionWasmBuilder::makeRefFunc(Element& s) {
ret->func = func;
// To support typed function refs, we give the reference not just a general
// funcref, but a specific subtype with the actual signature.
- ret->finalize(
- Type(HeapType(functionSignatures[func]), /* nullable = */ true));
+ ret->finalize(Type(HeapType(functionSignatures[func]), Nullable));
return ret;
}
@@ -2826,7 +2825,7 @@ HeapType SExpressionWasmBuilder::parseHeapType(Element& s) {
}
// It's a struct or an array.
auto parseField = [&](Element* t) {
- bool mutable_ = false;
+ Mutability mutable_ = Immutable;
// t is a list, containing either
// TYPE
// or
@@ -2842,7 +2841,7 @@ HeapType SExpressionWasmBuilder::parseHeapType(Element& s) {
}
// The element may also be (mut (..)).
if (elementStartsWith(t, MUT)) {
- mutable_ = true;
+ mutable_ = Mutable;
t = (*t)[1];
}
if (t->isStr()) {
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index ddad9c0ed..95d351ba2 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -39,7 +39,7 @@ struct TypeInfo {
} kind;
struct Ref {
HeapType heapType;
- bool nullable;
+ Nullability nullable;
};
union {
Tuple tuple;
@@ -49,7 +49,7 @@ struct TypeInfo {
TypeInfo(const Tuple& tuple) : kind(TupleKind), tuple(tuple) {}
TypeInfo(Tuple&& tuple) : kind(TupleKind), tuple(std::move(tuple)) {}
- TypeInfo(HeapType heapType, bool nullable)
+ TypeInfo(HeapType heapType, Nullability nullable)
: kind(RefKind), ref{heapType, nullable} {}
TypeInfo(Rtt rtt) : kind(RttKind), rtt(rtt) {}
TypeInfo(const TypeInfo& other);
@@ -351,7 +351,7 @@ Type::Type(Tuple&& tuple) {
new (this) Type(globalTypeStore.canonicalize(std::move(tuple)));
}
-Type::Type(HeapType heapType, bool nullable) {
+Type::Type(HeapType heapType, Nullability nullable) {
new (this) Type(globalTypeStore.canonicalize(TypeInfo(heapType, nullable)));
}
@@ -1053,7 +1053,7 @@ Type TypeBuilder::getTempTupleType(const Tuple& tuple) {
return impl->typeStore.canonicalize(tuple);
}
-Type TypeBuilder::getTempRefType(size_t i, bool nullable) {
+Type TypeBuilder::getTempRefType(size_t i, Nullability nullable) {
assert(i < impl->entries.size() && "Index out of bounds");
return impl->typeStore.canonicalize(
TypeInfo(impl->entries[i].get(), nullable));
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 8e6550c27..851e6a804 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -978,7 +978,7 @@ void MemoryGrow::finalize() {
}
}
-void RefNull::finalize(HeapType heapType) { type = Type(heapType, true); }
+void RefNull::finalize(HeapType heapType) { type = Type(heapType, Nullable); }
void RefNull::finalize(Type type_) {
type = type_;
@@ -1098,7 +1098,7 @@ void RefCast::finalize() {
type = Type::unreachable;
} else {
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
}
@@ -1125,7 +1125,7 @@ void StructNew::finalize() {
return;
}
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
void StructGet::finalize() {
@@ -1151,7 +1151,7 @@ void ArrayNew::finalize() {
return;
}
// TODO: make non-nullable when we support that
- type = Type(rtt->type.getHeapType(), /* nullable = */ true);
+ type = Type(rtt->type.getHeapType(), Nullable);
}
void ArrayGet::finalize() {