From 962344d35ca51d94a7bac3b8a06387aa1616c82e Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 20 May 2020 18:17:00 -0700 Subject: [PATCH] Address comments --- docs/wast2json.md | 5 +++-- src/binary-reader.cc | 10 +++++----- src/binary-writer-spec.cc | 4 ++-- src/decompiler-ls.h | 6 +++--- src/interp/interp-inl.h | 2 ++ src/interp/interp-util.cc | 6 +++--- src/interp/interp-wasm-c-api.cc | 12 ++++++------ src/interp/interp.cc | 12 ++++++------ src/ir.cc | 2 +- src/ir.h | 8 ++++---- src/lexer-keywords.txt | 14 +++++++------- src/prebuilt/lexer-keywords.cc | 14 +++++++------- src/shared-validator.cc | 4 ++-- src/test-interp.cc | 6 +++--- src/token.def | 6 +++--- src/tools/spectest-interp.cc | 18 +++++++++--------- src/type-checker.cc | 10 +++++----- src/type.h | 28 ++++++++++++++-------------- src/wast-parser.cc | 14 +++++++------- src/wat-writer.cc | 2 +- 20 files changed, 93 insertions(+), 90 deletions(-) diff --git a/docs/wast2json.md b/docs/wast2json.md index fa3a732be..90fcd5ee0 100644 --- a/docs/wast2json.md +++ b/docs/wast2json.md @@ -153,13 +153,14 @@ types are supported, with the given JSON format: | "f32" | `{"type": "f32", "value": }` | | "f64" | `{"type": "f64", "value": }` | -The `reference-types` proposal adds three more valid types: +The `reference-types` proposal adds three more valid types. In each case the +value can either be an integer or `"null"`: | type | JSON format | | - | - | | "externref" | `{"type": "externref", "value": }` | | "funcref" | `{"type": "funcref", "value": }` | - +| "exnref" | `{"type": "exnref", "value": }` | The `simd` proposal adds another type, with a slightly different syntax. diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 7250492e1..9780e39c4 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -410,11 +410,11 @@ bool BinaryReader::IsConcreteType(Type type) { case Type::V128: return options_.features.simd_enabled(); - case Type::Funcref: - case Type::Externref: + case Type::FuncRef: + case Type::ExternRef: return options_.features.reference_types_enabled(); - case Type::Exnref: + case Type::ExnRef: return options_.features.exceptions_enabled(); default: @@ -2197,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); @@ -2217,7 +2217,7 @@ Result BinaryReader::ReadElemSection(Offset section_size) { ERROR_UNLESS(kind == ExternalKind::Func, "segment elem type must be func (%s)", elem_type.GetName()); - elem_type = Type::Funcref; + elem_type = Type::FuncRef; } } diff --git a/src/binary-writer-spec.cc b/src/binary-writer-spec.cc index 112acfb3d..4499e0ff0 100644 --- a/src/binary-writer-spec.cc +++ b/src/binary-writer-spec.cc @@ -238,7 +238,7 @@ void BinaryWriterSpec::WriteConst(const Const& const_) { WriteF64(const_.f64_bits(), const_.expected_nan()); break; - case Type::Funcref: { + case Type::FuncRef: { WriteString("funcref"); WriteSeparator(); WriteKey("value"); @@ -246,7 +246,7 @@ void BinaryWriterSpec::WriteConst(const Const& const_) { break; } - case Type::Externref: { + case Type::ExternRef: { WriteString("externref"); WriteSeparator(); WriteKey("value"); diff --git a/src/decompiler-ls.h b/src/decompiler-ls.h index 7af595a82..b9261e8b9 100644 --- a/src/decompiler-ls.h +++ b/src/decompiler-ls.h @@ -37,9 +37,9 @@ inline const char *GetDecompTypeName(Type t) { case Type::F64: return "double"; case Type::V128: return "simd"; case Type::Func: return "func"; - case Type::Funcref: return "funcref"; - case Type::Externref: return "externref"; - case Type::Exnref: return "exnref"; + case Type::FuncRef: return "funcref"; + case Type::ExternRef: return "externref"; + case Type::ExnRef: return "exnref"; case Type::Void: return "void"; default: return "ILLEGAL"; } diff --git a/src/interp/interp-inl.h b/src/interp/interp-inl.h index 3c713ba90..0d306ebee 100644 --- a/src/interp/interp-inl.h +++ b/src/interp/interp-inl.h @@ -365,6 +365,8 @@ template void RequireType(ValueType type) { } inline bool TypesMatch(ValueType expected, ValueType actual) { + // Currently there is no subtyping, so expected and actual must match + // exactly. In the future this may be expanded. return expected == actual; } diff --git a/src/interp/interp-util.cc b/src/interp/interp-util.cc index ae16161da..5b9e702bc 100644 --- a/src/interp/interp-util.cc +++ b/src/interp/interp-util.cc @@ -49,13 +49,13 @@ std::string TypedValueToString(const TypedValue& tv) { case Type::I16: // For SIMD lane. return StringPrintf("i16:%u", tv.value.Get() & 0xffff); - case Type::Funcref: + case Type::FuncRef: return StringPrintf("funcref:%" PRIzd, tv.value.Get().index); - case Type::Externref: + case Type::ExternRef: return StringPrintf("externref:%" PRIzd, tv.value.Get().index); - case Type::Exnref: + case Type::ExnRef: return StringPrintf("exnref:%" PRIzd, tv.value.Get().index); case Type::Func: diff --git a/src/interp/interp-wasm-c-api.cc b/src/interp/interp-wasm-c-api.cc index d3bc58247..e3c7b6205 100644 --- a/src/interp/interp-wasm-c-api.cc +++ b/src/interp/interp-wasm-c-api.cc @@ -310,9 +310,9 @@ static ValueType ToWabtValueType(wasm_valkind_t kind) { case WASM_F64: return ValueType::F64; case WASM_ANYREF: - return ValueType::Externref; + return ValueType::ExternRef; case WASM_FUNCREF: - return ValueType::Funcref; + return ValueType::FuncRef; default: TRACE("unexpected wasm_valkind_t: %d", kind); WABT_UNREACHABLE; @@ -330,9 +330,9 @@ static wasm_valkind_t FromWabtValueType(ValueType type) { return WASM_F32; case ValueType::F64: return WASM_F64; - case ValueType::Externref: + case ValueType::ExternRef: return WASM_ANYREF; - case ValueType::Funcref: + case ValueType::FuncRef: return WASM_FUNCREF; default: WABT_UNREACHABLE; @@ -429,13 +429,13 @@ static wasm_val_t FromWabtValue(Store& store, const TypedValue& tv) { out_value.kind = WASM_F64; out_value.of.f64 = tv.value.Get(); break; - case Type::Funcref: { + case Type::FuncRef: { Ref ref = tv.value.Get(); out_value.kind = WASM_FUNCREF; out_value.of.ref = new wasm_func_t(store.UnsafeGet(ref)); break; } - case Type::Externref: { + case Type::ExternRef: { Ref ref = tv.value.Get(); out_value.kind = WASM_ANYREF; out_value.of.ref = new wasm_foreign_t(store.UnsafeGet(ref)); diff --git a/src/interp/interp.cc b/src/interp/interp.cc index c290c9f9b..7aee6012f 100644 --- a/src/interp/interp.cc +++ b/src/interp/interp.cc @@ -204,7 +204,7 @@ bool Store::HasValueType(Ref ref, ValueType type) const { if (!IsValid(ref)) { return false; } - if (type == ValueType::Externref) { + if (type == ValueType::ExternRef) { return true; } if (ref == Ref::Null) { @@ -213,10 +213,10 @@ bool Store::HasValueType(Ref ref, ValueType type) const { Object* obj = objects_.Get(ref.index).get(); switch (type) { - case ValueType::Funcref: + case ValueType::FuncRef: return obj->kind() == ObjectKind::DefinedFunc || obj->kind() == ObjectKind::HostFunc; - case ValueType::Exnref: // TODO + case ValueType::ExnRef: // TODO return false; default: return false; @@ -2197,9 +2197,9 @@ std::string Thread::TraceSource::Pick(Index index, Instr instr) { v.u32(2), v.u32(3)); } - case ValueType::Funcref: reftype = "funcref"; break; - case ValueType::Externref: reftype = "externref"; break; - case ValueType::Exnref: reftype = "exnref"; break; + case ValueType::FuncRef: reftype = "funcref"; break; + case ValueType::ExternRef: reftype = "externref"; break; + case ValueType::ExnRef: reftype = "exnref"; break; default: WABT_UNREACHABLE; diff --git a/src/ir.cc b/src/ir.cc index e07594f46..e521706e7 100644 --- a/src/ir.cc +++ b/src/ir.cc @@ -641,7 +641,7 @@ void Var::Destroy() { uint8_t ElemSegment::GetFlags(const Module* module) const { uint8_t flags = 0; - bool all_ref_func = elem_type == Type::Funcref; + bool all_ref_func = elem_type == Type::FuncRef; switch (kind) { case SegmentKind::Active: { diff --git a/src/ir.h b/src/ir.h index 540153d1d..424a11f5b 100644 --- a/src/ir.h +++ b/src/ir.h @@ -134,8 +134,8 @@ struct Const { // Only used for expectations. (e.g. wast assertions) void set_f32(ExpectedNan nan) { set_f32(0); set_expected_nan(0, nan); } void set_f64(ExpectedNan nan) { set_f64(0); set_expected_nan(0, nan); } - void set_funcref() { From(Type::Funcref, 0); } - void set_externref(uintptr_t x) { From(Type::Externref, x); } + void set_funcref() { From(Type::FuncRef, 0); } + void set_externref(uintptr_t x) { From(Type::ExternRef, x); } void set_null(Type type) { From(type, kRefNullBits); } bool is_expected_nan(int lane = 0) const { @@ -719,7 +719,7 @@ struct Global { struct Table { explicit Table(string_view name) - : name(name.to_string()), elem_type(Type::Funcref) {} + : name(name.to_string()), elem_type(Type::FuncRef) {} std::string name; Limits elem_limits; @@ -732,7 +732,7 @@ enum class ElemExprKind { }; struct ElemExpr { - ElemExpr() : kind(ElemExprKind::RefNull), type(Type::Funcref) {} + ElemExpr() : kind(ElemExprKind::RefNull), type(Type::FuncRef) {} explicit ElemExpr(Var var) : kind(ElemExprKind::RefFunc), var(var) {} explicit ElemExpr(Type type) : kind(ElemExprKind::RefNull), type(type) {} diff --git a/src/lexer-keywords.txt b/src/lexer-keywords.txt index 4a48813e5..fbf87ebe0 100644 --- a/src/lexer-keywords.txt +++ b/src/lexer-keywords.txt @@ -46,10 +46,10 @@ elem, TokenType::Elem else, TokenType::Else, Opcode::Else end, TokenType::End, Opcode::End event, TokenType::Event -exn, Type::Exnref, TokenType::Exn -exnref, Type::Exnref -extern, Type::Externref, TokenType::Extern -externref, Type::Externref +exn, Type::ExnRef, TokenType::Exn +exnref, Type::ExnRef +extern, Type::ExternRef, TokenType::Extern +externref, Type::ExternRef export, TokenType::Export f32.abs, TokenType::Unary, Opcode::F32Abs f32.add, TokenType::Binary, Opcode::F32Add @@ -152,8 +152,8 @@ f64x2.sqrt, TokenType::Unary, Opcode::F64X2Sqrt f64x2.sub, TokenType::Binary, Opcode::F64X2Sub f64x2, TokenType::F64X2 field, TokenType::Field -funcref, Type::Funcref -func, Type::Funcref, TokenType::Func +funcref, Type::FuncRef +func, Type::FuncRef, TokenType::Func get, TokenType::Get global.get, TokenType::GlobalGet, Opcode::GlobalGet global.set, TokenType::GlobalSet, Opcode::GlobalSet @@ -524,7 +524,7 @@ v8x16.load_splat, TokenType::Load, Opcode::V8X16LoadSplat v8x16.shuffle, TokenType::SimdShuffleOp, Opcode::V8X16Shuffle v8x16.swizzle, TokenType::Binary, Opcode::V8X16Swizzle # Deprecated names. -anyfunc, Type::Funcref +anyfunc, Type::FuncRef f32.convert_s/i32, TokenType::Convert, Opcode::F32ConvertI32S f32.convert_s/i64, TokenType::Convert, Opcode::F32ConvertI64S f32.convert_u/i32, TokenType::Convert, Opcode::F32ConvertI32U diff --git a/src/prebuilt/lexer-keywords.cc b/src/prebuilt/lexer-keywords.cc index b6bdd227d..adbe22487 100644 --- a/src/prebuilt/lexer-keywords.cc +++ b/src/prebuilt/lexer-keywords.cc @@ -198,7 +198,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len) {"mut", TokenType::Mut}, {""}, {""}, #line 49 "src/lexer-keywords.txt" - {"exn", Type::Exnref, TokenType::Exn}, + {"exn", Type::ExnRef, TokenType::Exn}, #line 127 "src/lexer-keywords.txt" {"f64.ne", TokenType::Compare, Opcode::F64Ne}, #line 77 "src/lexer-keywords.txt" @@ -216,7 +216,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len) {"event", TokenType::Event}, {""}, #line 50 "src/lexer-keywords.txt" - {"exnref", Type::Exnref}, + {"exnref", Type::ExnRef}, {""}, #line 119 "src/lexer-keywords.txt" {"f64.le", TokenType::Compare, Opcode::F64Le}, @@ -233,10 +233,10 @@ Perfect_Hash::InWordSet (const char *str, size_t len) #line 488 "src/lexer-keywords.txt" {"result", TokenType::Result}, #line 155 "src/lexer-keywords.txt" - {"funcref", Type::Funcref}, + {"funcref", Type::FuncRef}, {""}, {""}, {""}, #line 51 "src/lexer-keywords.txt" - {"extern", Type::Externref, TokenType::Extern}, + {"extern", Type::ExternRef, TokenType::Extern}, #line 492 "src/lexer-keywords.txt" {"return", TokenType::Return, Opcode::Return}, #line 504 "src/lexer-keywords.txt" @@ -266,7 +266,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len) #line 73 "src/lexer-keywords.txt" {"f32.min", TokenType::Binary, Opcode::F32Min}, #line 52 "src/lexer-keywords.txt" - {"externref", Type::Externref}, + {"externref", Type::ExternRef}, {""}, {""}, {""}, {""}, {""}, {""}, #line 398 "src/lexer-keywords.txt" {"i64.store32", TokenType::Store, Opcode::I64Store32}, @@ -297,7 +297,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len) #line 205 "src/lexer-keywords.txt" {"i32.and", TokenType::Binary, Opcode::I32And}, #line 156 "src/lexer-keywords.txt" - {"func", Type::Funcref, TokenType::Func}, + {"func", Type::FuncRef, TokenType::Func}, {""}, {""}, #line 153 "src/lexer-keywords.txt" {"f64x2", TokenType::F64X2}, @@ -977,7 +977,7 @@ Perfect_Hash::InWordSet (const char *str, size_t len) {"i32.atomic.rmw8.cmpxchg_u", TokenType::AtomicRmwCmpxchg, Opcode::I32AtomicRmw8CmpxchgU}, {""}, {""}, #line 527 "src/lexer-keywords.txt" - {"anyfunc", Type::Funcref}, + {"anyfunc", Type::FuncRef}, {""}, {""}, {""}, {""}, {""}, #line 474 "src/lexer-keywords.txt" {"memory", TokenType::Memory}, diff --git a/src/shared-validator.cc b/src/shared-validator.cc index a2bc3539a..f4a7303e4 100644 --- a/src/shared-validator.cc +++ b/src/shared-validator.cc @@ -119,7 +119,7 @@ Result SharedValidator::OnTable(const Location& loc, if (limits.is_shared) { result |= PrintError(loc, "tables may not be shared"); } - if (elem_type != Type::Funcref && + if (elem_type != Type::FuncRef && !options_.features.reference_types_enabled()) { result |= PrintError(loc, "tables must have funcref type"); } @@ -220,7 +220,7 @@ Result SharedValidator::OnGlobalInitExpr_RefFunc(const Location& loc, Result result = Result::Ok; result |= CheckFuncIndex(func_var); init_expr_funcs_.push_back(func_var); - result |= CheckType(loc, Type::Funcref, globals_.back().type, + result |= CheckType(loc, Type::FuncRef, globals_.back().type, "global initializer expression"); return result; } diff --git a/src/test-interp.cc b/src/test-interp.cc index f33d4f2d0..737f440c2 100644 --- a/src/test-interp.cc +++ b/src/test-interp.cc @@ -575,7 +575,7 @@ TEST_F(InterpGCTest, Collect_Basic) { } TEST_F(InterpGCTest, Collect_GlobalCycle) { - auto gt = GlobalType{ValueType::Externref, Mutability::Var}; + auto gt = GlobalType{ValueType::ExternRef, Mutability::Var}; auto g1 = Global::New(store_, gt, Value::Make(Ref::Null)); auto g2 = Global::New(store_, gt, Value::Make(g1->self())); g1->Set(store_, g2->self()); @@ -593,7 +593,7 @@ TEST_F(InterpGCTest, Collect_GlobalCycle) { } TEST_F(InterpGCTest, Collect_TableCycle) { - auto tt = TableType{ValueType::Externref, Limits{2}}; + auto tt = TableType{ValueType::ExternRef, Limits{2}}; auto t1 = Table::New(store_, tt); auto t2 = Table::New(store_, tt); auto t3 = Table::New(store_, tt); @@ -645,7 +645,7 @@ TEST_F(InterpGCTest, Collect_InstanceImport) { auto f = HostFunc::New(store_, FuncType{{}, {}}, [](Thread& thread, const Values&, Values&, Trap::Ptr*) -> Result { return Result::Ok; }); - auto t = Table::New(store_, TableType{ValueType::Funcref, Limits{0}}); + auto t = Table::New(store_, TableType{ValueType::FuncRef, Limits{0}}); auto m = Memory::New(store_, MemoryType{Limits{0}}); auto g = Global::New(store_, GlobalType{ValueType::I32, Mutability::Const}, Value::Make(5)); diff --git a/src/token.def b/src/token.def index df9f8fdcc..23d5d796b 100644 --- a/src/token.def +++ b/src/token.def @@ -20,6 +20,7 @@ /* Tokens with no additional data (i.e. bare). */ WABT_TOKEN(Invalid, "Invalid") +WABT_TOKEN(Array, "array") WABT_TOKEN(AssertExhaustion, "assert_exhaustion") WABT_TOKEN(AssertInvalid, "assert_invalid") WABT_TOKEN(AssertMalformed, "assert_malformed") @@ -55,6 +56,7 @@ WABT_TOKEN(Result, "result") WABT_TOKEN(Rpar, ")") WABT_TOKEN(Shared, "shared") WABT_TOKEN(Start, "start") +WABT_TOKEN(Struct, "struct") WABT_TOKEN(Table, "table") WABT_TOKEN(Then, "then") WABT_TOKEN(Type, "type") @@ -160,7 +162,5 @@ WABT_TOKEN_LAST(Type, ValueType) WABT_TOKEN(Func, "func") WABT_TOKEN(Extern, "extern") WABT_TOKEN(Exn, "exn") -WABT_TOKEN(Struct, "struct") -WABT_TOKEN(Array, "array") WABT_TOKEN_FIRST(RefKind, Func) -WABT_TOKEN_LAST(RefKind, Array) +WABT_TOKEN_LAST(RefKind, Exn) diff --git a/src/tools/spectest-interp.cc b/src/tools/spectest-interp.cc index 1a85e7904..693f2eaa7 100644 --- a/src/tools/spectest-interp.cc +++ b/src/tools/spectest-interp.cc @@ -587,11 +587,11 @@ wabt::Result JSONParser::ParseType(Type* out_type) { } else if (type_str == "i16") { *out_type = Type::I16; } else if (type_str == "funcref") { - *out_type = Type::Funcref; + *out_type = Type::FuncRef; } else if (type_str == "externref") { - *out_type = Type::Externref; + *out_type = Type::ExternRef; } else if (type_str == "exnref") { - *out_type = Type::Exnref; + *out_type = Type::ExnRef; } else { PrintError("unknown type: \"%s\"", type_str.c_str()); return wabt::Result::Error; @@ -803,7 +803,7 @@ wabt::Result JSONParser::ParseConstValue(Type type, assert(false); // Should use ParseLaneConstValue instead. break; - case Type::Funcref: + case Type::FuncRef: if (value_str == "null") { out_value->Set(Ref::Null); } else { @@ -812,7 +812,7 @@ wabt::Result JSONParser::ParseConstValue(Type type, } break; - case Type::Externref: + case Type::ExternRef: if (value_str == "null") { out_value->Set(Ref::Null); } else { @@ -1230,7 +1230,7 @@ CommandRunner::CommandRunner() : store_(s_features) { } spectest["table"] = - interp::Table::New(store_, TableType{ValueType::Funcref, Limits{10, 20}}); + interp::Table::New(store_, TableType{ValueType::FuncRef, Limits{10, 20}}); spectest["memory"] = interp::Memory::New(store_, MemoryType{Limits{1, 2}}); @@ -1723,13 +1723,13 @@ wabt::Result CommandRunner::CheckAssertReturnResult( break; } - case Type::Funcref: + case Type::FuncRef: // A funcref expectation only requires that the reference be a function, // but it doesn't check the actual index. - ok = (actual.type == Type::Funcref); + ok = (actual.type == Type::FuncRef); break; - case Type::Externref: + case Type::ExternRef: ok = expected.value.value.Get() == actual.value.Get(); break; diff --git a/src/type-checker.cc b/src/type-checker.cc index 77474a120..a025a4a84 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -390,7 +390,7 @@ Result TypeChecker::OnBrIf(Index depth) { } Result TypeChecker::OnBrOnExn(Index depth, const TypeVector& types) { - Result result = PopAndCheck1Type(Type::Exnref, "br_on_exn"); + Result result = PopAndCheck1Type(Type::ExnRef, "br_on_exn"); Label* label; CHECK_RESULT(GetLabel(depth, &label)); if (Failed(CheckTypes(types, label->br_types()))) { @@ -399,7 +399,7 @@ Result TypeChecker::OnBrOnExn(Index depth, const TypeVector& types) { TypesToString(types).c_str()); result = Result::Error; } - PushType(Type::Exnref); + PushType(Type::ExnRef); return result; } @@ -497,7 +497,7 @@ Result TypeChecker::OnCatch() { ResetTypeStackToLabel(label); label->label_type = LabelType::Catch; label->unreachable = false; - PushType(Type::Exnref); + PushType(Type::ExnRef); return result; } @@ -671,7 +671,7 @@ Result TypeChecker::OnTableFill(Type elem_type) { } Result TypeChecker::OnRefFuncExpr(Index) { - PushType(Type::Funcref); + PushType(Type::FuncRef); return Result::Ok; } @@ -687,7 +687,7 @@ Result TypeChecker::OnRefIsNullExpr(Type type) { } Result TypeChecker::OnRethrow() { - Result result = PopAndCheck1Type(Type::Exnref, "rethrow"); + Result result = PopAndCheck1Type(Type::ExnRef, "rethrow"); CHECK_RESULT(SetUnreachable()); return result; } diff --git a/src/type.h b/src/type.h index 841a5da11..ad7525d55 100644 --- a/src/type.h +++ b/src/type.h @@ -38,9 +38,9 @@ class Type { V128 = -0x05, // 0x7b I8 = -0x06, // 0x7a : packed-type only, used in gc and as v128 lane I16 = -0x07, // 0x79 : packed-type only, used in gc and as v128 lane - Funcref = -0x10, // 0x70 - Externref = -0x11, // 0x6f - Exnref = -0x18, // 0x68 + FuncRef = -0x10, // 0x70 + ExternRef = -0x11, // 0x6f + ExnRef = -0x18, // 0x68 Func = -0x20, // 0x60 Struct = -0x21, // 0x5f Array = -0x22, // 0x5e @@ -59,8 +59,8 @@ class Type { operator Enum() const { return enum_; } bool IsRef() const { - return enum_ == Type::Externref || enum_ == Type::Funcref || - enum_ == Type::Exnref; + return enum_ == Type::ExternRef || enum_ == Type::FuncRef || + enum_ == Type::ExnRef; } bool IsNullableRef() const { @@ -77,21 +77,21 @@ class Type { case Type::V128: return "v128"; case Type::I8: return "i8"; case Type::I16: return "i16"; - case Type::Funcref: return "funcref"; + case Type::FuncRef: return "funcref"; case Type::Func: return "func"; - case Type::Exnref: return "exnref"; + case Type::ExnRef: return "exnref"; case Type::Void: return "void"; case Type::Any: return "any"; - case Type::Externref: return "externref"; + case Type::ExternRef: return "externref"; default: return ""; } } const char* GetRefKindName() const { switch (enum_) { - case Type::Funcref: return "func"; - case Type::Externref: return "extern"; - case Type::Exnref: return "exn"; + case Type::FuncRef: return "func"; + case Type::ExternRef: return "extern"; + case Type::ExnRef: return "exn"; case Type::Struct: return "struct"; case Type::Array: return "array"; default: return ""; @@ -128,9 +128,9 @@ class Type { case Type::F32: case Type::F64: case Type::V128: - case Type::Funcref: - case Type::Externref: - case Type::Exnref: + case Type::FuncRef: + case Type::ExternRef: + case Type::ExnRef: return TypeVector(this, this + 1); default: diff --git a/src/wast-parser.cc b/src/wast-parser.cc index d3f94cc32..88189f0ab 100644 --- a/src/wast-parser.cc +++ b/src/wast-parser.cc @@ -780,11 +780,11 @@ Result WastParser::ParseValueType(Type* out_type) { case Type::V128: is_enabled = options_->features.simd_enabled(); break; - case Type::Funcref: - case Type::Externref: + case Type::FuncRef: + case Type::ExternRef: is_enabled = options_->features.reference_types_enabled(); break; - case Type::Exnref: + case Type::ExnRef: is_enabled = options_->features.exceptions_enabled(); break; default: @@ -818,7 +818,7 @@ Result WastParser::ParseRefKind(Type* out_type) { Token token = Consume(); Type type = token.type(); - if ((type == Type::Externref && + if ((type == Type::ExternRef && !options_->features.reference_types_enabled()) || ((type == Type::Struct || type == Type::Array) && !options_->features.gc_enabled())) { @@ -838,7 +838,7 @@ Result WastParser::ParseRefType(Type* out_type) { Token token = Consume(); Type type = token.type(); - if (type == Type::Externref && + if (type == Type::ExternRef && !options_->features.reference_types_enabled()) { Error(token.loc, "value type not allowed: %s", type.GetName()); return Result::Error; @@ -856,7 +856,7 @@ bool WastParser::ParseRefTypeOpt(Type* out_type) { Token token = Consume(); Type type = token.type(); - if (type == Type::Externref && + if (type == Type::ExternRef && !options_->features.reference_types_enabled()) { return false; } @@ -1131,7 +1131,7 @@ Result WastParser::ParseElemModuleField(Module* module) { if (ParseRefTypeOpt(&field->elem_segment.elem_type)) { ParseElemExprListOpt(&field->elem_segment.elem_exprs); } else { - field->elem_segment.elem_type = Type::Funcref; + field->elem_segment.elem_type = Type::FuncRef; if (PeekMatch(TokenType::Func)) { EXPECT(Func); } diff --git a/src/wat-writer.cc b/src/wat-writer.cc index 2cadaa382..573cb6f44 100644 --- a/src/wat-writer.cc +++ b/src/wat-writer.cc @@ -1286,7 +1286,7 @@ void WatWriter::WriteElemSegment(const ElemSegment& segment) { if (flags & SegUseElemExprs) { WriteType(segment.elem_type, NextChar::Space); } else { - assert(segment.elem_type == Type::Funcref); + assert(segment.elem_type == Type::FuncRef); WritePuts("func", NextChar::Space); }