[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 <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2020-10-15 18:04:44 +00:00 committed by Commit Bot service account
parent 481ecff293
commit 95dc655bf8
4 changed files with 58 additions and 58 deletions

View File

@ -74,9 +74,6 @@ std::string Module::to_str() const {
out << "Module{" << std::endl; out << "Module{" << std::endl;
const auto indent = 2; const auto indent = 2;
for (const auto& var : global_variables_) {
var->to_str(out, indent);
}
for (auto* const alias : alias_types_) { for (auto* const alias : alias_types_) {
for (size_t i = 0; i < indent; ++i) { for (size_t i = 0; i < indent; ++i) {
out << " "; out << " ";
@ -86,6 +83,9 @@ std::string Module::to_str() const {
alias->type()->AsStruct()->impl()->to_str(out, indent); alias->type()->AsStruct()->impl()->to_str(out, indent);
} }
} }
for (const auto& var : global_variables_) {
var->to_str(out, indent);
}
for (const auto& func : functions_) { for (const auto& func : functions_) {
func->to_str(out, indent); func->to_str(out, indent);
} }

View File

@ -799,17 +799,17 @@ TEST_F(SpvParserTest, RemapStorageBuffer_TypesAndVarDeclarations) {
<< assembly << p->error(); << assembly << p->error();
const auto module_str = p->module().to_str(); const auto module_str = p->module().to_str();
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
RTArr -> __array__u32_stride_4 RTArr -> __array__u32_stride_4
S -> __struct_S S -> __struct_S
Struct{ Struct{
[[block]] [[block]]
StructMember{[[ offset 0 ]] field0: __u32} StructMember{[[ offset 0 ]] field0: __u32}
StructMember{[[ offset 4 ]] field1: __alias_RTArr__array__u32_stride_4} StructMember{[[ offset 4 ]] field1: __alias_RTArr__array__u32_stride_4}
}
Variable{
myvar
storage_buffer
__alias_S__struct_S
})")); })"));
} }

View File

@ -1305,11 +1305,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonReadableDecoration_DroppedForNow) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str = p->module().to_str();
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
S -> __struct_S S -> __struct_S
Struct{ Struct{
[[block]] [[block]]
@ -1317,6 +1312,11 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonReadableDecoration_DroppedForNow) {
StructMember{field1: __f32} StructMember{field1: __f32}
StructMember{field2: __array__u32_2} StructMember{field2: __array__u32_2}
} }
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
})")) << module_str; })")) << module_str;
} }
@ -1333,11 +1333,6 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonWritableDecoration_DroppedForNow) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str = p->module().to_str();
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
S -> __struct_S S -> __struct_S
Struct{ Struct{
[[block]] [[block]]
@ -1345,6 +1340,11 @@ TEST_F(SpvParserTest, ModuleScopeVar_NonWritableDecoration_DroppedForNow) {
StructMember{field1: __f32} StructMember{field1: __f32}
StructMember{field2: __array__u32_2} StructMember{field2: __array__u32_2}
} }
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
})")) << module_str; })")) << module_str;
} }
@ -1365,16 +1365,16 @@ TEST_F(SpvParserTest, ModuleScopeVar_ColMajorDecoration_Dropped) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str = p->module().to_str();
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
S -> __struct_S S -> __struct_S
Struct{ Struct{
[[block]] [[block]]
StructMember{field0: __mat_2_3__f32} StructMember{field0: __mat_2_3__f32}
} }
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
})")) << module_str; })")) << module_str;
} }
@ -1395,16 +1395,16 @@ TEST_F(SpvParserTest, ModuleScopeVar_MatrixStrideDecoration_Dropped) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str = p->module().to_str();
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
S -> __struct_S S -> __struct_S
Struct{ Struct{
[[block]] [[block]]
StructMember{field0: __mat_2_3__f32} StructMember{field0: __mat_2_3__f32}
} }
Variable{
myvar
storage_buffer
__alias_S__struct_S
}
})")) << module_str; })")) << module_str;
} }

View File

@ -136,6 +136,11 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -158,11 +163,6 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -222,6 +222,11 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -244,11 +249,6 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -308,6 +308,11 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -330,11 +335,6 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -424,6 +424,11 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -468,11 +473,6 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -565,6 +565,11 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -592,11 +597,6 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
@ -751,6 +751,11 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
EXPECT_TRUE(transform()->Run()); EXPECT_TRUE(transform()->Run());
EXPECT_EQ(R"(Module{ EXPECT_EQ(R"(Module{
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Variable{ Variable{
var_a var_a
private private
@ -801,11 +806,6 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
storage_buffer storage_buffer
__alias_TintVertexData__struct_TintVertexData __alias_TintVertexData__struct_TintVertexData
} }
TintVertexData -> __struct_TintVertexData
Struct{
[[block]]
StructMember{[[ offset 0 ]] _tint_vertex_data: __array__u32_stride_4}
}
Function main -> __void Function main -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()