Have ProgramBuilder::Func() register the function

With the ast::Module::Functions().

Also remove pointless calls to td.Determine() that will automatically be
done when the program is built.

Change-Id: Ia7506e430b04d91d4f6b02fb6b678d0ea9912bcd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39900
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-02-02 14:29:15 +00:00 committed by Commit Bot service account
parent 611f727a09
commit 42d1e097e6
28 changed files with 893 additions and 1354 deletions

View File

@ -44,7 +44,7 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) {
TEST_F(ModuleTest, LookupFunction) {
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_EQ(func,
program.AST().Functions().Find(program.Symbols().Get("main")));
@ -111,10 +111,9 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) {
}
TEST_F(ModuleTest, IsValid_Function) {
auto* func = Func("main", VariableList(), ty.f32(), StatementList{},
Func("main", VariableList(), ty.f32(), StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_TRUE(program.AST().IsValid());
}
@ -126,10 +125,9 @@ TEST_F(ModuleTest, IsValid_Null_Function) {
}
TEST_F(ModuleTest, IsValid_Invalid_Function) {
auto* func = Func("main", VariableList{}, nullptr, StatementList{},
Func("main", VariableList{}, nullptr, StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_FALSE(program.AST().IsValid());
}

View File

@ -76,25 +76,20 @@ class InspectorHelper : public ProgramBuilder {
/// Generates an empty function
/// @param name name of the function created
/// @param decorations the function decorations
/// @returns a function object
ast::Function* MakeEmptyBodyFunction(
std::string name,
void MakeEmptyBodyFunction(std::string name,
ast::FunctionDecorationList decorations) {
return Func(name, ast::VariableList(), ty.void_(),
ast::StatementList{create<ast::ReturnStatement>()},
decorations);
Func(name, ast::VariableList(), ty.void_(),
ast::StatementList{create<ast::ReturnStatement>()}, decorations);
}
/// Generates a function that calls another
/// @param caller name of the function created
/// @param callee name of the function to be called
/// @param decorations the function decorations
/// @returns a function object
ast::Function* MakeCallerBodyFunction(
std::string caller,
void MakeCallerBodyFunction(std::string caller,
std::string callee,
ast::FunctionDecorationList decorations) {
return Func(caller, ast::VariableList(), ty.void_(),
Func(caller, ast::VariableList(), ty.void_(),
ast::StatementList{
create<ast::CallStatement>(Call(callee)),
create<ast::ReturnStatement>(),
@ -128,8 +123,7 @@ class InspectorHelper : public ProgramBuilder {
/// @param inout_vars tuples of {in, out} that will be converted into out = in
/// calls in the function body
/// @param decorations the function decorations
/// @returns a function object
ast::Function* MakeInOutVariableBodyFunction(
void MakeInOutVariableBodyFunction(
std::string name,
std::vector<std::tuple<std::string, std::string>> inout_vars,
ast::FunctionDecorationList decorations) {
@ -140,7 +134,7 @@ class InspectorHelper : public ProgramBuilder {
stmts.emplace_back(create<ast::AssignmentStatement>(Expr(out), Expr(in)));
}
stmts.emplace_back(create<ast::ReturnStatement>());
return Func(name, ast::VariableList(), ty.void_(), stmts, decorations);
Func(name, ast::VariableList(), ty.void_(), stmts, decorations);
}
/// Generates a function that references in/out variables and calls another
@ -363,8 +357,7 @@ class InspectorHelper : public ProgramBuilder {
/// @param func_name name of the function created
/// @param struct_name name of the struct variabler to be accessed
/// @param members list of members to access, by index and type
/// @returns a function that references all of the members specified
ast::Function* MakeStructVariableReferenceBodyFunction(
void MakeStructVariableReferenceBodyFunction(
std::string func_name,
std::string struct_name,
std::vector<std::tuple<size_t, type::Type*>> members) {
@ -392,7 +385,7 @@ class InspectorHelper : public ProgramBuilder {
stmts.emplace_back(create<ast::ReturnStatement>());
return Func(func_name, ast::VariableList(), ty.void_(), stmts,
Func(func_name, ast::VariableList(), ty.void_(), stmts,
ast::FunctionDecorationList{});
}
@ -711,8 +704,6 @@ TEST_F(InspectorGetEntryPointTest, NoFunctions) {
}
TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {
AST().Functions().Add(MakeEmptyBodyFunction("foo", {}));
Inspector& inspector = Build();
auto result = inspector.GetEntryPoints();
@ -722,11 +713,10 @@ TEST_F(InspectorGetEntryPointTest, NoEntryPoints) {
}
TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available.
@ -742,17 +732,15 @@ TEST_F(InspectorGetEntryPointTest, OneEntryPoint) {
}
TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
auto* bar = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when available.
@ -771,22 +759,19 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPoints) {
}
TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
auto* func = MakeEmptyBodyFunction("func", {});
AST().Functions().Add(func);
MakeEmptyBodyFunction("func", {});
auto* foo = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"foo", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
auto* bar = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"bar", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when available.
@ -805,11 +790,10 @@ TEST_F(InspectorGetEntryPointTest, MixFunctionsAndEntryPoints) {
}
TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -825,12 +809,11 @@ TEST_F(InspectorGetEntryPointTest, DefaultWorkgroupSize) {
}
TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
create<ast::WorkgroupDecoration>(8u, 2u, 1u),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -846,15 +829,13 @@ TEST_F(InspectorGetEntryPointTest, NonDefaultWorkgroupSize) {
}
TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
auto* func = MakeEmptyBodyFunction("func", {});
AST().Functions().Add(func);
MakeEmptyBodyFunction("func", {});
auto* foo = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"foo", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -869,12 +850,11 @@ TEST_F(InspectorGetEntryPointTest, NoInOutVariables) {
TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}});
auto* foo = MakeInOutVariableBodyFunction(
MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -896,16 +876,13 @@ TEST_F(InspectorGetEntryPointTest, EntryPointInOutVariables) {
TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}});
auto* func =
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
AST().Functions().Add(func);
auto* foo = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"foo", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -927,16 +904,13 @@ TEST_F(InspectorGetEntryPointTest, FunctionInOutVariables) {
TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}});
auto* func =
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
AST().Functions().Add(func);
auto* foo = MakeInOutVariableCallerBodyFunction(
MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -958,12 +932,11 @@ TEST_F(InspectorGetEntryPointTest, RepeatedInOutVariables) {
TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}});
auto* foo = MakeInOutVariableBodyFunction(
MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out_var"}, {"in2_var", "out2_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -991,16 +964,14 @@ TEST_F(InspectorGetEntryPointTest, EntryPointMultipleInOutVariables) {
TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}});
auto* func = MakeInOutVariableBodyFunction(
MakeInOutVariableBodyFunction(
"func", {{"in_var", "out_var"}, {"in2_var", "out2_var"}}, {});
AST().Functions().Add(func);
auto* foo = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"foo", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -1029,19 +1000,17 @@ TEST_F(InspectorGetEntryPointTest, FunctionMultipleInOutVariables) {
TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}});
auto* foo = MakeInOutVariableBodyFunction(
MakeInOutVariableBodyFunction(
"foo", {{"in_var", "out2_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
auto* bar = MakeInOutVariableBodyFunction(
MakeInOutVariableBodyFunction(
"bar", {{"in2_var", "out_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when
// available.
@ -1079,23 +1048,19 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsSharedInOutVariables) {
AddInOutVariables({{"in_var", "out_var"}, {"in2_var", "out2_var"}});
auto* func =
MakeInOutVariableBodyFunction("func", {{"in2_var", "out2_var"}}, {});
AST().Functions().Add(func);
auto* foo = MakeInOutVariableCallerBodyFunction(
MakeInOutVariableCallerBodyFunction(
"foo", "func", {{"in_var", "out_var"}},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
auto* bar = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"bar", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(bar);
// TODO(dsinclair): Update to run the namer transform when
// available.
@ -1146,16 +1111,14 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
AST().AddGlobalVariable(
Var("out_var", ast::StorageClass::kOutput, ty.u32(), nullptr,
ast::VariableDecorationList{create<ast::LocationDecoration>(0)}));
auto* func =
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
AST().Functions().Add(func);
auto* foo = MakeCallerBodyFunction(
MakeInOutVariableBodyFunction("func", {{"in_var", "out_var"}}, {});
MakeCallerBodyFunction(
"foo", "func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when available.
@ -1189,8 +1152,6 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoFunctions) {
// TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
// through
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) {
AST().Functions().Add(MakeEmptyBodyFunction("foo", {}));
Inspector& inspector = Build();
auto result = inspector.GetRemappedNameForEntryPoint("foo");
@ -1202,11 +1163,10 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_NoEntryPoints) {
// TODO(rharrison): Reenable once GetRemappedNameForEntryPoint isn't a pass
// through
TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when
// available.
@ -1223,20 +1183,18 @@ TEST_F(InspectorGetRemappedNameForEntryPointTest, DISABLED_OneEntryPoint) {
// through
TEST_F(InspectorGetRemappedNameForEntryPointTest,
DISABLED_MultipleEntryPoints) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
// TODO(dsinclair): Update to run the namer transform when
// available.
auto* bar = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"bar", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(bar);
Inspector& inspector = Build();
@ -1364,16 +1322,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, NonEntryPointFunc) {
MakeUniformBufferTypes("foo_type", {{ty.i32(), 0}});
AddUniformBuffer("foo_ub", foo_control_type, 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32()}});
AST().Functions().Add(ub_func);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "ub_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1392,16 +1347,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
auto* foo_type = ty.struct_("foo_type", str);
AddUniformBuffer("foo_ub", foo_type, 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32()}});
AST().Functions().Add(ub_func);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "ub_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1417,16 +1369,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, Simple) {
MakeUniformBufferTypes("foo_type", {{ty.i32(), 0}});
AddUniformBuffer("foo_ub", foo_control_type, 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32()}});
AST().Functions().Add(ub_func);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "ub_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1446,16 +1395,14 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleMembers) {
"foo_type", {{ty.i32(), 0}, {ty.u32(), 4}, {ty.f32(), 8}});
AddUniformBuffer("foo_ub", foo_control_type, 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction(
MakeStructVariableReferenceBodyFunction(
"ub_func", "foo_ub", {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}});
AST().Functions().Add(ub_func);
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "ub_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1479,9 +1426,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
auto AddReferenceFunc = [this](const std::string& func_name,
const std::string& var_name) {
auto* ub_func = MakeStructVariableReferenceBodyFunction(
MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}});
AST().Functions().Add(ub_func);
};
AddReferenceFunc("ub_foo_func", "ub_foo");
AddReferenceFunc("ub_bar_func", "ub_bar");
@ -1491,7 +1437,6 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
return create<ast::CallStatement>(Call(callee));
};
ast::Function* func =
Func("ep_func", ast::VariableList(), ty.void_(),
ast::StatementList{FuncCall("ub_foo_func"), FuncCall("ub_bar_func"),
FuncCall("ub_baz_func"),
@ -1499,7 +1444,6 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -1527,16 +1471,13 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, ContainingArray) {
"foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}});
AddUniformBuffer("foo_ub", foo_control_type, 0, 0);
auto* ub_func = MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub",
{{0, ty.i32()}});
AST().Functions().Add(ub_func);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "ub_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1556,16 +1497,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, Simple) {
MakeStorageBufferTypes("foo_type", {{ty.i32(), 0}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1585,16 +1523,14 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleMembers) {
"foo_type", {{ty.i32(), 0}, {ty.u32(), 4}, {ty.f32(), 8}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction(
MakeStructVariableReferenceBodyFunction(
"sb_func", "foo_sb", {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}});
AST().Functions().Add(sb_func);
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1618,9 +1554,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
auto AddReferenceFunc = [this](const std::string& func_name,
const std::string& var_name) {
auto* sb_func = MakeStructVariableReferenceBodyFunction(
MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}});
AST().Functions().Add(sb_func);
};
AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1630,7 +1565,6 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
return create<ast::CallStatement>(Call(callee));
};
ast::Function* func =
Func("ep_func", ast::VariableList(), ty.void_(),
ast::StatementList{
FuncCall("sb_foo_func"),
@ -1641,7 +1575,6 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -1669,16 +1602,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingArray) {
"foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1698,16 +1628,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, ContainingRuntimeArray) {
"foo_type", {{ty.i32(), 0}, {u32_array_type(0), 4}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1727,16 +1654,13 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, SkipReadOnly) {
MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32(), 0}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1752,16 +1676,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, Simple) {
MakeReadOnlyStorageBufferTypes("foo_type", {{ty.i32(), 0}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1786,9 +1707,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
auto AddReferenceFunc = [this](const std::string& func_name,
const std::string& var_name) {
auto* sb_func = MakeStructVariableReferenceBodyFunction(
MakeStructVariableReferenceBodyFunction(
func_name, var_name, {{0, ty.i32()}, {1, ty.u32()}, {2, ty.f32()}});
AST().Functions().Add(sb_func);
};
AddReferenceFunc("sb_foo_func", "sb_foo");
AddReferenceFunc("sb_bar_func", "sb_bar");
@ -1798,7 +1718,6 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
return create<ast::CallStatement>(Call(callee));
};
ast::Function* func =
Func("ep_func", ast::VariableList(), ty.void_(),
ast::StatementList{
FuncCall("sb_foo_func"),
@ -1809,7 +1728,6 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -1837,16 +1755,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, ContainingArray) {
"foo_type", {{ty.i32(), 0}, {u32_array_type(4), 4}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1867,16 +1782,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
"foo_type", {{ty.i32(), 0}, {u32_array_type(0), 4}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1896,16 +1808,13 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) {
MakeStorageBufferTypes("foo_type", {{ty.i32(), 0}});
AddStorageBuffer("foo_sb", foo_control_type, 0, 0);
auto* sb_func = MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb",
{{0, ty.i32()}});
AST().Functions().Add(sb_func);
MakeStructVariableReferenceBodyFunction("sb_func", "foo_sb", {{0, ty.i32()}});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "sb_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1921,12 +1830,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
AddSampler("foo_sampler", 0, 1);
AddGlobalVariable("foo_coords", ty.f32());
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -1939,11 +1847,10 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) {
}
TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) {
auto* func = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"ep_func", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -1960,16 +1867,14 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) {
AddSampler("foo_sampler", 0, 1);
AddGlobalVariable("foo_coords", ty.f32());
auto* foo_func = MakeSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", ty.f32(), {});
AST().Functions().Add(foo_func);
MakeSamplerReferenceBodyFunction("foo_func", "foo_texture", "foo_sampler",
"foo_coords", ty.f32(), {});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "foo_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -1988,12 +1893,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) {
AddSampler("foo_sampler", 0, 1);
AddGlobalVariable("foo_coords", ty.f32());
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2008,12 +1912,11 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) {
AddGlobalVariable("foo_coords", ty.f32());
AddGlobalVariable("foo_depth", ty.f32());
auto* func = MakeComparisonSamplerReferenceBodyFunction(
MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2030,12 +1933,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
AddGlobalVariable("foo_coords", ty.f32());
AddGlobalVariable("foo_depth", ty.f32());
auto* func = MakeComparisonSamplerReferenceBodyFunction(
MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2048,11 +1950,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) {
}
TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) {
auto* func = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"ep_func", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2069,17 +1970,15 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) {
AddGlobalVariable("foo_coords", ty.f32());
AddGlobalVariable("foo_depth", ty.f32());
auto* foo_func = MakeComparisonSamplerReferenceBodyFunction(
"foo_func", "foo_texture", "foo_sampler", "foo_coords", "foo_depth",
ty.f32(), {});
AST().Functions().Add(foo_func);
MakeComparisonSamplerReferenceBodyFunction("foo_func", "foo_texture",
"foo_sampler", "foo_coords",
"foo_depth", ty.f32(), {});
auto* ep_func = MakeCallerBodyFunction(
MakeCallerBodyFunction(
"ep_func", "foo_func",
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(ep_func);
Inspector& inspector = Build();
@ -2098,12 +1997,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) {
AddGlobalVariable("foo_coords", ty.f32());
AddGlobalVariable("foo_depth", ty.f32());
auto* func = MakeComparisonSamplerReferenceBodyFunction(
MakeComparisonSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_depth", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2118,12 +2016,11 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
AddSampler("foo_sampler", 0, 1);
AddGlobalVariable("foo_coords", ty.f32());
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", ty.f32(),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2134,11 +2031,10 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) {
}
TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -2157,13 +2053,12 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) {
GetCoordsType(GetParam().type_dim, GetParam().sampled_kind);
AddGlobalVariable("foo_coords", coord_type);
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords",
GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2248,13 +2143,12 @@ TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam,
AddGlobalVariable("foo_coords", coord_type);
AddGlobalVariable("foo_array_index", ty.u32());
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index",
GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2319,13 +2213,12 @@ TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam,
GetCoordsType(GetParam().type_dim, GetParam().sampled_kind);
AddGlobalVariable("foo_coords", coord_type);
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords",
GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();
@ -2376,11 +2269,10 @@ INSTANTIATE_TEST_SUITE_P(
inspector::ResourceBinding::SampledKind::kUInt}));
TEST_F(InspectorGetMultisampledArrayTextureResourceBindingsTest, Empty) {
auto* foo = MakeEmptyBodyFunction(
MakeEmptyBodyFunction(
"foo", ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(foo);
Inspector& inspector = Build();
@ -2401,13 +2293,12 @@ TEST_P(InspectorGetMultisampledArrayTextureResourceBindingsTestWithParam,
AddGlobalVariable("foo_coords", coord_type);
AddGlobalVariable("foo_array_index", ty.u32());
auto* func = MakeSamplerReferenceBodyFunction(
MakeSamplerReferenceBodyFunction(
"ep", "foo_texture", "foo_sampler", "foo_coords", "foo_array_index",
GetBaseType(GetParam().sampled_kind),
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
Inspector& inspector = Build();

View File

@ -419,7 +419,7 @@ class ProgramBuilder {
return array(Of<T>(), N);
}
/// creates an alias type
/// Creates an alias type
/// @param name the alias name
/// @param type the alias type
/// @returns the alias pointer
@ -847,14 +847,14 @@ class ProgramBuilder {
Expr(std::forward<IDX>(idx)));
}
/// creates a ast::StructMemberOffsetDecoration
/// Creates a ast::StructMemberOffsetDecoration
/// @param val the offset value
/// @returns the offset decoration pointer
ast::StructMemberOffsetDecoration* MemberOffset(uint32_t val) {
return create<ast::StructMemberOffsetDecoration>(source_, val);
}
/// creates a ast::Function
/// Creates an ast::Function and registers it with the ast::Module.
/// @param source the source information
/// @param name the function name
/// @param params the function parameters
@ -868,12 +868,14 @@ class ProgramBuilder {
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(source, Symbols().Register(name), params, type,
create<ast::BlockStatement>(body),
decorations);
auto* func =
create<ast::Function>(source, Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations);
AST().Functions().Add(func);
return func;
}
/// creates a ast::Function
/// Creates an ast::Function and registers it with the ast::Module.
/// @param name the function name
/// @param params the function parameters
/// @param type the function return type
@ -885,12 +887,14 @@ class ProgramBuilder {
type::Type* type,
ast::StatementList body,
ast::FunctionDecorationList decorations) {
return create<ast::Function>(Symbols().Register(name), params, type,
create<ast::BlockStatement>(body),
decorations);
auto* func =
create<ast::Function>(Symbols().Register(name), params, type,
create<ast::BlockStatement>(body), decorations);
AST().Functions().Add(func);
return func;
}
/// creates a ast::StructMember
/// Creates a ast::StructMember
/// @param source the source information
/// @param name the struct member name
/// @param type the struct member type
@ -902,7 +906,7 @@ class ProgramBuilder {
ast::StructMemberDecorationList{});
}
/// creates a ast::StructMember
/// Creates a ast::StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @returns the struct member pointer
@ -911,7 +915,7 @@ class ProgramBuilder {
ast::StructMemberDecorationList{});
}
/// creates a ast::StructMember
/// Creates a ast::StructMember
/// @param name the struct member name
/// @param type the struct member type
/// @param decorations the struct member decorations

View File

@ -25,8 +25,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
Program inner([] {
ProgramBuilder builder;
auto* ty = builder.ty.f32();
auto* func = builder.Func("a", {}, ty, {}, {});
builder.AST().Functions().Add(func);
builder.Func("a", {}, ty, {}, {});
return builder;
}());
@ -47,8 +46,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
EXPECT_FALSE(outer.Symbols().Get("b").IsValid());
auto* ty = outer.ty.f32();
auto* func = outer.Func("b", {}, ty, {}, {});
outer.AST().Functions().Add(func);
outer.Func("b", {}, ty, {}, {});
ASSERT_EQ(inner.AST().Functions().size(), 1u);
ASSERT_EQ(outer.AST().Functions().size(), 2u);

View File

@ -104,9 +104,8 @@ TEST_F(ProgramTest, IsValid_Struct_EmptyName) {
}
TEST_F(ProgramTest, IsValid_Function) {
auto* func = Func("main", ast::VariableList(), ty.f32(), ast::StatementList{},
Func("main", ast::VariableList(), ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_TRUE(program.IsValid());
@ -120,9 +119,8 @@ TEST_F(ProgramTest, IsValid_Null_Function) {
}
TEST_F(ProgramTest, IsValid_Invalid_Function) {
auto* func = Func("main", ast::VariableList{}, nullptr, ast::StatementList{},
Func("main", ast::VariableList{}, nullptr, ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
Program program(std::move(*this));
EXPECT_FALSE(program.IsValid());

View File

@ -4395,7 +4395,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) {
auto* layers_ident = create<ast::IdentifierExpression>(
Source{}, builder_.Symbols().Register("textureNumLayers"));
exprs.push_back(create<ast::CallExpression>(
Source{}, layers_ident, ast::ExpressionList{GetImageExpression(inst)}));
Source{}, layers_ident,
ast::ExpressionList{GetImageExpression(inst)}));
}
auto* result_type = parser_impl_.ConvertType(inst.type_id());
TypedExpression expr = {

View File

@ -293,9 +293,8 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) {
TEST_F(TypeDeterminerTest, Stmt_Call) {
ast::VariableList params;
auto* func = Func("my_func", params, ty.f32(), ast::StatementList{},
Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
// Register the function
EXPECT_TRUE(td()->Determine());
@ -316,20 +315,18 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) {
auto* call_expr = Call("func");
ast::VariableList params0;
auto* func_main = Func("main", params0, ty.f32(),
Func("main", params0, ty.f32(),
ast::StatementList{
create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func_main);
auto* func = Func("func", params0, ty.f32(),
Func("func", params0, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_FALSE(td()->Determine()) << td()->error();
EXPECT_EQ(td()->error(),
@ -471,9 +468,8 @@ TEST_F(TypeDeterminerTest, Expr_Bitcast) {
TEST_F(TypeDeterminerTest, Expr_Call) {
ast::VariableList params;
auto* func = Func("my_func", params, ty.f32(), ast::StatementList{},
Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
// Register the function
EXPECT_TRUE(td()->Determine());
@ -486,9 +482,8 @@ TEST_F(TypeDeterminerTest, Expr_Call) {
TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
ast::VariableList params;
auto* func = Func("my_func", params, ty.f32(), ast::StatementList{},
Func("my_func", params, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
// Register the function
EXPECT_TRUE(td()->Determine());
@ -621,9 +616,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
}
TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.f32(), ast::StatementList{},
ast::FunctionDecorationList{});
// Register the function
EXPECT_TRUE(td()->Determine());
@ -662,8 +656,6 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
// Register the function
EXPECT_TRUE(td()->Determine());
@ -689,8 +681,7 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
AST().AddGlobalVariable(wg_var);
AST().AddGlobalVariable(priv_var);
auto* func = Func(
"my_func", ast::VariableList{}, ty.f32(),
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")),
@ -699,8 +690,6 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
auto* func2 = Func(
"func", ast::VariableList{}, ty.f32(),
ast::StatementList{
@ -708,8 +697,6 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func2);
// Register the function
EXPECT_TRUE(td()->Determine());
@ -733,8 +720,6 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
auto* v = Var("var", ast::StorageClass::kFunction, ty.f32());
td()->RegisterVariableForTesting(v);
@ -1545,10 +1530,8 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
auto* var = Var("var", ast::StorageClass::kNone, ty.i32());
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* func = Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{stmt}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var->storage_class(), ast::StorageClass::kFunction);
@ -1557,10 +1540,8 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) {
TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) {
auto* var = Const("var", ast::StorageClass::kNone, ty.i32());
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* func = Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{stmt}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_EQ(var->storage_class(), ast::StorageClass::kNone);
@ -1570,10 +1551,8 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) {
auto* var = Var("var", ast::StorageClass::kWorkgroup, ty.i32());
auto* stmt = create<ast::VariableDeclStatement>(var);
auto* func = Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{stmt}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("func", ast::VariableList{}, ty.i32(), ast::StatementList{stmt},
ast::FunctionDecorationList{});
EXPECT_FALSE(td()->Determine());
EXPECT_EQ(td()->error(),
@ -2296,12 +2275,6 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func_b);
AST().Functions().Add(func_c);
AST().Functions().Add(func_a);
AST().Functions().Add(ep_1);
AST().Functions().Add(ep_2);
AST().AddGlobalVariable(Var("first", ast::StorageClass::kPrivate, ty.f32()));
AST().AddGlobalVariable(Var("second", ast::StorageClass::kPrivate, ty.f32()));
AST().AddGlobalVariable(Var("call_a", ast::StorageClass::kPrivate, ty.f32()));

View File

@ -41,15 +41,14 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
auto* func = Func(
Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.void_(),
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -62,13 +61,12 @@ TEST_F(ValidateFunctionTest,
VoidFunctionEndWithoutReturnStatementEmptyBody_Pass) {
// [[stage(vertex)]]
// fn func -> void {}
auto* func =
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -83,13 +81,11 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), Expr(2),
ast::VariableDecorationList{});
auto* func = Func(Source{Source::Location{12, 34}}, "func",
ast::VariableList{}, ty.i32(),
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -102,10 +98,9 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
// fn func -> int {}
auto* func =
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.i32(), ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{}, ast::FunctionDecorationList{});
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -119,7 +114,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
// [[stage(vertex)]]
// fn func -> void { return; }
auto* func =
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -127,7 +122,6 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->DetermineFunctions(AST().Functions())) << td()->error();
@ -139,13 +133,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
// fn func -> void { return 2; }
auto* func = Func("func", ast::VariableList{}, ty.void_(),
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(
Source{Source::Location{12, 34}}, Expr(2)),
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -160,13 +153,12 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
// fn func -> f32 { return 2; }
auto* func = Func("func", ast::VariableList{}, ty.f32(),
Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(
Source{Source::Location{12, 34}}, Expr(2)),
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
Expr(2)),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -182,22 +174,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(),
Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr(2)),
},
ast::FunctionDecorationList{});
auto* func_copy = Func(Source{Source::Location{12, 34}}, "func",
ast::VariableList{}, ty.i32(),
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr(2)),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
AST().Functions().Add(func_copy);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -212,13 +200,12 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}}, Expr("func"), call_params);
auto* func0 = Func("func", ast::VariableList{}, ty.f32(),
Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -236,13 +223,12 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.i32(), call_expr,
ast::VariableDecorationList{});
auto* func0 = Func("func", ast::VariableList{}, ty.i32(),
Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>(Expr(2)),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -255,7 +241,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
// [[stage(vertex)]]
// fn vtx_main() -> i32 { return 0; }
auto* func =
Func(Source{Source::Location{12, 34}}, "vtx_main", ast::VariableList{},
ty.i32(),
ast::StatementList{
@ -265,7 +251,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -278,10 +263,10 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
// [[stage(vertex)]]
// fn vtx_func(a : i32) -> void { return; }
auto* func =
Func(Source{Source::Location{12, 34}}, "vtx_func",
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32(),
nullptr, ast::VariableDecorationList{})},
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.i32(), nullptr,
ast::VariableDecorationList{})},
ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -290,7 +275,6 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -305,8 +289,8 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
// [[stage(fragment)]]
// [[stage(vertex)]]
// fn main() -> void { return; }
auto* func = Func(
Source{Source::Location{12, 34}}, "main", ast::VariableList{}, ty.void_(),
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
@ -315,7 +299,6 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -329,7 +312,7 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
// [[stage(vertex)]]
// fn vtx_func() -> void { return; }
auto* func =
Func("vtx_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -337,7 +320,6 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -348,12 +330,11 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
// fn vtx_func() -> void { return; }
auto* func = Func("vtx_func", ast::VariableList{}, ty.void_(),
Func("vtx_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -431,13 +431,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
auto* lhs = Expr("not_global_var");
auto* rhs = Expr(3.14f);
auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, lhs, rhs),
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
lhs, rhs),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
ValidatorImpl& v = Build();
@ -456,8 +455,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
ty.f32(), Expr(2.1f),
ast::VariableDecorationList{}));
auto* func = Func(
"my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
Expr("global_var"), Expr(3.14f)),
@ -466,7 +464,6 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -654,15 +651,13 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
auto* var = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(2.0f),
ast::VariableDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -682,16 +677,14 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
auto* var_a_float = Var("a", ast::StorageClass::kNone, ty.f32(), Expr(0.1f),
ast::VariableDecorationList{});
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var_a_float),
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var_a_float),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();
@ -818,28 +811,24 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
auto* var1 = Var("a", ast::StorageClass::kNone, ty.void_(), Expr(1.0f),
ast::VariableDecorationList{});
auto* func0 = Func("func0", ast::VariableList{}, ty.void_(),
Func("func0", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var0),
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var0),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
auto* func1 =
Func("func1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, var1),
create<ast::VariableDeclStatement>(Source{Source::Location{13, 34}},
var1),
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func0);
AST().Functions().Add(func1);
EXPECT_TRUE(td()->Determine()) << td()->error();
ValidatorImpl& v = Build();

View File

@ -168,16 +168,15 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) {
// fn func -> void { var a : array<i32>; }
auto* var = Var("a", ast::StorageClass::kNone, ty.array<i32>());
auto* func =
Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, var),
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}},
var),
},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
@ -197,14 +196,12 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
Var(Source{Source::Location{12, 34}}, "a", ast::StorageClass::kNone,
ty.array<i32>(), nullptr, ast::VariableDecorationList{});
auto* func = Func("func", ast::VariableList{param}, ty.void_(),
Func("func", ast::VariableList{param}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
auto* main =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -212,7 +209,6 @@ TEST_F(ValidatorTypeTest, RuntimeArrayAsParameter_Fail) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(main);
EXPECT_TRUE(td()->Determine()) << td()->error();

View File

@ -505,9 +505,8 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
// foo(a && b, c || d, (a || c) && (b || d))
auto* func = Func("foo", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,

View File

@ -32,9 +32,8 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
auto* call = Call("my_func");
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();
@ -45,9 +44,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
auto* call = Call("my_func", "param1", "param2");
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();
@ -58,9 +56,8 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
auto* call = create<ast::CallStatement>(Call("my_func", "param1", "param2"));
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();

View File

@ -60,7 +60,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -70,14 +69,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct vtx_main_in {
float foo : TEXCOORD0;
@ -113,7 +109,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -123,14 +118,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct vtx_main_out {
float foo : TEXCOORD0;
@ -166,7 +158,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -176,14 +167,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_in {
float foo : TEXCOORD0;
@ -219,7 +207,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -229,14 +216,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_out {
float foo : SV_Target0;
@ -269,7 +253,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -279,14 +262,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -314,7 +294,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.f32(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
@ -324,14 +303,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_FALSE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -367,7 +343,6 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
@ -377,14 +352,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
std::unordered_set<Symbol> globals;
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(out, func, globals)) << gen.error();
EXPECT_EQ(result(), R"(struct main_in {
float4 coord : SV_Position;

View File

@ -53,14 +53,12 @@ namespace {
using HlslGeneratorImplTest_Function = TestHelper;
TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -74,14 +72,12 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) {
}
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
auto* func = Func("GeometryShader", ast::VariableList{}, ty.void_(),
Func("GeometryShader", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -95,7 +91,6 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) {
}
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
auto* func =
Func("my_func",
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.f32()),
Var("b", ast::StorageClass::kNone, ty.i32())},
@ -105,8 +100,6 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -121,17 +114,12 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_NoReturn_Void) {
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{/* no explicit return */},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -160,7 +148,6 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
@ -169,10 +156,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -211,7 +194,6 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
@ -221,10 +203,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -265,7 +243,6 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
@ -276,10 +253,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -315,7 +288,6 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -325,10 +297,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -368,7 +336,6 @@ TEST_F(HlslGeneratorImplTest_Function,
MemberAccessor("uniforms", "coord"), Expr("x")),
ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -378,10 +345,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -421,7 +384,6 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -431,10 +393,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -471,7 +429,6 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -481,10 +438,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -517,7 +470,6 @@ TEST_F(HlslGeneratorImplTest_Function,
td.RegisterVariableForTesting(coord_var);
AST().AddGlobalVariable(coord_var);
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
@ -528,10 +480,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -571,8 +519,7 @@ TEST_F(
AST().AddGlobalVariable(bar_var);
AST().AddGlobalVariable(val_var);
auto* sub_func = Func(
"sub_func",
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
ty.f32(),
ast::StatementList{
@ -582,9 +529,7 @@ TEST_F(
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto* func_1 = Func(
Func(
"ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
@ -594,10 +539,6 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -637,8 +578,7 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(depth_var);
auto* sub_func = Func(
"sub_func",
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
ty.f32(),
ast::StatementList{
@ -646,9 +586,6 @@ TEST_F(HlslGeneratorImplTest_Function,
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
@ -659,10 +596,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -704,8 +637,7 @@ TEST_F(
AST().AddGlobalVariable(coord_var);
AST().AddGlobalVariable(depth_var);
auto* sub_func = Func(
"sub_func",
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
ty.f32(),
ast::StatementList{
@ -715,9 +647,6 @@ TEST_F(
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"),
@ -728,10 +657,6 @@ TEST_F(
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -770,8 +695,7 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(coord_var);
auto* sub_func = Func(
"sub_func",
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
ty.f32(),
ast::StatementList{
@ -779,12 +703,9 @@ TEST_F(HlslGeneratorImplTest_Function,
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
Call("sub_func", 1.0f), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -794,10 +715,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -830,8 +747,7 @@ TEST_F(HlslGeneratorImplTest_Function,
AST().AddGlobalVariable(coord_var);
auto* sub_func = Func(
"sub_func",
Func("sub_func",
ast::VariableList{Var("param", ast::StorageClass::kFunction, ty.f32())},
ty.f32(),
ast::StatementList{
@ -839,12 +755,9 @@ TEST_F(HlslGeneratorImplTest_Function,
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
Call("sub_func", 1.0f), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -854,10 +767,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -889,7 +798,7 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::ReturnStatement>(),
});
auto* func_1 = Func(
Func(
"ep_1", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.0f)),
@ -902,10 +811,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -927,14 +832,11 @@ ep_1_out ep_1() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_WithNameCollision) {
auto* func = Func(
"GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{},
Func("GeometryShader", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -947,7 +849,6 @@ TEST_F(HlslGeneratorImplTest_Function,
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_Compute) {
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -956,10 +857,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -973,7 +870,6 @@ void main() {
TEST_F(HlslGeneratorImplTest_Function,
Emit_FunctionDecoration_EntryPoint_Compute_WithWorkgroup) {
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
@ -983,10 +879,6 @@ TEST_F(HlslGeneratorImplTest_Function,
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -999,7 +891,7 @@ void main() {
}
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
auto* func = Func(
Func(
"my_func",
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.array<f32, 5>())},
ty.void_(),
@ -1008,8 +900,6 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -1061,7 +951,6 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -1070,15 +959,12 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -1087,11 +973,8 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error();

View File

@ -103,7 +103,6 @@ ast::CallExpression* GenerateCall(ast::Intrinsic intrinsic,
case ast::Intrinsic::kTrunc:
case ast::Intrinsic::kSign:
return builder->Call(str.str(), "f1");
break;
case ast::Intrinsic::kAtan2:
case ast::Intrinsic::kCross:
case ast::Intrinsic::kDot:

View File

@ -28,9 +28,8 @@ namespace {
using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();

View File

@ -44,8 +44,8 @@ class TestHelperBase : public BODY, public ProgramBuilder {
if (gen_) {
return *gen_;
}
program_ = std::make_unique<Program>(std::move(*this));
gen_ = std::make_unique<GeneratorImpl>(program_.get());
program = std::make_unique<Program>(std::move(*this));
gen_ = std::make_unique<GeneratorImpl>(program.get());
return *gen_;
}
@ -62,9 +62,10 @@ class TestHelperBase : public BODY, public ProgramBuilder {
std::ostringstream out;
/// The pre-output stream
std::ostringstream pre;
/// The program built with a call to Build()
std::unique_ptr<Program> program;
private:
std::unique_ptr<Program> program_;
std::unique_ptr<GeneratorImpl> gen_;
};
using TestHelper = TestHelperBase<testing::Test>;

View File

@ -33,9 +33,8 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
auto* call = Call("my_func");
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();
@ -45,9 +44,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
auto* call = Call("my_func", "param1", "param2");
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();
@ -57,9 +55,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
auto* call = Call("my_func", "param1", "param2");
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{}, ast::FunctionDecorationList{});
AST().Functions().Add(func);
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
auto* expr = create<ast::CallStatement>(call);

View File

@ -65,18 +65,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct vtx_main_in {
float foo [[attribute(0)]];
@ -113,18 +110,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("vtx_main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct vtx_main_out {
float foo [[user(locn0)]];
@ -161,18 +155,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_in {
float foo [[user(locn0)]];
@ -209,18 +200,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_out {
float foo [[color(0)]];
@ -254,18 +242,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -294,18 +279,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
};
auto* func =
Func("main", ast::VariableList{}, ty.f32(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_FALSE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.error(), R"(invalid location variable for pipeline stage)");
}
@ -339,18 +321,15 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
auto body = ast::StatementList{create<ast::AssignmentStatement>(
Expr("depth"), MemberAccessor("coord", "x"))};
auto* func =
Func("main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(gen.EmitEntryPointData(func)) << gen.error();
EXPECT_EQ(gen.result(), R"(struct main_out {
float depth [[depth(any)]];

View File

@ -56,14 +56,12 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Function) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -79,14 +77,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function) {
}
TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) {
auto* func = Func("main", ast::VariableList{}, ty.void_(),
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -106,14 +102,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
params.push_back(Var("a", ast::StorageClass::kNone, ty.f32()));
params.push_back(Var("b", ast::StorageClass::kNone, ty.i32()));
auto* func = Func("my_func", params, ty.void_(),
Func("my_func", params, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -129,14 +123,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) {
}
TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_NoReturn_Void) {
auto* func = Func("main", ast::VariableList{}, ty.void_(),
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{/* no explicit return */},
ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kFragment)});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build();
@ -166,7 +156,6 @@ TEST_F(MslGeneratorImplTest,
AST().AddGlobalVariable(foo_var);
AST().AddGlobalVariable(bar_var);
auto* func =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
@ -174,10 +163,6 @@ TEST_F(MslGeneratorImplTest,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -219,13 +204,9 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::ReturnStatement>(),
};
auto* func = Func("frag_main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{create<ast::StageDecoration>(
ast::PipelineStage::kFragment)});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
Func("frag_main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build();
@ -272,16 +253,12 @@ TEST_F(MslGeneratorImplTest,
MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(),
};
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -313,7 +290,6 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "x"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -323,10 +299,6 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -364,7 +336,6 @@ TEST_F(MslGeneratorImplTest,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -374,10 +345,6 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -418,7 +385,6 @@ TEST_F(MslGeneratorImplTest,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("coord", "b"), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -428,10 +394,6 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -480,25 +442,19 @@ TEST_F(
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
create<ast::ReturnStatement>(Expr("foo"))};
auto* sub_func =
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
};
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -541,29 +497,22 @@ TEST_F(MslGeneratorImplTest,
ast::VariableList params;
params.push_back(Var("param", ast::StorageClass::kFunction, ty.f32()));
auto* sub_func = Func("sub_func", params, ty.f32(),
Func("sub_func", params, ty.f32(),
ast::StatementList{
create<ast::ReturnStatement>(Expr("param")),
},
ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
};
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -613,25 +562,19 @@ TEST_F(
MemberAccessor("coord", "x")),
create<ast::ReturnStatement>(Expr("param")),
};
auto* sub_func =
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
create<ast::ReturnStatement>(),
};
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -671,10 +614,8 @@ TEST_F(MslGeneratorImplTest,
auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "x")),
};
auto* sub_func =
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
ast::ExpressionList expr;
expr.push_back(Expr(1.0f));
@ -682,7 +623,6 @@ TEST_F(MslGeneratorImplTest,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
Call("sub_func", 1.0f), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -692,10 +632,6 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -738,15 +674,12 @@ TEST_F(MslGeneratorImplTest,
auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
auto* sub_func =
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
Call("sub_func", 1.0f), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -756,10 +689,6 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -807,10 +736,8 @@ TEST_F(MslGeneratorImplTest,
auto body = ast::StatementList{
create<ast::ReturnStatement>(MemberAccessor("coord", "b"))};
auto* sub_func =
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
AST().Functions().Add(sub_func);
Func("sub_func", params, ty.f32(), body, ast::FunctionDecorationList{});
ast::ExpressionList expr;
expr.push_back(Expr(1.0f));
@ -818,7 +745,6 @@ TEST_F(MslGeneratorImplTest,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
Call("sub_func", 1.0f), ast::VariableDecorationList{});
auto* func =
Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -828,10 +754,6 @@ TEST_F(MslGeneratorImplTest,
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -875,16 +797,11 @@ TEST_F(MslGeneratorImplTest,
create<ast::ReturnStatement>(),
};
auto* func_1 =
Func("ep_1", ast::VariableList{}, ty.void_(), body,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(func_1);
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -908,14 +825,11 @@ fragment ep_1_out ep_1() {
TEST_F(MslGeneratorImplTest,
Emit_FunctionDecoration_EntryPoint_WithNameCollision) {
auto* func =
Func("main", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();
@ -932,14 +846,12 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
ast::VariableList params;
params.push_back(Var("a", ast::StorageClass::kNone, ty.array<f32, 5>()));
auto* func = Func("my_func", params, ty.void_(),
Func("my_func", params, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
ast::FunctionDecorationList{});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();
gen.increment_indent();
@ -994,7 +906,6 @@ TEST_F(MslGeneratorImplTest,
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -1003,26 +914,19 @@ TEST_F(MslGeneratorImplTest,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{create<ast::VariableDeclStatement>(var),
create<ast::ReturnStatement>()},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
AST().Functions().Add(func);
}
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();

View File

@ -105,7 +105,6 @@ ast::CallExpression* GenerateCall(ast::Intrinsic intrinsic,
case ast::Intrinsic::kTrunc:
case ast::Intrinsic::kSign:
return builder->Call(str.str(), "f1");
break;
case ast::Intrinsic::kAtan2:
case ast::Intrinsic::kCross:
case ast::Intrinsic::kDot:

View File

@ -48,12 +48,10 @@ namespace {
using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Generate) {
auto* func =
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
GeneratorImpl& gen = Build();

View File

@ -43,16 +43,17 @@ class TestHelperBase : public BASE, public ProgramBuilder {
if (gen_) {
return *gen_;
}
program_ = std::make_unique<Program>(std::move(*this));
gen_ = std::make_unique<GeneratorImpl>(program_.get());
program = std::make_unique<Program>(std::move(*this));
gen_ = std::make_unique<GeneratorImpl>(program.get());
return *gen_;
}
/// The type determiner
TypeDeterminer td;
/// The program built with a call to Build()
std::unique_ptr<Program> program;
private:
std::unique_ptr<Program> program_;
std::unique_ptr<GeneratorImpl> gen_;
};
using TestHelper = TestHelperBase<testing::Test>;

View File

@ -46,11 +46,12 @@ namespace {
using BuilderTest = TestHelper;
TEST_F(BuilderTest, Function_Empty) {
auto* func = Func("a_func", {}, ty.void_(), ast::StatementList{},
Func("a_func", {}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
%2 = OpTypeVoid
@ -63,7 +64,7 @@ OpFunctionEnd
}
TEST_F(BuilderTest, Function_Terminator_Return) {
auto* func = Func("a_func", {}, ty.void_(),
Func("a_func", {}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
@ -71,6 +72,7 @@ TEST_F(BuilderTest, Function_Terminator_Return) {
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
%2 = OpTypeVoid
@ -83,17 +85,17 @@ OpFunctionEnd
}
TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
auto* var_a = Var("a", ast::StorageClass::kPrivate, ty.f32());
td.RegisterVariableForTesting(var_a);
AST().AddGlobalVariable(Var("a", ast::StorageClass::kPrivate, ty.f32()));
auto* func = Func("a_func", {}, ty.void_(),
Func("a_func", {}, ty.void_(),
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
ast::FunctionDecorationList{});
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
spirv::Builder& b = Build();
auto* var_a = program->AST().GlobalVariables()[0];
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "a"
@ -113,7 +115,7 @@ OpFunctionEnd
}
TEST_F(BuilderTest, Function_Terminator_Discard) {
auto* func = Func("a_func", {}, ty.void_(),
Func("a_func", {}, ty.void_(),
ast::StatementList{
create<ast::DiscardStatement>(),
},
@ -121,6 +123,7 @@ TEST_F(BuilderTest, Function_Terminator_Discard) {
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
%2 = OpTypeVoid
@ -136,16 +139,13 @@ TEST_F(BuilderTest, Function_WithParams) {
ast::VariableList params = {Var("a", ast::StorageClass::kFunction, ty.f32()),
Var("b", ast::StorageClass::kFunction, ty.i32())};
auto* func = Func("a_func", params, ty.f32(),
Func("a_func", params, ty.f32(),
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
ast::FunctionDecorationList{});
td.RegisterVariableForTesting(func->params()[0]);
td.RegisterVariableForTesting(func->params()[1]);
EXPECT_TRUE(td.DetermineFunction(func));
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
OpName %5 "a"
@ -164,7 +164,7 @@ OpFunctionEnd
}
TEST_F(BuilderTest, Function_WithBody) {
auto* func = Func("a_func", {}, ty.void_(),
Func("a_func", {}, ty.void_(),
ast::StatementList{
create<ast::ReturnStatement>(),
},
@ -172,6 +172,7 @@ TEST_F(BuilderTest, Function_WithBody) {
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func"
%2 = OpTypeVoid
@ -184,11 +185,12 @@ OpFunctionEnd
}
TEST_F(BuilderTest, FunctionType) {
auto* func = Func("a_func", {}, ty.void_(), ast::StatementList{},
Func("a_func", {}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
spirv::Builder& b = Build();
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
@ -244,14 +246,12 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
AST().AddConstructedType(s);
td.RegisterVariableForTesting(data_var);
AST().AddGlobalVariable(data_var);
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -260,15 +260,12 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
{
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32(),
MemberAccessor("data", "d"), ast::VariableDecorationList{});
auto* func =
Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -277,12 +274,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
ASSERT_TRUE(td.Determine()) << td.error();
spirv::Builder& b = Build();
ASSERT_TRUE(b.Build());

View File

@ -4155,7 +4155,6 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
auto* call =
create<ast::CallExpression>(Expr(param.function), param.args(this));
auto* main =
Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::CallStatement>(call),
@ -4164,8 +4163,6 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
AST().Functions().Add(main);
ASSERT_TRUE(td.Determine()) << td.error();
spirv::Builder& b = Build();

View File

@ -43,13 +43,15 @@ class TestHelperBase : public ProgramBuilder, public BASE {
if (spirv_builder) {
return *spirv_builder;
}
program_ = std::make_unique<Program>(std::move(*this));
spirv_builder = std::make_unique<spirv::Builder>(program_.get());
program = std::make_unique<Program>(std::move(*this));
spirv_builder = std::make_unique<spirv::Builder>(program.get());
return *spirv_builder;
}
/// The type determiner
TypeDeterminer td;
/// The program built with a call to Build()
std::unique_ptr<Program> program;
protected:
/// Called whenever a new variable is built with `Var()`.
@ -59,7 +61,6 @@ class TestHelperBase : public ProgramBuilder, public BASE {
}
private:
std::unique_ptr<Program> program_;
std::unique_ptr<spirv::Builder> spirv_builder;
};
using TestHelper = TestHelperBase<testing::Test>;

View File

@ -202,7 +202,6 @@ TEST_F(WgslGeneratorImplTest,
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
ast::VariableDecorationList{});
auto* func =
Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -211,8 +210,6 @@ TEST_F(WgslGeneratorImplTest,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
{
@ -221,7 +218,6 @@ TEST_F(WgslGeneratorImplTest,
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")),
ast::VariableDecorationList{});
auto* func =
Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{
create<ast::VariableDeclStatement>(var),
@ -230,12 +226,8 @@ TEST_F(WgslGeneratorImplTest,
ast::FunctionDecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
});
AST().Functions().Add(func);
}
ASSERT_TRUE(td.Determine()) << td.error();
GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate()) << gen.error();

View File

@ -30,9 +30,8 @@ namespace {
using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Generate) {
AST().Functions().Add(Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{},
ast::FunctionDecorationList{}));
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::FunctionDecorationList{});
GeneratorImpl& gen = Build();