From 42d1e097e6292172a872709bb9f199bdbdd2a349 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 2 Feb 2021 14:29:15 +0000 Subject: [PATCH] Have ProgramBuilder::Func() register the function With the ast::Module::Functions(). Also remove pointless calls to td.Determine() that will automatically be done when the program is built. Change-Id: Ia7506e430b04d91d4f6b02fb6b678d0ea9912bcd Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39900 Commit-Queue: dan sinclair Reviewed-by: dan sinclair --- src/ast/module_test.cc | 12 +- src/inspector/inspector_test.cc | 361 +++++------- src/program_builder.h | 30 +- src/program_builder_test.cc | 6 +- src/program_test.cc | 10 +- src/reader/spirv/function.cc | 3 +- src/type_determiner_test.cc | 93 ++-- src/validator/validator_function_test.cc | 231 ++++---- src/validator/validator_test.cc | 99 ++-- src/validator/validator_type_test.cc | 46 +- src/writer/hlsl/generator_impl_binary_test.cc | 5 +- src/writer/hlsl/generator_impl_call_test.cc | 15 +- ...tor_impl_function_entry_point_data_test.cc | 154 +++--- .../hlsl/generator_impl_function_test.cc | 515 +++++++----------- .../hlsl/generator_impl_intrinsic_test.cc | 1 - src/writer/hlsl/generator_impl_test.cc | 5 +- src/writer/hlsl/test_helper.h | 7 +- src/writer/msl/generator_impl_call_test.cc | 15 +- ...tor_impl_function_entry_point_data_test.cc | 91 ++-- .../msl/generator_impl_function_test.cc | 352 +++++------- .../msl/generator_impl_intrinsic_test.cc | 1 - src/writer/msl/generator_impl_test.cc | 10 +- src/writer/msl/test_helper.h | 7 +- src/writer/spirv/builder_function_test.cc | 109 ++-- .../spirv/builder_intrinsic_texture_test.cc | 17 +- src/writer/spirv/test_helper.h | 7 +- .../wgsl/generator_impl_function_test.cc | 40 +- src/writer/wgsl/generator_impl_test.cc | 5 +- 28 files changed, 893 insertions(+), 1354 deletions(-) diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 2f62568322..0be0aedda9 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -44,7 +44,7 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) { TEST_F(ModuleTest, LookupFunction) { auto* func = Func("main", VariableList{}, ty.f32(), StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Program program(std::move(*this)); EXPECT_EQ(func, program.AST().Functions().Find(program.Symbols().Get("main"))); @@ -111,10 +111,9 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) { } TEST_F(ModuleTest, IsValid_Function) { - auto* func = Func("main", VariableList(), ty.f32(), StatementList{}, - ast::FunctionDecorationList{}); + Func("main", VariableList(), ty.f32(), StatementList{}, + ast::FunctionDecorationList{}); - AST().Functions().Add(func); Program program(std::move(*this)); EXPECT_TRUE(program.AST().IsValid()); } @@ -126,10 +125,9 @@ TEST_F(ModuleTest, IsValid_Null_Function) { } TEST_F(ModuleTest, IsValid_Invalid_Function) { - auto* func = Func("main", VariableList{}, nullptr, StatementList{}, - ast::FunctionDecorationList{}); + Func("main", VariableList{}, nullptr, StatementList{}, + ast::FunctionDecorationList{}); - AST().Functions().Add(func); Program program(std::move(*this)); EXPECT_FALSE(program.AST().IsValid()); } diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 572b6c0cf0..de785417e5 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -76,30 +76,25 @@ class InspectorHelper : public ProgramBuilder { /// Generates an empty function /// @param name name of the function created /// @param decorations the function decorations - /// @returns a function object - ast::Function* MakeEmptyBodyFunction( - std::string name, - ast::FunctionDecorationList decorations) { - return Func(name, ast::VariableList(), ty.void_(), - ast::StatementList{create()}, - decorations); + void MakeEmptyBodyFunction(std::string name, + ast::FunctionDecorationList decorations) { + Func(name, ast::VariableList(), ty.void_(), + ast::StatementList{create()}, decorations); } /// Generates a function that calls another /// @param caller name of the function created /// @param callee name of the function to be called /// @param decorations the function decorations - /// @returns a function object - ast::Function* MakeCallerBodyFunction( - std::string caller, - std::string callee, - ast::FunctionDecorationList decorations) { - return Func(caller, ast::VariableList(), ty.void_(), - ast::StatementList{ - create(Call(callee)), - create(), - }, - decorations); + void MakeCallerBodyFunction(std::string caller, + std::string callee, + ast::FunctionDecorationList decorations) { + Func(caller, ast::VariableList(), ty.void_(), + ast::StatementList{ + create(Call(callee)), + create(), + }, + decorations); } /// Add In/Out variables to the global variables @@ -128,8 +123,7 @@ class InspectorHelper : public ProgramBuilder { /// @param inout_vars tuples of {in, out} that will be converted into out = in /// calls in the function body /// @param decorations the function decorations - /// @returns a function object - ast::Function* MakeInOutVariableBodyFunction( + void MakeInOutVariableBodyFunction( std::string name, std::vector> inout_vars, ast::FunctionDecorationList decorations) { @@ -140,7 +134,7 @@ class InspectorHelper : public ProgramBuilder { stmts.emplace_back(create(Expr(out), Expr(in))); } stmts.emplace_back(create()); - return Func(name, ast::VariableList(), ty.void_(), stmts, decorations); + Func(name, ast::VariableList(), ty.void_(), stmts, decorations); } /// Generates a function that references in/out variables and calls another @@ -363,8 +357,7 @@ class InspectorHelper : public ProgramBuilder { /// @param func_name name of the function created /// @param struct_name name of the struct variabler to be accessed /// @param members list of members to access, by index and type - /// @returns a function that references all of the members specified - ast::Function* MakeStructVariableReferenceBodyFunction( + void MakeStructVariableReferenceBodyFunction( std::string func_name, std::string struct_name, std::vector> members) { @@ -392,8 +385,8 @@ class InspectorHelper : public ProgramBuilder { stmts.emplace_back(create()); - return Func(func_name, ast::VariableList(), ty.void_(), stmts, - ast::FunctionDecorationList{}); + Func(func_name, ast::VariableList(), ty.void_(), stmts, + ast::FunctionDecorationList{}); } /// Adds a regular sampler variable to the program @@ -711,8 +704,6 @@ TEST_F(InspectorGetEntryPointTest, NoFunctions) { } TEST_F(InspectorGetEntryPointTest, NoEntryPoints) { - AST().Functions().Add(MakeEmptyBodyFunction("foo", {})); - Inspector& inspector = Build(); auto result = inspector.GetEntryPoints(); @@ -722,11 +713,10 @@ TEST_F(InspectorGetEntryPointTest, NoEntryPoints) { } TEST_F(InspectorGetEntryPointTest, OneEntryPoint) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); // TODO(dsinclair): Update to run the namer transform when available. @@ -742,17 +732,15 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) { } TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); - auto* bar = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "bar", ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), }); - AST().Functions().Add(bar); // TODO(dsinclair): Update to run the namer transform when available. @@ -771,22 +759,19 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { } TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { - auto* func = MakeEmptyBodyFunction("func", {}); - AST().Functions().Add(func); + MakeEmptyBodyFunction("func", {}); - auto* foo = MakeCallerBodyFunction( + MakeCallerBodyFunction( "foo", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); - auto* bar = MakeCallerBodyFunction( + MakeCallerBodyFunction( "bar", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment), }); - AST().Functions().Add(bar); // TODO(dsinclair): Update to run the namer transform when available. @@ -805,11 +790,10 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { } TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -825,12 +809,11 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) { } TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), create(8u, 2u, 1u), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -846,15 +829,13 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) { } TEST_F(InspectorGetEntryPointTest, NoInOutVariables) { - auto* func = MakeEmptyBodyFunction("func", {}); - AST().Functions().Add(func); + MakeEmptyBodyFunction("func", {}); - auto* foo = MakeCallerBodyFunction( + MakeCallerBodyFunction( "foo", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -869,12 +850,11 @@ TEST_F(InspectorGetEntryPointTest, NoInOutVariables) { TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) { AddInOutVariables({{"in_var", "out_var"}}); - auto* foo = MakeInOutVariableBodyFunction( + MakeInOutVariableBodyFunction( "foo", {{"in_var", "out_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -896,16 +876,13 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) { TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { AddInOutVariables({{"in_var", "out_var"}}); - auto* func = - MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); - AST().Functions().Add(func); + MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); - auto* foo = MakeCallerBodyFunction( + MakeCallerBodyFunction( "foo", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -927,16 +904,13 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) { AddInOutVariables({{"in_var", "out_var"}}); - auto* func = - MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); - AST().Functions().Add(func); + MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); - auto* foo = MakeInOutVariableCallerBodyFunction( + MakeInOutVariableCallerBodyFunction( "foo", "func", {{"in_var", "out_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -958,12 +932,11 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) { TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) { AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}}); - auto* foo = MakeInOutVariableBodyFunction( + MakeInOutVariableBodyFunction( "foo", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -991,16 +964,14 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) { TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) { AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}}); - auto* func = MakeInOutVariableBodyFunction( + MakeInOutVariableBodyFunction( "func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, {}); - AST().Functions().Add(func); - auto* foo = MakeCallerBodyFunction( + MakeCallerBodyFunction( "foo", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -1029,19 +1000,17 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) { TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}}); - auto* foo = MakeInOutVariableBodyFunction( + MakeInOutVariableBodyFunction( "foo", {{"in_var", "out2_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); - auto* bar = MakeInOutVariableBodyFunction( + MakeInOutVariableBodyFunction( "bar", {{"in2_var", "out_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), }); - AST().Functions().Add(bar); // TODO(dsinclair): Update to run the namer transform when // available. @@ -1079,23 +1048,19 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) { TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) { AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}}); - auto* func = - MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {}); - AST().Functions().Add(func); + MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {}); - auto* foo = MakeInOutVariableCallerBodyFunction( + MakeInOutVariableCallerBodyFunction( "foo", "func", {{"in_var", "out_var"}}, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); - auto* bar = MakeCallerBodyFunction( + MakeCallerBodyFunction( "bar", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), }); - AST().Functions().Add(bar); // TODO(dsinclair): Update to run the namer transform when // available. @@ -1146,16 +1111,14 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) { AST().AddGlobalVariable( Var("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr, ast::VariableDecorationList{create(0)})); - auto* func = - MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); - AST().Functions().Add(func); - auto* foo = MakeCallerBodyFunction( + MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); + + MakeCallerBodyFunction( "foo", "func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); // TODO(dsinclair): Update to run the namer transform when available. @@ -1189,8 +1152,6 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) { // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass // through TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) { - AST().Functions().Add(MakeEmptyBodyFunction("foo", {})); - Inspector& inspector = Build(); auto result = inspector.GetRemappedNameForEntryPoint("foo"); @@ -1202,11 +1163,10 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) { // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass // through TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); // TODO(dsinclair): Update to run the namer transform when // available. @@ -1223,20 +1183,18 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) { // through TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_MultipleEntryPoints) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); // TODO(dsinclair): Update to run the namer transform when // available. - auto* bar = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "bar", ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), }); - AST().Functions().Add(bar); Inspector& inspector = Build(); @@ -1364,16 +1322,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) { MakeUniformBufferTypes("foo_type", {{ty.i32(), 0}}); AddUniformBuffer("foo_ub", foo_control_type, 0, 0); - auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", - {{0, ty.i32()}}); - AST().Functions().Add(ub_func); + MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "ub_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1392,16 +1347,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) { auto* foo_type = ty.struct_("foo_type", str); AddUniformBuffer("foo_ub", foo_type, 0, 0); - auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", - {{0, ty.i32()}}); - AST().Functions().Add(ub_func); + MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "ub_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1417,16 +1369,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) { MakeUniformBufferTypes("foo_type", {{ty.i32(), 0}}); AddUniformBuffer("foo_ub", foo_control_type, 0, 0); - auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", - {{0, ty.i32()}}); - AST().Functions().Add(ub_func); + MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "ub_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1446,16 +1395,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) { "foo_type", {{ty.i32(), 0}, {ty.u32(), 4}, {ty.f32(), 8}}); AddUniformBuffer("foo_ub", foo_control_type, 0, 0); - auto* ub_func = MakeStructVariableReferenceBodyFunction( + MakeStructVariableReferenceBodyFunction( "ub_func", "foo_ub", {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}}); - AST().Functions().Add(ub_func); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "ub_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1479,9 +1426,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { auto AddReferenceFunc = [this](const std::string& func_name, const std::string& var_name) { - auto* ub_func = MakeStructVariableReferenceBodyFunction( + MakeStructVariableReferenceBodyFunction( func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}}); - AST().Functions().Add(ub_func); }; AddReferenceFunc("ub_foo_func", "ub_foo"); AddReferenceFunc("ub_bar_func", "ub_bar"); @@ -1491,15 +1437,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { return create(Call(callee)); }; - ast::Function* func = - Func("ep_func", ast::VariableList(), ty.void_(), - ast::StatementList{FuncCall("ub_foo_func"), FuncCall("ub_bar_func"), - FuncCall("ub_baz_func"), - create()}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func("ep_func", ast::VariableList(), ty.void_(), + ast::StatementList{FuncCall("ub_foo_func"), FuncCall("ub_bar_func"), + FuncCall("ub_baz_func"), + create()}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); Inspector& inspector = Build(); @@ -1527,16 +1471,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) { "foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}}); AddUniformBuffer("foo_ub", foo_control_type, 0, 0); - auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", - {{0, ty.i32()}}); - AST().Functions().Add(ub_func); + MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "ub_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1556,16 +1497,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) { MakeStorageBufferTypes("foo_type", {{ty.i32(), 0}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1585,16 +1523,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) { "foo_type", {{ty.i32(), 0}, {ty.u32(), 4}, {ty.f32(), 8}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction( + MakeStructVariableReferenceBodyFunction( "sb_func", "foo_sb", {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}}); - AST().Functions().Add(sb_func); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1618,9 +1554,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { auto AddReferenceFunc = [this](const std::string& func_name, const std::string& var_name) { - auto* sb_func = MakeStructVariableReferenceBodyFunction( + MakeStructVariableReferenceBodyFunction( func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}}); - AST().Functions().Add(sb_func); }; AddReferenceFunc("sb_foo_func", "sb_foo"); AddReferenceFunc("sb_bar_func", "sb_bar"); @@ -1630,18 +1565,16 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { return create(Call(callee)); }; - ast::Function* func = - Func("ep_func", ast::VariableList(), ty.void_(), - ast::StatementList{ - FuncCall("sb_foo_func"), - FuncCall("sb_bar_func"), - FuncCall("sb_baz_func"), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func("ep_func", ast::VariableList(), ty.void_(), + ast::StatementList{ + FuncCall("sb_foo_func"), + FuncCall("sb_bar_func"), + FuncCall("sb_baz_func"), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); Inspector& inspector = Build(); @@ -1669,16 +1602,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) { "foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1698,16 +1628,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) { "foo_type", {{ty.i32(), 0}, {u32_array_type(0), 4}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1727,16 +1654,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) { MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32(), 0}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1752,16 +1676,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) { MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32(), 0}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1786,9 +1707,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, auto AddReferenceFunc = [this](const std::string& func_name, const std::string& var_name) { - auto* sb_func = MakeStructVariableReferenceBodyFunction( + MakeStructVariableReferenceBodyFunction( func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}}); - AST().Functions().Add(sb_func); }; AddReferenceFunc("sb_foo_func", "sb_foo"); AddReferenceFunc("sb_bar_func", "sb_bar"); @@ -1798,18 +1718,16 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, return create(Call(callee)); }; - ast::Function* func = - Func("ep_func", ast::VariableList(), ty.void_(), - ast::StatementList{ - FuncCall("sb_foo_func"), - FuncCall("sb_bar_func"), - FuncCall("sb_baz_func"), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func("ep_func", ast::VariableList(), ty.void_(), + ast::StatementList{ + FuncCall("sb_foo_func"), + FuncCall("sb_bar_func"), + FuncCall("sb_baz_func"), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); Inspector& inspector = Build(); @@ -1837,16 +1755,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) { "foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1867,16 +1782,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, "foo_type", {{ty.i32(), 0}, {u32_array_type(0), 4}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1896,16 +1808,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { MakeStorageBufferTypes("foo_type", {{ty.i32(), 0}}); AddStorageBuffer("foo_sb", foo_control_type, 0, 0); - auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", - {{0, ty.i32()}}); - AST().Functions().Add(sb_func); + MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "sb_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1921,12 +1830,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -1939,11 +1847,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { } TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { - auto* func = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "ep_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -1960,16 +1867,14 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); - auto* foo_func = MakeSamplerReferenceBodyFunction( - "foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), {}); - AST().Functions().Add(foo_func); + MakeSamplerReferenceBodyFunction("foo_func", "foo_texture", "foo_sampler", + "foo_coords", ty.f32(), {}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "foo_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -1988,12 +1893,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2008,12 +1912,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { AddGlobalVariable("foo_coords", ty.f32()); AddGlobalVariable("foo_depth", ty.f32()); - auto* func = MakeComparisonSamplerReferenceBodyFunction( + MakeComparisonSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2030,12 +1933,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { AddGlobalVariable("foo_coords", ty.f32()); AddGlobalVariable("foo_depth", ty.f32()); - auto* func = MakeComparisonSamplerReferenceBodyFunction( + MakeComparisonSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2048,11 +1950,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { - auto* func = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "ep_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2069,17 +1970,15 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { AddGlobalVariable("foo_coords", ty.f32()); AddGlobalVariable("foo_depth", ty.f32()); - auto* foo_func = MakeComparisonSamplerReferenceBodyFunction( - "foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", - ty.f32(), {}); - AST().Functions().Add(foo_func); + MakeComparisonSamplerReferenceBodyFunction("foo_func", "foo_texture", + "foo_sampler", "foo_coords", + "foo_depth", ty.f32(), {}); - auto* ep_func = MakeCallerBodyFunction( + MakeCallerBodyFunction( "ep_func", "foo_func", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(ep_func); Inspector& inspector = Build(); @@ -2098,12 +1997,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { AddGlobalVariable("foo_coords", ty.f32()); AddGlobalVariable("foo_depth", ty.f32()); - auto* func = MakeComparisonSamplerReferenceBodyFunction( + MakeComparisonSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2118,12 +2016,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2134,11 +2031,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { } TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -2157,13 +2053,12 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) { GetCoordsType(GetParam().type_dim, GetParam().sampled_kind); AddGlobalVariable("foo_coords", coord_type); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", GetBaseType(GetParam().sampled_kind), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2248,13 +2143,12 @@ TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam, AddGlobalVariable("foo_coords", coord_type); AddGlobalVariable("foo_array_index", ty.u32()); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index", GetBaseType(GetParam().sampled_kind), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2319,13 +2213,12 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam, GetCoordsType(GetParam().type_dim, GetParam().sampled_kind); AddGlobalVariable("foo_coords", coord_type); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", GetBaseType(GetParam().sampled_kind), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); @@ -2376,11 +2269,10 @@ INSTANTIATE_TEST_SUITE_P( inspector::ResourceBinding::SampledKind::kUInt})); TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) { - auto* foo = MakeEmptyBodyFunction( + MakeEmptyBodyFunction( "foo", ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(foo); Inspector& inspector = Build(); @@ -2401,13 +2293,12 @@ TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam, AddGlobalVariable("foo_coords", coord_type); AddGlobalVariable("foo_array_index", ty.u32()); - auto* func = MakeSamplerReferenceBodyFunction( + MakeSamplerReferenceBodyFunction( "ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index", GetBaseType(GetParam().sampled_kind), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func); Inspector& inspector = Build(); diff --git a/src/program_builder.h b/src/program_builder.h index b683ac90ae..a509c60fc3 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -419,7 +419,7 @@ class ProgramBuilder { return array(Of(), N); } - /// creates an alias type + /// Creates an alias type /// @param name the alias name /// @param type the alias type /// @returns the alias pointer @@ -847,14 +847,14 @@ class ProgramBuilder { Expr(std::forward(idx))); } - /// creates a ast::StructMemberOffsetDecoration + /// Creates a ast::StructMemberOffsetDecoration /// @param val the offset value /// @returns the offset decoration pointer ast::StructMemberOffsetDecoration* MemberOffset(uint32_t val) { return create(source_, val); } - /// creates a ast::Function + /// Creates an ast::Function and registers it with the ast::Module. /// @param source the source information /// @param name the function name /// @param params the function parameters @@ -868,12 +868,14 @@ class ProgramBuilder { type::Type* type, ast::StatementList body, ast::FunctionDecorationList decorations) { - return create(source, Symbols().Register(name), params, type, - create(body), - decorations); + auto* func = + create(source, Symbols().Register(name), params, type, + create(body), decorations); + AST().Functions().Add(func); + return func; } - /// creates a ast::Function + /// Creates an ast::Function and registers it with the ast::Module. /// @param name the function name /// @param params the function parameters /// @param type the function return type @@ -885,12 +887,14 @@ class ProgramBuilder { type::Type* type, ast::StatementList body, ast::FunctionDecorationList decorations) { - return create(Symbols().Register(name), params, type, - create(body), - decorations); + auto* func = + create(Symbols().Register(name), params, type, + create(body), decorations); + AST().Functions().Add(func); + return func; } - /// creates a ast::StructMember + /// Creates a ast::StructMember /// @param source the source information /// @param name the struct member name /// @param type the struct member type @@ -902,7 +906,7 @@ class ProgramBuilder { ast::StructMemberDecorationList{}); } - /// creates a ast::StructMember + /// Creates a ast::StructMember /// @param name the struct member name /// @param type the struct member type /// @returns the struct member pointer @@ -911,7 +915,7 @@ class ProgramBuilder { ast::StructMemberDecorationList{}); } - /// creates a ast::StructMember + /// Creates a ast::StructMember /// @param name the struct member name /// @param type the struct member type /// @param decorations the struct member decorations diff --git a/src/program_builder_test.cc b/src/program_builder_test.cc index b5dbaa7876..828a9e228d 100644 --- a/src/program_builder_test.cc +++ b/src/program_builder_test.cc @@ -25,8 +25,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { Program inner([] { ProgramBuilder builder; auto* ty = builder.ty.f32(); - auto* func = builder.Func("a", {}, ty, {}, {}); - builder.AST().Functions().Add(func); + builder.Func("a", {}, ty, {}, {}); return builder; }()); @@ -47,8 +46,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { EXPECT_FALSE(outer.Symbols().Get("b").IsValid()); auto* ty = outer.ty.f32(); - auto* func = outer.Func("b", {}, ty, {}, {}); - outer.AST().Functions().Add(func); + outer.Func("b", {}, ty, {}, {}); ASSERT_EQ(inner.AST().Functions().size(), 1u); ASSERT_EQ(outer.AST().Functions().size(), 2u); diff --git a/src/program_test.cc b/src/program_test.cc index 333fab7888..75dde4925f 100644 --- a/src/program_test.cc +++ b/src/program_test.cc @@ -104,9 +104,8 @@ TEST_F(ProgramTest, IsValid_Struct_EmptyName) { } TEST_F(ProgramTest, IsValid_Function) { - auto* func = Func("main", ast::VariableList(), ty.f32(), ast::StatementList{}, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("main", ast::VariableList(), ty.f32(), ast::StatementList{}, + ast::FunctionDecorationList{}); Program program(std::move(*this)); EXPECT_TRUE(program.IsValid()); @@ -120,9 +119,8 @@ TEST_F(ProgramTest, IsValid_Null_Function) { } TEST_F(ProgramTest, IsValid_Invalid_Function) { - auto* func = Func("main", ast::VariableList{}, nullptr, ast::StatementList{}, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("main", ast::VariableList{}, nullptr, ast::StatementList{}, + ast::FunctionDecorationList{}); Program program(std::move(*this)); EXPECT_FALSE(program.IsValid()); diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index ddc2c149ef..b47dccac28 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -4395,7 +4395,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { auto* layers_ident = create( Source{}, builder_.Symbols().Register("textureNumLayers")); exprs.push_back(create( - Source{}, layers_ident, ast::ExpressionList{GetImageExpression(inst)})); + Source{}, layers_ident, + ast::ExpressionList{GetImageExpression(inst)})); } auto* result_type = parser_impl_.ConvertType(inst.type_id()); TypedExpression expr = { diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index fd5d7693cb..8559765cbe 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -293,9 +293,8 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) { TEST_F(TypeDeterminerTest, Stmt_Call) { ast::VariableList params; - auto* func = Func("my_func", params, ty.f32(), ast::StatementList{}, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", params, ty.f32(), ast::StatementList{}, + ast::FunctionDecorationList{}); // Register the function EXPECT_TRUE(td()->Determine()); @@ -316,20 +315,18 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) { auto* call_expr = Call("func"); ast::VariableList params0; - auto* func_main = Func("main", params0, ty.f32(), - ast::StatementList{ - create(call_expr), - create(), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func_main); + Func("main", params0, ty.f32(), + ast::StatementList{ + create(call_expr), + create(), + }, + ast::FunctionDecorationList{}); - auto* func = Func("func", params0, ty.f32(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("func", params0, ty.f32(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); EXPECT_FALSE(td()->Determine()) << td()->error(); EXPECT_EQ(td()->error(), @@ -471,9 +468,8 @@ TEST_F(TypeDeterminerTest, Expr_Bitcast) { TEST_F(TypeDeterminerTest, Expr_Call) { ast::VariableList params; - auto* func = Func("my_func", params, ty.f32(), ast::StatementList{}, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", params, ty.f32(), ast::StatementList{}, + ast::FunctionDecorationList{}); // Register the function EXPECT_TRUE(td()->Determine()); @@ -486,9 +482,8 @@ TEST_F(TypeDeterminerTest, Expr_Call) { TEST_F(TypeDeterminerTest, Expr_Call_WithParams) { ast::VariableList params; - auto* func = Func("my_func", params, ty.f32(), ast::StatementList{}, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", params, ty.f32(), ast::StatementList{}, + ast::FunctionDecorationList{}); // Register the function EXPECT_TRUE(td()->Determine()); @@ -621,9 +616,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { } TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { - auto* func = Func("my_func", ast::VariableList{}, ty.f32(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.f32(), ast::StatementList{}, + ast::FunctionDecorationList{}); // Register the function EXPECT_TRUE(td()->Determine()); @@ -662,8 +656,6 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) { }, ast::FunctionDecorationList{}); - AST().Functions().Add(func); - // Register the function EXPECT_TRUE(td()->Determine()); @@ -689,17 +681,14 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { AST().AddGlobalVariable(wg_var); AST().AddGlobalVariable(priv_var); - auto* func = Func( - "my_func", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("out_var"), Expr("in_var")), - create(Expr("wg_var"), Expr("wg_var")), - create(Expr("sb_var"), Expr("sb_var")), - create(Expr("priv_var"), Expr("priv_var")), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("out_var"), Expr("in_var")), + create(Expr("wg_var"), Expr("wg_var")), + create(Expr("sb_var"), Expr("sb_var")), + create(Expr("priv_var"), Expr("priv_var")), + }, + ast::FunctionDecorationList{}); auto* func2 = Func( "func", ast::VariableList{}, ty.f32(), @@ -708,8 +697,6 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { }, ast::FunctionDecorationList{}); - AST().Functions().Add(func2); - // Register the function EXPECT_TRUE(td()->Determine()); @@ -733,8 +720,6 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) { }, ast::FunctionDecorationList{}); - AST().Functions().Add(func); - auto* v = Var("var", ast::StorageClass::kFunction, ty.f32()); td()->RegisterVariableForTesting(v); @@ -1545,10 +1530,8 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) { auto* var = Var("var", ast::StorageClass::kNone, ty.i32()); auto* stmt = create(var); - auto* func = Func("func", ast::VariableList{}, ty.i32(), - ast::StatementList{stmt}, ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_EQ(var->storage_class(), ast::StorageClass::kFunction); @@ -1557,10 +1540,8 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) { TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) { auto* var = Const("var", ast::StorageClass::kNone, ty.i32()); auto* stmt = create(var); - auto* func = Func("func", ast::VariableList{}, ty.i32(), - ast::StatementList{stmt}, ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); EXPECT_EQ(var->storage_class(), ast::StorageClass::kNone); @@ -1570,10 +1551,8 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) { auto* var = Var("var", ast::StorageClass::kWorkgroup, ty.i32()); auto* stmt = create(var); - auto* func = Func("func", ast::VariableList{}, ty.i32(), - ast::StatementList{stmt}, ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt}, + ast::FunctionDecorationList{}); EXPECT_FALSE(td()->Determine()); EXPECT_EQ(td()->error(), @@ -2296,12 +2275,6 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) { create(ast::PipelineStage::kVertex), }); - AST().Functions().Add(func_b); - AST().Functions().Add(func_c); - AST().Functions().Add(func_a); - AST().Functions().Add(ep_1); - AST().Functions().Add(ep_2); - AST().AddGlobalVariable(Var("first", ast::StorageClass::kPrivate, ty.f32())); AST().AddGlobalVariable(Var("second", ast::StorageClass::kPrivate, ty.f32())); AST().AddGlobalVariable(Var("call_a", ast::StorageClass::kPrivate, ty.f32())); diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 1d3653d077..8d757e85c4 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -41,15 +41,14 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2), ast::VariableDecorationList{}); - auto* func = Func( - Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, + ty.void_(), + ast::StatementList{ + create(var), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -62,13 +61,12 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) { // [[stage(vertex)]] // fn func -> void {} - auto* func = - Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, - ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, + ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -83,13 +81,11 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2), ast::VariableDecorationList{}); - auto* func = Func(Source{Source::Location{12, 34}}, "func", - ast::VariableList{}, ty.i32(), - ast::StatementList{ - create(var), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), + ast::StatementList{ + create(var), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -102,10 +98,9 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) { TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) { // fn func -> int {} - auto* func = - Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, - ty.i32(), ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), + ast::StatementList{}, ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -119,15 +114,14 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { // [[stage(vertex)]] // fn func -> void { return; } - auto* func = - Func("func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + + Func("func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->DetermineFunctions(AST().Functions())) << td()->error(); @@ -139,13 +133,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { // fn func -> void { return 2; } - auto* func = Func("func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, Expr(2)), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + Expr(2)), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -160,13 +153,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) { // fn func -> f32 { return 2; } - auto* func = Func("func", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, Expr(2)), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("func", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + Expr(2)), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -182,21 +174,17 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) { TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) { // fn func -> i32 { return 2; } // fn func -> i32 { return 2; } - auto* func = Func("func", ast::VariableList{}, ty.i32(), - ast::StatementList{ - create(Expr(2)), - }, - ast::FunctionDecorationList{}); + Func("func", ast::VariableList{}, ty.i32(), + ast::StatementList{ + create(Expr(2)), + }, + ast::FunctionDecorationList{}); - auto* func_copy = Func(Source{Source::Location{12, 34}}, "func", - ast::VariableList{}, ty.i32(), - ast::StatementList{ - create(Expr(2)), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); - AST().Functions().Add(func_copy); + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), + ast::StatementList{ + create(Expr(2)), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -212,13 +200,12 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) { auto* call_expr = create( Source{Source::Location{12, 34}}, Expr("func"), call_params); - auto* func0 = Func("func", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(call_expr), - create(), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func0); + Func("func", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(call_expr), + create(), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -236,13 +223,12 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), call_expr, ast::VariableDecorationList{}); - auto* func0 = Func("func", ast::VariableList{}, ty.i32(), - ast::StatementList{ - create(var), - create(Expr(2)), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func0); + Func("func", ast::VariableList{}, ty.i32(), + ast::StatementList{ + create(var), + create(Expr(2)), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -255,17 +241,16 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) { TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) { // [[stage(vertex)]] // fn vtx_main() -> i32 { return 0; } - auto* func = - Func(Source{Source::Location{12, 34}}, "vtx_main", ast::VariableList{}, - ty.i32(), - ast::StatementList{ - create(Expr(0)), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func(Source{Source::Location{12, 34}}, "vtx_main", ast::VariableList{}, + ty.i32(), + ast::StatementList{ + create(Expr(0)), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); + EXPECT_TRUE(td()->Determine()) << td()->error(); ValidatorImpl& v = Build(); @@ -278,19 +263,18 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) { TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) { // [[stage(vertex)]] // fn vtx_func(a : i32) -> void { return; } - auto* func = - Func(Source{Source::Location{12, 34}}, "vtx_func", - ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32(), - nullptr, ast::VariableDecorationList{})}, - ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func(Source{Source::Location{12, 34}}, "vtx_func", + ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32(), nullptr, + ast::VariableDecorationList{})}, + ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); + EXPECT_TRUE(td()->Determine()) << td()->error(); ValidatorImpl& v = Build(); @@ -305,17 +289,16 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) { // [[stage(fragment)]] // [[stage(vertex)]] // fn main() -> void { return; } - auto* func = Func( - Source{Source::Location{12, 34}}, "main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - create(ast::PipelineStage::kFragment), - }); + Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{}, + ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + create(ast::PipelineStage::kFragment), + }); - AST().Functions().Add(func); EXPECT_TRUE(td()->Determine()) << td()->error(); ValidatorImpl& v = Build(); @@ -329,15 +312,14 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) { TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) { // [[stage(vertex)]] // fn vtx_func() -> void { return; } - auto* func = - Func("vtx_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + + Func("vtx_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -348,12 +330,11 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) { TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) { // fn vtx_func() -> void { return; } - auto* func = Func("vtx_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("vtx_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc index 1a0f97296d..9ef4176d89 100644 --- a/src/validator/validator_test.cc +++ b/src/validator/validator_test.cc @@ -431,13 +431,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) { auto* lhs = Expr("not_global_var"); auto* rhs = Expr(3.14f); - auto* func = Func("my_func", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, lhs, rhs), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + lhs, rhs), + }, + ast::FunctionDecorationList{}); ValidatorImpl& v = Build(); @@ -456,17 +455,15 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) { ty.f32(), Expr(2.1f), ast::VariableDecorationList{})); - auto* func = Func( - "my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Source{Source::Location{12, 34}}, - Expr("global_var"), Expr(3.14f)), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + Expr("global_var"), Expr(3.14f)), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -654,14 +651,12 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f), ast::VariableDecorationList{}); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, var), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + var), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -682,15 +677,13 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) { auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(0.1f), ast::VariableDecorationList{}); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create( - Source{Source::Location{12, 34}}, var_a_float), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(Source{Source::Location{12, 34}}, + var_a_float), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -818,27 +811,23 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) { auto* var1 = Var("a", ast::StorageClass::kNone, ty.void_(), Expr(1.0f), ast::VariableDecorationList{}); - auto* func0 = Func("func0", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, var0), - create(), - }, - ast::FunctionDecorationList{}); + Func("func0", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + var0), + create(), + }, + ast::FunctionDecorationList{}); - auto* func1 = - Func("func1", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create( - Source{Source::Location{13, 34}}, var1), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - - AST().Functions().Add(func0); - AST().Functions().Add(func1); + Func("func1", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{13, 34}}, + var1), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc index 879e0c6849..aa95c92995 100644 --- a/src/validator/validator_type_test.cc +++ b/src/validator/validator_type_test.cc @@ -168,16 +168,15 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) { // fn func -> void { var a : array; } auto* var = Var("a", ast::StorageClass::kNone, ty.array()); - auto* func = - Func("func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create( - Source{Source::Location{12, 34}}, var), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); + + Func("func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Source{Source::Location{12, 34}}, + var), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -197,22 +196,19 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) { Var(Source{Source::Location{12, 34}}, "a", ast::StorageClass::kNone, ty.array(), nullptr, ast::VariableDecorationList{}); - auto* func = Func("func", ast::VariableList{param}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("func", ast::VariableList{param}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); - auto* main = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(main); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); EXPECT_TRUE(td()->Determine()) << td()->error(); diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc index 0067d408b1..e295e43a99 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -505,9 +505,8 @@ if (_tint_tmp) { TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) { // foo(a && b, c || d, (a || c) && (b || d)) - auto* func = Func("foo", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); ast::ExpressionList params; params.push_back(create(ast::BinaryOp::kLogicalAnd, diff --git a/src/writer/hlsl/generator_impl_call_test.cc b/src/writer/hlsl/generator_impl_call_test.cc index 5cb93dcda1..bf7661f0cb 100644 --- a/src/writer/hlsl/generator_impl_call_test.cc +++ b/src/writer/hlsl/generator_impl_call_test.cc @@ -32,9 +32,8 @@ using HlslGeneratorImplTest_Call = TestHelper; TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { auto* call = Call("my_func"); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -45,9 +44,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { auto* call = Call("my_func", "param1", "param2"); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -58,9 +56,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { auto* call = create(Call("my_func", "param1", "param2")); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); diff --git a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc index 800ce5bf55..add244ebab 100644 --- a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc @@ -60,24 +60,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("vtx_main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - - AST().Functions().Add(func); + Func("vtx_main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(result(), R"(struct vtx_main_in { float foo : TEXCOORD0; @@ -113,24 +109,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("vtx_main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - - AST().Functions().Add(func); + Func("vtx_main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(result(), R"(struct vtx_main_out { float foo : TEXCOORD0; @@ -166,24 +158,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(result(), R"(struct main_in { float foo : TEXCOORD0; @@ -219,24 +207,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(result(), R"(struct main_out { float foo : SV_Target0; @@ -269,24 +253,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)"); } @@ -314,24 +294,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.f32(), - ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.f32(), + ast::StatementList{ + create(Expr("foo"), Expr("foo")), + create(Expr("bar"), Expr("bar")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)"); } @@ -367,24 +343,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, AST().AddGlobalVariable(coord_var); AST().AddGlobalVariable(depth_var); - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("depth"), + MemberAccessor("coord", "x")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); std::unordered_set globals; - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error(); EXPECT_EQ(result(), R"(struct main_in { float4 coord : SV_Position; diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index ff489f8242..cc8bf8c864 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -53,13 +53,11 @@ namespace { using HlslGeneratorImplTest_Function = TestHelper; TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -74,13 +72,11 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { - auto* func = Func("GeometryShader", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("GeometryShader", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -95,17 +91,14 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { - auto* func = - Func("my_func", - ast::VariableList{Var("a", ast::StorageClass::kNone, ty.f32()), - Var("b", ast::StorageClass::kNone, ty.i32())}, - ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", + ast::VariableList{Var("a", ast::StorageClass::kNone, ty.f32()), + Var("b", ast::StorageClass::kNone, ty.i32())}, + ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -121,16 +114,11 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_NoReturn_Void) { - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{/* no explicit return */}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{/* no explicit return */}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -160,18 +148,13 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("bar"), Expr("foo")), - /* no explicit return */}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("bar"), Expr("foo")), + /* no explicit return */}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -211,19 +194,14 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("bar"), Expr("foo")), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("bar"), Expr("foo")), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -265,20 +243,15 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(coord_var); AST().AddGlobalVariable(depth_var); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("depth"), + MemberAccessor("coord", "x")), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -315,19 +288,14 @@ TEST_F(HlslGeneratorImplTest_Function, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "x"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -368,19 +336,14 @@ TEST_F(HlslGeneratorImplTest_Function, MemberAccessor("uniforms", "coord"), Expr("x")), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -421,19 +384,14 @@ TEST_F(HlslGeneratorImplTest_Function, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -471,19 +429,14 @@ TEST_F(HlslGeneratorImplTest_Function, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -517,20 +470,15 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(coord_var); AST().AddGlobalVariable(coord_var); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(MemberAccessor("coord", "b"), - Expr(2.0f)), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(MemberAccessor("coord", "b"), + Expr(2.0f)), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -571,20 +519,17 @@ TEST_F( AST().AddGlobalVariable(bar_var); AST().AddGlobalVariable(val_var); - auto* sub_func = Func( - "sub_func", - ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, - ty.f32(), - ast::StatementList{ - create(Expr("bar"), Expr("foo")), - create(Expr("val"), Expr("param")), - create(Expr("foo")), - }, - ast::FunctionDecorationList{}); + Func("sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, + ty.f32(), + ast::StatementList{ + create(Expr("bar"), Expr("foo")), + create(Expr("val"), Expr("param")), + create(Expr("foo")), + }, + ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); - - auto* func_1 = Func( + Func( "ep_1", ast::VariableList{}, ty.void_(), ast::StatementList{ create(Expr("bar"), Call("sub_func", 1.0f)), @@ -594,10 +539,6 @@ TEST_F( create(ast::PipelineStage::kFragment), }); - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); @@ -637,31 +578,23 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(depth_var); - auto* sub_func = Func( - "sub_func", - ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, - ty.f32(), - ast::StatementList{ - create(Expr("param")), - }, - ast::FunctionDecorationList{}); + Func("sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, + ty.f32(), + ast::StatementList{ + create(Expr("param")), + }, + ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); - - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("depth"), - Call("sub_func", 1.0f)), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("depth"), + Call("sub_func", 1.0f)), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -704,33 +637,25 @@ TEST_F( AST().AddGlobalVariable(coord_var); AST().AddGlobalVariable(depth_var); - auto* sub_func = Func( - "sub_func", - ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, - ty.f32(), - ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - create(Expr("param")), - }, - ast::FunctionDecorationList{}); + Func("sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, + ty.f32(), + ast::StatementList{ + create(Expr("depth"), + MemberAccessor("coord", "x")), + create(Expr("param")), + }, + ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); - - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("depth"), - Call("sub_func", 1.0f)), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("depth"), + Call("sub_func", 1.0f)), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -770,33 +695,25 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(coord_var); - auto* sub_func = Func( - "sub_func", - ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, - ty.f32(), - ast::StatementList{ - create(MemberAccessor("coord", "x")), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(sub_func); + Func("sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, + ty.f32(), + ast::StatementList{ + create(MemberAccessor("coord", "x")), + }, + ast::FunctionDecorationList{}); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), Call("sub_func", 1.0f), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -830,33 +747,25 @@ TEST_F(HlslGeneratorImplTest_Function, AST().AddGlobalVariable(coord_var); - auto* sub_func = Func( - "sub_func", - ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, - ty.f32(), - ast::StatementList{ - create(MemberAccessor("coord", "x")), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(sub_func); + Func("sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())}, + ty.f32(), + ast::StatementList{ + create(MemberAccessor("coord", "x")), + }, + ast::FunctionDecorationList{}); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), Call("sub_func", 1.0f), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -889,7 +798,7 @@ TEST_F(HlslGeneratorImplTest_Function, create(), }); - auto* func_1 = Func( + Func( "ep_1", ast::VariableList{}, ty.void_(), ast::StatementList{ create(Expr("bar"), Expr(1.0f)), @@ -902,10 +811,6 @@ TEST_F(HlslGeneratorImplTest_Function, create(ast::PipelineStage::kFragment), }); - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); @@ -927,13 +832,10 @@ ep_1_out ep_1() { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_WithNameCollision) { - auto* func = Func( - "GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); + Func("GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -947,18 +849,13 @@ TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_Compute) { - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); GeneratorImpl& gen = Build(); @@ -973,19 +870,14 @@ void main() { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_Compute_WithWorkgroup) { - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - create(2u, 4u, 6u), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + create(2u, 4u, 6u), + }); GeneratorImpl& gen = Build(); @@ -999,7 +891,7 @@ void main() { } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { - auto* func = Func( + Func( "my_func", ast::VariableList{Var("a", ast::StorageClass::kNone, ty.array())}, ty.void_(), @@ -1008,8 +900,6 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { }, ast::FunctionDecorationList{}); - AST().Functions().Add(func); - GeneratorImpl& gen = Build(); gen.increment_indent(); @@ -1061,37 +951,30 @@ TEST_F(HlslGeneratorImplTest_Function, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("a", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("a", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } { auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("b", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("b", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } - ASSERT_TRUE(td.Determine()) << td.error(); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); diff --git a/src/writer/hlsl/generator_impl_intrinsic_test.cc b/src/writer/hlsl/generator_impl_intrinsic_test.cc index ae6708b816..f1d42c0aa0 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_test.cc @@ -103,7 +103,6 @@ ast::CallExpression* GenerateCall(ast::Intrinsic intrinsic, case ast::Intrinsic::kTrunc: case ast::Intrinsic::kSign: return builder->Call(str.str(), "f1"); - break; case ast::Intrinsic::kAtan2: case ast::Intrinsic::kCross: case ast::Intrinsic::kDot: diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index da195eff95..cae4d60200 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -28,9 +28,8 @@ namespace { using HlslGeneratorImplTest = TestHelper; TEST_F(HlslGeneratorImplTest, Generate) { - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); diff --git a/src/writer/hlsl/test_helper.h b/src/writer/hlsl/test_helper.h index 344ee66fd3..0bdd45657f 100644 --- a/src/writer/hlsl/test_helper.h +++ b/src/writer/hlsl/test_helper.h @@ -44,8 +44,8 @@ class TestHelperBase : public BODY, public ProgramBuilder { if (gen_) { return *gen_; } - program_ = std::make_unique(std::move(*this)); - gen_ = std::make_unique(program_.get()); + program = std::make_unique(std::move(*this)); + gen_ = std::make_unique(program.get()); return *gen_; } @@ -62,9 +62,10 @@ class TestHelperBase : public BODY, public ProgramBuilder { std::ostringstream out; /// The pre-output stream std::ostringstream pre; + /// The program built with a call to Build() + std::unique_ptr program; private: - std::unique_ptr program_; std::unique_ptr gen_; }; using TestHelper = TestHelperBase; diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 5c33043ce1..a031f3f0f8 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -33,9 +33,8 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { auto* call = Call("my_func"); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -45,9 +44,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { auto* call = Call("my_func", "param1", "param2"); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -57,9 +55,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { TEST_F(MslGeneratorImplTest, EmitStatement_Call) { auto* call = Call("my_func", "param1", "param2"); - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, ast::FunctionDecorationList{}); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); auto* expr = create(call); diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index e669d76c1f..6e225be7d9 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -65,18 +65,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("vtx_main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("vtx_main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.result(), R"(struct vtx_main_in { float foo [[attribute(0)]]; @@ -113,18 +110,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("vtx_main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("vtx_main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.result(), R"(struct vtx_main_out { float foo [[user(locn0)]]; @@ -161,18 +155,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.result(), R"(struct main_in { float foo [[user(locn0)]]; @@ -209,18 +200,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.result(), R"(struct main_out { float foo [[color(0)]]; @@ -254,18 +242,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)"); } @@ -294,18 +279,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) { create(Expr("foo"), Expr("foo")), create(Expr("bar"), Expr("bar")), }; - auto* func = - Func("main", ast::VariableList{}, ty.f32(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.f32(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)"); } @@ -339,18 +321,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { auto body = ast::StatementList{create( Expr("depth"), MemberAccessor("coord", "x"))}; - auto* func = - Func("main", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error(); EXPECT_EQ(gen.result(), R"(struct main_out { float depth [[depth(any)]]; diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 025b00dcc1..440ad81c89 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -56,13 +56,11 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Function) { - auto* func = Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -79,13 +77,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function) { } TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { - auto* func = Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -106,13 +102,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { params.push_back(Var("a", ast::StorageClass::kNone, ty.f32())); params.push_back(Var("b", ast::StorageClass::kNone, ty.i32())); - auto* func = Func("my_func", params, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", params, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -129,14 +123,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { } TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_NoReturn_Void) { - auto* func = Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{/* no explicit return */}, - ast::FunctionDecorationList{create( - ast::PipelineStage::kFragment)}); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{/* no explicit return */}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment)}); GeneratorImpl& gen = Build(); @@ -166,17 +156,12 @@ TEST_F(MslGeneratorImplTest, AST().AddGlobalVariable(foo_var); AST().AddGlobalVariable(bar_var); - auto* func = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(Expr("bar"), Expr("foo")), - /* no explicit return */}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment)}); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(Expr("bar"), Expr("foo")), + /* no explicit return */}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment)}); GeneratorImpl& gen = Build(); @@ -219,13 +204,9 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { create(Expr("bar"), Expr("foo")), create(), }; - auto* func = Func("frag_main", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{create( - ast::PipelineStage::kFragment)}); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment)}); GeneratorImpl& gen = Build(); @@ -272,15 +253,11 @@ TEST_F(MslGeneratorImplTest, MemberAccessor("coord", "x")), create(), }; - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -313,19 +290,14 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "x"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -364,19 +336,14 @@ TEST_F(MslGeneratorImplTest, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -418,19 +385,14 @@ TEST_F(MslGeneratorImplTest, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -480,24 +442,18 @@ TEST_F( create(Expr("bar"), Expr("foo")), create(Expr("val"), Expr("param")), create(Expr("foo"))}; - auto* sub_func = - Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); body = ast::StatementList{ create(Expr("bar"), Call("sub_func", 1.0f)), create(), }; - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -541,28 +497,21 @@ TEST_F(MslGeneratorImplTest, ast::VariableList params; params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32())); - auto* sub_func = Func("sub_func", params, ty.f32(), - ast::StatementList{ - create(Expr("param")), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), + ast::StatementList{ + create(Expr("param")), + }, + ast::FunctionDecorationList{}); auto body = ast::StatementList{ create(Expr("depth"), Call("sub_func", 1.0f)), create(), }; - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -613,24 +562,18 @@ TEST_F( MemberAccessor("coord", "x")), create(Expr("param")), }; - auto* sub_func = - Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); body = ast::StatementList{ create(Expr("depth"), Call("sub_func", 1.0f)), create(), }; - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -671,10 +614,8 @@ TEST_F(MslGeneratorImplTest, auto body = ast::StatementList{ create(MemberAccessor("coord", "x")), }; - auto* sub_func = - Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); ast::ExpressionList expr; expr.push_back(Expr(1.0f)); @@ -682,19 +623,14 @@ TEST_F(MslGeneratorImplTest, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), Call("sub_func", 1.0f), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -738,27 +674,20 @@ TEST_F(MslGeneratorImplTest, auto body = ast::StatementList{ create(MemberAccessor("coord", "b"))}; - auto* sub_func = - Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), Call("sub_func", 1.0f), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -807,10 +736,8 @@ TEST_F(MslGeneratorImplTest, auto body = ast::StatementList{ create(MemberAccessor("coord", "b"))}; - auto* sub_func = - Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); - AST().Functions().Add(sub_func); + Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{}); ast::ExpressionList expr; expr.push_back(Expr(1.0f)); @@ -818,19 +745,14 @@ TEST_F(MslGeneratorImplTest, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), Call("sub_func", 1.0f), ast::VariableDecorationList{}); - auto* func = - Func("frag_main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("frag_main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -875,15 +797,10 @@ TEST_F(MslGeneratorImplTest, create(), }; - auto* func_1 = - Func("ep_1", ast::VariableList{}, ty.void_(), body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(func_1); - - ASSERT_TRUE(td.Determine()) << td.error(); + Func("ep_1", ast::VariableList{}, ty.void_(), body, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); GeneratorImpl& gen = Build(); @@ -908,13 +825,10 @@ fragment ep_1_out ep_1() { TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithNameCollision) { - auto* func = - Func("main", ast::VariableList{}, ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("main", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); GeneratorImpl& gen = Build(); @@ -932,13 +846,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) { ast::VariableList params; params.push_back(Var("a", ast::StorageClass::kNone, ty.array())); - auto* func = Func("my_func", params, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); - - AST().Functions().Add(func); + Func("my_func", params, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build(); @@ -994,35 +906,27 @@ TEST_F(MslGeneratorImplTest, auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("a", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("a", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } { auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("b", ast::VariableList{}, ty.void_(), - ast::StatementList{create(var), - create()}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute)}); - - AST().Functions().Add(func); + Func("b", ast::VariableList{}, ty.void_(), + ast::StatementList{create(var), + create()}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute)}); } - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index a9fd9362de..d5809f050c 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -105,7 +105,6 @@ ast::CallExpression* GenerateCall(ast::Intrinsic intrinsic, case ast::Intrinsic::kTrunc: case ast::Intrinsic::kSign: return builder->Call(str.str(), "f1"); - break; case ast::Intrinsic::kAtan2: case ast::Intrinsic::kCross: case ast::Intrinsic::kDot: diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index fc26f40ae4..f2ce025ace 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -48,12 +48,10 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Generate) { - auto* func = - Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - AST().Functions().Add(func); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); GeneratorImpl& gen = Build(); diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h index 6fe1797ac3..d5af650bde 100644 --- a/src/writer/msl/test_helper.h +++ b/src/writer/msl/test_helper.h @@ -43,16 +43,17 @@ class TestHelperBase : public BASE, public ProgramBuilder { if (gen_) { return *gen_; } - program_ = std::make_unique(std::move(*this)); - gen_ = std::make_unique(program_.get()); + program = std::make_unique(std::move(*this)); + gen_ = std::make_unique(program.get()); return *gen_; } /// The type determiner TypeDeterminer td; + /// The program built with a call to Build() + std::unique_ptr program; private: - std::unique_ptr program_; std::unique_ptr gen_; }; using TestHelper = TestHelperBase; diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index e7a086a2bf..7ac66cd6f0 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -46,11 +46,12 @@ namespace { using BuilderTest = TestHelper; TEST_F(BuilderTest, Function_Empty) { - auto* func = Func("a_func", {}, ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{}); + Func("a_func", {}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid @@ -63,14 +64,15 @@ OpFunctionEnd } TEST_F(BuilderTest, Function_Terminator_Return) { - auto* func = Func("a_func", {}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); + Func("a_func", {}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid @@ -83,17 +85,17 @@ OpFunctionEnd } TEST_F(BuilderTest, Function_Terminator_ReturnValue) { - auto* var_a = Var("a", ast::StorageClass::kPrivate, ty.f32()); - td.RegisterVariableForTesting(var_a); + AST().AddGlobalVariable(Var("a", ast::StorageClass::kPrivate, ty.f32())); - auto* func = Func("a_func", {}, ty.void_(), - ast::StatementList{create(Expr("a"))}, - ast::FunctionDecorationList{}); - - ASSERT_TRUE(td.DetermineFunction(func)) << td.error(); + Func("a_func", {}, ty.void_(), + ast::StatementList{create(Expr("a"))}, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* var_a = program->AST().GlobalVariables()[0]; + auto* func = program->AST().Functions()[0]; + ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a" @@ -113,14 +115,15 @@ OpFunctionEnd } TEST_F(BuilderTest, Function_Terminator_Discard) { - auto* func = Func("a_func", {}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); + Func("a_func", {}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid @@ -136,16 +139,13 @@ TEST_F(BuilderTest, Function_WithParams) { ast::VariableList params = {Var("a", ast::StorageClass::kFunction, ty.f32()), Var("b", ast::StorageClass::kFunction, ty.i32())}; - auto* func = Func("a_func", params, ty.f32(), - ast::StatementList{create(Expr("a"))}, - ast::FunctionDecorationList{}); - - td.RegisterVariableForTesting(func->params()[0]); - td.RegisterVariableForTesting(func->params()[1]); - EXPECT_TRUE(td.DetermineFunction(func)); + Func("a_func", params, ty.f32(), + ast::StatementList{create(Expr("a"))}, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func" OpName %5 "a" @@ -164,14 +164,15 @@ OpFunctionEnd } TEST_F(BuilderTest, Function_WithBody) { - auto* func = Func("a_func", {}, ty.void_(), - ast::StatementList{ - create(), - }, - ast::FunctionDecorationList{}); + Func("a_func", {}, ty.void_(), + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" %2 = OpTypeVoid @@ -184,11 +185,12 @@ OpFunctionEnd } TEST_F(BuilderTest, FunctionType) { - auto* func = Func("a_func", {}, ty.void_(), ast::StatementList{}, - ast::FunctionDecorationList{}); + Func("a_func", {}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); spirv::Builder& b = Build(); + auto* func = program->AST().Functions()[0]; ASSERT_TRUE(b.GenerateFunction(func)); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid %1 = OpTypeFunction %2 @@ -244,45 +246,36 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { AST().AddConstructedType(s); - td.RegisterVariableForTesting(data_var); AST().AddGlobalVariable(data_var); { auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("a", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("a", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } { auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(), MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* func = - Func("b", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("b", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } - ASSERT_TRUE(td.Determine()) << td.error(); - spirv::Builder& b = Build(); ASSERT_TRUE(b.Build()); diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index 49dab51322..0b8b5051bc 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -4155,16 +4155,13 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) { auto* call = create(Expr(param.function), param.args(this)); - auto* main = - Func("main", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(call), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); - - AST().Functions().Add(main); + Func("main", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(call), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); ASSERT_TRUE(td.Determine()) << td.error(); diff --git a/src/writer/spirv/test_helper.h b/src/writer/spirv/test_helper.h index fdd084f11e..533eb4b762 100644 --- a/src/writer/spirv/test_helper.h +++ b/src/writer/spirv/test_helper.h @@ -43,13 +43,15 @@ class TestHelperBase : public ProgramBuilder, public BASE { if (spirv_builder) { return *spirv_builder; } - program_ = std::make_unique(std::move(*this)); - spirv_builder = std::make_unique(program_.get()); + program = std::make_unique(std::move(*this)); + spirv_builder = std::make_unique(program.get()); return *spirv_builder; } /// The type determiner TypeDeterminer td; + /// The program built with a call to Build() + std::unique_ptr program; protected: /// Called whenever a new variable is built with `Var()`. @@ -59,7 +61,6 @@ class TestHelperBase : public ProgramBuilder, public BASE { } private: - std::unique_ptr program_; std::unique_ptr spirv_builder; }; using TestHelper = TestHelperBase; diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 7f53616eed..67e4145980 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -202,17 +202,14 @@ TEST_F(WgslGeneratorImplTest, create(Expr("data"), Expr("d")), ast::VariableDecorationList{}); - auto* func = - Func("a", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("a", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } { @@ -221,21 +218,16 @@ TEST_F(WgslGeneratorImplTest, create(Expr("data"), Expr("d")), ast::VariableDecorationList{}); - auto* func = - Func("b", ast::VariableList{}, ty.void_(), - ast::StatementList{ - create(var), - create(), - }, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); - - AST().Functions().Add(func); + Func("b", ast::VariableList{}, ty.void_(), + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); } - ASSERT_TRUE(td.Determine()) << td.error(); - GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index 0e6ca83625..5619268b93 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -30,9 +30,8 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Generate) { - AST().Functions().Add(Func("my_func", ast::VariableList{}, ty.void_(), - ast::StatementList{}, - ast::FunctionDecorationList{})); + Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, + ast::FunctionDecorationList{}); GeneratorImpl& gen = Build();