Add helper for function creation.

This CL adds a Func helper to the ast builder class. The helper is then
used through the various files to simplify function creation.

Change-Id: Ie93777586e9311d82cff5932dfba2c4ca763ae08
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35823
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2020-12-16 15:15:40 +00:00 committed by Commit Bot service account
parent 5e5e36e7d2
commit 181d8baf8f
24 changed files with 1186 additions and 1523 deletions

View File

@ -581,6 +581,42 @@ class Builder {
return mod->create<StructMemberOffsetDecoration>(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<ast::Function>(
source, mod->RegisterSymbol(name), name, params, type,
create<ast::BlockStatement>(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<ast::Function>(mod->RegisterSymbol(name), name, params, type,
create<ast::BlockStatement>(body),
decorations);
}
/// Creates a StructMember
/// @param name the struct member name
/// @param type the struct member type

View File

@ -81,13 +81,9 @@ class InspectorHelper : public ast::BuilderWithModule {
/// @returns a function object
ast::Function* MakeEmptyBodyFunction(
std::string name,
ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
return create<ast::Function>(Source{}, mod->RegisterSymbol(name), name,
ast::VariableList(), ty.void_, body,
ast::FunctionDecorationList decorations) {
return Func(name, ast::VariableList(), ty.void_,
ast::StatementList{create<ast::ReturnStatement>(Source{})},
decorations);
}
@ -99,18 +95,17 @@ class InspectorHelper : public ast::BuilderWithModule {
ast::Function* MakeCallerBodyFunction(
std::string caller,
std::string callee,
ast::FunctionDecorationList decorations = {}) {
ast::FunctionDecorationList decorations) {
auto* ident_expr = create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol(callee), callee);
auto* call_expr = create<ast::CallExpression>(Source{}, ident_expr,
ast::ExpressionList());
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
return Func(caller, ast::VariableList(), ty.void_,
ast::StatementList{
create<ast::CallStatement>(Source{}, call_expr),
create<ast::ReturnStatement>(Source{}),
});
return create<ast::Function>(Source{}, mod->RegisterSymbol(caller), caller,
ast::VariableList(), ty.void_, body,
},
decorations);
}
@ -152,7 +147,7 @@ class InspectorHelper : public ast::BuilderWithModule {
ast::Function* MakeInOutVariableBodyFunction(
std::string name,
std::vector<std::tuple<std::string, std::string>> 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<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(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<std::tuple<std::string, std::string>> 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<ast::CallStatement>(Source{}, call_expr));
stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(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,9 +457,8 @@ class InspectorHelper : public ast::BuilderWithModule {
}
stmts.emplace_back(create<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(Source{}, mod->RegisterSymbol(func_name),
func_name, ast::VariableList(), ty.void_, body,
return Func(func_name, ast::VariableList(), ty.void_, stmts,
ast::FunctionDecorationList{});
}
@ -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<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(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<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(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<ast::ReturnStatement>(Source{}));
auto* body = create<ast::BlockStatement>(Source{}, stmts);
return create<ast::Function>(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,19 +1525,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
ast::ExpressionList());
return create<ast::CallStatement>(Source{}, call_expr);
};
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
FuncCall("ub_foo_func"),
FuncCall("ub_bar_func"),
FuncCall("ub_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
ast::Function* func = create<ast::Function>(
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("ub_foo_func"), FuncCall("ub_bar_func"),
FuncCall("ub_baz_func"),
create<ast::ReturnStatement>()},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
mod->AddFunction(func);
@ -1690,17 +1668,15 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
ast::ExpressionList());
return create<ast::CallStatement>(Source{}, call_expr);
};
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
ast::Function* func = Func(
"ep_func", ast::VariableList(), ty.void_,
ast::StatementList{
FuncCall("sb_foo_func"),
FuncCall("sb_bar_func"),
FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
ast::Function* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(),
ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
});
@ -1865,17 +1841,15 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ast::ExpressionList());
return create<ast::CallStatement>(Source{}, call_expr);
};
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
ast::Function* func = Func(
"ep_func", ast::VariableList(), ty.void_,
ast::StatementList{
FuncCall("sb_foo_func"),
FuncCall("sb_bar_func"),
FuncCall("sb_baz_func"),
create<ast::ReturnStatement>(Source{}),
});
ast::Function* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(),
ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(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(

View File

@ -93,9 +93,7 @@ class BoundArrayAccessorsTest : public testing::Test {
struct ModuleBuilder : public ast::BuilderWithModule {
ast::Module Module() {
Build();
auto* body = create<ast::BlockStatement>(statements);
mod->AddFunction(create<ast::Function>(mod->RegisterSymbol("func"), "func",
ast::VariableList{}, ty.void_, body,
mod->AddFunction(Func("func", ast::VariableList{}, ty.void_, statements,
ast::FunctionDecorationList{}));
return std::move(*mod);
}

View File

@ -53,30 +53,24 @@ struct ModuleBuilder : public ast::BuilderWithModule {
TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
struct Builder : ModuleBuilder {
void Build() override {
auto* block = create<ast::BlockStatement>(ast::StatementList{
mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_,
ast::StatementList{},
ast::FunctionDecorationList{}));
auto* entry =
Func("entry", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(
Var("builtin_assignments_should_happen_before_this",
tint::ast::StorageClass::kFunction, ty.f32)),
});
auto a_sym = mod->RegisterSymbol("non_entry_a");
mod->AddFunction(create<ast::Function>(
a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}));
auto entry_sym = mod->RegisterSymbol("entry");
auto* entry = create<ast::Function>(
entry_sym, "entry", ast::VariableList{}, ty.void_, block,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
mod->AddFunction(entry);
auto b_sym = mod->RegisterSymbol("non_entry_b");
mod->AddFunction(create<ast::Function>(
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
mod->AddFunction(Func("non_entry_b", ast::VariableList{}, ty.void_,
ast::StatementList{},
ast::FunctionDecorationList{}));
}
};
@ -127,24 +121,18 @@ 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<ast::Function>(
a_sym, "non_entry_a", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
mod->AddFunction(Func("non_entry_a", ast::VariableList{}, ty.void_,
ast::StatementList{},
ast::FunctionDecorationList{}));
auto entry_sym = mod->RegisterSymbol("entry");
mod->AddFunction(create<ast::Function>(
entry_sym, "entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
mod->AddFunction(
Func("entry", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}));
auto b_sym = mod->RegisterSymbol("non_entry_b");
mod->AddFunction(create<ast::Function>(
b_sym, "non_entry_b", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
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<ast::Function>(
frag_sym, "fragment_entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
auto* fragment_entry = Func(
"fragment_entry", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
mod->AddFunction(fragment_entry);
auto comp_sym = mod->RegisterSymbol("compute_entry");
auto* compute_entry = create<ast::Function>(
comp_sym, "compute_entry", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
auto* compute_entry = Func(
"compute_entry", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});

View File

@ -58,9 +58,8 @@ struct ModuleBuilder : public ast::BuilderWithModule {
ast::Function* AddFunction(const std::string& name,
ast::StatementList stmts) {
auto* func = create<ast::Function>(
mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32,
create<ast::BlockStatement>(stmts), ast::FunctionDecorationList{});
auto* func = Func(name, ast::VariableList{}, ty.u32, stmts,
ast::FunctionDecorationList{});
mod->AddFunction(func);
return func;
}

View File

@ -46,10 +46,8 @@ class VertexPullingHelper : public ast::BuilderWithModule {
// Create basic module with an entry point and vertex function
void InitBasicModule() {
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", ast::VariableList{},
mod->create<ast::type::Void>(),
create<ast::BlockStatement>(ast::StatementList{}),
auto* func =
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
mod->AddFunction(func);
@ -115,10 +113,8 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) {
}
TEST_F(VertexPullingTest, Error_EntryPointWrongStage) {
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", ast::VariableList{},
mod->create<ast::type::Void>(),
create<ast::BlockStatement>(ast::StatementList{}),
auto* func =
Func("main", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});

View File

@ -290,9 +290,7 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::VariableList params;
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", params, ty.f32,
create<ast::BlockStatement>(ast::StatementList{}),
auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -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::BlockStatement>(ast::StatementList{
auto* func_main = Func("main", params0, ty.f32,
ast::StatementList{
create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(),
});
auto* func_main =
create<ast::Function>(mod->RegisterSymbol("main"), "main", params0,
ty.f32, main_body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(func_main);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func("func", params0, ty.f32,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("func"), "func", params0,
ty.f32, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
EXPECT_FALSE(td()->Determine()) << td()->error();
@ -481,9 +477,7 @@ TEST_F(TypeDeterminerTest, Expr_Bitcast) {
TEST_F(TypeDeterminerTest, Expr_Call) {
ast::VariableList params;
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", params, ty.f32,
create<ast::BlockStatement>(ast::StatementList{}),
auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -498,9 +492,7 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::VariableList params;
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", params, ty.f32,
create<ast::BlockStatement>(ast::StatementList{}),
auto* func = Func("my_func", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -589,12 +581,11 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) {
auto* var = Const("my_var", ast::StorageClass::kNone, ty.f32);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* f = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(my_var, Expr("my_var")),
});
auto* f = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->DetermineFunction(f));
@ -606,14 +597,12 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) {
TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
auto* my_var = Expr("my_var");
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* f = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::VariableDeclStatement>(
Var("my_var", ast::StorageClass::kNone, ty.f32)),
create<ast::AssignmentStatement>(my_var, Expr("my_var")),
});
auto* f = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->DetermineFunction(f));
@ -631,16 +620,12 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
auto* my_var = Expr("my_var");
auto* body = create<ast::BlockStatement>(
auto* f = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::VariableDeclStatement>(
Var("my_var", ast::StorageClass::kNone, &ptr)),
create<ast::AssignmentStatement>(my_var, Expr("my_var")),
});
auto* f = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
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<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.f32,
create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func);
// Register the function
@ -687,14 +670,14 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
mod->AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func(
"my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
});
auto* func = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -724,24 +707,23 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
mod->AddGlobalVariable(wg_var);
mod->AddGlobalVariable(priv_var);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func(
"my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
});
auto* func = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
body = create<ast::BlockStatement>(ast::StatementList{
auto* func2 = Func(
"func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("out_var"), Call("my_func")),
});
auto* func2 = create<ast::Function>(mod->RegisterSymbol("func"), "func",
ast::VariableList{}, ty.f32, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(func2);
@ -761,16 +743,14 @@ 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::BlockStatement>(
auto* func =
Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(
Expr("var"), create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(ty.f32, 1.f))),
});
auto* func = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.f32, body,
},
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<ast::VariableDeclStatement>(var);
auto* body = create<ast::BlockStatement>(ast::StatementList{stmt});
auto* func = create<ast::Function>(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<ast::VariableDeclStatement>(var);
auto* body = create<ast::BlockStatement>(ast::StatementList{stmt});
auto* func = create<ast::Function>(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<ast::VariableDeclStatement>(var);
auto* body = create<ast::BlockStatement>(ast::StatementList{stmt});
auto* func = create<ast::Function>(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,48 +2860,37 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
// ep_2 -> {}
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{});
auto* func_b =
create<ast::Function>(mod->RegisterSymbol("b"), "b", params, ty.f32, body,
auto* func_b = Func("b", params, ty.f32, ast::StatementList{},
ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(
auto* func_c =
Func("c", params, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("second"), Call("b")),
});
auto* func_c =
create<ast::Function>(mod->RegisterSymbol("c"), "c", params, ty.f32, body,
},
ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(
auto* func_a =
Func("a", params, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("first"), Call("c")),
});
auto* func_a =
create<ast::Function>(mod->RegisterSymbol("a"), "a", params, ty.f32, body,
},
ast::FunctionDecorationList{});
body = create<ast::BlockStatement>(
auto* ep_1 =
Func("ep_1", params, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("call_a"), Call("a")),
create<ast::AssignmentStatement>(Expr("call_b"), Call("b")),
});
auto* ep_1 = create<ast::Function>(
mod->RegisterSymbol("ep_1"), "ep_1", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
body = create<ast::BlockStatement>(
auto* ep_2 =
Func("ep_2", params, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("call_c"), Call("c")),
});
auto* ep_2 = create<ast::Function>(
mod->RegisterSymbol("ep_2"), "ep_2", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});

View File

@ -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::BlockStatement>(ast::StatementList{
auto* func = Func(
Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
});
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func",
params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -61,10 +59,9 @@ TEST_F(ValidateFunctionTest,
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
// [[stage(vertex)]]
// fn func -> void {}
ast::VariableList params;
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func",
params, ty.void_, create<ast::BlockStatement>(ast::StatementList{}),
auto* func =
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -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::BlockStatement>(ast::StatementList{
auto* func = Func(Source{Source::Location{12, 34}}, "func",
ast::VariableList{}, ty.i32,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
});
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func",
params, ty.i32, body, ast::FunctionDecorationList{});
},
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<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("func"), "func",
params, ty.i32, create<ast::BlockStatement>(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,13 +107,11 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
// [[stage(vertex)]]
// fn func -> void { return; }
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("func"), "func", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -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::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("func"), "func", params,
ty.void_, body, ast::FunctionDecorationList{});
auto* func = Func("func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(
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::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
return_expr),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("func"), "func", params, ty.f32,
body, ast::FunctionDecorationList{});
auto* func = Func("func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::ReturnStatement>(
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<ast::ReturnStatement>(Expr(2)),
},
ast::FunctionDecorationList{});
ast::VariableList params;
auto* return_expr = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(return_expr),
});
auto* func =
create<ast::Function>(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::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(return_expr_copy),
});
auto* func_copy = create<ast::Function>(
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<ast::ReturnStatement>(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<ast::CallExpression>(
Source{Source::Location{12, 34}}, Expr("func"), call_params);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(ast::StatementList{
auto* func0 = Func("func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(),
});
auto* func0 =
create<ast::Function>(mod->RegisterSymbol("func"), "func", params0,
ty.f32, body0, ast::FunctionDecorationList{});
},
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::BlockStatement>(ast::StatementList{
auto* func0 = Func("func", ast::VariableList{}, ty.i32,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(return_expr),
});
auto* func0 =
create<ast::Function>(mod->RegisterSymbol("func"), "func", params0,
ty.i32, body0, ast::FunctionDecorationList{});
create<ast::ReturnStatement>(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::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(return_expr),
});
auto* func = create<ast::Function>(
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<ast::ReturnStatement>(Expr(0)),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -279,15 +243,14 @@ 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::BlockStatement>(ast::StatementList{
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::ReturnStatement>(),
});
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("vtx_func"),
"vtx_func", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -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::BlockStatement>(ast::StatementList{
auto* func = Func(
Source{Source::Location{12, 34}}, "main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
Source{Source::Location{12, 34}}, mod->RegisterSymbol("main"), "main",
params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
@ -327,12 +288,11 @@ 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::BlockStatement>(ast::StatementList{
auto* func =
Func("vtx_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("vtx_func"), "vtx_func", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -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::BlockStatement>(ast::StatementList{
auto* func = Func("vtx_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("vtx_func"), "vtx_func", params,
ty.void_, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -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::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func", params,
ty.f32, body, ast::FunctionDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
EXPECT_FALSE(v()->Validate(mod));
@ -284,16 +281,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
mod->RegisterSymbol("global_var"), "global_var");
auto* rhs = Expr(3.14f);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
auto* func =
Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -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::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, var),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func", params,
ty.void_, body, ast::FunctionDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(
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::BlockStatement>(ast::StatementList{
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var_a_float),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func", params,
ty.void_, body, ast::FunctionDecorationList{});
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float),
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -547,25 +537,21 @@ 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::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var0),
auto* func0 = Func("func0", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var0),
create<ast::ReturnStatement>(),
});
},
ast::FunctionDecorationList{});
auto* func0 =
create<ast::Function>(mod->RegisterSymbol("func0"), "func0", params0,
ty.void_, body0, ast::FunctionDecorationList{});
ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{Source::Location{13, 34}},
var1),
auto* func1 =
Func("func1", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, var1),
create<ast::ReturnStatement>(),
});
auto* func1 = create<ast::Function>(
mod->RegisterSymbol("func1"), "func1", params1, ty.void_, body1,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});

View File

@ -149,12 +149,12 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
// fn func -> void { var a : array<i32>; }
auto* var = Var("a", ast::StorageClass::kNone, ty.array<i32>());
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, var),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("func"), "func", params, ty.void_, body,
auto* func =
Func("func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});

View File

@ -459,9 +459,7 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
// foo(a && b, c || d, (a || c) && (b || d))
auto* func = create<ast::Function>(
mod->RegisterSymbol("foo"), "foo", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
auto* func = Func("foo", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{});
mod->AddFunction(func);

View File

@ -32,10 +32,8 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
auto* call = Call("my_func");
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::CallStatement>(Call("my_func", "param1", "param2"));
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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();

View File

@ -60,13 +60,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -111,14 +110,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -163,14 +160,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
@ -215,13 +210,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -263,13 +257,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
@ -306,13 +299,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.f32, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
@ -357,13 +349,12 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod->AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
MemberAccessor("coord", "x")),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});

View File

@ -53,11 +53,10 @@ namespace {
using HlslGeneratorImplTest_Function = TestHelper;
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.void_, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -72,12 +71,11 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
}
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func("GeometryShader", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("GeometryShader"), "GeometryShader",
ast::VariableList{}, ty.void_, body, ast::FunctionDecorationList{});
},
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::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func =
create<ast::Function>(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::ReturnStatement>(),
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
gen.increment_indent();
@ -131,13 +128,12 @@ TEST_F(HlslGeneratorImplTest_Function,
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -183,14 +179,13 @@ TEST_F(HlslGeneratorImplTest_Function,
mod->AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -228,16 +223,15 @@ 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::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -277,18 +271,17 @@ 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<ast::MemberAccessorExpression>(
MemberAccessor("uniforms", "coord"), Expr("x")),
ast::VariableDecorationList{});
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -331,16 +324,15 @@ 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::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -380,16 +372,15 @@ 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::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -426,18 +417,15 @@ TEST_F(HlslGeneratorImplTest_Function,
});
td.RegisterVariableForTesting(coord_var);
mod->AddGlobalVariable(coord_var);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
Expr(2.0f)),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", ast::VariableList{},
ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -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::BlockStatement>(ast::StatementList{
auto* sub_func = Func(
"sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)},
ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
create<ast::ReturnStatement>(Expr("foo")),
});
auto* sub_func =
create<ast::Function>(mod->RegisterSymbol("sub_func"), "sub_func", params,
ty.f32, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(sub_func);
body = create<ast::BlockStatement>(ast::StatementList{
auto* func_1 = Func(
"ep_1", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
});
auto* func_1 = create<ast::Function>(
mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -547,24 +534,24 @@ 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::BlockStatement>(ast::StatementList{
auto* sub_func = Func(
"sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)},
ty.f32,
ast::StatementList{
create<ast::ReturnStatement>(Expr("param")),
});
auto* sub_func =
create<ast::Function>(mod->RegisterSymbol("sub_func"), "sub_func", params,
ty.f32, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(sub_func);
body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
});
auto* func_1 = create<ast::Function>(
mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -612,26 +599,26 @@ 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::BlockStatement>(ast::StatementList{
auto* sub_func = Func(
"sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)},
ty.f32,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(Expr("param")),
});
auto* sub_func =
create<ast::Function>(mod->RegisterSymbol("sub_func"), "sub_func", params,
ty.f32, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(sub_func);
body = create<ast::BlockStatement>(ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
});
auto* func_1 = create<ast::Function>(
mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -675,29 +662,26 @@ 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::BlockStatement>(ast::StatementList{
auto* sub_func = Func(
"sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)},
ty.f32,
ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
});
auto* sub_func =
create<ast::Function>(mod->RegisterSymbol("sub_func"), "sub_func", params,
ty.f32, body, ast::FunctionDecorationList{});
},
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::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -736,29 +720,26 @@ 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::BlockStatement>(ast::StatementList{
auto* sub_func = Func(
"sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32)},
ty.f32,
ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
});
auto* sub_func =
create<ast::Function>(mod->RegisterSymbol("sub_func"), "sub_func", params,
ty.f32, body, ast::FunctionDecorationList{});
},
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::BlockStatement>(ast::StatementList{
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("frag_main"), "frag_main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -795,17 +776,15 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::ReturnStatement>(),
});
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func_1 = Func(
"ep_1", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.0f)),
create<ast::IfStatement>(create<ast::BinaryExpression>(
ast::BinaryOp::kEqual, Expr(1), Expr(1)),
list, ast::ElseStatementList{}),
create<ast::ReturnStatement>(),
});
auto* func_1 = create<ast::Function>(
mod->RegisterSymbol("ep_1"), "ep_1", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -832,10 +811,8 @@ ep_1_out ep_1() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithNameCollision) {
auto* func = create<ast::Function>(
mod->RegisterSymbol("GeometryShader"), "GeometryShader",
ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(ast::StatementList{}),
auto* func = Func(
"GeometryShader", ast::VariableList{}, ty.void_, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -851,13 +828,11 @@ TEST_F(HlslGeneratorImplTest_Function,
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_Compute) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
@ -876,13 +851,11 @@ void main() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_Compute_WithWorkgroup) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("main"), "main", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
@ -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::BlockStatement>(ast::StatementList{
auto* func = Func("my_func",
ast::VariableList{Var("a", ast::StorageClass::kNone, &ary)},
ty.void_,
ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func", params,
ty.void_, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
gen.increment_indent();
@ -960,17 +931,15 @@ 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::BlockStatement>(ast::StatementList{
auto* func =
Func("a", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("a"), "a", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
@ -979,17 +948,15 @@ TEST_F(HlslGeneratorImplTest_Function,
}
{
ast::VariableList params;
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("b", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("b"), "b", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});

View File

@ -29,10 +29,8 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) {
ast::type::Void void_type;
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(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();

View File

@ -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<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(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<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(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<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
ast::FunctionDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, &void_type,
ast::StatementList{}, ast::FunctionDecorationList{});
mod->AddFunction(func);
gen.increment_indent();

View File

@ -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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"vtx_main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"vtx_main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", params, &f32, body,
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar")),
};
auto* func = Func(
"main", ast::VariableList{}, &f32, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
});
@ -529,11 +517,7 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
mod->AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
@ -544,9 +528,9 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
Source{}, mod->RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("x"), "x"))),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", params, &void_type, body,
};
auto* func = Func(
"main", ast::VariableList{}, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});

View File

@ -58,14 +58,11 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Function) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("my_func", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"),
"my_func", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{});
},
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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("main"),
"main", ast::VariableList{}, &void_type,
body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
gen.increment_indent();
@ -129,13 +123,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("my_func", params, &void_type,
ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -185,20 +176,16 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
mod->AddGlobalVariable(foo_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
};
auto* func = Func("frag_main", ast::VariableList{}, &void_type, body,
ast::FunctionDecorationList{create<ast::StageDecoration>(
Source{}, ast::PipelineStage::kFragment)});
@ -262,10 +249,7 @@ TEST_F(MslGeneratorImplTest,
mod->AddGlobalVariable(coord_var);
mod->AddGlobalVariable(depth_var);
ast::VariableList params;
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
@ -277,10 +261,9 @@ TEST_F(MslGeneratorImplTest,
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("x"), "x"))),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
};
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type, body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::Variable>(
Source{}, // source
"v", // name
@ -342,14 +324,12 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
"x")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -400,7 +380,6 @@ TEST_F(MslGeneratorImplTest,
mod->AddGlobalVariable(coord_var);
ast::VariableList params;
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
@ -415,14 +394,12 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(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<ast::Variable>(
Source{}, // source
"v", // name
@ -493,14 +467,12 @@ TEST_F(MslGeneratorImplTest,
"b")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -585,28 +557,25 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("param"), "param")),
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("foo"), "foo")),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
};
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<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func"),
expr)),
create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>(
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<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -697,15 +664,13 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
auto* sub_func = Func(
"sub_func", params, &f32,
ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
},
ast::FunctionDecorationList{});
mod->AddFunction(sub_func);
@ -714,9 +679,7 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
@ -727,10 +690,10 @@ TEST_F(MslGeneratorImplTest,
Source{}, mod->RegisterSymbol("sub_func"), "sub_func"),
expr)),
create<ast::ReturnStatement>(Source{}),
});
};
auto* func_1 = create<ast::Function>(
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<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -806,9 +769,7 @@ TEST_F(
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
@ -822,10 +783,9 @@ TEST_F(
create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("param"), "param")),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
};
auto* sub_func =
Func("sub_func", params, &f32, body, ast::FunctionDecorationList{});
mod->AddFunction(sub_func);
@ -833,9 +793,7 @@ TEST_F(
expr.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
@ -846,9 +804,9 @@ TEST_F(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func"),
expr)),
create<ast::ReturnStatement>(Source{}),
});
auto* func_1 = create<ast::Function>(
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<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -910,21 +868,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("x"), "x"))),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{});
};
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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -1016,21 +967,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b"))),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, ty.f32,
body, ast::FunctionDecorationList{});
};
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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -1128,21 +1072,17 @@ TEST_F(MslGeneratorImplTest,
nullptr, // constructor
ast::VariableDecorationList{})); // decorations
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::ReturnStatement>(
Source{},
create<ast::MemberAccessorExpression>(
Source{}, create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("b"), "b"))),
});
auto* sub_func = create<ast::Function>(
Source{}, mod->RegisterSymbol("sub_func"), "sub_func", params, ty.f32,
body, ast::FunctionDecorationList{});
};
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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func(
"frag_main", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("frag_main"), "frag_main", params,
&void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -1221,19 +1158,16 @@ TEST_F(MslGeneratorImplTest,
td.RegisterVariableForTesting(bar_var);
mod->AddGlobalVariable(bar_var);
ast::VariableList params;
auto* list = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* body = create<ast::BlockStatement>(
Source{},
ast::StatementList{
auto body = ast::StatementList{
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod->RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(Source{},
mod->RegisterSymbol("bar"), "bar"),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f))),
create<ast::IfStatement>(
@ -1246,10 +1180,10 @@ TEST_F(MslGeneratorImplTest,
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1))),
list, ast::ElseStatementList{}),
create<ast::ReturnStatement>(Source{}),
});
};
auto* func_1 = create<ast::Function>(
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<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
});
@ -1280,9 +1214,8 @@ TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoint_WithNameCollision) {
ast::type::Void void_type;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
auto* func = Func(
"main", ast::VariableList{}, &void_type, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
});
@ -1314,13 +1247,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::type::Void void_type;
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(Source{}, mod->RegisterSymbol("my_func"),
"my_func", params, &void_type, body,
auto* func = Func("my_func", params, &void_type,
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
mod->AddFunction(func);
@ -1385,7 +1315,6 @@ TEST_F(MslGeneratorImplTest,
mod->AddGlobalVariable(data_var);
{
ast::VariableList params;
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
@ -1401,23 +1330,20 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("a", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{},
ast::PipelineStage::kCompute),
create<ast::StageDecoration>(
Source{}, ast::PipelineStage::kCompute),
});
mod->AddFunction(func);
}
{
ast::VariableList params;
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
@ -1433,16 +1359,14 @@ TEST_F(MslGeneratorImplTest,
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("b", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{},
ast::PipelineStage::kCompute),
create<ast::StageDecoration>(
Source{}, ast::PipelineStage::kCompute),
});
mod->AddFunction(func);

View File

@ -50,9 +50,8 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Generate) {
ast::type::Void void_type;
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
auto* func = Func(
"my_func", ast::VariableList{}, &void_type, ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
});

