diff --git a/src/ast/builder.h b/src/ast/builder.h index a450a6e847..807dba2c72 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -581,6 +581,42 @@ class Builder { return mod->create(source_, val); } + /// Creates a Function + /// @param source the source information + /// @param name the function name + /// @param params the function parameters + /// @param type the function return type + /// @param body the function body + /// @param decorations the function decorations + /// @returns the function pointer + Function* Func(Source source, + std::string name, + ast::VariableList params, + type::Type* type, + ast::StatementList body, + ast::FunctionDecorationList decorations) { + return mod->create( + source, mod->RegisterSymbol(name), name, params, type, + create(body), decorations); + } + + /// Creates a Function + /// @param name the function name + /// @param params the function parameters + /// @param type the function return type + /// @param body the function body + /// @param decorations the function decorations + /// @returns the function pointer + Function* Func(std::string name, + ast::VariableList params, + type::Type* type, + ast::StatementList body, + ast::FunctionDecorationList decorations) { + return create(mod->RegisterSymbol(name), name, params, type, + create(body), + decorations); + } + /// Creates a StructMember /// @param name the struct member name /// @param type the struct member type diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index ec3193798f..fe18df05cb 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -81,14 +81,10 @@ class InspectorHelper : public ast::BuilderWithModule { /// @returns a function object ast::Function* MakeEmptyBodyFunction( std::string name, - ast::FunctionDecorationList decorations = {}) { - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}), - }); - return create(Source{}, mod->RegisterSymbol(name), name, - ast::VariableList(), ty.void_, body, - decorations); + ast::FunctionDecorationList decorations) { + return Func(name, ast::VariableList(), ty.void_, + ast::StatementList{create(Source{})}, + decorations); } /// Generates a function that calls another @@ -99,19 +95,18 @@ class InspectorHelper : public ast::BuilderWithModule { ast::Function* MakeCallerBodyFunction( std::string caller, std::string callee, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { auto* ident_expr = create( Source{}, mod->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, call_expr), - create(Source{}), - }); - return create(Source{}, mod->RegisterSymbol(caller), caller, - ast::VariableList(), ty.void_, body, - decorations); + + return Func(caller, ast::VariableList(), ty.void_, + ast::StatementList{ + create(Source{}, call_expr), + create(Source{}), + }, + decorations); } /// Add In/Out variables to the global variables @@ -152,7 +147,7 @@ class InspectorHelper : public ast::BuilderWithModule { ast::Function* MakeInOutVariableBodyFunction( std::string name, std::vector> inout_vars, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { ast::StatementList stmts; for (auto inout : inout_vars) { std::string in, out; @@ -165,10 +160,7 @@ class InspectorHelper : public ast::BuilderWithModule { in))); } stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(name), name, - ast::VariableList(), ty.void_, body, - decorations); + return Func(name, ast::VariableList(), ty.void_, stmts, decorations); } /// Generates a function that references in/out variables and calls another @@ -183,7 +175,7 @@ class InspectorHelper : public ast::BuilderWithModule { std::string caller, std::string callee, std::vector> inout_vars, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { ast::StatementList stmts; for (auto inout : inout_vars) { std::string in, out; @@ -201,10 +193,8 @@ class InspectorHelper : public ast::BuilderWithModule { ast::ExpressionList()); stmts.emplace_back(create(Source{}, call_expr)); stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(caller), caller, - ast::VariableList(), ty.void_, body, - decorations); + + return Func(caller, ast::VariableList(), ty.void_, stmts, decorations); } /// Add a Constant ID to the global variables. @@ -467,10 +457,9 @@ class InspectorHelper : public ast::BuilderWithModule { } stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(func_name), - func_name, ast::VariableList(), ty.void_, body, - ast::FunctionDecorationList{}); + + return Func(func_name, ast::VariableList(), ty.void_, stmts, + ast::FunctionDecorationList{}); } /// Adds a regular sampler variable to the module @@ -584,7 +573,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& sampler_name, const std::string& coords_name, ast::type::Type* base_type, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; ast::StatementList stmts; @@ -619,10 +608,7 @@ class InspectorHelper : public ast::BuilderWithModule { call_expr)); stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(func_name), - func_name, ast::VariableList(), ty.void_, body, - decorations); + return Func(func_name, ast::VariableList(), ty.void_, stmts, decorations); } /// Generates a function that references a specific sampler variable @@ -641,7 +627,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& coords_name, const std::string& array_index, ast::type::Type* base_type, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; ast::StatementList stmts; @@ -679,10 +665,7 @@ class InspectorHelper : public ast::BuilderWithModule { call_expr)); stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(func_name), - func_name, ast::VariableList(), ty.void_, body, - decorations); + return Func(func_name, ast::VariableList(), ty.void_, stmts, decorations); } /// Generates a function that references a specific comparison sampler @@ -702,7 +685,7 @@ class InspectorHelper : public ast::BuilderWithModule { const std::string& coords_name, const std::string& depth_name, ast::type::Type* base_type, - ast::FunctionDecorationList decorations = {}) { + ast::FunctionDecorationList decorations) { std::string result_name = "sampler_result"; ast::StatementList stmts; @@ -741,10 +724,7 @@ class InspectorHelper : public ast::BuilderWithModule { call_expr)); stmts.emplace_back(create(Source{})); - auto* body = create(Source{}, stmts); - return create(Source{}, mod->RegisterSymbol(func_name), - func_name, ast::VariableList(), ty.void_, body, - decorations); + return Func(func_name, ast::VariableList(), ty.void_, stmts, decorations); } /// Gets an appropriate type for the data in a given texture type. @@ -876,7 +856,7 @@ TEST_F(InspectorGetEntryPointTest, NoFunctions) { } TEST_F(InspectorGetEntryPointTest, NoEntryPoints) { - mod->AddFunction(MakeEmptyBodyFunction("foo")); + mod->AddFunction(MakeEmptyBodyFunction("foo", {})); auto result = inspector()->GetEntryPoints(); ASSERT_FALSE(inspector()->has_error()) << inspector()->error(); @@ -933,7 +913,7 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) { } TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) { - auto* func = MakeEmptyBodyFunction("func"); + auto* func = MakeEmptyBodyFunction("func", {}); mod->AddFunction(func); auto* foo = MakeCallerBodyFunction( @@ -1004,7 +984,7 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) { } TEST_F(InspectorGetEntryPointTest, NoInOutVariables) { - auto* func = MakeEmptyBodyFunction("func"); + auto* func = MakeEmptyBodyFunction("func", {}); mod->AddFunction(func); auto* foo = MakeCallerBodyFunction( @@ -1048,7 +1028,8 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) { TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { AddInOutVariables({{"in_var", "out_var"}}); - auto* func = MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}); + auto* func = + MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); mod->AddFunction(func); auto* foo = MakeCallerBodyFunction( @@ -1074,7 +1055,8 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) { TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) { AddInOutVariables({{"in_var", "out_var"}}); - auto* func = MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}); + auto* func = + MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {}); mod->AddFunction(func); auto* foo = MakeInOutVariableCallerBodyFunction( @@ -1126,7 +1108,7 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) { AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}}); auto* func = MakeInOutVariableBodyFunction( - "func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}); + "func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, {}); mod->AddFunction(func); auto* foo = MakeCallerBodyFunction( @@ -1195,7 +1177,8 @@ 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"}}); + auto* func = + MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {}); mod->AddFunction(func); auto* foo = MakeInOutVariableCallerBodyFunction( @@ -1250,7 +1233,7 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) { // TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass // through TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) { - mod->AddFunction(MakeEmptyBodyFunction("foo")); + mod->AddFunction(MakeEmptyBodyFunction("foo", {})); auto result = inspector()->GetRemappedNameForEntryPoint("foo"); ASSERT_TRUE(inspector()->has_error()); @@ -1542,20 +1525,15 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { ast::ExpressionList()); return create(Source{}, call_expr); }; - auto* body = create( - Source{}, ast::StatementList{ - FuncCall("ub_foo_func"), - FuncCall("ub_bar_func"), - FuncCall("ub_baz_func"), - create(Source{}), - }); - ast::Function* func = create( - Source{}, mod->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), - ty.void_, body, - ast::FunctionDecorationList{ - create(Source{}, ast::PipelineStage::kVertex), - }); + 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), + }); mod->AddFunction(func); ASSERT_TRUE(td()->Determine()) << td()->error(); @@ -1690,17 +1668,15 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { ast::ExpressionList()); return create(Source{}, call_expr); }; - auto* body = create( - Source{}, ast::StatementList{ - FuncCall("sb_foo_func"), - FuncCall("sb_bar_func"), - FuncCall("sb_baz_func"), - create(Source{}), - }); - ast::Function* func = create( - Source{}, mod->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), - ty.void_, body, + 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(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kVertex), }); @@ -1865,17 +1841,15 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ast::ExpressionList()); return create(Source{}, call_expr); }; - auto* body = create( - Source{}, ast::StatementList{ - FuncCall("sb_foo_func"), - FuncCall("sb_bar_func"), - FuncCall("sb_baz_func"), - create(Source{}), - }); - ast::Function* func = create( - Source{}, mod->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), - ty.void_, body, + 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(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kVertex), }); @@ -2036,7 +2010,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { AddGlobalVariable("foo_coords", ty.f32); auto* foo_func = MakeSamplerReferenceBodyFunction( - "foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32); + "foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32, {}); mod->AddFunction(foo_func); auto* ep_func = MakeCallerBodyFunction( @@ -2150,7 +2124,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { auto* foo_func = MakeComparisonSamplerReferenceBodyFunction( "foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", - ty.f32); + ty.f32, {}); mod->AddFunction(foo_func); auto* ep_func = MakeCallerBodyFunction( diff --git a/src/transform/bound_array_accessors_test.cc b/src/transform/bound_array_accessors_test.cc index 1f33e0006a..a3c148f5c9 100644 --- a/src/transform/bound_array_accessors_test.cc +++ b/src/transform/bound_array_accessors_test.cc @@ -93,10 +93,8 @@ class BoundArrayAccessorsTest : public testing::Test { struct ModuleBuilder : public ast::BuilderWithModule { ast::Module Module() { Build(); - auto* body = create(statements); - mod->AddFunction(create(mod->RegisterSymbol("func"), "func", - ast::VariableList{}, ty.void_, body, - ast::FunctionDecorationList{})); + mod->AddFunction(Func("func", ast::VariableList{}, ty.void_, statements, + ast::FunctionDecorationList{})); return std::move(*mod); } diff --git a/src/transform/emit_vertex_point_size_test.cc b/src/transform/emit_vertex_point_size_test.cc index 347dab3754..c3c5f70775 100644 --- a/src/transform/emit_vertex_point_size_test.cc +++ b/src/transform/emit_vertex_point_size_test.cc @@ -53,31 +53,25 @@ struct ModuleBuilder : public ast::BuilderWithModule { TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { struct Builder : ModuleBuilder { void Build() override { - auto* block = create(ast::StatementList{ - create( - Var("builtin_assignments_should_happen_before_this", - tint::ast::StorageClass::kFunction, ty.f32)), - }); + mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_, + ast::StatementList{}, + ast::FunctionDecorationList{})); - auto a_sym = mod->RegisterSymbol("non_entry_a"); - mod->AddFunction(create( - a_sym, "non_entry_a", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{})); - - auto entry_sym = mod->RegisterSymbol("entry"); - auto* entry = create( - entry_sym, "entry", ast::VariableList{}, ty.void_, block, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* entry = + Func("entry", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Var("builtin_assignments_should_happen_before_this", + tint::ast::StorageClass::kFunction, ty.f32)), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(entry); - auto b_sym = mod->RegisterSymbol("non_entry_b"); - mod->AddFunction(create( - b_sym, "non_entry_b", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{})); + mod->AddFunction(Func("non_entry_b", ast::VariableList{}, ty.void_, + ast::StatementList{}, + ast::FunctionDecorationList{})); } }; @@ -127,25 +121,19 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { struct Builder : ModuleBuilder { void Build() override { - auto a_sym = mod->RegisterSymbol("non_entry_a"); - mod->AddFunction(create( - a_sym, "non_entry_a", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{})); + mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_, + ast::StatementList{}, + ast::FunctionDecorationList{})); - auto entry_sym = mod->RegisterSymbol("entry"); - mod->AddFunction(create( - entry_sym, "entry", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - })); + mod->AddFunction( + Func("entry", ast::VariableList{}, ty.void_, ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + })); - auto b_sym = mod->RegisterSymbol("non_entry_b"); - mod->AddFunction(create( - b_sym, "non_entry_b", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{})); + mod->AddFunction(Func("non_entry_b", ast::VariableList{}, ty.void_, + ast::StatementList{}, + ast::FunctionDecorationList{})); } }; @@ -188,19 +176,15 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { TEST_F(EmitVertexPointSizeTest, NonVertexStage) { struct Builder : ModuleBuilder { void Build() override { - auto frag_sym = mod->RegisterSymbol("fragment_entry"); - auto* fragment_entry = create( - frag_sym, "fragment_entry", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), + auto* fragment_entry = Func( + "fragment_entry", ast::VariableList{}, ty.void_, ast::StatementList{}, ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment), }); mod->AddFunction(fragment_entry); - auto comp_sym = mod->RegisterSymbol("compute_entry"); - auto* compute_entry = create( - comp_sym, "compute_entry", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), + auto* compute_entry = Func( + "compute_entry", ast::VariableList{}, ty.void_, ast::StatementList{}, ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute), }); diff --git a/src/transform/first_index_offset_test.cc b/src/transform/first_index_offset_test.cc index 886ae64e52..5538577445 100644 --- a/src/transform/first_index_offset_test.cc +++ b/src/transform/first_index_offset_test.cc @@ -58,9 +58,8 @@ struct ModuleBuilder : public ast::BuilderWithModule { ast::Function* AddFunction(const std::string& name, ast::StatementList stmts) { - auto* func = create( - mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32, - create(stmts), ast::FunctionDecorationList{}); + auto* func = Func(name, ast::VariableList{}, ty.u32, stmts, + ast::FunctionDecorationList{}); mod->AddFunction(func); return func; } diff --git a/src/transform/vertex_pulling_test.cc b/src/transform/vertex_pulling_test.cc index 3a7c2f0c60..61a968edb5 100644 --- a/src/transform/vertex_pulling_test.cc +++ b/src/transform/vertex_pulling_test.cc @@ -46,12 +46,10 @@ class VertexPullingHelper : public ast::BuilderWithModule { // Create basic module with an entry point and vertex function void InitBasicModule() { - auto* func = create( - mod->RegisterSymbol("main"), "main", ast::VariableList{}, - mod->create(), - create(ast::StatementList{}), - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex)}); + auto* func = + Func("main", ast::VariableList{}, ty.void_, ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex)}); mod->AddFunction(func); } @@ -115,13 +113,11 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) { } TEST_F(VertexPullingTest, Error_EntryPointWrongStage) { - auto* func = create( - mod->RegisterSymbol("main"), "main", ast::VariableList{}, - mod->create(), - create(ast::StatementList{}), - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("main", ast::VariableList{}, ty.void_, ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); InitTransform({}); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index a3abb7fa7c..f35214040f 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -290,10 +290,8 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) { TEST_F(TypeDeterminerTest, Stmt_Call) { ast::VariableList params; - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", params, ty.f32, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -314,22 +312,20 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) { SetSource(Source::Location{12, 34}); auto* call_expr = Call("func"); ast::VariableList params0; - auto* main_body = create(ast::StatementList{ - create(call_expr), - create(), - }); - auto* func_main = - create(mod->RegisterSymbol("main"), "main", params0, - ty.f32, main_body, ast::FunctionDecorationList{}); + auto* func_main = Func("main", params0, ty.f32, + ast::StatementList{ + create(call_expr), + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func_main); - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = - create(mod->RegisterSymbol("func"), "func", params0, - ty.f32, body, ast::FunctionDecorationList{}); + auto* func = Func("func", params0, ty.f32, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_FALSE(td()->Determine()) << td()->error(); @@ -481,10 +477,8 @@ TEST_F(TypeDeterminerTest, Expr_Bitcast) { TEST_F(TypeDeterminerTest, Expr_Call) { ast::VariableList params; - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", params, ty.f32, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -498,10 +492,8 @@ TEST_F(TypeDeterminerTest, Expr_Call) { TEST_F(TypeDeterminerTest, Expr_Call_WithParams) { ast::VariableList params; - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", params, ty.f32, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", params, ty.f32, ast::StatementList{}, + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -589,13 +581,12 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { auto* var = Const("my_var", ast::StorageClass::kNone, ty.f32); - auto* body = create(ast::StatementList{ - create(var), - create(my_var, Expr("my_var")), - }); - auto* f = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + auto* f = Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create(var), + create(my_var, Expr("my_var")), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->DetermineFunction(f)); @@ -606,15 +597,13 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) { auto* my_var = Expr("my_var"); - auto* body = create(ast::StatementList{ - create( - Var("my_var", ast::StorageClass::kNone, ty.f32)), - create(my_var, Expr("my_var")), - }); - - auto* f = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + auto* f = Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create( + Var("my_var", ast::StorageClass::kNone, ty.f32)), + create(my_var, Expr("my_var")), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->DetermineFunction(f)); @@ -631,17 +620,13 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { auto* my_var = Expr("my_var"); - auto* body = create( - - ast::StatementList{ - create( - Var("my_var", ast::StorageClass::kNone, &ptr)), - create(my_var, Expr("my_var")), - }); - - auto* f = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + auto* f = Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create( + Var("my_var", ast::StorageClass::kNone, &ptr)), + create(my_var, Expr("my_var")), + }, + ast::FunctionDecorationList{}); EXPECT_TRUE(td()->DetermineFunction(f)); @@ -654,10 +639,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { } TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.f32, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -687,15 +670,15 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) { mod->AddGlobalVariable(wg_var); mod->AddGlobalVariable(priv_var); - auto* body = create(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")), - }); - auto* func = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(func); @@ -724,25 +707,24 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { mod->AddGlobalVariable(wg_var); mod->AddGlobalVariable(priv_var); - auto* body = create(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")), - }); - auto* func = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(func); - body = create(ast::StatementList{ - create(Expr("out_var"), Call("my_func")), - }); - - auto* func2 = create(mod->RegisterSymbol("func"), "func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + auto* func2 = Func( + "func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create(Expr("out_var"), Call("my_func")), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func2); @@ -761,17 +743,15 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) { auto* var = Var("in_var", ast::StorageClass::kFunction, ty.f32); - auto* body = create( - - ast::StatementList{ - create(var), - create( - Expr("var"), create( - create(ty.f32, 1.f))), - }); - auto* func = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.f32, body, - ast::FunctionDecorationList{}); + auto* func = + Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create(var), + create( + Expr("var"), create( + create(ty.f32, 1.f))), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -1742,10 +1722,8 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) { auto* var = Var("var", ast::StorageClass::kNone, ty.i32); auto* stmt = create(var); - auto* body = create(ast::StatementList{stmt}); - auto* func = create(mod->RegisterSymbol("func"), "func", - ast::VariableList{}, ty.i32, body, - ast::FunctionDecorationList{}); + auto* func = Func("func", ast::VariableList{}, ty.i32, + ast::StatementList{stmt}, ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -1756,10 +1734,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* body = create(ast::StatementList{stmt}); - auto* func = create(mod->RegisterSymbol("func"), "func", - ast::VariableList{}, ty.i32, body, - ast::FunctionDecorationList{}); + auto* func = Func("func", ast::VariableList{}, ty.i32, + ast::StatementList{stmt}, ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -1771,10 +1747,8 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) { auto* var = Var("var", ast::StorageClass::kWorkgroup, ty.i32); auto* stmt = create(var); - auto* body = create(ast::StatementList{stmt}); - auto* func = create(mod->RegisterSymbol("func"), "func", - ast::VariableList{}, ty.i32, body, - ast::FunctionDecorationList{}); + auto* func = Func("func", ast::VariableList{}, ty.i32, + ast::StatementList{stmt}, ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -2886,51 +2860,40 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) { // ep_2 -> {} ast::VariableList params; - auto* body = create(ast::StatementList{}); - auto* func_b = - create(mod->RegisterSymbol("b"), "b", params, ty.f32, body, - ast::FunctionDecorationList{}); - - body = create( - - ast::StatementList{ - create(Expr("second"), Call("b")), - }); + auto* func_b = Func("b", params, ty.f32, ast::StatementList{}, + ast::FunctionDecorationList{}); auto* func_c = - create(mod->RegisterSymbol("c"), "c", params, ty.f32, body, - ast::FunctionDecorationList{}); + Func("c", params, ty.f32, + ast::StatementList{ + create(Expr("second"), Call("b")), + }, + ast::FunctionDecorationList{}); - body = create( - - ast::StatementList{ - create(Expr("first"), Call("c")), - }); auto* func_a = - create(mod->RegisterSymbol("a"), "a", params, ty.f32, body, - ast::FunctionDecorationList{}); + Func("a", params, ty.f32, + ast::StatementList{ + create(Expr("first"), Call("c")), + }, + ast::FunctionDecorationList{}); - body = create( + auto* ep_1 = + Func("ep_1", params, ty.f32, + ast::StatementList{ + create(Expr("call_a"), Call("a")), + create(Expr("call_b"), Call("b")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); - ast::StatementList{ - create(Expr("call_a"), Call("a")), - create(Expr("call_b"), Call("b")), - }); - auto* ep_1 = create( - mod->RegisterSymbol("ep_1"), "ep_1", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); - - body = create( - - ast::StatementList{ - create(Expr("call_c"), Call("c")), - }); - auto* ep_2 = create( - mod->RegisterSymbol("ep_2"), "ep_2", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* ep_2 = + Func("ep_2", params, ty.f32, + ast::StatementList{ + create(Expr("call_c"), Call("c")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func_b); mod->AddFunction(func_c); diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 5d2b2466cf..b4855fe1aa 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -41,13 +41,11 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2), ast::VariableDecorationList{}); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(var), - }); - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func", - params, ty.void_, body, + auto* func = Func( + Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + }, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex), }); @@ -61,13 +59,12 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) { // [[stage(vertex)]] // fn func -> void {} - ast::VariableList params; - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func", - params, ty.void_, create(ast::StatementList{}), - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func = + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, + ty.void_, ast::StatementList{}, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -80,13 +77,12 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32, Expr(2), ast::VariableDecorationList{}); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(var), - }); - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func", - params, ty.i32, body, ast::FunctionDecorationList{}); + auto* func = Func(Source{Source::Location{12, 34}}, "func", + ast::VariableList{}, ty.i32, + ast::StatementList{ + create(var), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -97,11 +93,9 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) { TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) { // fn func -> int {} - ast::VariableList params; - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func", - params, ty.i32, create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = + Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, + ty.i32, ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -113,16 +107,14 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { // [[stage(vertex)]] // fn func -> void { return; } - ast::VariableList params; - - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create( - mod->RegisterSymbol("func"), "func", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func = + Func("func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func); EXPECT_TRUE(td()->DetermineFunctions(mod->functions())) << td()->error(); @@ -131,17 +123,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { // fn func -> void { return 2; } - ast::VariableList params; - auto* return_expr = Expr(2); - - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, - return_expr), - }); - - auto* func = - create(mod->RegisterSymbol("func"), "func", params, - ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, Expr(2)), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -154,17 +141,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) { // fn func -> f32 { return 2; } - ast::VariableList params; - auto* return_expr = Expr(2); - - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, - return_expr), - }); - - auto* func = - create(mod->RegisterSymbol("func"), "func", params, ty.f32, - body, ast::FunctionDecorationList{}); + auto* func = Func("func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, Expr(2)), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -178,26 +160,18 @@ 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{}); - ast::VariableList params; - auto* return_expr = Expr(2); - - auto* body = create(ast::StatementList{ - create(return_expr), - }); - auto* func = - create(mod->RegisterSymbol("func"), "func", params, ty.i32, - body, ast::FunctionDecorationList{}); - - ast::VariableList params_copy; - auto* return_expr_copy = Expr(2); - auto* body_copy = create(ast::StatementList{ - create(return_expr_copy), - }); - - auto* func_copy = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func", - params_copy, ty.i32, body_copy, ast::FunctionDecorationList{}); + auto* func_copy = Func(Source{Source::Location{12, 34}}, "func", + ast::VariableList{}, ty.i32, + ast::StatementList{ + create(Expr(2)), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); mod->AddFunction(func_copy); @@ -212,14 +186,13 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) { ast::ExpressionList call_params; auto* call_expr = create( Source{Source::Location{12, 34}}, Expr("func"), call_params); - ast::VariableList params0; - auto* body0 = create(ast::StatementList{ - create(call_expr), - create(), - }); - auto* func0 = - create(mod->RegisterSymbol("func"), "func", params0, - ty.f32, body0, ast::FunctionDecorationList{}); + + auto* func0 = Func("func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create(call_expr), + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func0); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -235,17 +208,12 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.i32, call_expr, ast::VariableDecorationList{}); - ast::VariableList params0; - auto* return_expr = Expr(2); - - auto* body0 = create(ast::StatementList{ - create(var), - create(return_expr), - }); - - auto* func0 = - create(mod->RegisterSymbol("func"), "func", params0, - ty.i32, body0, ast::FunctionDecorationList{}); + auto* func0 = Func("func", ast::VariableList{}, ty.i32, + ast::StatementList{ + create(var), + create(Expr(2)), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func0); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -256,15 +224,11 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) { TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) { // [[stage(vertex)]] // fn vtx_main() -> i32 { return 0; } - ast::VariableList params; - auto* return_expr = Expr(0); - - auto* body = create(ast::StatementList{ - create(return_expr), - }); - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("vtx_main"), - "vtx_main", params, ty.i32, body, + 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), }); @@ -279,18 +243,17 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) { TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) { // [[stage(vertex)]] // fn vtx_func(a : i32) -> void { return; } - ast::VariableList params; - params.push_back(Var("a", ast::StorageClass::kNone, ty.i32, nullptr, - ast::VariableDecorationList{})); - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("vtx_func"), - "vtx_func", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + 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), + }); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -304,13 +267,11 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) { // [[stage(fragment)]] // [[stage(vertex)]] // fn main() -> void { return; } - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create( - Source{Source::Location{12, 34}}, mod->RegisterSymbol("main"), "main", - params, ty.void_, body, + 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), @@ -327,15 +288,14 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) { TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) { // [[stage(vertex)]] // fn vtx_func() -> void { return; } - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create( - mod->RegisterSymbol("vtx_func"), "vtx_func", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func = + Func("vtx_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -344,13 +304,11 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) { TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) { // fn vtx_func() -> void { return; } - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = - create(mod->RegisterSymbol("vtx_func"), "vtx_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("vtx_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc index 7a19bb5bfd..bc37db6346 100644 --- a/src/validator/validator_test.cc +++ b/src/validator/validator_test.cc @@ -255,15 +255,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) { auto* lhs = Expr("not_global_var"); auto* rhs = Expr(3.14f); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, lhs, - rhs), - }); - - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.f32, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); EXPECT_FALSE(v()->Validate(mod)); @@ -284,19 +281,16 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) { mod->RegisterSymbol("global_var"), "global_var"); auto* rhs = Expr(3.14f); - ast::VariableList params; - - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, lhs, - rhs), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func = + Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func); EXPECT_TRUE(td()->Determine()) << td()->error(); @@ -435,14 +429,13 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) { auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f), ast::VariableDecorationList{}); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, var), - }); - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -463,16 +456,13 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) { auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32, Expr(0.1f), ast::VariableDecorationList{}); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(var), - create(Source{Source::Location{12, 34}}, - var_a_float), - }); - - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create( + Source{Source::Location{12, 34}}, var_a_float), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -547,28 +537,24 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) { auto* var1 = Var("a", ast::StorageClass::kNone, ty.void_, Expr(1.0f), ast::VariableDecorationList{}); - ast::VariableList params0; - auto* body0 = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, - var0), - create(), - }); + auto* func0 = Func("func0", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var0), + create(), + }, + ast::FunctionDecorationList{}); - auto* func0 = - create(mod->RegisterSymbol("func0"), "func0", params0, - ty.void_, body0, ast::FunctionDecorationList{}); - - ast::VariableList params1; - auto* body1 = create(ast::StatementList{ - create(Source{Source::Location{13, 34}}, - var1), - create(), - }); - auto* func1 = create( - mod->RegisterSymbol("func1"), "func1", params1, ty.void_, body1, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func1 = + Func("func1", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{13, 34}}, var1), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func0); mod->AddFunction(func1); diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc index 1bc997c6f4..597ce7de13 100644 --- a/src/validator/validator_type_test.cc +++ b/src/validator/validator_type_test.cc @@ -149,15 +149,15 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) { // fn func -> void { var a : array; } auto* var = Var("a", ast::StorageClass::kNone, ty.array()); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Source{Source::Location{12, 34}}, var), - }); - auto* func = create( - mod->RegisterSymbol("func"), "func", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + auto* func = + Func("func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kVertex), + }); mod->AddFunction(func); 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 cce256af81..457acde5c8 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -459,10 +459,8 @@ if (_tint_tmp) { TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) { // foo(a && b, c || d, (a || c) && (b || d)) - auto* func = create( - mod->RegisterSymbol("foo"), "foo", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("foo", ast::VariableList{}, ty.void_, ast::StatementList{}, + ast::FunctionDecorationList{}); mod->AddFunction(func); ast::ExpressionList params; diff --git a/src/writer/hlsl/generator_impl_call_test.cc b/src/writer/hlsl/generator_impl_call_test.cc index 5cb1e0a40d..c9b40b4342 100644 --- a/src/writer/hlsl/generator_impl_call_test.cc +++ b/src/writer/hlsl/generator_impl_call_test.cc @@ -32,10 +32,8 @@ using HlslGeneratorImplTest_Call = TestHelper; TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { auto* call = Call("my_func"); - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); @@ -45,10 +43,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { auto* call = Call("my_func", "param1", "param2"); - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); @@ -58,10 +54,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { auto* call = create(Call("my_func", "param1", "param2")); - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(out, call)) << gen.error(); 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 366ab7a4d1..6bce585852 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,16 +60,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + 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), + }); mod->AddFunction(func); @@ -111,17 +110,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + 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), + }); mod->AddFunction(func); @@ -163,17 +160,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kVertex), - }); + 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), + }); mod->AddFunction(func); @@ -215,16 +210,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + 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), + }); mod->AddFunction(func); @@ -263,16 +257,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + 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), + }); mod->AddFunction(func); @@ -306,16 +299,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("foo"), Expr("foo")), - create(Expr("bar"), Expr("bar")), - }); - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.f32, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + 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), + }); mod->AddFunction(func); @@ -357,16 +349,15 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod->AddGlobalVariable(coord_var); mod->AddGlobalVariable(depth_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - }); - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(Expr("depth"), + MemberAccessor("coord", "x")), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 7ac56d409d..7f3741e372 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -53,12 +53,11 @@ namespace { using HlslGeneratorImplTest_Function = TestHelper; TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.void_, body, - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -72,12 +71,11 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = create( - mod->RegisterSymbol("GeometryShader"), "GeometryShader", - ast::VariableList{}, ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("GeometryShader", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -91,16 +89,15 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { - ast::VariableList params; - params.push_back(Var("a", ast::StorageClass::kNone, ty.f32)); - params.push_back(Var("b", ast::StorageClass::kNone, ty.i32)); - - auto* body = create(ast::StatementList{ - create(), - }); auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(func); gen.increment_indent(); @@ -131,16 +128,15 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("bar"), Expr("foo")), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(Expr("bar"), Expr("foo")), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -183,17 +179,16 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(coord_var); mod->AddGlobalVariable(depth_var); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(Expr("depth"), + MemberAccessor("coord", "x")), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -228,19 +223,18 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(coord_var); mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, MemberAccessor("coord", "x"), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -277,21 +271,20 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(coord_var); mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, create( MemberAccessor("uniforms", "coord"), Expr("x")), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -331,19 +324,18 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(coord_var); mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -380,19 +372,18 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(coord_var); mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, MemberAccessor("coord", "b"), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -426,21 +417,18 @@ TEST_F(HlslGeneratorImplTest_Function, }); td.RegisterVariableForTesting(coord_var); - mod->AddGlobalVariable(coord_var); - auto* body = create(ast::StatementList{ - create(MemberAccessor("coord", "b"), - Expr(2.0f)), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", ast::VariableList{}, - ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + 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), + }); mod->AddFunction(func); @@ -483,26 +471,25 @@ TEST_F( mod->AddGlobalVariable(bar_var); mod->AddGlobalVariable(val_var); - ast::VariableList params; - params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); - - auto* body = create(ast::StatementList{ - create(Expr("bar"), Expr("foo")), - create(Expr("val"), Expr("param")), - create(Expr("foo")), - }); - auto* sub_func = - create(mod->RegisterSymbol("sub_func"), "sub_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(sub_func); - body = create(ast::StatementList{ - create(Expr("bar"), Call("sub_func", 1.0f)), - create(), - }); - auto* func_1 = create( - mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body, + auto* func_1 = Func( + "ep_1", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(Expr("bar"), Call("sub_func", 1.0f)), + create(), + }, ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment), }); @@ -547,27 +534,27 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(depth_var); - ast::VariableList params; - params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); - - auto* body = create(ast::StatementList{ - create(Expr("param")), - }); - auto* sub_func = - create(mod->RegisterSymbol("sub_func"), "sub_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + auto* sub_func = Func( + "sub_func", + ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)}, + ty.f32, + ast::StatementList{ + create(Expr("param")), + }, + ast::FunctionDecorationList{}); mod->AddFunction(sub_func); - body = create(ast::StatementList{ - create(Expr("depth"), Call("sub_func", 1.0f)), - create(), - }); - auto* func_1 = create( - mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + 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), + }); mod->AddFunction(func_1); @@ -612,29 +599,29 @@ TEST_F( mod->AddGlobalVariable(coord_var); mod->AddGlobalVariable(depth_var); - ast::VariableList params; - params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); - - auto* body = create(ast::StatementList{ - create(Expr("depth"), - MemberAccessor("coord", "x")), - create(Expr("param")), - }); - auto* sub_func = - create(mod->RegisterSymbol("sub_func"), "sub_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(sub_func); - body = create(ast::StatementList{ - create(Expr("depth"), Call("sub_func", 1.0f)), - create(), - }); - auto* func_1 = create( - mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + 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), + }); mod->AddFunction(func_1); @@ -675,32 +662,29 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(coord_var); - ast::VariableList params; - params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); - - auto* body = create(ast::StatementList{ - create(MemberAccessor("coord", "x")), - }); - - auto* sub_func = - create(mod->RegisterSymbol("sub_func"), "sub_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(sub_func); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, Call("sub_func", 1.0f), ast::VariableDecorationList{}); - body = create(ast::StatementList{ - create(var), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -736,32 +720,29 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(coord_var); - ast::VariableList params; - params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32)); - - auto* body = create(ast::StatementList{ - create(MemberAccessor("coord", "x")), - }); - - auto* sub_func = - create(mod->RegisterSymbol("sub_func"), "sub_func", params, - ty.f32, body, ast::FunctionDecorationList{}); + 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{}); mod->AddFunction(sub_func); auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, Call("sub_func", 1.0f), ast::VariableDecorationList{}); - body = create(ast::StatementList{ - create(var), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("frag_main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); mod->AddFunction(func); @@ -795,17 +776,15 @@ TEST_F(HlslGeneratorImplTest_Function, create(), }); - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(Expr("bar"), Expr(1.0f)), - create(create( - ast::BinaryOp::kEqual, Expr(1), Expr(1)), - list, ast::ElseStatementList{}), - create(), - }); - - auto* func_1 = create( - mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body, + auto* func_1 = Func( + "ep_1", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(Expr("bar"), Expr(1.0f)), + create(create( + ast::BinaryOp::kEqual, Expr(1), Expr(1)), + list, ast::ElseStatementList{}), + create(), + }, ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment), }); @@ -832,10 +811,8 @@ ep_1_out ep_1() { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_WithNameCollision) { - auto* func = create( - mod->RegisterSymbol("GeometryShader"), "GeometryShader", - ast::VariableList{}, ty.void_, - create(ast::StatementList{}), + auto* func = Func( + "GeometryShader", ast::VariableList{}, ty.void_, ast::StatementList{}, ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment), }); @@ -851,16 +828,14 @@ TEST_F(HlslGeneratorImplTest_Function, TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_Compute) { - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(), - }); - - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + auto* func = + Func("main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); mod->AddFunction(func); @@ -876,17 +851,15 @@ void main() { TEST_F(HlslGeneratorImplTest_Function, Emit_FunctionDecoration_EntryPoint_Compute_WithWorkgroup) { - ast::VariableList params; - auto* body = create(ast::StatementList{ - create(), - }); - - auto* func = create( - mod->RegisterSymbol("main"), "main", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - create(2u, 4u, 6u), - }); + auto* func = + Func("main", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + create(2u, 4u, 6u), + }); mod->AddFunction(func); @@ -903,15 +876,13 @@ void main() { TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { ast::type::Array ary(ty.f32, 5, ast::ArrayDecorationList{}); - ast::VariableList params; - params.push_back(Var("a", ast::StorageClass::kNone, &ary)); - - auto* body = create(ast::StatementList{ - create(), - }); - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + auto* func = Func("my_func", + ast::VariableList{Var("a", ast::StorageClass::kNone, &ary)}, + ty.void_, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -960,39 +931,35 @@ TEST_F(HlslGeneratorImplTest_Function, mod->AddGlobalVariable(data_var); { - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("a"), "a", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + auto* func = + Func("a", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } { - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, MemberAccessor("data", "d"), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("b"), "b", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + auto* func = + Func("b", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index 0d1baa6875..a3f2af4084 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -29,10 +29,8 @@ using HlslGeneratorImplTest = TestHelper; TEST_F(HlslGeneratorImplTest, Generate) { ast::type::Void void_type; - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); ASSERT_TRUE(gen.Generate(out)) << gen.error(); diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index da883866e4..ea149a3505 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -38,10 +38,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { Source{}, mod->RegisterSymbol("my_func"), "my_func"); ast::CallExpression call(Source{}, id, {}); - auto* func = create( - Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}, ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -60,10 +58,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { Source{}, mod->RegisterSymbol("param2"), "param2")); ast::CallExpression call(Source{}, id, params); - auto* func = create( - Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}, ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -83,10 +79,8 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) { ast::CallStatement call(Source{}, create(Source{}, id, params)); - auto* func = create( - Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}, ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{}, ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); 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 fe17c53af5..08510478f6 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 @@ -80,24 +80,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "vtx_main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kVertex), }); @@ -157,24 +155,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "vtx_main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kVertex), }); @@ -234,24 +230,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -311,24 +305,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -385,24 +377,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kCompute), }); @@ -454,24 +444,22 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("foo"), "foo"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("bar"), "bar")), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body, + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("foo"), "foo"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("bar"), "bar")), + }; + auto* func = Func( + "main", ast::VariableList{}, &f32, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kCompute), }); @@ -529,24 +517,20 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { mod->AddGlobalVariable(coord_var); mod->AddGlobalVariable(depth_var); - ast::VariableList params; - - auto* body = create( - Source{}, - ast::StatementList{ - create( + auto body = ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("depth"), "depth"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("depth"), "depth"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("x"), "x"))), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", params, &void_type, body, + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("x"), "x"))), + }; + auto* func = Func( + "main", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index b7e539e5dd..f926bbfb7d 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -58,14 +58,11 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Function) { ast::type::Void void_type; - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}), - }); - - auto* func = create(Source{}, mod->RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - body, ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -83,14 +80,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function) { TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { ast::type::Void void_type; - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}), - }); - - auto* func = create(Source{}, mod->RegisterSymbol("main"), - "main", ast::VariableList{}, &void_type, - body, ast::FunctionDecorationList{}); + auto* func = Func("main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -129,14 +123,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { ast::type::Void void_type; - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}), - }); - - auto* func = create(Source{}, mod->RegisterSymbol("my_func"), - "my_func", params, &void_type, body, - ast::FunctionDecorationList{}); + auto* func = Func("my_func", params, &void_type, + ast::StatementList{ + create(Source{}), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); gen.increment_indent(); @@ -185,22 +176,18 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { mod->AddGlobalVariable(foo_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; - auto* body = create( - Source{}, ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, - ast::FunctionDecorationList{create( - Source{}, ast::PipelineStage::kFragment)}); + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create(Source{}), + }; + auto* func = Func("frag_main", ast::VariableList{}, &void_type, body, + ast::FunctionDecorationList{create( + Source{}, ast::PipelineStage::kFragment)}); mod->AddFunction(func); @@ -262,25 +249,21 @@ TEST_F(MslGeneratorImplTest, mod->AddGlobalVariable(coord_var); mod->AddGlobalVariable(depth_var); - ast::VariableList params; - auto* body = create( - Source{}, - ast::StatementList{ - create( + auto body = ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("depth"), "depth"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("depth"), "depth"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("x"), "x"))), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("x"), "x"))), + create(Source{}), + }; + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -327,7 +310,6 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -342,14 +324,12 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { "x")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -400,7 +380,6 @@ TEST_F(MslGeneratorImplTest, mod->AddGlobalVariable(coord_var); - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -415,14 +394,12 @@ TEST_F(MslGeneratorImplTest, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -474,11 +451,8 @@ TEST_F(MslGeneratorImplTest, }); td.RegisterVariableForTesting(coord_var); - mod->AddGlobalVariable(coord_var); - ast::VariableList params; - auto* var = create( Source{}, // source "v", // name @@ -493,14 +467,12 @@ TEST_F(MslGeneratorImplTest, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -585,28 +557,25 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, - ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("val"), "val"), - create( - Source{}, mod->RegisterSymbol("param"), "param")), - create( - Source{}, create( - Source{}, mod->RegisterSymbol("foo"), "foo")), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body, - ast::FunctionDecorationList{}); + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create(Source{}, + mod->RegisterSymbol("foo"), "foo")), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("val"), "val"), + create( + Source{}, mod->RegisterSymbol("param"), "param")), + create( + Source{}, create( + Source{}, mod->RegisterSymbol("foo"), "foo")), + }; + auto* sub_func = + Func("sub_func", params, &f32, body, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -614,22 +583,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create( - Source{}, - ast::StatementList{ - create( + body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("bar"), "bar"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), - expr)), - create(Source{}), - }); - auto* func_1 = create( - Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, + Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }; + auto* func_1 = Func( + "ep_1", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -697,15 +664,13 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, + auto* sub_func = Func( + "sub_func", params, &f32, ast::StatementList{ create( Source{}, create( Source{}, mod->RegisterSymbol("param"), "param")), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body, + }, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -714,23 +679,21 @@ TEST_F(MslGeneratorImplTest, expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create( - Source{}, - ast::StatementList{ - create( + auto body = ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("depth"), "depth"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("depth"), "depth"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), - expr)), - create(Source{}), - }); + Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }; - auto* func_1 = create( - Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, + auto* func_1 = Func( + "ep_1", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -806,26 +769,23 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, - ast::StatementList{ - create( + auto body = ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("depth"), "depth"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("depth"), "depth"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("x"), "x"))), - create( - Source{}, create( - Source{}, mod->RegisterSymbol("param"), "param")), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body, - ast::FunctionDecorationList{}); + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("x"), "x"))), + create( + Source{}, create( + Source{}, mod->RegisterSymbol("param"), "param")), + }; + auto* sub_func = + Func("sub_func", params, &f32, body, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -833,22 +793,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create( - Source{}, - ast::StatementList{ - create( + body = ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("depth"), "depth"), + create( Source{}, create( - Source{}, mod->RegisterSymbol("depth"), "depth"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), - expr)), - create(Source{}), - }); - auto* func_1 = create( - Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, + Source{}, mod->RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }; + auto* func_1 = Func( + "ep_1", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -910,21 +868,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, - ast::StatementList{ - create( - Source{}, - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("x"), "x"))), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body, - ast::FunctionDecorationList{}); + auto body = ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("x"), "x"))), + }; + auto* sub_func = + Func("sub_func", params, &f32, body, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -945,15 +899,12 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -1016,21 +967,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, - ast::StatementList{ - create( - Source{}, - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("b"), "b"))), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, ty.f32, - body, ast::FunctionDecorationList{}); + auto body = ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("b"), "b"))), + }; + auto* sub_func = + Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -1051,15 +998,12 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -1128,21 +1072,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create( - Source{}, - ast::StatementList{ - create( - Source{}, - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("coord"), "coord"), - create( - Source{}, mod->RegisterSymbol("b"), "b"))), - }); - auto* sub_func = create( - Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, ty.f32, - body, ast::FunctionDecorationList{}); + auto body = ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod->RegisterSymbol("coord"), "coord"), + create( + Source{}, mod->RegisterSymbol("b"), "b"))), + }; + auto* sub_func = + Func("sub_func", params, ty.f32, body, ast::FunctionDecorationList{}); mod->AddFunction(sub_func); @@ -1163,15 +1103,12 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - - auto* func = create( - Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + auto* func = Func( + "frag_main", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -1221,35 +1158,32 @@ TEST_F(MslGeneratorImplTest, td.RegisterVariableForTesting(bar_var); mod->AddGlobalVariable(bar_var); - ast::VariableList params; auto* list = create( Source{}, ast::StatementList{ create(Source{}), }); - auto* body = create( - Source{}, - ast::StatementList{ - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("bar"), "bar"), + auto body = ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("bar"), "bar"), + create( + Source{}, create(Source{}, &f32, 1.0f))), + create( + Source{}, + create( + Source{}, ast::BinaryOp::kEqual, create( - Source{}, create(Source{}, &f32, 1.0f))), - create( - Source{}, - create( - Source{}, ast::BinaryOp::kEqual, - create( - Source{}, create(Source{}, &i32, 1)), - create( - Source{}, create(Source{}, &i32, 1))), - list, ast::ElseStatementList{}), - create(Source{}), - }); + Source{}, create(Source{}, &i32, 1)), + create( + Source{}, create(Source{}, &i32, 1))), + list, ast::ElseStatementList{}), + create(Source{}), + }; - auto* func_1 = create( - Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, + auto* func_1 = Func( + "ep_1", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kFragment), }); @@ -1280,9 +1214,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithNameCollision) { ast::type::Void void_type; - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", ast::VariableList{}, - &void_type, create(Source{}, ast::StatementList{}), + auto* func = Func( + "main", ast::VariableList{}, &void_type, ast::StatementList{}, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kCompute), }); @@ -1314,14 +1247,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) { ast::type::Void void_type; - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}), - }); - - auto* func = create(Source{}, mod->RegisterSymbol("my_func"), - "my_func", params, &void_type, body, - ast::FunctionDecorationList{}); + auto* func = Func("my_func", params, &void_type, + ast::StatementList{ + create(), + }, + ast::FunctionDecorationList{}); mod->AddFunction(func); @@ -1385,7 +1315,6 @@ TEST_F(MslGeneratorImplTest, mod->AddGlobalVariable(data_var); { - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -1401,23 +1330,20 @@ TEST_F(MslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body, - ast::FunctionDecorationList{ - create(Source{}, - ast::PipelineStage::kCompute), - }); + auto* func = Func("a", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, + ast::FunctionDecorationList{ + create( + Source{}, ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } { - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -1433,17 +1359,15 @@ TEST_F(MslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body, - ast::FunctionDecorationList{ - create(Source{}, - ast::PipelineStage::kCompute), - }); + auto* func = Func("b", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, + ast::FunctionDecorationList{ + create( + Source{}, ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index cf6df0e222..585f5581f7 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -50,9 +50,8 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Generate) { ast::type::Void void_type; - auto* func = create( - Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}, ast::StatementList{}), + auto* func = Func( + "my_func", ast::VariableList{}, &void_type, ast::StatementList{}, ast::FunctionDecorationList{ create(Source{}, ast::PipelineStage::kCompute), }); diff --git a/src/writer/spirv/builder_function_decoration_test.cc b/src/writer/spirv/builder_function_decoration_test.cc index 4f28dc5123..33fd1437d8 100644 --- a/src/writer/spirv/builder_function_decoration_test.cc +++ b/src/writer/spirv/builder_function_decoration_test.cc @@ -352,13 +352,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) { }); mod->AddGlobalVariable(fragdepth); - auto* body = create(ast::StatementList{ - create(Expr("fragdepth"), Expr(1.f)), - }); - - auto* func = create( - Source{}, mod->RegisterSymbol("main"), "main", ast::VariableList{}, - create(), body, ast::FunctionDecorationList{}); + auto* func = + Func("main", ast::VariableList{}, create(), + ast::StatementList{ + create(Expr("fragdepth"), Expr(1.f)), + }, + ast::FunctionDecorationList{}); func->add_referenced_module_variable(fragdepth); diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index adc847a609..600401c885 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -299,7 +299,6 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { mod->AddGlobalVariable(data_var); { - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -315,23 +314,20 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body, - ast::FunctionDecorationList{ - create(Source{}, - ast::PipelineStage::kCompute), - }); + auto* func = Func("a", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, + ast::FunctionDecorationList{ + create( + Source{}, ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } { - ast::VariableList params; auto* var = create( Source{}, // source "v", // name @@ -347,17 +343,15 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create( - Source{}, ast::StatementList{ - create(Source{}, var), - create(Source{}), - }); - auto* func = create( - Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body, - ast::FunctionDecorationList{ - create(Source{}, - ast::PipelineStage::kCompute), - }); + auto* func = Func("b", ast::VariableList{}, &void_type, + ast::StatementList{ + create(Source{}, var), + create(Source{}), + }, + ast::FunctionDecorationList{ + create( + Source{}, ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index 97b80282e0..e8e2fa7900 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -471,10 +471,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -506,10 +504,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) { auto* expr = Call(param.name, 1.0f); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -535,10 +531,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) { auto* expr = Call(param.name, vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -590,10 +584,8 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -616,10 +608,8 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) { auto* expr = Call("length", vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -644,10 +634,8 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) { auto* expr = Call("normalize", vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -677,10 +665,8 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -707,10 +693,8 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -745,10 +729,8 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -772,10 +754,8 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -802,10 +782,8 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -834,10 +812,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) { auto* expr = Call(param.name, 1.0f, 1.0f, 1.0f); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -865,10 +841,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -907,10 +881,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) { auto* expr = Call(param.name, 1); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -936,10 +908,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) { auto* expr = Call(param.name, vec2(1, 1)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -972,10 +942,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) { auto* expr = Call(param.name, 1u); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1001,10 +969,8 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) { auto* expr = Call(param.name, vec2(1u, 1u)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1037,10 +1003,8 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) { auto* expr = Call(param.name, 1, 1); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1066,10 +1030,8 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) { auto* expr = Call(param.name, vec2(1, 1), vec2(1, 1)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1103,10 +1065,8 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) { auto* expr = Call(param.name, 1u, 1u); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1132,10 +1092,8 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) { auto* expr = Call(param.name, vec2(1u, 1u), vec2(1u, 1u)); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1169,10 +1127,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) { auto* expr = Call(param.name, 1, 1, 1); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1200,10 +1156,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1236,10 +1190,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) { auto* expr = Call(param.name, 1u, 1u, 1u); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1267,10 +1219,8 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1301,10 +1251,8 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); @@ -1344,10 +1292,8 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -1383,10 +1329,8 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) { ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -1428,10 +1372,8 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) { auto* expr = Call("arrayLength", "ptr_var"); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error(); - auto* func = create( - mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_, - create(ast::StatementList{}), - ast::FunctionDecorationList{}); + auto* func = Func("a_func", ast::VariableList{}, ty.void_, + ast::StatementList{}, ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index 2b224c383a..59b70053cf 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -41,14 +41,12 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Function) { - auto* body = create(ast::StatementList{ - create(), - create(), - }); - - auto* func = create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.void_, body, - ast::FunctionDecorationList{}); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + create(), + }, + ast::FunctionDecorationList{}); gen.increment_indent(); @@ -61,18 +59,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { - auto* body = create(ast::StatementList{ - create(), - create(), - }); - - ast::VariableList params; - params.push_back(Var("a", ast::StorageClass::kNone, ty.f32)); - params.push_back(Var("b", ast::StorageClass::kNone, ty.i32)); - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", params, - ty.void_, body, ast::FunctionDecorationList{}); + Func("my_func", + ast::VariableList{Var("a", ast::StorageClass::kNone, ty.f32), + Var("b", ast::StorageClass::kNone, ty.i32)}, + ty.void_, + ast::StatementList{ + create(), + create(), + }, + ast::FunctionDecorationList{}); gen.increment_indent(); @@ -85,17 +81,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { - auto* body = create(ast::StatementList{ - create(), - create(), - }); - - auto* func = - create(mod->RegisterSymbol("my_func"), "my_func", - ast::VariableList{}, ty.void_, body, - ast::FunctionDecorationList{ - create(2u, 4u, 6u), - }); + auto* func = Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + create(), + }, + ast::FunctionDecorationList{ + create(2u, 4u, 6u), + }); gen.increment_indent(); @@ -109,17 +102,15 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { - auto* body = create(ast::StatementList{ - create(), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_, - body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - }); + auto* func = + Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + }); gen.increment_indent(); @@ -133,18 +124,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { - auto* body = create(ast::StatementList{ - create(), - create(), - }); - - auto* func = create( - mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_, - body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kFragment), - create(2u, 4u, 6u), - }); + auto* func = + Func("my_func", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kFragment), + create(2u, 4u, 6u), + }); gen.increment_indent(); @@ -198,41 +187,39 @@ TEST_F(WgslGeneratorImplTest, mod->AddGlobalVariable(data_var); { - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, create(Expr("data"), Expr("d")), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("a"), "a", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + auto* func = + Func("a", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } { - ast::VariableList params; auto* var = Var("v", ast::StorageClass::kFunction, ty.f32, create(Expr("data"), Expr("d")), ast::VariableDecorationList{}); - auto* body = create(ast::StatementList{ - create(var), - create(), - }); - auto* func = create( - mod->RegisterSymbol("b"), "b", params, ty.void_, body, - ast::FunctionDecorationList{ - create(ast::PipelineStage::kCompute), - }); + auto* func = + Func("b", ast::VariableList{}, ty.void_, + ast::StatementList{ + create(var), + create(), + }, + ast::FunctionDecorationList{ + create(ast::PipelineStage::kCompute), + }); mod->AddFunction(func); } diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index abc82a70e1..0bdd97fa84 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -32,10 +32,8 @@ using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Generate) { ast::type::Void void_type; - mod->AddFunction(create( - mod->RegisterSymbol("a_func"), "my_func", ast::VariableList{}, &void_type, - create(ast::StatementList{}), - ast::FunctionDecorationList{})); + mod->AddFunction(Func("my_func", ast::VariableList{}, &void_type, + ast::StatementList{}, ast::FunctionDecorationList{})); ASSERT_TRUE(gen.Generate(*mod)) << gen.error(); EXPECT_EQ(gen.result(), R"(fn my_func() -> void {