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