View File

@ -352,13 +352,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_FragDepth) {
});
mod->AddGlobalVariable(fragdepth);
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("main", ast::VariableList{}, create<ast::type::Void>(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("fragdepth"), Expr(1.f)),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("main"), "main", ast::VariableList{},
create<ast::type::Void>(), body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
func->add_referenced_module_variable(fragdepth);

View File

@ -299,7 +299,6 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
mod->AddGlobalVariable(data_var);
{
ast::VariableList params;
auto* var = create<ast::Variable>(
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<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("a", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{},
ast::PipelineStage::kCompute),
create<ast::StageDecoration>(
Source{}, ast::PipelineStage::kCompute),
});
mod->AddFunction(func);
}
{
ast::VariableList params;
auto* var = create<ast::Variable>(
Source{}, // source
"v", // name
@ -347,16 +343,14 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
"d")), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
auto* func = Func("b", ast::VariableList{}, &void_type,
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::ReturnStatement>(Source{}),
});
auto* func = create<ast::Function>(
Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{},
ast::PipelineStage::kCompute),
create<ast::StageDecoration>(
Source{}, ast::PipelineStage::kCompute),
});
mod->AddFunction(func);

View File

@ -471,10 +471,8 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) {
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<f32>(1.0f, 1.0f));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<i32>(1, 1), vec2<i32>(1, 1));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<u32>(1u, 1u), vec2<u32>(1u, 1u));
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
auto* func = create<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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<ast::Function>(
mod->RegisterSymbol("a_func"), "a_func", ast::VariableList{}, ty.void_,
create<ast::BlockStatement>(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();

View File

@ -41,13 +41,11 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Function) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.void_, body,
},
ast::FunctionDecorationList{});
gen.increment_indent();
@ -61,18 +59,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
}
TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("my_func",
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.f32),
Var("b", ast::StorageClass::kNone, ty.i32)},
ty.void_,
ast::StatementList{
create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(),
});
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<ast::Function>(mod->RegisterSymbol("my_func"), "my_func", params,
ty.void_, body, ast::FunctionDecorationList{});
},
ast::FunctionDecorationList{});
gen.increment_indent();
@ -85,14 +81,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
}
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(),
});
auto* func =
create<ast::Function>(mod->RegisterSymbol("my_func"), "my_func",
ast::VariableList{}, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
});
@ -109,14 +102,12 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
}
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
@ -133,14 +124,12 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
}
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("my_func", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
@ -198,18 +187,17 @@ TEST_F(WgslGeneratorImplTest,
mod->AddGlobalVariable(data_var);
{
ast::VariableList params;
auto* var =
Var("v", ast::StorageClass::kFunction, ty.f32,
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
ast::VariableDecorationList{});
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("a", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("a"), "a", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
@ -218,18 +206,17 @@ TEST_F(WgslGeneratorImplTest,
}
{
ast::VariableList params;
auto* var =
Var("v", ast::StorageClass::kFunction, ty.f32,
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
ast::VariableDecorationList{});
auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* func =
Func("b", ast::VariableList{}, ty.void_,
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(),
});
auto* func = create<ast::Function>(
mod->RegisterSymbol("b"), "b", params, ty.void_, body,
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});

View File

@ -32,10 +32,8 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Generate) {
ast::type::Void void_type;
mod->AddFunction(create<ast::Function>(
mod->RegisterSymbol("a_func"), "my_func", ast::VariableList{}, &void_type,
create<ast::BlockStatement>(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 {