From 95dc655bf8a6999b59ef8f93194526a0e64d2d23 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 15 Oct 2020 18:04:44 +0000 Subject: [PATCH] [ast] Change module dump order. This CL changes the AST dumping order to emit alias types before global variables. This makes the output easier to read as the types come before the usages. Bug: tint:175 Change-Id: Ib7325384b910472e89d6d01853503be989ce4210 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30281 Reviewed-by: Ryan Harrison Commit-Queue: dan sinclair --- src/ast/module.cc | 6 +- src/reader/spirv/function_memory_test.cc | 10 ++-- .../spirv/parser_impl_module_var_test.cc | 40 ++++++------- .../vertex_pulling_transform_test.cc | 60 +++++++++---------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/ast/module.cc b/src/ast/module.cc index dfb2ab8450..48731cc5f9 100644 --- a/src/ast/module.cc +++ b/src/ast/module.cc @@ -74,9 +74,6 @@ std::string Module::to_str() const { out << "Module{" << std::endl; const auto indent = 2; - for (const auto& var : global_variables_) { - var->to_str(out, indent); - } for (auto* const alias : alias_types_) { for (size_t i = 0; i < indent; ++i) { out << " "; @@ -86,6 +83,9 @@ std::string Module::to_str() const { alias->type()->AsStruct()->impl()->to_str(out, indent); } } + for (const auto& var : global_variables_) { + var->to_str(out, indent); + } for (const auto& func : functions_) { func->to_str(out, indent); } diff --git a/src/reader/spirv/function_memory_test.cc b/src/reader/spirv/function_memory_test.cc index 267ae07600..6c6b87153a 100644 --- a/src/reader/spirv/function_memory_test.cc +++ b/src/reader/spirv/function_memory_test.cc @@ -799,17 +799,17 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) { << assembly << p->error(); const auto module_str = p->module().to_str(); EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - myvar - storage_buffer - __alias_S__struct_S - } RTArr -> __array__u32_stride_4 S -> __struct_S Struct{ [[block]] StructMember{[[ offset 0 ]] field0: __u32} StructMember{[[ offset 4 ]] field1: __alias_RTArr__array__u32_stride_4} + } + Variable{ + myvar + storage_buffer + __alias_S__struct_S })")); } diff --git a/src/reader/spirv/parser_impl_module_var_test.cc b/src/reader/spirv/parser_impl_module_var_test.cc index 06a81c8243..6831cd85ef 100644 --- a/src/reader/spirv/parser_impl_module_var_test.cc +++ b/src/reader/spirv/parser_impl_module_var_test.cc @@ -1305,11 +1305,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonReadableDecoration_DroppedForNow) { EXPECT_TRUE(p->error().empty()); const auto module_str = p->module().to_str(); EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - myvar - storage_buffer - __alias_S__struct_S - } S -> __struct_S Struct{ [[block]] @@ -1317,6 +1312,11 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonReadableDecoration_DroppedForNow) { StructMember{field1: __f32} StructMember{field2: __array__u32_2} } + Variable{ + myvar + storage_buffer + __alias_S__struct_S + } })")) << module_str; } @@ -1333,11 +1333,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonWritableDecoration_DroppedForNow) { EXPECT_TRUE(p->error().empty()); const auto module_str = p->module().to_str(); EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - myvar - storage_buffer - __alias_S__struct_S - } S -> __struct_S Struct{ [[block]] @@ -1345,6 +1340,11 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonWritableDecoration_DroppedForNow) { StructMember{field1: __f32} StructMember{field2: __array__u32_2} } + Variable{ + myvar + storage_buffer + __alias_S__struct_S + } })")) << module_str; } @@ -1365,16 +1365,16 @@ TEST_F(SpvParserTest, ModuleScopeVar_ColMajorDecoration_Dropped) { EXPECT_TRUE(p->error().empty()); const auto module_str = p->module().to_str(); EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - myvar - storage_buffer - __alias_S__struct_S - } S -> __struct_S Struct{ [[block]] StructMember{field0: __mat_2_3__f32} } + Variable{ + myvar + storage_buffer + __alias_S__struct_S + } })")) << module_str; } @@ -1395,16 +1395,16 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixStrideDecoration_Dropped) { EXPECT_TRUE(p->error().empty()); const auto module_str = p->module().to_str(); EXPECT_THAT(module_str, HasSubstr(R"( - Variable{ - myvar - storage_buffer - __alias_S__struct_S - } S -> __struct_S Struct{ [[block]] StructMember{field0: __mat_2_3__f32} } + Variable{ + myvar + storage_buffer + __alias_S__struct_S + } })")) << module_str; } diff --git a/src/transform/vertex_pulling_transform_test.cc b/src/transform/vertex_pulling_transform_test.cc index cc44466d7b..73fdaad087 100644 --- a/src/transform/vertex_pulling_transform_test.cc +++ b/src/transform/vertex_pulling_transform_test.cc @@ -136,6 +136,11 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -158,11 +163,6 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} () @@ -222,6 +222,11 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -244,11 +249,6 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} () @@ -308,6 +308,11 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -330,11 +335,6 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} () @@ -424,6 +424,11 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -468,11 +473,6 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} () @@ -565,6 +565,11 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -592,11 +597,6 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} () @@ -751,6 +751,11 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { EXPECT_TRUE(transform()->Run()); EXPECT_EQ(R"(Module{ + TintVertexData -> __struct_TintVertexData + Struct{ + [[block]] + StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} + } Variable{ var_a private @@ -801,11 +806,6 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { storage_buffer __alias_TintVertexData__struct_TintVertexData } - TintVertexData -> __struct_TintVertexData - Struct{ - [[block]] - StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4} - } Function main -> __void StageDecoration{vertex} ()