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