mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 22:17:51 +00:00
ast: Add type nodes
Copy all of the type classes from src/type into ast. Required the merging of: * type::Struct into the existing ast::Struct - ast::Struct now has a name. * type::AccessControl into the existing ast::AccessControl enumerator - The old ast::AccessControl enumerator is now ast::AccessControl::Access Bug: tint:724 Change-Id: Ibb950036ed551ec769c6d3d2c8fb411809cf6931 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48383 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
ba6f260629
commit
8a8d26bbd9
@@ -1338,7 +1338,8 @@ bool FunctionEmitter::LabelControlFlowConstructs() {
|
||||
if (top->ContainsPos(target0_pos) &&
|
||||
top->ContainsPos(target1_pos)) {
|
||||
// Insert a synthetic if-selection
|
||||
top = push_construct(depth+1, Construct::kIfSelection, header, ct);
|
||||
top = push_construct(depth + 1, Construct::kIfSelection, header,
|
||||
ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
RTArr -> __array__u32_stride_4
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{[[ offset 0 ]] field0: __u32}
|
||||
StructMember{[[ offset 4 ]] field1: __alias_RTArr__array__u32_stride_4}
|
||||
|
||||
@@ -551,7 +551,7 @@ Source ParserImpl::GetSourceForInst(
|
||||
if (where == inst_source_.end()) {
|
||||
return {};
|
||||
}
|
||||
return Source{where->second };
|
||||
return Source{where->second};
|
||||
}
|
||||
|
||||
bool ParserImpl::ParseInternalModuleExceptFunctions() {
|
||||
@@ -940,15 +940,16 @@ sem::Type* ParserImpl::ConvertType(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Now make the struct.
|
||||
auto* ast_struct = create<ast::Struct>(Source{}, std::move(ast_members),
|
||||
std::move(ast_struct_decorations));
|
||||
|
||||
namer_.SuggestSanitizedName(type_id, "S");
|
||||
|
||||
auto name = namer_.GetName(type_id);
|
||||
auto* result = builder_.create<sem::StructType>(
|
||||
builder_.Symbols().Register(name), ast_struct);
|
||||
|
||||
// Now make the struct.
|
||||
auto sym = builder_.Symbols().Register(name);
|
||||
auto* ast_struct = create<ast::Struct>(Source{}, sym, std::move(ast_members),
|
||||
std::move(ast_struct_decorations));
|
||||
|
||||
auto* result = builder_.create<sem::StructType>(sym, ast_struct);
|
||||
id_to_type_[type_id] = result;
|
||||
if (num_non_writable_members == members.size()) {
|
||||
read_only_struct_types_.insert(result);
|
||||
|
||||
@@ -553,7 +553,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
|
||||
EXPECT_TRUE(type->Is<sem::StructType>());
|
||||
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct S {
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __f32}
|
||||
}
|
||||
@@ -574,7 +574,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
|
||||
EXPECT_TRUE(type->Is<sem::StructType>());
|
||||
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __u32}
|
||||
}
|
||||
@@ -599,7 +599,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
|
||||
EXPECT_TRUE(type->Is<sem::StructType>());
|
||||
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct{
|
||||
EXPECT_THAT(program.str(type->As<sem::StructType>()->impl()), Eq(R"(Struct S {
|
||||
StructMember{[[ offset 0 ]] field0: __f32}
|
||||
StructMember{[[ offset 8 ]] field1: __vec_2__f32}
|
||||
StructMember{[[ offset 16 ]] field2: __mat_2_2__f32}
|
||||
|
||||
@@ -1654,7 +1654,7 @@ TEST_F(SpvModuleScopeVarParserTest,
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __f32}
|
||||
@@ -1685,7 +1685,7 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __mat_2_3__f32}
|
||||
}
|
||||
@@ -1714,7 +1714,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Dropped) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __mat_2_3__f32}
|
||||
}
|
||||
@@ -1763,7 +1763,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __f32}
|
||||
StructMember{field1: __f32}
|
||||
@@ -1792,7 +1792,7 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __f32}
|
||||
StructMember{field1: __f32}
|
||||
@@ -1824,7 +1824,7 @@ TEST_F(
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
S Struct{
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{field0: __f32}
|
||||
StructMember{field1: __f32}
|
||||
|
||||
@@ -29,7 +29,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) {
|
||||
%s = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("S Struct"));
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("Struct S"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
|
||||
@@ -39,7 +39,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
|
||||
%s = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("mystruct Struct"));
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("Struct mystruct"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
|
||||
@@ -49,11 +49,11 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
|
||||
%s2 = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr(R"(S Struct{
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr(R"(Struct S {
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __u32}
|
||||
}
|
||||
S_1 Struct{
|
||||
Struct S_1 {
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __u32}
|
||||
})"));
|
||||
|
||||
@@ -836,7 +836,7 @@ Expect<ParserImpl::TypedIdentifier> ParserImpl::expect_variable_ident_decl(
|
||||
return TypedIdentifier{ty, ident.value, ident.source};
|
||||
}
|
||||
|
||||
Expect<ast::AccessControl> ParserImpl::expect_access_type() {
|
||||
Expect<ast::AccessControl::Access> ParserImpl::expect_access_type() {
|
||||
auto ident = expect_ident("access_type");
|
||||
if (ident.errored)
|
||||
return Failure::kErrored;
|
||||
@@ -1134,9 +1134,10 @@ Maybe<sem::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
|
||||
if (body.errored)
|
||||
return Failure::kErrored;
|
||||
|
||||
auto sym = builder_.Symbols().Register(name.value);
|
||||
return create<sem::StructType>(
|
||||
builder_.Symbols().Register(name.value),
|
||||
create<ast::Struct>(source, std::move(body.value), std::move(decos)));
|
||||
sym, create<ast::Struct>(source, sym, std::move(body.value),
|
||||
std::move(decos)));
|
||||
}
|
||||
|
||||
// struct_body_decl
|
||||
|
||||
@@ -437,7 +437,7 @@ class ParserImpl {
|
||||
/// Parses an access type identifier, erroring if the next token does not
|
||||
/// match a valid access type name.
|
||||
/// @returns the parsed access control.
|
||||
Expect<ast::AccessControl> expect_access_type();
|
||||
Expect<ast::AccessControl::Access> expect_access_type();
|
||||
/// Parses a builtin identifier, erroring if the next token does not match a
|
||||
/// valid builtin name.
|
||||
/// @returns the parsed builtin.
|
||||
|
||||
@@ -115,7 +115,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
@@ -140,7 +140,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
@@ -165,7 +165,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
@@ -187,7 +187,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
@@ -225,7 +225,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
Reference in New Issue
Block a user