summaryrefslogtreecommitdiff
path: root/src/binary-reader.cc
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2020-05-28 11:30:38 -0700
committerGitHub <noreply@github.com>2020-05-28 11:30:38 -0700
commitbf46c08b05fc6fcc457f1657e936fab24b4dceee (patch)
treef57a19c670a3e222896c252c829d5eb5ec4db6d2 /src/binary-reader.cc
parent0630dc53755678239d7609b61776b125221eefb8 (diff)
downloadwabt-bf46c08b05fc6fcc457f1657e936fab24b4dceee.tar.gz
wabt-bf46c08b05fc6fcc457f1657e936fab24b4dceee.tar.bz2
wabt-bf46c08b05fc6fcc457f1657e936fab24b4dceee.zip
Reference types changes to remove subtyping (#1407)
Main changes: * Rename `anyref` -> `externref` * Remove `nullref` * Rename `hostref` -> `externref` * `ref.null` and `ref.is_null` now have "ref kind" parameter * Add ref kind keywords: `func`, `extern`, `exn`
Diffstat (limited to 'src/binary-reader.cc')
-rw-r--r--src/binary-reader.cc52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc
index 9a09560e..9780e39c 100644
--- a/src/binary-reader.cc
+++ b/src/binary-reader.cc
@@ -99,6 +99,7 @@ class BinaryReader {
Result ReadS32Leb128(uint32_t* out_value, const char* desc) WABT_WARN_UNUSED;
Result ReadS64Leb128(uint64_t* out_value, const char* desc) WABT_WARN_UNUSED;
Result ReadType(Type* out_value, const char* desc) WABT_WARN_UNUSED;
+ Result ReadRefType(Type* out_value, const char* desc) WABT_WARN_UNUSED;
Result ReadExternalKind(ExternalKind* out_value,
const char* desc) WABT_WARN_UNUSED;
Result ReadStr(string_view* out_str, const char* desc) WABT_WARN_UNUSED;
@@ -302,6 +303,14 @@ Result BinaryReader::ReadType(Type* out_value, const char* desc) {
return Result::Ok;
}
+Result BinaryReader::ReadRefType(Type* out_value, const char* desc) {
+ uint32_t type = 0;
+ CHECK_RESULT(ReadS32Leb128(&type, desc));
+ *out_value = static_cast<Type>(type);
+ ERROR_UNLESS(out_value->IsRef(), "%s must be a reference type", desc);
+ return Result::Ok;
+}
+
Result BinaryReader::ReadExternalKind(ExternalKind* out_value,
const char* desc) {
uint8_t value = 0;
@@ -401,12 +410,11 @@ bool BinaryReader::IsConcreteType(Type type) {
case Type::V128:
return options_.features.simd_enabled();
- case Type::Funcref:
- case Type::Anyref:
- case Type::Nullref:
+ case Type::FuncRef:
+ case Type::ExternRef:
return options_.features.reference_types_enabled();
- case Type::Exnref:
+ case Type::ExnRef:
return options_.features.exceptions_enabled();
default:
@@ -483,9 +491,12 @@ Result BinaryReader::ReadInitExpr(Index index, bool require_i32) {
break;
}
- case Opcode::RefNull:
- CALLBACK(OnInitExprRefNull, index);
+ case Opcode::RefNull: {
+ Type type;
+ CHECK_RESULT(ReadRefType(&type, "ref.null type"));
+ CALLBACK(OnInitExprRefNull, index, type);
break;
+ }
case Opcode::RefFunc: {
Index func_index;
@@ -514,9 +525,7 @@ Result BinaryReader::ReadInitExpr(Index index, bool require_i32) {
}
Result BinaryReader::ReadTable(Type* out_elem_type, Limits* out_elem_limits) {
- CHECK_RESULT(ReadType(out_elem_type, "table elem type"));
- ERROR_UNLESS(out_elem_type->IsRef(),
- "table elem type must be a reference type");
+ CHECK_RESULT(ReadRefType(out_elem_type, "table elem type"));
uint32_t flags;
uint32_t initial;
@@ -1545,14 +1554,18 @@ Result BinaryReader::ReadFunctionBody(Offset end_offset) {
}
case Opcode::RefNull: {
- CALLBACK(OnRefNullExpr);
- CALLBACK0(OnOpcodeBare);
+ Type type;
+ CHECK_RESULT(ReadRefType(&type, "ref.null type"));
+ CALLBACK(OnRefNullExpr, type);
+ CALLBACK(OnOpcodeType, type);
break;
}
case Opcode::RefIsNull: {
- CALLBACK(OnRefIsNullExpr);
- CALLBACK0(OnOpcodeBare);
+ Type type;
+ CHECK_RESULT(ReadRefType(&type, "ref.is_null type"));
+ CALLBACK(OnRefIsNullExpr, type);
+ CALLBACK(OnOpcodeType, type);
break;
}
@@ -2184,7 +2197,7 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
if ((flags & (SegPassive | SegExplicitIndex)) == SegExplicitIndex) {
CHECK_RESULT(ReadIndex(&table_index, "elem segment table index"));
}
- Type elem_type = Type::Funcref;
+ Type elem_type = Type::FuncRef;
CALLBACK(BeginElemSegment, i, table_index, flags);
@@ -2197,17 +2210,14 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
// For backwards compat we support not declaring the element kind.
if (flags & (SegPassive | SegExplicitIndex)) {
if (flags & SegUseElemExprs) {
- CHECK_RESULT(ReadType(&elem_type, "table elem type"));
- ERROR_UNLESS(elem_type.IsRef(),
- "segment elem expr type must be a reference type (got %s)",
- elem_type.GetName());
+ CHECK_RESULT(ReadRefType(&elem_type, "table elem type"));
} else {
ExternalKind kind;
CHECK_RESULT(ReadExternalKind(&kind, "export kind"));
ERROR_UNLESS(kind == ExternalKind::Func,
"segment elem type must be func (%s)",
elem_type.GetName());
- elem_type = Type::Funcref;
+ elem_type = Type::FuncRef;
}
}
@@ -2222,7 +2232,9 @@ Result BinaryReader::ReadElemSection(Offset section_size) {
Opcode opcode;
CHECK_RESULT(ReadOpcode(&opcode, "elem expr opcode"));
if (opcode == Opcode::RefNull) {
- CALLBACK(OnElemSegmentElemExpr_RefNull, i);
+ Type type;
+ CHECK_RESULT(ReadRefType(&type, "elem expr ref.null type"));
+ CALLBACK(OnElemSegmentElemExpr_RefNull, i, type);
} else if (opcode == Opcode::RefFunc) {
Index func_index;
CHECK_RESULT(ReadIndex(&func_index, "elem expr func index"));