tests: Use ProgramBuilder helpers where we can
A general code cleanup Change-Id: Ib251ca2d4b71f75736bdba8b4255965593a76c31 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48680 Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
261642e4e3
commit
43073d8aa3
|
@ -268,11 +268,11 @@ TEST_F(FunctionListTest, FindSymbolMissing) {
|
|||
TEST_F(FunctionListTest, FindSymbolStage) {
|
||||
auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(PipelineStage::kFragment),
|
||||
Stage(PipelineStage::kFragment),
|
||||
});
|
||||
auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(PipelineStage::kVertex),
|
||||
Stage(PipelineStage::kVertex),
|
||||
});
|
||||
FunctionList list;
|
||||
list.Add(fs);
|
||||
|
@ -286,7 +286,7 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
|
|||
FunctionList list;
|
||||
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(PipelineStage::kFragment),
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_EQ(nullptr,
|
||||
list.Find(Symbols().Register("main"), PipelineStage::kVertex));
|
||||
|
@ -296,7 +296,7 @@ TEST_F(FunctionListTest, HasStage) {
|
|||
FunctionList list;
|
||||
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(PipelineStage::kFragment),
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));
|
||||
EXPECT_FALSE(list.HasStage(PipelineStage::kVertex));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1203,10 +1203,26 @@ class ProgramBuilder {
|
|||
return func;
|
||||
}
|
||||
|
||||
/// Creates an ast::ReturnStatement with no return value
|
||||
/// @param source the source information
|
||||
/// @returns the return statement pointer
|
||||
ast::ReturnStatement* Return(const Source& source) {
|
||||
return create<ast::ReturnStatement>(source);
|
||||
}
|
||||
|
||||
/// Creates an ast::ReturnStatement with no return value
|
||||
/// @returns the return statement pointer
|
||||
ast::ReturnStatement* Return() { return create<ast::ReturnStatement>(); }
|
||||
|
||||
/// Creates an ast::ReturnStatement with the given return value
|
||||
/// @param source the source information
|
||||
/// @param val the return value
|
||||
/// @returns the return statement pointer
|
||||
template <typename EXPR>
|
||||
ast::ReturnStatement* Return(const Source& source, EXPR&& val) {
|
||||
return create<ast::ReturnStatement>(source, Expr(std::forward<EXPR>(val)));
|
||||
}
|
||||
|
||||
/// Creates an ast::ReturnStatement with the given return value
|
||||
/// @param val the return value
|
||||
/// @returns the return statement pointer
|
||||
|
@ -1330,6 +1346,20 @@ class ProgramBuilder {
|
|||
std::forward<ELSE_STATEMENTS>(elseStatements)...});
|
||||
}
|
||||
|
||||
/// Creates a ast::AssignmentStatement with input lhs and rhs expressions
|
||||
/// @param source the source information
|
||||
/// @param lhs the left hand side expression initializer
|
||||
/// @param rhs the right hand side expression initializer
|
||||
/// @returns the assignment statement pointer
|
||||
template <typename LhsExpressionInit, typename RhsExpressionInit>
|
||||
ast::AssignmentStatement* Assign(const Source& source,
|
||||
LhsExpressionInit&& lhs,
|
||||
RhsExpressionInit&& rhs) {
|
||||
return create<ast::AssignmentStatement>(
|
||||
source, Expr(std::forward<LhsExpressionInit>(lhs)),
|
||||
Expr(std::forward<RhsExpressionInit>(rhs)));
|
||||
}
|
||||
|
||||
/// Creates a ast::AssignmentStatement with input lhs and rhs expressions
|
||||
/// @param lhs the left hand side expression initializer
|
||||
/// @param rhs the right hand side expression initializer
|
||||
|
@ -1351,6 +1381,14 @@ class ProgramBuilder {
|
|||
return create<ast::LoopStatement>(body, continuing);
|
||||
}
|
||||
|
||||
/// Creates a ast::VariableDeclStatement for the input variable
|
||||
/// @param source the source information
|
||||
/// @param var the variable to wrap in a decl statement
|
||||
/// @returns the variable decl statement pointer
|
||||
ast::VariableDeclStatement* Decl(const Source& source, ast::Variable* var) {
|
||||
return create<ast::VariableDeclStatement>(source, var);
|
||||
}
|
||||
|
||||
/// Creates a ast::VariableDeclStatement for the input variable
|
||||
/// @param var the variable to wrap in a decl statement
|
||||
/// @returns the variable decl statement pointer
|
||||
|
|
|
@ -115,8 +115,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
|||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_(str);
|
||||
auto* s = Structure(Sym("S"), members, decos);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
|
@ -140,8 +139,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
|||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_(str);
|
||||
auto* s = Structure(Sym("S"), members, decos);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
|
@ -165,8 +163,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
|||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_(str);
|
||||
auto* s = Structure(Sym("S"), members, decos);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
|
@ -187,8 +184,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
|
|||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_(str);
|
||||
auto* s = Structure(Sym("S"), members, decos);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
|
@ -225,8 +221,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
|
|||
ast::DecorationList decos;
|
||||
decos.push_back(block_deco);
|
||||
|
||||
auto* str = create<ast::Struct>(Sym("S"), members, decos);
|
||||
auto* s = ty.struct_(str);
|
||||
auto* s = Structure(Sym("S"), members, decos);
|
||||
|
||||
p->register_constructed("S", s);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignIncompatibleTypes) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(var, assign);
|
||||
|
||||
ASSERT_FALSE(r()->Resolve());
|
||||
|
@ -57,7 +57,7 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(var_a, var_b, assign);
|
||||
|
||||
ASSERT_FALSE(r()->Resolve());
|
||||
|
@ -77,10 +77,7 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
|
||||
});
|
||||
auto* body = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
|
||||
WrapInFunction(body);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -97,10 +94,7 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
|
||||
});
|
||||
auto* block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
|
||||
WrapInFunction(block);
|
||||
|
||||
ASSERT_FALSE(r()->Resolve());
|
||||
|
@ -123,14 +117,9 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* inner_block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
|
||||
});
|
||||
auto* inner_block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
|
||||
|
||||
auto* outer_block = create<ast::BlockStatement>(ast::StatementList{
|
||||
inner_block,
|
||||
});
|
||||
auto* outer_block = Block(inner_block);
|
||||
|
||||
WrapInFunction(outer_block);
|
||||
|
||||
|
@ -149,7 +138,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToScalar_Fail) {
|
|||
auto* lhs = Expr(1);
|
||||
auto* rhs = Expr("my_var");
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var), assign);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -166,8 +155,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignCompatibleTypes_Pass) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var), assign);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -184,8 +172,7 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var), assign);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -202,8 +189,7 @@ TEST_F(ResolverAssignmentValidationTest,
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr("b");
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var_a), Decl(var_b), assign);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -220,8 +206,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
|
|||
auto* lhs = Expr("b");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(
|
||||
Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var_a), Decl(var_b), assign);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -237,11 +222,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
rhs),
|
||||
});
|
||||
auto* body =
|
||||
Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
|
||||
|
||||
WrapInFunction(body);
|
||||
|
||||
|
@ -267,7 +249,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignFromPointer_Fail) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr("b");
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs);
|
||||
auto* assign = Assign(Source{{12, 34}}, lhs, rhs);
|
||||
WrapInFunction(Decl(var_a), Decl(var_b), assign);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -31,15 +31,13 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f));
|
||||
|
||||
ast::CaseStatementList body;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
body.push_back(
|
||||
create<ast::CaseStatement>(ast::CaseSelectorList{}, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr(Source{Source::Location{12, 34}}, "a"),
|
||||
body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(
|
||||
Expr(Source{Source::Location{12, 34}}, "a"), body));
|
||||
|
||||
WrapInFunction(block);
|
||||
|
||||
|
@ -60,14 +58,11 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithoutDefault_Fail) {
|
|||
csl.push_back(Literal(1));
|
||||
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(create<ast::CaseStatement>(
|
||||
csl, create<ast::BlockStatement>(ast::StatementList{})));
|
||||
body.push_back(create<ast::CaseStatement>(csl, Block()));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, Expr("a"),
|
||||
body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(
|
||||
Source{Source::Location{12, 34}}, Expr("a"), body));
|
||||
|
||||
WrapInFunction(block);
|
||||
|
||||
|
@ -87,24 +82,22 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithTwoDefault_Fail) {
|
|||
|
||||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList default_csl_1;
|
||||
auto* block_default_1 = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default_1 = Block();
|
||||
switch_body.push_back(
|
||||
create<ast::CaseStatement>(default_csl_1, block_default_1));
|
||||
|
||||
ast::CaseSelectorList csl_case_1;
|
||||
csl_case_1.push_back(Literal(1));
|
||||
auto* block_case_1 = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_case_1 = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
|
||||
|
||||
ast::CaseSelectorList default_csl_2;
|
||||
auto* block_default_2 = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default_2 = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, default_csl_2, block_default_2));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
|
||||
|
||||
WrapInFunction(block);
|
||||
|
||||
|
@ -128,17 +121,14 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
ast::CaseSelectorList csl;
|
||||
csl.push_back(create<ast::UintLiteral>(ty.u32(), 1));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
Source{Source::Location{12, 34}}, csl, Block()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -160,17 +150,14 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
ast::CaseSelectorList csl;
|
||||
csl.push_back(Literal(-1));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
Source{Source::Location{12, 34}}, csl, Block()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -192,24 +179,20 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl_1;
|
||||
csl_1.push_back(create<ast::UintLiteral>(ty.u32(), 0));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
|
||||
switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
|
||||
|
||||
ast::CaseSelectorList csl_2;
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
|
||||
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl_2,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
Source{Source::Location{12, 34}}, csl_2, Block()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -231,8 +214,7 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
ast::CaseStatementList switch_body;
|
||||
ast::CaseSelectorList csl_1;
|
||||
csl_1.push_back(Literal(10));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
|
||||
switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
|
||||
|
||||
ast::CaseSelectorList csl_2;
|
||||
csl_2.push_back(Literal(0));
|
||||
|
@ -240,17 +222,14 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
csl_2.push_back(Literal(2));
|
||||
csl_2.push_back(Literal(10));
|
||||
switch_body.push_back(create<ast::CaseStatement>(
|
||||
Source{Source::Location{12, 34}}, csl_2,
|
||||
create<ast::BlockStatement>(ast::StatementList{})));
|
||||
Source{Source::Location{12, 34}}, csl_2, Block()));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), switch_body),
|
||||
});
|
||||
auto* block =
|
||||
Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -269,18 +248,12 @@ TEST_F(ResolverControlBlockValidationTest,
|
|||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(
|
||||
|
||||
ast::StatementList{
|
||||
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}),
|
||||
});
|
||||
auto* block_default = Block(
|
||||
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), body),
|
||||
});
|
||||
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -299,19 +272,16 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCase_Pass) {
|
|||
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||
default_csl, block_default));
|
||||
ast::CaseSelectorList case_csl;
|
||||
case_csl.push_back(Literal(5));
|
||||
auto* block_case = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_case = Block();
|
||||
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), body),
|
||||
});
|
||||
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
|
||||
WrapInFunction(block);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -328,15 +298,12 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCaseAlias_Pass) {
|
|||
auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u));
|
||||
|
||||
ast::CaseSelectorList default_csl;
|
||||
auto* block_default = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* block_default = Block();
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
|
||||
default_csl, block_default));
|
||||
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::SwitchStatement>(Expr("a"), body),
|
||||
});
|
||||
auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
|
||||
AST().AddConstructedType(my_int);
|
||||
|
||||
WrapInFunction(block);
|
||||
|
|
|
@ -62,21 +62,19 @@ static ast::Decoration* createDecoration(const Source& source,
|
|||
case DecorationKind::kBinding:
|
||||
return builder.create<ast::BindingDecoration>(source, 1);
|
||||
case DecorationKind::kBuiltin:
|
||||
return builder.create<ast::BuiltinDecoration>(source,
|
||||
ast::Builtin::kPosition);
|
||||
return builder.Builtin(source, ast::Builtin::kPosition);
|
||||
case DecorationKind::kConstantId:
|
||||
return builder.create<ast::ConstantIdDecoration>(source, 0u);
|
||||
case DecorationKind::kGroup:
|
||||
return builder.create<ast::GroupDecoration>(source, 1u);
|
||||
case DecorationKind::kLocation:
|
||||
return builder.create<ast::LocationDecoration>(source, 1);
|
||||
return builder.Location(source, 1);
|
||||
case DecorationKind::kOffset:
|
||||
return builder.create<ast::StructMemberOffsetDecoration>(source, 4u);
|
||||
case DecorationKind::kSize:
|
||||
return builder.create<ast::StructMemberSizeDecoration>(source, 4u);
|
||||
case DecorationKind::kStage:
|
||||
return builder.create<ast::StageDecoration>(source,
|
||||
ast::PipelineStage::kCompute);
|
||||
return builder.Stage(source, ast::PipelineStage::kCompute);
|
||||
case DecorationKind::kStride:
|
||||
return builder.create<ast::StrideDecoration>(source, 4u);
|
||||
case DecorationKind::kStructBlock:
|
||||
|
@ -91,10 +89,8 @@ using FunctionReturnTypeDecorationTest = TestWithParams;
|
|||
TEST_P(FunctionReturnTypeDecorationTest, IsValid) {
|
||||
auto& params = GetParam();
|
||||
|
||||
Func("main", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{create<ast::ReturnStatement>(Expr(1.f))},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute)},
|
||||
Func("main", ast::VariableList{}, ty.f32(), ast::StatementList{Return(1.f)},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kCompute)},
|
||||
ast::DecorationList{createDecoration({}, *this, params.kind)});
|
||||
|
||||
if (params.should_pass) {
|
||||
|
@ -126,15 +122,16 @@ using ArrayDecorationTest = TestWithParams;
|
|||
TEST_P(ArrayDecorationTest, IsValid) {
|
||||
auto& params = GetParam();
|
||||
|
||||
ast::StructMemberList members{Member(
|
||||
"a", create<sem::ArrayType>(ty.f32(), 0,
|
||||
ast::DecorationList{createDecoration(
|
||||
Source{{12, 34}}, *this, params.kind)}))};
|
||||
auto* s = create<ast::Struct>(
|
||||
Sym("mystruct"), members,
|
||||
ast::DecorationList{create<ast::StructBlockDecoration>()});
|
||||
auto* s_ty = ty.struct_(s);
|
||||
AST().AddConstructedType(s_ty);
|
||||
auto* arr = create<sem::ArrayType>(
|
||||
ty.f32(), 0,
|
||||
ast::DecorationList{
|
||||
createDecoration(Source{{12, 34}}, *this, params.kind),
|
||||
});
|
||||
Structure("mystruct",
|
||||
{
|
||||
Member("a", arr),
|
||||
},
|
||||
{create<ast::StructBlockDecoration>()});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -167,11 +164,8 @@ using StructDecorationTest = TestWithParams;
|
|||
TEST_P(StructDecorationTest, IsValid) {
|
||||
auto& params = GetParam();
|
||||
|
||||
auto* s = create<ast::Struct>(Sym("mystruct"), ast::StructMemberList{},
|
||||
ast::DecorationList{createDecoration(
|
||||
Source{{12, 34}}, *this, params.kind)});
|
||||
auto* s_ty = ty.struct_(s);
|
||||
AST().AddConstructedType(s_ty);
|
||||
Structure("mystruct", {},
|
||||
{createDecoration(Source{{12, 34}}, *this, params.kind)});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -208,10 +202,8 @@ TEST_P(StructMemberDecorationTest, IsValid) {
|
|||
Member("a", ty.i32(),
|
||||
ast::DecorationList{
|
||||
createDecoration(Source{{12, 34}}, *this, params.kind)})};
|
||||
auto* s =
|
||||
create<ast::Struct>(Sym("mystruct"), members, ast::DecorationList{});
|
||||
auto* s_ty = ty.struct_(s);
|
||||
AST().AddConstructedType(s_ty);
|
||||
|
||||
Structure("mystruct", members);
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -281,7 +273,7 @@ TEST_P(FunctionDecorationTest, IsValid) {
|
|||
|
||||
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
createDecoration(Source{{12, 34}}, *this, params.kind)});
|
||||
|
||||
if (params.should_pass) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class ResolverEntryPointValidationTest : public resolver::TestHelper,
|
|||
TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Location) {
|
||||
// [[stage(vertex)]]
|
||||
// fn main() -> [[location(0)]] f32 { return 1.0; }
|
||||
Func(Source{{12, 34}}, "main", {}, ty.f32(), {Return(Expr(1.0f))},
|
||||
Func(Source{{12, 34}}, "main", {}, ty.f32(), {Return(1.0f)},
|
||||
{Stage(ast::PipelineStage::kFragment)}, {Location(0)});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -30,13 +30,13 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
|
|||
// fn func -> i32 { return 2; }
|
||||
Func("func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(2)),
|
||||
Return(2),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(2)),
|
||||
Return(2),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -53,7 +53,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -66,7 +66,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
|||
|
||||
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -105,7 +105,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
|
||||
Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -116,8 +116,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
// fn func { return 2; }
|
||||
Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
Expr(2)),
|
||||
Return(Source{Source::Location{12, 34}}, Expr(2)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -132,8 +131,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
// fn func -> f32 { return 2.0; }
|
||||
Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
Expr(2.f)),
|
||||
Return(Source{Source::Location{12, 34}}, Expr(2.f)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -145,8 +143,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
// fn func -> f32 { return 2; }
|
||||
Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
Expr(2)),
|
||||
Return(Source{Source::Location{12, 34}}, Expr(2)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -163,8 +160,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
auto* myf32 = ty.alias("myf32", ty.f32());
|
||||
Func("func", ast::VariableList{}, myf32,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
Expr(2.f)),
|
||||
Return(Source{Source::Location{12, 34}}, Expr(2.f)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -178,8 +174,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
auto* myf32 = ty.alias("myf32", ty.f32());
|
||||
Func("func", ast::VariableList{}, myf32,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
|
||||
Expr(2u)),
|
||||
Return(Source{Source::Location{12, 34}}, Expr(2u)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -196,11 +191,11 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
|||
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
|
||||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -212,7 +207,7 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
|
|||
TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
|
||||
Func("vtx_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ TEST_F(ResolverTest, Stmt_Assign) {
|
|||
auto* lhs = Expr("v");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
WrapInFunction(v, assign);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -78,7 +78,7 @@ TEST_F(ResolverTest, Stmt_Case) {
|
|||
auto* lhs = Expr("v");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
auto* block = Block(assign);
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32(), 3));
|
||||
|
@ -101,7 +101,7 @@ TEST_F(ResolverTest, Stmt_Block) {
|
|||
auto* lhs = Expr("v");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
auto* block = Block(assign);
|
||||
WrapInFunction(v, block);
|
||||
|
||||
|
@ -123,7 +123,7 @@ TEST_F(ResolverTest, Stmt_If) {
|
|||
auto* else_lhs = Expr("v");
|
||||
auto* else_rhs = Expr(2.3f);
|
||||
|
||||
auto* else_body = Block(create<ast::AssignmentStatement>(else_lhs, else_rhs));
|
||||
auto* else_body = Block(Assign(else_lhs, else_rhs));
|
||||
|
||||
auto* else_cond = Expr(3);
|
||||
auto* else_stmt = create<ast::ElseStatement>(else_cond, else_body);
|
||||
|
@ -131,7 +131,7 @@ TEST_F(ResolverTest, Stmt_If) {
|
|||
auto* lhs = Expr("v");
|
||||
auto* rhs = Expr(2.3f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
auto* body = Block(assign);
|
||||
auto* cond = Expr(true);
|
||||
auto* stmt =
|
||||
|
@ -165,14 +165,12 @@ TEST_F(ResolverTest, Stmt_Loop) {
|
|||
auto* body_lhs = Expr("v");
|
||||
auto* body_rhs = Expr(2.3f);
|
||||
|
||||
auto* body = Block(create<ast::AssignmentStatement>(body_lhs, body_rhs));
|
||||
auto* body = Block(Assign(body_lhs, body_rhs));
|
||||
auto* continuing_lhs = Expr("v");
|
||||
auto* continuing_rhs = Expr(2.3f);
|
||||
|
||||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(continuing_lhs, continuing_rhs),
|
||||
});
|
||||
auto* stmt = create<ast::LoopStatement>(body, continuing);
|
||||
auto* continuing = Block(Assign(continuing_lhs, continuing_rhs));
|
||||
auto* stmt = Loop(body, continuing);
|
||||
WrapInFunction(v, stmt);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -194,7 +192,7 @@ TEST_F(ResolverTest, Stmt_Loop) {
|
|||
TEST_F(ResolverTest, Stmt_Return) {
|
||||
auto* cond = Expr(2);
|
||||
|
||||
auto* ret = create<ast::ReturnStatement>(cond);
|
||||
auto* ret = Return(cond);
|
||||
Func("test", {}, ty.i32(), {ret}, {});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -204,7 +202,7 @@ TEST_F(ResolverTest, Stmt_Return) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, Stmt_Return_WithoutValue) {
|
||||
auto* ret = create<ast::ReturnStatement>();
|
||||
auto* ret = Return();
|
||||
WrapInFunction(ret);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -233,7 +231,7 @@ TEST_F(ResolverTest, Stmt_Switch) {
|
|||
|
||||
TEST_F(ResolverTest, Stmt_Call) {
|
||||
ast::VariableList params;
|
||||
Func("my_func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
|
||||
Func("my_func", params, ty.f32(), ast::StatementList{Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* expr = Call("my_func");
|
||||
|
@ -252,7 +250,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl) {
|
|||
auto* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
auto* init = var->constructor();
|
||||
|
||||
auto* decl = create<ast::VariableDeclStatement>(var);
|
||||
auto* decl = Decl(var);
|
||||
WrapInFunction(decl);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -266,7 +264,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_Alias) {
|
|||
auto* var = Var("my_var", my_int, ast::StorageClass::kNone, Expr(2));
|
||||
auto* init = var->constructor();
|
||||
|
||||
auto* decl = create<ast::VariableDeclStatement>(var);
|
||||
auto* decl = Decl(var);
|
||||
WrapInFunction(decl);
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -301,25 +299,24 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
|
|||
// Declare i32 "foo" inside a block
|
||||
auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2));
|
||||
auto* foo_i32_init = foo_i32->constructor();
|
||||
auto* foo_i32_decl = create<ast::VariableDeclStatement>(foo_i32);
|
||||
auto* foo_i32_decl = Decl(foo_i32);
|
||||
|
||||
// Reference "foo" inside the block
|
||||
auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo"));
|
||||
auto* bar_i32_init = bar_i32->constructor();
|
||||
auto* bar_i32_decl = create<ast::VariableDeclStatement>(bar_i32);
|
||||
auto* bar_i32_decl = Decl(bar_i32);
|
||||
|
||||
auto* inner = create<ast::BlockStatement>(
|
||||
ast::StatementList{foo_i32_decl, bar_i32_decl});
|
||||
auto* inner = Block(foo_i32_decl, bar_i32_decl);
|
||||
|
||||
// Declare f32 "foo" at function scope
|
||||
auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f));
|
||||
auto* foo_f32_init = foo_f32->constructor();
|
||||
auto* foo_f32_decl = create<ast::VariableDeclStatement>(foo_f32);
|
||||
auto* foo_f32_decl = Decl(foo_f32);
|
||||
|
||||
// Reference "foo" at function scope
|
||||
auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo"));
|
||||
auto* bar_f32_init = bar_f32->constructor();
|
||||
auto* bar_f32_decl = create<ast::VariableDeclStatement>(bar_f32);
|
||||
auto* bar_f32_decl = Decl(bar_f32);
|
||||
|
||||
Func("func", params, ty.void_(),
|
||||
ast::StatementList{inner, foo_f32_decl, bar_f32_decl},
|
||||
|
@ -360,7 +357,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
|
|||
// Declare i32 "foo" inside a function
|
||||
auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kFunction, Expr(2));
|
||||
auto* fn_i32_init = fn_i32->constructor();
|
||||
auto* fn_i32_decl = create<ast::VariableDeclStatement>(fn_i32);
|
||||
auto* fn_i32_decl = Decl(fn_i32);
|
||||
Func("func_i32", params, ty.void_(), ast::StatementList{fn_i32_decl},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -373,7 +370,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
|
|||
auto* fn_f32 =
|
||||
Var("bar", ty.f32(), ast::StorageClass::kFunction, Expr("foo"));
|
||||
auto* fn_f32_init = fn_f32->constructor();
|
||||
auto* fn_f32_decl = create<ast::VariableDeclStatement>(fn_f32);
|
||||
auto* fn_f32_decl = Decl(fn_f32);
|
||||
Func("func_f32", params, ty.void_(), ast::StatementList{fn_f32_decl},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -498,7 +495,7 @@ TEST_F(ResolverTest, Expr_Bitcast) {
|
|||
|
||||
TEST_F(ResolverTest, Expr_Call) {
|
||||
ast::VariableList params;
|
||||
Func("my_func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
|
||||
Func("my_func", params, ty.f32(), ast::StatementList{Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* call = Call("my_func");
|
||||
|
@ -512,7 +509,7 @@ TEST_F(ResolverTest, Expr_Call) {
|
|||
|
||||
TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
|
||||
ast::VariableList params;
|
||||
Func("func", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
|
||||
Func("func", params, ty.f32(), ast::StatementList{Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* expr = Add(Call("func"), Call("func"));
|
||||
|
@ -646,7 +643,7 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
|
|||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
decl,
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
@ -664,13 +661,13 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
|
|||
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
|
||||
auto* my_var_a = Expr("my_var");
|
||||
auto* my_var_b = Expr("my_var");
|
||||
auto* assign = create<ast::AssignmentStatement>(my_var_a, my_var_b);
|
||||
auto* assign = Assign(my_var_a, my_var_b);
|
||||
|
||||
auto* var = Var("my_var", ty.f32(), ast::StorageClass::kNone);
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
assign,
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
@ -695,13 +692,12 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
|
|||
TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
|
||||
auto* my_var_a = Expr("my_var");
|
||||
auto* my_var_b = Expr("my_var");
|
||||
auto* assign = create<ast::AssignmentStatement>(my_var_a, my_var_b);
|
||||
auto* assign = Assign(my_var_a, my_var_b);
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction),
|
||||
ast::StorageClass::kNone)),
|
||||
Decl(Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction),
|
||||
ast::StorageClass::kNone)),
|
||||
assign,
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
@ -720,7 +716,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
|
|||
|
||||
TEST_F(ResolverTest, Expr_Call_Function) {
|
||||
Func("my_func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{Return(Expr(0.0f))}, ast::DecorationList{});
|
||||
ast::StatementList{Return(0.0f)}, ast::DecorationList{});
|
||||
|
||||
auto* call = Call("my_func");
|
||||
WrapInFunction(call);
|
||||
|
@ -775,15 +771,14 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
|
|||
auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
|
||||
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* func = Func(
|
||||
"my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
|
||||
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
|
||||
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
|
||||
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Assign("out_var", "in_var"),
|
||||
Assign("wg_var", "wg_var"),
|
||||
Assign("sb_var", "sb_var"),
|
||||
Assign("priv_var", "priv_var"),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -811,22 +806,19 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables_SubFunction) {
|
|||
auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
|
||||
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
|
||||
|
||||
Func("my_func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")),
|
||||
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")),
|
||||
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")),
|
||||
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")),
|
||||
Return(Expr(0.0f))},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* func2 = Func(
|
||||
"func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("out_var"), Call("my_func")),
|
||||
},
|
||||
Func(
|
||||
"my_func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{Assign("out_var", "in_var"),
|
||||
Assign("wg_var", "wg_var"), Assign("sb_var", "sb_var"),
|
||||
Assign("priv_var", "priv_var"), Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* func2 = Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Assign("out_var", Call("my_func")),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
auto* func2_sem = Sem().Get(func2);
|
||||
|
@ -846,13 +838,12 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
|
|||
auto* var = Var("in_var", ty.f32(), ast::StorageClass::kFunction);
|
||||
Global("var", ty.f32(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* func =
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Decl(var),
|
||||
Assign("var", 1.f),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -865,13 +856,12 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
|
|||
TEST_F(ResolverTest, Function_ReturnStatements) {
|
||||
auto* var = Var("foo", ty.f32(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* ret_1 = create<ast::ReturnStatement>(Expr(1.f));
|
||||
auto* ret_foo = create<ast::ReturnStatement>(Expr("foo"));
|
||||
|
||||
auto* ret_1 = Return(1.f);
|
||||
auto* ret_foo = Return("foo");
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
If(Expr(true), Block(ret_1)),
|
||||
Decl(var),
|
||||
If(true, Block(ret_1)),
|
||||
ret_foo,
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
@ -888,13 +878,8 @@ TEST_F(ResolverTest, Function_ReturnStatements) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
|
||||
auto* strct = create<ast::Struct>(
|
||||
Sym("S"),
|
||||
ast::StructMemberList{Member("first_member", ty.i32()),
|
||||
Member("second_member", ty.f32())},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* st = ty.struct_(strct);
|
||||
auto* st = Structure("S", {Member("first_member", ty.i32()),
|
||||
Member("second_member", ty.f32())});
|
||||
Global("my_struct", st, ast::StorageClass::kInput);
|
||||
|
||||
auto* mem = MemberAccessor("my_struct", "second_member");
|
||||
|
@ -918,13 +903,8 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
|
||||
auto* strct = create<ast::Struct>(
|
||||
Sym("alias"),
|
||||
ast::StructMemberList{Member("first_member", ty.i32()),
|
||||
Member("second_member", ty.f32())},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* st = ty.struct_(strct);
|
||||
auto* st = Structure("alias", {Member("first_member", ty.i32()),
|
||||
Member("second_member", ty.f32())});
|
||||
auto* alias = ty.alias("alias", st);
|
||||
Global("my_struct", alias, ast::StorageClass::kInput);
|
||||
|
||||
|
@ -1001,17 +981,11 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
|
|||
// }
|
||||
//
|
||||
|
||||
auto* strctB = create<ast::Struct>(
|
||||
Sym("B"), ast::StructMemberList{Member("foo", ty.vec4<f32>())},
|
||||
ast::DecorationList{});
|
||||
auto* stB = ty.struct_(strctB);
|
||||
auto* stB = Structure("B", {Member("foo", ty.vec4<f32>())});
|
||||
|
||||
sem::Vector vecB(stB, 3);
|
||||
auto* strctA =
|
||||
create<ast::Struct>(Sym("A"), ast::StructMemberList{Member("mem", &vecB)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* stA = ty.struct_(strctA);
|
||||
auto* stA = Structure("A", {Member("mem", &vecB)});
|
||||
Global("c", stA, ast::StorageClass::kInput);
|
||||
|
||||
auto* mem = MemberAccessor(
|
||||
|
@ -1029,13 +1003,8 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
|
||||
auto* strct = create<ast::Struct>(
|
||||
Sym("S"),
|
||||
ast::StructMemberList{Member("first_member", ty.f32()),
|
||||
Member("second_member", ty.f32())},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* st = ty.struct_(strct);
|
||||
auto* st = Structure("S", {Member("first_member", ty.f32()),
|
||||
Member("second_member", ty.f32())});
|
||||
Global("my_struct", st, ast::StorageClass::kInput);
|
||||
|
||||
auto* expr = Add(MemberAccessor("my_struct", "first_member"),
|
||||
|
@ -1470,7 +1439,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest,
|
|||
TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
|
||||
auto* var = Var("var", ty.i32(), ast::StorageClass::kNone);
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -1481,7 +1450,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
|
|||
|
||||
TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
|
||||
auto* var = Const("var", ty.i32());
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -1510,39 +1479,34 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
|
|||
Global("call_c", ty.f32(), ast::StorageClass::kPrivate);
|
||||
|
||||
ast::VariableList params;
|
||||
auto* func_b =
|
||||
Func("b", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))},
|
||||
auto* func_b = Func("b", params, ty.f32(), ast::StatementList{Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
auto* func_c =
|
||||
Func("c", params, ty.f32(),
|
||||
ast::StatementList{Assign("second", Call("b")), Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
auto* func_c = Func("c", params, ty.f32(),
|
||||
ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Expr("second"), Call("b")),
|
||||
Return(Expr(0.0f))},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* func_a = Func("a", params, ty.f32(),
|
||||
ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Expr("first"), Call("c")),
|
||||
Return(Expr(0.0f))},
|
||||
ast::DecorationList{});
|
||||
auto* func_a =
|
||||
Func("a", params, ty.f32(),
|
||||
ast::StatementList{Assign("first", Call("c")), Return(0.0f)},
|
||||
ast::DecorationList{});
|
||||
|
||||
auto* ep_1 =
|
||||
Func("ep_1", params, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("call_a"), Call("a")),
|
||||
create<ast::AssignmentStatement>(Expr("call_b"), Call("b")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* ep_1 = Func("ep_1", params, ty.void_(),
|
||||
ast::StatementList{
|
||||
Assign("call_a", Call("a")),
|
||||
Assign("call_b", Call("b")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
auto* ep_2 =
|
||||
Func("ep_2", params, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("call_c"), Call("c")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* ep_2 = Func("ep_2", params, ty.void_(),
|
||||
ast::StatementList{
|
||||
Assign("call_c", Call("c")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -1620,7 +1584,7 @@ TEST_F(ResolverTest, Function_EntryPoints_LinearTime) {
|
|||
create<ast::CallStatement>(Call(fn_b(0))),
|
||||
},
|
||||
{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -28,8 +28,7 @@ namespace {
|
|||
using ResolverPipelineStageUseTest = ResolverTest;
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -39,8 +38,7 @@ TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
|
||||
Func("foo", {Param("param", s)}, ty.void_(), {}, {});
|
||||
|
||||
|
@ -52,8 +50,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointReturnType) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
|
||||
Func("foo", {}, s, {Return(Construct(s, Expr(0.f)))}, {});
|
||||
|
||||
|
@ -96,11 +93,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderReturnType) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
|
||||
Func("main", {Param("param", s)}, ty.void_(), {},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -111,11 +107,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
|
||||
Func("main", {}, s, {Return(Construct(s, Expr(0.f)))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -126,12 +121,12 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) {
|
||||
auto* s = Structure("S", {Member("a", ty.u32(),
|
||||
{create<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kLocalInvocationIndex)})});
|
||||
auto* s = Structure(
|
||||
"S",
|
||||
{Member("a", ty.u32(), {Builtin(ast::Builtin::kLocalInvocationIndex)})});
|
||||
|
||||
Func("main", {Param("param", s)}, ty.void_(), {},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -162,12 +157,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
auto* s_alias = ty.alias("S_alias", s);
|
||||
|
||||
Func("main", {Param("param", s_alias)}, ty.void_(), {},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -178,12 +172,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderReturnTypeViaAlias) {
|
||||
auto* s = Structure(
|
||||
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
|
||||
auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
|
||||
auto* s_alias = ty.alias("S_alias", s);
|
||||
|
||||
Func("main", {}, s_alias, {Return(Construct(s_alias, Expr(0.f)))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
|
|
@ -38,11 +38,8 @@ TEST_F(ResolverTypeValidationTest, VariableDeclNoConstructor_Pass) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
rhs),
|
||||
});
|
||||
auto* body =
|
||||
Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
|
||||
|
||||
WrapInFunction(body);
|
||||
|
||||
|
@ -133,7 +130,7 @@ TEST_F(ResolverTypeValidationTest,
|
|||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var),
|
||||
Decl(Source{{12, 34}}, var),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -152,8 +149,8 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifier_Fail) {
|
|||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float),
|
||||
Decl(var),
|
||||
Decl(Source{{12, 34}}, var_a_float),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -169,16 +166,13 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScope_Pass) {
|
|||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
auto* body = Block(Decl(var));
|
||||
|
||||
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f));
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float),
|
||||
});
|
||||
auto* outer_body =
|
||||
Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
Decl(Source{{12, 34}}, var_a_float));
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -198,14 +192,11 @@ TEST_F(ResolverTypeValidationTest,
|
|||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var),
|
||||
});
|
||||
auto* body = Block(Decl(Source{{12, 34}}, var));
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var_a_float),
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
});
|
||||
auto* outer_body =
|
||||
Block(Decl(var_a_float),
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -219,15 +210,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Pass) {
|
|||
// var a : f32;
|
||||
// }
|
||||
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* inner = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
|
||||
});
|
||||
auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
|
||||
|
||||
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
inner,
|
||||
create<ast::VariableDeclStatement>(var_outer),
|
||||
});
|
||||
auto* outer_body = Block(inner, Decl(var_outer));
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -240,15 +226,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
|
|||
// { var a : f32; }
|
||||
// }
|
||||
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* inner = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
|
||||
});
|
||||
auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
|
||||
|
||||
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var_outer),
|
||||
inner,
|
||||
});
|
||||
auto* outer_body = Block(Decl(var_outer), inner);
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -266,15 +247,15 @@ TEST_F(ResolverTypeValidationTest,
|
|||
|
||||
Func("func0", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{12, 34}}, var0),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(Source{{12, 34}}, var0),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
Func("func1", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{{13, 34}}, var1),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(Source{{13, 34}}, var1),
|
||||
Return(),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -289,10 +270,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayInFunction_Fail) {
|
|||
|
||||
Func("func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -309,16 +290,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLast_Pass) {
|
|||
// rt: array<f32>;
|
||||
// };
|
||||
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st =
|
||||
create<ast::Struct>(Sym("Foo"),
|
||||
ast::StructMemberList{Member("vf", ty.f32()),
|
||||
Member("rt", ty.array<f32>())},
|
||||
decos);
|
||||
|
||||
auto* struct_type = ty.struct_(st);
|
||||
AST().AddConstructedType(struct_type);
|
||||
Structure("Foo",
|
||||
{
|
||||
Member("vf", ty.f32()),
|
||||
Member("rt", ty.array<f32>()),
|
||||
},
|
||||
{create<ast::StructBlockDecoration>()});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -331,15 +308,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLastNoBlock_Fail) {
|
|||
// rt: array<f32>;
|
||||
// };
|
||||
|
||||
ast::DecorationList decos;
|
||||
auto* st = create<ast::Struct>(
|
||||
Sym("Foo"),
|
||||
ast::StructMemberList{Member("vf", ty.f32()),
|
||||
Member(Source{{12, 34}}, "rt", ty.array<f32>())},
|
||||
decos);
|
||||
|
||||
auto* struct_type = ty.struct_(st);
|
||||
AST().AddConstructedType(struct_type);
|
||||
Structure("Foo", {
|
||||
Member("vf", ty.f32()),
|
||||
Member(Source{{12, 34}}, "rt", ty.array<f32>()),
|
||||
});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -356,16 +328,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsNotLast_Fail) {
|
|||
// vf: f32;
|
||||
// };
|
||||
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
|
||||
auto* rt = Member(Source{{12, 34}}, "rt", ty.array<f32>());
|
||||
auto* st = create<ast::Struct>(
|
||||
Sym("Foo"), ast::StructMemberList{rt, Member("vf", ty.f32())}, decos);
|
||||
|
||||
auto* struct_type = ty.struct_(st);
|
||||
|
||||
AST().AddConstructedType(struct_type);
|
||||
Structure("Foo",
|
||||
{
|
||||
Member(Source{{12, 34}}, "rt", ty.array<f32>()),
|
||||
Member("vf", ty.f32()),
|
||||
},
|
||||
{create<ast::StructBlockDecoration>()});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -405,16 +373,16 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayAsParameter_Fail) {
|
|||
|
||||
Func("func", ast::VariableList{param}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve()) << r()->error();
|
||||
|
@ -434,16 +402,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsNotLast_Fail) {
|
|||
|
||||
auto* alias = ty.alias("RTArr", ty.array<u32>());
|
||||
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st = create<ast::Struct>(
|
||||
Sym("s"),
|
||||
ast::StructMemberList{Member(Source{{12, 34}}, "b", alias),
|
||||
Member("a", ty.u32())},
|
||||
decos);
|
||||
|
||||
auto* struct_type = ty.struct_(st);
|
||||
AST().AddConstructedType(struct_type);
|
||||
Structure("s",
|
||||
{
|
||||
Member(Source{{12, 34}}, "b", alias),
|
||||
Member("a", ty.u32()),
|
||||
},
|
||||
{create<ast::StructBlockDecoration>()});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
@ -464,14 +428,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
|
|||
|
||||
auto* alias = ty.alias("RTArr", ty.array<u32>());
|
||||
|
||||
ast::DecorationList decos;
|
||||
decos.push_back(create<ast::StructBlockDecoration>());
|
||||
auto* st = create<ast::Struct>(
|
||||
Sym("s"),
|
||||
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos);
|
||||
|
||||
auto* struct_type = ty.struct_(st);
|
||||
AST().AddConstructedType(struct_type);
|
||||
Structure("s",
|
||||
{
|
||||
Member("a", ty.u32()),
|
||||
Member("b", alias),
|
||||
},
|
||||
{create<ast::StructBlockDecoration>()});
|
||||
|
||||
WrapInFunction();
|
||||
|
||||
|
|
|
@ -95,13 +95,13 @@ TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
|
|||
Func("main", params0, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::CallStatement>(call_expr),
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
Func("func", params0, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -123,7 +123,7 @@ TEST_F(ResolverValidationTest, Stmt_Call_recursive) {
|
|||
create<ast::CallStatement>(call_expr),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -153,8 +153,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* var =
|
||||
Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(unsigned_value));
|
||||
|
||||
auto* decl =
|
||||
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
|
||||
auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
|
||||
WrapInFunction(decl);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -170,8 +169,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* var =
|
||||
Var("my_var", my_int, ast::StorageClass::kNone, Expr(unsigned_value));
|
||||
|
||||
auto* decl =
|
||||
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
|
||||
auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
|
||||
WrapInFunction(decl);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -216,7 +214,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariable_Fail) {
|
|||
|
||||
auto* lhs = Expr(Source{{12, 34}}, "b");
|
||||
auto* rhs = Expr(2);
|
||||
auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
WrapInFunction(assign);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -232,9 +230,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInBlockStatement_Fail) {
|
|||
auto* lhs = Expr(Source{{12, 34}}, "b");
|
||||
auto* rhs = Expr(2);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(lhs, rhs),
|
||||
});
|
||||
auto* body = Block(Assign(lhs, rhs));
|
||||
WrapInFunction(body);
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -253,10 +249,9 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
|
|||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(lhs, rhs),
|
||||
Assign(lhs, rhs),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kVertex)});
|
||||
|
||||
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f));
|
||||
|
||||
|
@ -277,9 +272,8 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariable_Pass) {
|
|||
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}},
|
||||
Expr("global_var"), Expr(3.14f)),
|
||||
create<ast::ReturnStatement>(),
|
||||
Assign(Expr(Source{Source::Location{12, 34}}, "global_var"), 3.14f),
|
||||
Return(),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -293,18 +287,15 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInnerScope_Fail) {
|
|||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
auto* body = Block(Decl(var));
|
||||
|
||||
SetSource(Source{Source::Location{12, 34}});
|
||||
auto* lhs = Expr(Source{{12, 34}}, "a");
|
||||
auto* rhs = Expr(3.14f);
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
create<ast::AssignmentStatement>(lhs, rhs),
|
||||
});
|
||||
auto* outer_body =
|
||||
Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
Assign(lhs, rhs));
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -324,14 +315,11 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableOuterScope_Pass) {
|
|||
auto* rhs = Expr(3.14f);
|
||||
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(lhs, rhs),
|
||||
});
|
||||
auto* body = Block(Assign(lhs, rhs));
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
|
||||
});
|
||||
auto* outer_body =
|
||||
Block(Decl(var),
|
||||
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -344,20 +332,13 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
|
|||
// { a = 3.14; }
|
||||
// }
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
|
||||
auto* first_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
});
|
||||
auto* first_body = Block(Decl(var));
|
||||
|
||||
auto* lhs = Expr(Source{{12, 34}}, "a");
|
||||
auto* rhs = Expr(3.14f);
|
||||
auto* second_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(lhs, rhs),
|
||||
});
|
||||
auto* second_body = Block(Assign(lhs, rhs));
|
||||
|
||||
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
first_body,
|
||||
second_body,
|
||||
});
|
||||
auto* outer_body = Block(first_body, second_body);
|
||||
|
||||
WrapInFunction(outer_body);
|
||||
|
||||
|
@ -369,7 +350,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
|
|||
TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) {
|
||||
auto* var = Var("var", ty.i32(), ast::StorageClass::kWorkgroup);
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -436,7 +417,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto error_loc = Source{Source::Location{12, 34}};
|
||||
auto* body = Block(create<ast::ContinueStatement>(),
|
||||
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -462,7 +443,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* body = Block(create<ast::ContinueStatement>(),
|
||||
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
|
||||
create<ast::ContinueStatement>());
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -487,7 +468,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto error_loc = Source{Source::Location{12, 34}};
|
||||
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
|
||||
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -517,7 +498,7 @@ TEST_F(
|
|||
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
|
||||
auto* continuing =
|
||||
Block(If(Expr(true), Block(Assign(Expr(error_loc, "z"), Expr(2)))));
|
||||
Block(If(Expr(true), Block(Assign(Expr(error_loc, "z"), 2))));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -545,7 +526,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
|
||||
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
|
||||
auto* continuing = Block(Loop(Block(Assign(Expr(error_loc, "z"), Expr(2)))));
|
||||
auto* continuing = Block(Loop(Block(Assign(Expr(error_loc, "z"), 2))));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -571,7 +552,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
|
||||
auto* body =
|
||||
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
auto* continuing = Block(Assign(Expr("z"), Expr(2)));
|
||||
auto* continuing = Block(Assign("z", 2));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -596,7 +577,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
|
||||
auto* body =
|
||||
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
auto* continuing = Block(If(Expr(true), Block(Assign(Expr("z"), Expr(2)))));
|
||||
auto* continuing = Block(If(Expr(true), Block(Assign("z", 2))));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -621,7 +602,7 @@ TEST_F(ResolverValidationTest,
|
|||
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
|
||||
auto* body =
|
||||
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
|
||||
auto* continuing = Block(Loop(Block(Assign(Expr("z"), Expr(2)))));
|
||||
auto* continuing = Block(Loop(Block(Assign("z", 2))));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
@ -641,7 +622,7 @@ TEST_F(ResolverTest, Stmt_Loop_ContinueInLoopBodyAfterDecl_UsageInContinuing) {
|
|||
auto error_loc = Source{Source::Location{12, 34}};
|
||||
auto* body = Block(Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
|
||||
create<ast::ContinueStatement>());
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), Expr(2)));
|
||||
auto* continuing = Block(Assign(Expr(error_loc, "z"), 2));
|
||||
auto* loop_stmt = Loop(body, continuing);
|
||||
WrapInFunction(loop_stmt);
|
||||
|
||||
|
|
|
@ -182,10 +182,9 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
|||
|
||||
// Construct the variable that'll hold the result of
|
||||
// RWByteAddressBuffer.GetDimensions()
|
||||
auto* buffer_size_result =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Var(
|
||||
ctx.dst->Symbols().New(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
|
||||
auto* buffer_size_result = ctx.dst->Decl(ctx.dst->Var(
|
||||
ctx.dst->Symbols().New(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
|
||||
|
||||
// Call storage_buffer.GetDimensions(buffer_size_result)
|
||||
auto* call_get_dims =
|
||||
|
@ -203,14 +202,12 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
|||
auto name = ctx.dst->Symbols().New();
|
||||
uint32_t array_offset = array_member_sem->Offset();
|
||||
uint32_t array_stride = array_member_sem->Size();
|
||||
auto* array_length_var =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Const(
|
||||
name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Div(
|
||||
ctx.dst->Sub(
|
||||
buffer_size_result->variable()->symbol(),
|
||||
array_offset),
|
||||
array_stride)));
|
||||
auto* array_length_var = ctx.dst->Decl(ctx.dst->Const(
|
||||
name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Div(
|
||||
ctx.dst->Sub(buffer_size_result->variable()->symbol(),
|
||||
array_offset),
|
||||
array_stride)));
|
||||
|
||||
// Insert the array length calculations at the top of the block
|
||||
ctx.InsertBefore(block->statements(), *block->begin(),
|
||||
|
|
|
@ -257,8 +257,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
|
|||
ret_values.push_back(new_ret_value());
|
||||
}
|
||||
|
||||
auto* new_ret = ctx.dst->create<ast::ReturnStatement>(
|
||||
ctx.dst->Construct(new_ret_type, ret_values));
|
||||
auto* new_ret =
|
||||
ctx.dst->Return(ctx.dst->Construct(new_ret_type, ret_values));
|
||||
ctx.Replace(ret, new_ret);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -356,10 +356,10 @@ sem::Type* UnwrapPtrAndAlias(sem::Type* ty) {
|
|||
|
||||
/// StorageBufferAccess describes a single storage buffer access
|
||||
struct StorageBufferAccess {
|
||||
sem::Expression const* var = nullptr; // Storage buffer variable
|
||||
std::unique_ptr<Offset> offset; // The byte offset on var
|
||||
sem::Type* type = nullptr; // The type of the access
|
||||
operator bool() const { return var; } // Returns true if valid
|
||||
sem::Expression const* var = nullptr; // Storage buffer variable
|
||||
std::unique_ptr<Offset> offset; // The byte offset on var
|
||||
sem::Type* type = nullptr; // The type of the access
|
||||
operator bool() const { return var; } // Returns true if valid
|
||||
};
|
||||
|
||||
/// Store describes a single storage buffer write
|
||||
|
@ -459,8 +459,8 @@ struct State {
|
|||
}
|
||||
func = ctx.dst->create<ast::Function>(
|
||||
ctx.dst->Symbols().New(), params, ctx.Clone(el_ty),
|
||||
ctx.dst->Block(ctx.dst->create<ast::ReturnStatement>(
|
||||
ctx.dst->create<ast::TypeConstructorExpression>(
|
||||
ctx.dst->Block(
|
||||
ctx.dst->Return(ctx.dst->create<ast::TypeConstructorExpression>(
|
||||
ctx.Clone(el_ty), values))),
|
||||
ast::DecorationList{}, ast::DecorationList{});
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ Output EmitVertexPointSize::Run(const Program* in, const DataMap&) {
|
|||
// Declare the pointsize builtin output variable.
|
||||
out.Global(pointsize, out.ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
out.create<ast::BuiltinDecoration>(ast::Builtin::kPointSize),
|
||||
out.Builtin(ast::Builtin::kPointSize),
|
||||
});
|
||||
|
||||
// Add the pointsize assignment statement to the front of all vertex stages.
|
||||
|
|
|
@ -106,8 +106,7 @@ void Hlsl::PromoteInitializersToConstVar(CloneContext& ctx) const {
|
|||
// Construct the constant that holds the hoisted initializer
|
||||
auto* dst_var = ctx.dst->Const(dst_symbol, dst_ty, dst_init);
|
||||
// Construct the variable declaration statement
|
||||
auto* dst_var_decl =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(dst_var);
|
||||
auto* dst_var_decl = ctx.dst->Decl(dst_var);
|
||||
// Construct the identifier for referencing the constant
|
||||
auto* dst_ident = ctx.dst->Expr(dst_symbol);
|
||||
|
||||
|
@ -127,10 +126,9 @@ void Hlsl::AddEmptyEntryPoint(CloneContext& ctx) const {
|
|||
return;
|
||||
}
|
||||
}
|
||||
ctx.dst->Func(
|
||||
ctx.dst->Symbols().New("tint_unused_entry_point"), {},
|
||||
ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
ctx.dst->Func(ctx.dst->Symbols().New("tint_unused_entry_point"), {},
|
||||
ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->Stage(ast::PipelineStage::kCompute)});
|
||||
}
|
||||
|
||||
} // namespace transform
|
||||
|
|
|
@ -176,7 +176,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
|
|||
auto* call = ctx.dst->Call(return_func_symbol, ctx.Clone(ret->value()));
|
||||
ctx.InsertBefore(ret_sem->Block()->statements(), ret,
|
||||
ctx.dst->create<ast::CallStatement>(call));
|
||||
ctx.Replace(ret, ctx.dst->create<ast::ReturnStatement>());
|
||||
ctx.Replace(ret, ctx.dst->Return());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,9 +245,8 @@ void Spirv::AddEmptyEntryPoint(CloneContext& ctx) const {
|
|||
return;
|
||||
}
|
||||
}
|
||||
ctx.dst->Func(
|
||||
"_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
ctx.dst->Func("_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->Stage(ast::PipelineStage::kCompute)});
|
||||
}
|
||||
|
||||
Symbol Spirv::HoistToInputVariables(
|
||||
|
|
|
@ -117,12 +117,11 @@ struct State {
|
|||
static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index";
|
||||
vertex_index_name = ctx.dst->Symbols().New(kDefaultVertexIndexName);
|
||||
|
||||
ctx.dst->Global(
|
||||
vertex_index_name, ctx.dst->ty.u32(), ast::StorageClass::kInput,
|
||||
nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(ast::Builtin::kVertexIndex),
|
||||
});
|
||||
ctx.dst->Global(vertex_index_name, ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->Builtin(ast::Builtin::kVertexIndex),
|
||||
});
|
||||
}
|
||||
|
||||
/// Inserts instance_index binding, or finds the existing one
|
||||
|
@ -163,8 +162,7 @@ struct State {
|
|||
ctx.dst->Global(instance_index_name, ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kInstanceIndex),
|
||||
ctx.dst->Builtin(ast::Builtin::kInstanceIndex),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -230,9 +228,9 @@ struct State {
|
|||
ast::StatementList stmts;
|
||||
|
||||
// Declare the pulling position variable in the shader
|
||||
stmts.emplace_back(ctx.dst->create<ast::VariableDeclStatement>(
|
||||
ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction)));
|
||||
stmts.emplace_back(
|
||||
ctx.dst->Decl(ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction)));
|
||||
|
||||
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
|
||||
const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i];
|
||||
|
|
|
@ -24,7 +24,7 @@ using HlslGeneratorImplTest_Assign = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
|
||||
Global("lhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
Global("rhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs"));
|
||||
auto* assign = Assign("lhs", "rhs");
|
||||
WrapInFunction(assign);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -315,22 +315,16 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
|
|||
Global("b", ty.bool_(), ast::StorageClass::kPrivate);
|
||||
Global("c", ty.bool_(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
Return(Expr(3)),
|
||||
});
|
||||
auto* body = Block(Return(3));
|
||||
auto* else_stmt = create<ast::ElseStatement>(nullptr, body);
|
||||
|
||||
body = create<ast::BlockStatement>(ast::StatementList{
|
||||
Return(Expr(2)),
|
||||
});
|
||||
body = Block(Return(2));
|
||||
auto* else_if_stmt = create<ast::ElseStatement>(
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"),
|
||||
Expr("c")),
|
||||
body);
|
||||
|
||||
body = create<ast::BlockStatement>(ast::StatementList{
|
||||
Return(Expr(1)),
|
||||
});
|
||||
body = Block(Return(1));
|
||||
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("a"),
|
||||
|
@ -402,7 +396,7 @@ TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
|
|||
Global("c", ty.bool_(), ast::StorageClass::kPrivate);
|
||||
Global("d", ty.bool_(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* expr = create<ast::AssignmentStatement>(
|
||||
auto* expr = Assign(
|
||||
Expr("a"), create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalAnd,
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||
|
|
|
@ -34,18 +34,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(),
|
||||
ast::StatementList{
|
||||
Assign(Expr("foo"), Expr("foo")),
|
||||
Assign(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
Return(Construct(ty.vec4<f32>())),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kVertex)},
|
||||
|
@ -77,18 +77,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(),
|
||||
ast::StatementList{
|
||||
Assign(Expr("foo"), Expr("foo")),
|
||||
Assign(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
Return(Construct(ty.vec4<f32>())),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kVertex)},
|
||||
|
@ -120,21 +120,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
std::unordered_set<Symbol> globals;
|
||||
|
@ -163,21 +163,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
std::unordered_set<Symbol> globals;
|
||||
|
@ -203,21 +203,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
std::unordered_set<Symbol> globals;
|
||||
|
@ -239,21 +239,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
std::unordered_set<Symbol> globals;
|
||||
|
@ -281,21 +281,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
|
|||
|
||||
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||
Builtin(ast::Builtin::kPosition),
|
||||
});
|
||||
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||
Builtin(ast::Builtin::kFragDepth),
|
||||
});
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("depth"),
|
||||
MemberAccessor("coord", "x")),
|
||||
Assign("depth", MemberAccessor("coord", "x")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
std::unordered_set<Symbol> globals;
|
||||
|
|
|
@ -106,10 +106,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
// fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 {
|
||||
// return foo;
|
||||
// }
|
||||
auto* foo_in = Param("foo", ty.f32(), {create<ast::LocationDecoration>(0)});
|
||||
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return(Expr("foo"))},
|
||||
{Stage(ast::PipelineStage::kFragment)},
|
||||
{create<ast::LocationDecoration>(1)});
|
||||
auto* foo_in = Param("foo", ty.f32(), {Location(0)});
|
||||
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return("foo")},
|
||||
{Stage(ast::PipelineStage::kFragment)}, {Location(1)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -138,12 +137,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
// return coord.x;
|
||||
// }
|
||||
auto* coord_in =
|
||||
Param("coord", ty.vec4<f32>(),
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
Param("coord", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)});
|
||||
Func("frag_main", ast::VariableList{coord_in}, ty.f32(),
|
||||
{Return(MemberAccessor("coord", "x"))},
|
||||
{Stage(ast::PipelineStage::kFragment)},
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -196,10 +194,9 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", {Param("inputs", interface_struct)}, ty.void_(),
|
||||
{
|
||||
Decl(Const("r", ty.f32(), MemberAccessor(Expr("inputs"), "col1"))),
|
||||
Decl(Const("g", ty.f32(), MemberAccessor(Expr("inputs"), "col2"))),
|
||||
Decl(Const("p", ty.vec4<f32>(),
|
||||
MemberAccessor(Expr("inputs"), "pos"))),
|
||||
Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))),
|
||||
Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))),
|
||||
Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
@ -257,13 +254,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
// }
|
||||
auto* vertex_output_struct = Structure(
|
||||
"VertexOutput",
|
||||
{Member("pos", ty.vec4<f32>(),
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)})});
|
||||
{Member("pos", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)})});
|
||||
|
||||
Func("foo", {Param("x", ty.f32())}, vertex_output_struct,
|
||||
{Return(Construct(vertex_output_struct,
|
||||
Construct(ty.vec4<f32>(), Expr("x"), Expr("x"),
|
||||
Expr("x"), Expr(1.f))))},
|
||||
Construct(ty.vec4<f32>(), "x", "x", "x", Expr(1.f))))},
|
||||
{});
|
||||
|
||||
Func("vert_main1", {}, vertex_output_struct,
|
||||
|
@ -374,12 +369,11 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
});
|
||||
|
||||
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
create<ast::MemberAccessorExpression>(
|
||||
MemberAccessor("uniforms", "coord"), Expr("x")));
|
||||
MemberAccessor(MemberAccessor("uniforms", "coord"), "x"));
|
||||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -427,7 +421,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -473,7 +467,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -516,8 +510,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
|
||||
Expr(2.0f)),
|
||||
Assign(MemberAccessor("coord", "b"), Expr(2.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -560,8 +553,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"),
|
||||
Expr(2.0f)),
|
||||
Assign(MemberAccessor("coord", "b"), Expr(2.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -591,35 +583,34 @@ TEST_F(
|
|||
Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{
|
||||
create<ast::LocationDecoration>(0),
|
||||
Location(0),
|
||||
});
|
||||
|
||||
Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
|
||||
Return(Expr("foo")),
|
||||
Assign("bar", "foo"),
|
||||
Assign("val", "param"),
|
||||
Return("foo"),
|
||||
});
|
||||
|
||||
Func(
|
||||
"ep_1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
Func("ep_1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
Assign("bar", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -654,18 +645,17 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||
Builtin(ast::Builtin::kFragDepth),
|
||||
});
|
||||
|
||||
Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
|
||||
{
|
||||
Return(Expr("param")),
|
||||
Return("param"),
|
||||
});
|
||||
|
||||
Func("ep_1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("depth"),
|
||||
Call("sub_func", 1.0f)),
|
||||
Assign("depth", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -700,25 +690,23 @@ TEST_F(
|
|||
Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
||||
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
|
||||
{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||
Builtin(ast::Builtin::kPosition),
|
||||
});
|
||||
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||
Builtin(ast::Builtin::kFragDepth),
|
||||
});
|
||||
|
||||
Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("depth"),
|
||||
MemberAccessor("coord", "x")),
|
||||
Return(Expr("param")),
|
||||
Assign("depth", MemberAccessor("coord", "x")),
|
||||
Return("param"),
|
||||
});
|
||||
|
||||
Func("ep_1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("depth"),
|
||||
Call("sub_func", 1.0f)),
|
||||
Assign("depth", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -772,7 +760,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -823,7 +811,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -855,13 +843,13 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{
|
||||
create<ast::LocationDecoration>(1),
|
||||
Location(1),
|
||||
});
|
||||
|
||||
Func(
|
||||
"ep_1", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.0f)),
|
||||
Assign("bar", Expr(1.0f)),
|
||||
create<ast::IfStatement>(create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual, Expr(1), Expr(1)),
|
||||
Block(Return()), ast::ElseStatementList{}),
|
||||
|
@ -1010,7 +998,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("a", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -1024,7 +1012,7 @@ TEST_F(HlslGeneratorImplTest_Function,
|
|||
|
||||
Func("b", ast::VariableList{}, ty.void_(),
|
||||
{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
|
|
@ -416,7 +416,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) {
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::CallStatement>(Call("storageBarrier"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -435,7 +435,7 @@ void main() {
|
|||
TEST_F(HlslGeneratorImplTest_Intrinsic, WorkgroupBarrier) {
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::CallStatement>(Call("workgroupBarrier"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
|
|||
create<ast::CallStatement>(call),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
|
|
@ -25,7 +25,7 @@ using HlslGeneratorImplTest_Loop = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block();
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* l = Loop(body, continuing);
|
||||
|
||||
WrapInFunction(l);
|
||||
|
||||
|
@ -43,7 +43,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
|
|||
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block(Return());
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* l = Loop(body, continuing);
|
||||
|
||||
WrapInFunction(l);
|
||||
|
||||
|
@ -72,16 +72,16 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
|
|||
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block(Return());
|
||||
auto* inner = create<ast::LoopStatement>(body, continuing);
|
||||
auto* inner = Loop(body, continuing);
|
||||
|
||||
body = Block(inner);
|
||||
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
continuing = Block(create<ast::AssignmentStatement>(lhs, rhs));
|
||||
continuing = Block(Assign(lhs, rhs));
|
||||
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
auto* outer = Loop(body, continuing);
|
||||
WrapInFunction(outer);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -139,15 +139,14 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
|
|||
|
||||
auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f));
|
||||
|
||||
auto* body = Block(create<ast::VariableDeclStatement>(var),
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("other", ty.f32(), ast::StorageClass::kFunction)));
|
||||
auto* body = Block(
|
||||
Decl(var), Decl(Var("other", ty.f32(), ast::StorageClass::kFunction)));
|
||||
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* continuing = Block(create<ast::AssignmentStatement>(lhs, rhs));
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
auto* continuing = Block(Assign(lhs, rhs));
|
||||
auto* outer = Loop(body, continuing);
|
||||
WrapInFunction(outer);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -113,7 +113,7 @@ class HlslGeneratorImplTest_MemberAccessorBase : public BASE {
|
|||
ProgramBuilder& b = *this;
|
||||
b.Func("main", ast::VariableList{}, b.ty.void_(), statements,
|
||||
ast::DecorationList{
|
||||
b.create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
b.Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -179,9 +179,8 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferLoad, Test) {
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(Var("x", nullptr,
|
||||
ast::StorageClass::kFunction,
|
||||
MemberAccessor("data", "b"))),
|
||||
Decl(Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor("data", "b"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -256,8 +255,7 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) {
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("value", type, ast::StorageClass::kFunction, Construct(type))),
|
||||
Decl(Var("value", type, ast::StorageClass::kFunction, Construct(type))),
|
||||
Assign(MemberAccessor("data", "b"), Expr("value")),
|
||||
});
|
||||
|
||||
|
@ -386,7 +384,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Decl(
|
||||
Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(IndexAccessor(MemberAccessor("data", "a"), 2), 1))),
|
||||
});
|
||||
|
@ -423,9 +421,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(MemberAccessor("data", "a"), 2))),
|
||||
Decl(Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(MemberAccessor("data", "a"), 2))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -458,10 +455,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(MemberAccessor("data", "a"),
|
||||
Sub(Add(2, Expr(4)), Expr(3))))),
|
||||
Decl(Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(MemberAccessor("data", "a"),
|
||||
Sub(Add(2, Expr(4)), Expr(3))))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -534,7 +530,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) {
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(Var(
|
||||
Decl(Var(
|
||||
"x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2), "b"))),
|
||||
});
|
||||
|
@ -580,12 +576,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor(
|
||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
|
||||
"b"),
|
||||
"xy"))),
|
||||
Decl(Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor(
|
||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
|
||||
"b"),
|
||||
"xy"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -629,12 +624,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor(
|
||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
|
||||
"b"),
|
||||
"g"))),
|
||||
Decl(Var("x", nullptr, ast::StorageClass::kFunction,
|
||||
MemberAccessor(
|
||||
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
|
||||
"b"),
|
||||
"g"))),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -678,7 +672,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
|
|||
});
|
||||
|
||||
SetupFunction({
|
||||
create<ast::VariableDeclStatement>(Var(
|
||||
Decl(Var(
|
||||
"x", nullptr, ast::StorageClass::kFunction,
|
||||
IndexAccessor(MemberAccessor(
|
||||
IndexAccessor(MemberAccessor("data", "c"), 2), "b"),
|
||||
|
|
|
@ -45,12 +45,11 @@ TEST_F(HlslSanitizerTest, ArrayLength) {
|
|||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("len", ty.u32(), ast::StorageClass::kFunction,
|
||||
Call("arrayLength", MemberAccessor("sb", "arr")))),
|
||||
Decl(Var("len", ty.u32(), ast::StorageClass::kFunction,
|
||||
Call("arrayLength", MemberAccessor("sb", "arr")))),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -80,10 +79,10 @@ TEST_F(HlslSanitizerTest, PromoteArrayInitializerToConstVar) {
|
|||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(pos),
|
||||
Decl(pos),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -114,10 +113,10 @@ TEST_F(HlslSanitizerTest, PromoteStructInitializerToConstVar) {
|
|||
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(pos),
|
||||
Decl(pos),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
|
|
@ -336,7 +336,7 @@ TEST_P(HlslDepthTexturesTest, Emit) {
|
|||
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::CallStatement>(Call("textureDimensions", "tex"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -395,7 +395,7 @@ TEST_P(HlslSampledTexturesTest, Emit) {
|
|||
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::CallStatement>(Call("textureDimensions", "tex"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -539,7 +539,7 @@ TEST_P(HlslStorageTexturesTest, Emit) {
|
|||
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::CallStatement>(Call("textureDimensions", "tex"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)});
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ using HlslGeneratorImplTest_VariableDecl = TestHelper;
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
|
|||
|
||||
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ty.f32());
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -96,7 +96,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
auto* var =
|
||||
Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, vec3<f32>());
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -111,7 +111,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
|
|||
auto* var =
|
||||
Var("a", ty.mat2x3<f32>(), ast::StorageClass::kFunction, mat2x3<f32>());
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -28,9 +28,8 @@ using HlslGeneratorImplTest_WorkgroupVar = TestHelper;
|
|||
TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) {
|
||||
Global("wg", ty.f32(), ast::StorageClass::kWorkgroup);
|
||||
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::AssignmentStatement>(Expr("wg"), Expr(1.2f))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
|
@ -45,9 +44,8 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
|
|||
|
||||
Global("wg", alias, ast::StorageClass::kWorkgroup);
|
||||
|
||||
Func("main", {}, ty.void_(),
|
||||
{create<ast::AssignmentStatement>(Expr("wg"), Expr(1.2f))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
ASSERT_TRUE(gen.Generate(out)) << gen.error();
|
||||
|
|
|
@ -24,7 +24,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, Emit_Assign) {
|
||||
auto* lhs = Var("lhs", ty.i32(), ast::StorageClass::kFunction);
|
||||
auto* rhs = Var("rhs", ty.i32(), ast::StorageClass::kFunction);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs"));
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
WrapInFunction(lhs, rhs, assign);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -32,14 +32,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
// };
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
Assign(Expr("foo"), Expr("foo")),
|
||||
Assign(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
Return(Construct(ty.vec4<f32>())),
|
||||
};
|
||||
|
||||
|
@ -69,14 +69,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
// };
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
Assign(Expr("foo"), Expr("foo")),
|
||||
Assign(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
Return(Construct(ty.vec4<f32>())),
|
||||
};
|
||||
|
||||
|
@ -106,19 +106,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
// };
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
};
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -143,19 +143,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
// };
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
};
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -177,19 +177,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
// -> Error, not allowed
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
};
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -207,19 +207,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
// -> Error not allowed
|
||||
|
||||
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{create<ast::LocationDecoration>(1)});
|
||||
ast::DecorationList{Location(1)});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
Assign("foo", "foo"),
|
||||
Assign("bar", "bar"),
|
||||
};
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -242,19 +242,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
// };
|
||||
|
||||
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
ast::DecorationList{Builtin(ast::Builtin::kPosition)});
|
||||
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
ast::DecorationList{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
auto body = ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Expr("depth"), MemberAccessor("coord", "x"))};
|
||||
auto body = ast::StatementList{Assign("depth", MemberAccessor("coord", "x"))};
|
||||
|
||||
Func("main", ast::VariableList{}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -95,10 +95,9 @@ TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOutVars) {
|
|||
// fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 {
|
||||
// return foo;
|
||||
// }
|
||||
auto* foo_in = Param("foo", ty.f32(), {create<ast::LocationDecoration>(0)});
|
||||
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return(Expr("foo"))},
|
||||
{Stage(ast::PipelineStage::kFragment)},
|
||||
{create<ast::LocationDecoration>(1)});
|
||||
auto* foo_in = Param("foo", ty.f32(), {Location(0)});
|
||||
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return("foo")},
|
||||
{Stage(ast::PipelineStage::kFragment)}, {Location(1)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -128,12 +127,11 @@ TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOut_Builtins) {
|
|||
// return coord.x;
|
||||
// }
|
||||
auto* coord_in =
|
||||
Param("coord", ty.vec4<f32>(),
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
Param("coord", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)});
|
||||
Func("frag_main", ast::VariableList{coord_in}, ty.f32(),
|
||||
{Return(MemberAccessor("coord", "x"))},
|
||||
{Stage(ast::PipelineStage::kFragment)},
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
||||
|
@ -188,9 +186,9 @@ TEST_F(MslGeneratorImplTest,
|
|||
Func("frag_main", {Param("colors", interface_struct)}, ty.void_(),
|
||||
{
|
||||
WrapInStatement(
|
||||
Const("r", ty.f32(), MemberAccessor(Expr("colors"), "col1"))),
|
||||
Const("r", ty.f32(), MemberAccessor("colors", "col1"))),
|
||||
WrapInStatement(
|
||||
Const("g", ty.f32(), MemberAccessor(Expr("colors"), "col2"))),
|
||||
Const("g", ty.f32(), MemberAccessor("colors", "col2"))),
|
||||
},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
@ -249,13 +247,11 @@ TEST_F(MslGeneratorImplTest,
|
|||
// }
|
||||
auto* vertex_output_struct = Structure(
|
||||
"VertexOutput",
|
||||
{Member("pos", ty.vec4<f32>(),
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)})});
|
||||
{Member("pos", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)})});
|
||||
|
||||
Func("foo", {Param("x", ty.f32())}, vertex_output_struct,
|
||||
{Return(Construct(vertex_output_struct,
|
||||
Construct(ty.vec4<f32>(), Expr("x"), Expr("x"),
|
||||
Expr("x"), Expr(1.f))))},
|
||||
Construct(ty.vec4<f32>(), "x", "x", "x", Expr(1.f))))},
|
||||
{});
|
||||
|
||||
Func("vert_main1", {}, vertex_output_struct,
|
||||
|
@ -321,7 +317,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -366,7 +362,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -396,27 +392,22 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
|
|||
TEST_F(
|
||||
MslGeneratorImplTest,
|
||||
Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
|
||||
{create<ast::LocationDecoration>(0)});
|
||||
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, {Location(0)});
|
||||
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{create<ast::LocationDecoration>(1)});
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(1)});
|
||||
|
||||
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{create<ast::LocationDecoration>(0)});
|
||||
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(0)});
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(Param("param", ty.f32()));
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
|
||||
Return(Expr("foo"))};
|
||||
auto body = ast::StatementList{Assign("bar", "foo"), Assign("val", "param"),
|
||||
Return("foo")};
|
||||
|
||||
Func("sub_func", params, ty.f32(), body, {});
|
||||
|
||||
body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)),
|
||||
Assign("bar", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
};
|
||||
|
||||
|
@ -459,19 +450,19 @@ fragment ep_1_out ep_1(ep_1_in _tint_in [[stage_in]]) {
|
|||
TEST_F(MslGeneratorImplTest,
|
||||
Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(Param("param", ty.f32()));
|
||||
|
||||
Func("sub_func", params, ty.f32(),
|
||||
ast::StatementList{
|
||||
Return(Expr("param")),
|
||||
Return("param"),
|
||||
},
|
||||
{});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
|
||||
Assign("depth", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
};
|
||||
|
||||
|
@ -508,24 +499,23 @@ TEST_F(
|
|||
MslGeneratorImplTest,
|
||||
Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
|
||||
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
{Builtin(ast::Builtin::kPosition)});
|
||||
|
||||
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(Param("param", ty.f32()));
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("depth"),
|
||||
MemberAccessor("coord", "x")),
|
||||
Return(Expr("param")),
|
||||
Assign("depth", MemberAccessor("coord", "x")),
|
||||
Return("param"),
|
||||
};
|
||||
|
||||
Func("sub_func", params, ty.f32(), body, {});
|
||||
|
||||
body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)),
|
||||
Assign("depth", Call("sub_func", 1.0f)),
|
||||
Return(),
|
||||
};
|
||||
|
||||
|
@ -635,7 +625,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -691,7 +681,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
Func("frag_main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -724,15 +714,12 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
|
|||
// TODO(crbug.com/tint/697): Remove this test
|
||||
TEST_F(MslGeneratorImplTest,
|
||||
Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
{create<ast::LocationDecoration>(1)});
|
||||
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(1)});
|
||||
|
||||
auto* list = create<ast::BlockStatement>(ast::StatementList{
|
||||
Return(),
|
||||
});
|
||||
auto* list = Block(Return());
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.f)),
|
||||
Assign("bar", Expr(1.f)),
|
||||
create<ast::IfStatement>(create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual, Expr(1), Expr(1)),
|
||||
list, ast::ElseStatementList{}),
|
||||
|
@ -823,7 +810,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
|
||||
Func("a", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
{
|
||||
|
@ -836,7 +823,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
MemberAccessor("data", "d"));
|
||||
|
||||
Func("b", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{create<ast::VariableDeclStatement>(var), Return()},
|
||||
ast::StatementList{Decl(var), Return()},
|
||||
{Stage(ast::PipelineStage::kCompute)});
|
||||
}
|
||||
|
||||
|
|
|
@ -23,11 +23,9 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block();
|
||||
auto* l = Loop(body, continuing);
|
||||
WrapInFunction(l);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -42,13 +40,9 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block(Return());
|
||||
auto* l = Loop(body, continuing);
|
||||
WrapInFunction(l);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -74,23 +68,15 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
|||
Global("lhs", ty.f32(), ast::StorageClass::kInput);
|
||||
Global("rhs", ty.f32(), ast::StorageClass::kInput);
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
auto* inner = create<ast::LoopStatement>(body, continuing);
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block(Return());
|
||||
auto* inner = Loop(body, continuing);
|
||||
|
||||
body = create<ast::BlockStatement>(ast::StatementList{
|
||||
inner,
|
||||
});
|
||||
body = Block(inner);
|
||||
|
||||
continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")),
|
||||
});
|
||||
continuing = Block(Assign("lhs", "rhs"));
|
||||
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
auto* outer = Loop(body, continuing);
|
||||
WrapInFunction(outer);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -148,16 +134,12 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
|||
|
||||
auto* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f));
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("other", ty.f32(), ast::StorageClass::kFunction))});
|
||||
auto* body = Block(
|
||||
Decl(var), Decl(Var("other", ty.f32(), ast::StorageClass::kFunction)));
|
||||
|
||||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")),
|
||||
});
|
||||
auto* continuing = Block(Assign("lhs", "rhs"));
|
||||
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
auto* outer = Loop(body, continuing);
|
||||
WrapInFunction(outer);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -25,7 +25,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, Generate) {
|
||||
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -27,7 +27,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ty.f32());
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -55,7 +55,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
|||
sem::ArrayType ary(ty.f32(), 5, ast::DecorationList{});
|
||||
|
||||
auto* var = Var("a", &ary, ast::StorageClass::kNone);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -73,7 +73,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
|||
});
|
||||
|
||||
auto* var = Var("a", s, ast::StorageClass::kNone);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -87,7 +87,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
||||
auto* var = Var("a", ty.vec2<f32>(), ast::StorageClass::kFunction);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -101,7 +101,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||
auto* var = Var("a", ty.mat3x2<f32>(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -146,7 +146,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
|||
auto* zero_vec = vec3<f32>();
|
||||
|
||||
auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, zero_vec);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -442,8 +442,8 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
|||
auto* s_type = Structure("my_struct", {Member("inner", inner_struct)});
|
||||
|
||||
auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
|
||||
auto* expr = create<ast::AssignmentStatement>(
|
||||
MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
|
||||
auto* expr =
|
||||
Assign(MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -494,7 +494,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
|
|||
auto* store = Global("store", ty.f32(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
|
||||
auto* expr = create<ast::AssignmentStatement>(Expr("store"), rhs);
|
||||
auto* expr = Assign("store", rhs);
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -25,7 +25,7 @@ using BuilderTest = TestHelper;
|
|||
TEST_F(BuilderTest, Assign_Var) {
|
||||
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
|
||||
auto* assign = Assign("var", 1.f);
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -53,7 +53,7 @@ TEST_F(BuilderTest, Assign_Var) {
|
|||
TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
||||
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
|
||||
auto* assign = Assign("var", Expr(1.f));
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -73,7 +73,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
|||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* val = vec3<f32>();
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
auto* assign = Assign("var", val);
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -103,7 +103,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
|||
|
||||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
auto* assign = Assign("var", init);
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -140,7 +140,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
|||
|
||||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
auto* assign = Assign("var", init);
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -183,8 +183,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
|||
|
||||
auto* v = Global("ident", s, ast::StorageClass::kFunction);
|
||||
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(MemberAccessor("ident", "b"), Expr(4.f));
|
||||
auto* assign = Assign(MemberAccessor("ident", "b"), Expr(4.f));
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -217,7 +216,7 @@ TEST_F(BuilderTest, Assign_Vector) {
|
|||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* val = vec3<f32>(1.f, 1.f, 3.f);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
auto* assign = Assign("var", val);
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -250,8 +249,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
|||
|
||||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(MemberAccessor("var", "y"), Expr(1.f));
|
||||
auto* assign = Assign(MemberAccessor("var", "y"), Expr(1.f));
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
@ -286,8 +284,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
|||
|
||||
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
|
||||
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(IndexAccessor("var", 1), Expr(1.f));
|
||||
auto* assign = Assign(IndexAccessor("var", 1), Expr(1.f));
|
||||
|
||||
WrapInFunction(assign);
|
||||
|
||||
|
|
|
@ -27,15 +27,10 @@ using BuilderTest = TestHelper;
|
|||
TEST_F(BuilderTest, DISABLED_Block) {
|
||||
// Note, this test uses shadow variables which aren't allowed in WGSL but
|
||||
// serves to prove the block code is pushing new scopes as needed.
|
||||
auto* inner = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("var", ty.f32(), ast::StorageClass::kFunction)),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(2.f))});
|
||||
auto* outer = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("var", ty.f32(), ast::StorageClass::kFunction)),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), inner,
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(3.f))});
|
||||
auto* inner = Block(Decl(Var("var", ty.f32(), ast::StorageClass::kFunction)),
|
||||
Assign("var", 2.f));
|
||||
auto* outer = Block(Decl(Var("var", ty.f32(), ast::StorageClass::kFunction)),
|
||||
Assign("var", 1.f), inner, Assign("var", 3.f));
|
||||
|
||||
WrapInFunction(outer);
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ TEST_F(BuilderTest, Expression_Call) {
|
|||
|
||||
auto* a_func =
|
||||
Func("a_func", func_params, ty.f32(),
|
||||
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
|
||||
ast::DecorationList{});
|
||||
ast::StatementList{Return(Add("a", "b"))}, ast::DecorationList{});
|
||||
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});
|
||||
|
@ -78,8 +77,7 @@ TEST_F(BuilderTest, Statement_Call) {
|
|||
|
||||
auto* a_func =
|
||||
Func("a_func", func_params, ty.f32(),
|
||||
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
|
||||
ast::DecorationList{});
|
||||
ast::StatementList{Return(Add("a", "b"))}, ast::DecorationList{});
|
||||
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});
|
||||
|
|
|
@ -44,15 +44,14 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
|
|||
// }
|
||||
auto f32 = ty.f32();
|
||||
auto* vec4 = ty.vec4<float>();
|
||||
auto* coord = Param(
|
||||
"coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
auto* loc1 = Param("loc1", f32, {create<ast::LocationDecoration>(1u)});
|
||||
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
||||
auto* loc1 = Param("loc1", f32, {Location(1u)});
|
||||
auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1"));
|
||||
auto* col = Var("col", f32, ast::StorageClass::kFunction, mul, {});
|
||||
Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
|
||||
ast::StatementList{WrapInStatement(col)},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
@ -108,18 +107,18 @@ TEST_F(BuilderTest, EntryPoint_ReturnValue) {
|
|||
// }
|
||||
auto f32 = ty.f32();
|
||||
auto u32 = ty.u32();
|
||||
auto* loc_in = Param("loc_in", u32, {create<ast::LocationDecoration>(0)});
|
||||
auto* loc_in = Param("loc_in", u32, {Location(0)});
|
||||
auto* cond = create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThan,
|
||||
Expr("loc_in"), Expr(10u));
|
||||
Func("frag_main", ast::VariableList{loc_in}, f32,
|
||||
ast::StatementList{
|
||||
If(cond, Block(create<ast::ReturnStatement>(Expr(0.5f)))),
|
||||
create<ast::ReturnStatement>(Expr(1.0f)),
|
||||
If(cond, Block(Return(0.5f))),
|
||||
Return(1.0f),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
ast::DecorationList{create<ast::LocationDecoration>(0)});
|
||||
ast::DecorationList{Location(0)});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
||||
|
@ -201,15 +200,14 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) {
|
|||
});
|
||||
|
||||
auto* vert_retval = Construct(interface, 42.f, Construct(ty.vec4<f32>()));
|
||||
Func("vert_main", ast::VariableList{}, interface,
|
||||
{create<ast::ReturnStatement>(vert_retval)},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
|
||||
Func("vert_main", ast::VariableList{}, interface, {Return(vert_retval)},
|
||||
{Stage(ast::PipelineStage::kVertex)});
|
||||
|
||||
auto* frag_inputs = Param("inputs", interface);
|
||||
Func("frag_main", ast::VariableList{frag_inputs}, ty.f32(),
|
||||
{create<ast::ReturnStatement>(MemberAccessor(Expr("inputs"), "value"))},
|
||||
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)},
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
|
||||
{Return(MemberAccessor(Expr("inputs"), "value"))},
|
||||
{Stage(ast::PipelineStage::kFragment)},
|
||||
{Builtin(ast::Builtin::kFragDepth)});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
||||
|
|
|
@ -25,11 +25,10 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Decoration_Stage) {
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -61,7 +60,7 @@ TEST_P(Decoration_StageTest, Emit) {
|
|||
|
||||
auto* func = Func("main", {}, ty.void_(), body,
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(params.stage),
|
||||
Stage(params.stage),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -90,11 +89,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
SpvExecutionModelGLCompute}));
|
||||
|
||||
TEST_F(BuilderTest, Decoration_Stage_WithUnusedInterfaceIds) {
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
auto* v_in = Global("my_in", ty.f32(), ast::StorageClass::kInput);
|
||||
auto* v_out = Global("my_out", ty.f32(), ast::StorageClass::kOutput);
|
||||
|
@ -133,17 +131,15 @@ TEST_F(BuilderTest, Decoration_Stage_WithUsedInterfaceIds) {
|
|||
auto* v_out = Global("my_out", ty.f32(), ast::StorageClass::kOutput);
|
||||
auto* v_wg = Global("my_wg", ty.f32(), ast::StorageClass::kWorkgroup);
|
||||
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in")),
|
||||
create<ast::AssignmentStatement>(Expr("my_wg"), Expr("my_wg")),
|
||||
// Add duplicate usages so we show they don't get
|
||||
// output multiple times.
|
||||
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in"))},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_(),
|
||||
ast::StatementList{Assign("my_out", "my_in"), Assign("my_wg", "my_wg"),
|
||||
// Add duplicate usages so we show they
|
||||
// don't get output multiple times.
|
||||
Assign("my_out", "my_in")},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -174,11 +170,10 @@ OpName %11 "main"
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -189,11 +184,10 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) {
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -204,12 +198,11 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize) {
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -220,17 +213,15 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Decoration_ExecutionMode_MultipleFragment) {
|
||||
auto* func1 =
|
||||
Func("main1", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func1 = Func("main1", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
auto* func2 =
|
||||
Func("main2", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func2 = Func("main2", {}, ty.void_(), ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
@ -259,15 +250,14 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) {
|
||||
Global("fragdepth", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
|
||||
Builtin(ast::Builtin::kFragDepth),
|
||||
});
|
||||
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("fragdepth"), Expr(1.f)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
auto* func = Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
Assign("fragdepth", Expr(1.f)),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_Terminator_Return) {
|
||||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -65,8 +65,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
|
||||
Global("a", ty.f32(), ast::StorageClass::kPrivate);
|
||||
|
||||
Func("a_func", {}, ty.f32(),
|
||||
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
|
||||
Func("a_func", {}, ty.f32(), ast::StatementList{Return("a")},
|
||||
ast::DecorationList{});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -115,8 +114,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_WithParams) {
|
||||
ast::VariableList params = {Param("a", ty.f32()), Param("b", ty.i32())};
|
||||
|
||||
Func("a_func", params, ty.f32(),
|
||||
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
|
||||
Func("a_func", params, ty.f32(), ast::StatementList{Return("a")},
|
||||
ast::DecorationList{});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -141,7 +139,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_WithBody) {
|
||||
Func("a_func", {}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -220,11 +218,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
Func("a", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -234,11 +232,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
Func("b", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
||||
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(5),
|
||||
Location(5),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -186,7 +186,7 @@ OpDecorate %1 DescriptorSet 3
|
|||
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
||||
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||
Builtin(ast::Builtin::kPosition),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -621,7 +621,7 @@ TEST_F(BuilderTest, SampleIndex) {
|
|||
auto* var =
|
||||
Global("sample_index", ty.u32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kSampleIndex),
|
||||
Builtin(ast::Builtin::kSampleIndex),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -655,18 +655,18 @@ TEST_F(BuilderTest, SampleMask) {
|
|||
|
||||
Global("mask_in", ty.u32(), ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kSampleMask),
|
||||
Builtin(ast::Builtin::kSampleMask),
|
||||
});
|
||||
Global("mask_out", ty.u32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kSampleMask),
|
||||
Builtin(ast::Builtin::kSampleMask),
|
||||
});
|
||||
Func("main", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("mask_out"), Expr("mask_in")),
|
||||
Assign("mask_out", "mask_in"),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
|
|
@ -74,8 +74,7 @@ TEST_F(BuilderTest, If_WithStatements) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
auto* expr =
|
||||
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
|
||||
WrapInFunction(expr);
|
||||
|
@ -112,10 +111,8 @@ TEST_F(BuilderTest, If_WithElse) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
auto* else_body = Block(Assign("v", 3));
|
||||
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
|
@ -158,10 +155,8 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
auto* else_body = Block(Assign("v", 3));
|
||||
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
|
@ -215,14 +210,10 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* elseif_1_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* elseif_2_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(4))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(5))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
auto* elseif_1_body = Block(Assign("v", 3));
|
||||
auto* elseif_2_body = Block(Assign("v", 4));
|
||||
auto* else_body = Block(Assign("v", 5));
|
||||
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
|
@ -294,7 +285,7 @@ TEST_F(BuilderTest, If_WithBreak) {
|
|||
|
||||
auto* loop_body = Block(if_stmt);
|
||||
|
||||
auto* expr = create<ast::LoopStatement>(loop_body, Block());
|
||||
auto* expr = Loop(loop_body, Block());
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -338,7 +329,7 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
|||
|
||||
auto* loop_body = Block(if_stmt);
|
||||
|
||||
auto* expr = create<ast::LoopStatement>(loop_body, Block());
|
||||
auto* expr = Loop(loop_body, Block());
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -382,7 +373,7 @@ TEST_F(BuilderTest, If_WithContinue) {
|
|||
|
||||
auto* loop_body = Block(if_stmt);
|
||||
|
||||
auto* expr = create<ast::LoopStatement>(loop_body, Block());
|
||||
auto* expr = Loop(loop_body, Block());
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -426,7 +417,7 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
|||
|
||||
auto* loop_body = Block(if_stmt);
|
||||
|
||||
auto* expr = create<ast::LoopStatement>(loop_body, Block());
|
||||
auto* expr = Loop(loop_body, Block());
|
||||
WrapInFunction(expr);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -461,7 +452,7 @@ TEST_F(BuilderTest, If_WithReturn) {
|
|||
// if (true) {
|
||||
// return;
|
||||
// }
|
||||
auto* if_body = Block(create<ast::ReturnStatement>());
|
||||
auto* if_body = Block(Return());
|
||||
|
||||
auto* expr =
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||
|
@ -489,9 +480,9 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
|||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
auto* if_body = Block(Return(Expr(false)));
|
||||
auto* if_body = Block(Return(false));
|
||||
auto* expr = If(Expr(true), if_body);
|
||||
Func("test", {}, ty.bool_(), {expr, Return(Expr(true))}, {});
|
||||
Func("test", {}, ty.bool_(), {expr, Return(true)}, {});
|
||||
spirv::Builder& b = Build();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
|
|
@ -1257,11 +1257,11 @@ TEST_F(IntrinsicBuilderTest, Call_Modf) {
|
|||
auto* expr = Call("modf", vec2<f32>(1.0f, 2.0f), "out");
|
||||
Func("a_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(out),
|
||||
Decl(out),
|
||||
create<ast::CallStatement>(expr),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -1301,11 +1301,11 @@ TEST_F(IntrinsicBuilderTest, Call_Frexp) {
|
|||
auto* expr = Call("frexp", vec2<f32>(1.0f, 2.0f), "out");
|
||||
Func("a_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(out),
|
||||
Decl(out),
|
||||
create<ast::CallStatement>(expr),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -1395,7 +1395,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
|
|||
create<ast::CallStatement>(expr),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -1445,7 +1445,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
|
|||
create<ast::CallStatement>(expr),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -1605,7 +1605,7 @@ TEST_F(IntrinsicBuilderTest, Call_WorkgroupBarrier) {
|
|||
create<ast::CallStatement>(Call("workgroupBarrier")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -1637,7 +1637,7 @@ TEST_F(IntrinsicBuilderTest, Call_StorageBarrier) {
|
|||
create<ast::CallStatement>(Call("storageBarrier")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -3494,7 +3494,7 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
|
|||
create<ast::CallStatement>(call),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -26,9 +26,7 @@ TEST_F(BuilderTest, Loop_Empty) {
|
|||
// loop {
|
||||
// }
|
||||
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
create<ast::BlockStatement>(ast::StatementList{}));
|
||||
auto* loop = Loop(Block(), Block());
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -55,11 +53,9 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
auto* loop = Loop(body, Block());
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -97,12 +93,10 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
|||
// }
|
||||
|
||||
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* continuing = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* body = Block(Assign("v", 2));
|
||||
auto* continuing = Block(Assign("v", 3));
|
||||
|
||||
auto* loop = create<ast::LoopStatement>(body, continuing);
|
||||
auto* loop = Loop(body, continuing);
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -143,11 +137,10 @@ TEST_F(BuilderTest, Loop_WithBodyVariableAccessInContinuing) {
|
|||
|
||||
auto* var = Var("a", ty.i32(), ast::StorageClass::kFunction);
|
||||
auto* var_decl = WrapInStatement(var);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{var_decl});
|
||||
auto* continuing = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("a"), Expr(3))});
|
||||
auto* body = Block(var_decl);
|
||||
auto* continuing = Block(Assign("a", 3));
|
||||
|
||||
auto* loop = create<ast::LoopStatement>(body, continuing);
|
||||
auto* loop = Loop(body, continuing);
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -178,11 +171,8 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
|||
// loop {
|
||||
// continue;
|
||||
// }
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ContinueStatement>(),
|
||||
});
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
auto* body = Block(create<ast::ContinueStatement>());
|
||||
auto* loop = Loop(body, Block());
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
@ -207,11 +197,8 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
|||
// loop {
|
||||
// break;
|
||||
// }
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
auto* body = Block(create<ast::BreakStatement>());
|
||||
auto* loop = Loop(body, Block());
|
||||
WrapInFunction(loop);
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -62,7 +62,7 @@ TEST_F(BuilderTest, Return_WithValue) {
|
|||
TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
|
||||
auto* var = Global("param", ty.f32(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* ret = Return(Expr("param"));
|
||||
auto* ret = Return(var);
|
||||
Func("test", {}, ty.f32(), {ret}, {});
|
||||
|
||||
spirv::Builder& b = Build();
|
||||
|
|
|
@ -178,8 +178,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
|||
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
auto* default_body = Block(Assign("v", 1));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(
|
||||
|
@ -238,14 +237,11 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
auto* case_1_body = Block(Assign("v", Expr(1)));
|
||||
|
||||
auto* case_2_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* case_2_body = Block(Assign("v", Expr(2)));
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* default_body = Block(Assign("v", Expr(3)));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
@ -322,15 +318,12 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
|
||||
create<ast::FallthroughStatement>()});
|
||||
auto* case_1_body =
|
||||
Block(Assign("v", Expr(1)), create<ast::FallthroughStatement>());
|
||||
|
||||
auto* case_2_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* case_2_body = Block(Assign("v", Expr(2)));
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* default_body = Block(Assign("v", Expr(3)));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
|
|
@ -22,9 +22,9 @@ namespace {
|
|||
using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Assign) {
|
||||
Global("lhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
Global("rhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs"));
|
||||
auto* lhs = Global("lhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* rhs = Global("rhs", ty.i32(), ast::StorageClass::kPrivate);
|
||||
auto* assign = Assign(lhs, rhs);
|
||||
WrapInFunction(assign);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedFunction) {
|
|||
create<ast::CallStatement>(call_func),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -65,10 +65,10 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedVariable) {
|
|||
|
||||
Func("main", {}, ty.void_(),
|
||||
{
|
||||
create<ast::AssignmentStatement>(Expr("global_used"), Expr(1.f)),
|
||||
Assign("global_used", 1.f),
|
||||
},
|
||||
{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -105,10 +105,10 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_GlobalsInterleaved) {
|
|||
{
|
||||
Decl(Var("s0", s0, ast::StorageClass::kFunction)),
|
||||
Decl(Var("s1", s1, ast::StorageClass::kFunction)),
|
||||
create<ast::AssignmentStatement>(Expr("a1"), Call("func")),
|
||||
Assign("a1", Call("func")),
|
||||
},
|
||||
{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -30,7 +30,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
|
|||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -52,7 +52,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
|
|||
ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -72,7 +72,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
|
|||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
create<ast::ReturnStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
|
@ -92,15 +92,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
|
||||
auto* func =
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -116,16 +115,15 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
|
||||
auto* func =
|
||||
Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
});
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -143,15 +141,13 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
|
|||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
|
||||
auto* vec4 = ty.vec4<f32>();
|
||||
auto* coord = Param(
|
||||
"coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
|
||||
auto* loc1 = Param("loc1", ty.f32(), {create<ast::LocationDecoration>(1u)});
|
||||
auto* func =
|
||||
Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
|
||||
ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
|
||||
auto* loc1 = Param("loc1", ty.f32(), {Location(1u)});
|
||||
auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
|
||||
ast::StatementList{},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -165,17 +161,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) {
|
||||
auto* func =
|
||||
Func("frag_main", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(1.f)),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(1u),
|
||||
});
|
||||
auto* func = Func("frag_main", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
Return(1.f),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
ast::DecorationList{
|
||||
Location(1u),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
|
@ -219,32 +214,30 @@ TEST_F(WgslGeneratorImplTest,
|
|||
});
|
||||
|
||||
{
|
||||
auto* var =
|
||||
Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")));
|
||||
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
MemberAccessor("data", "d"));
|
||||
|
||||
Func("a", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
auto* var =
|
||||
Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")));
|
||||
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
|
||||
MemberAccessor("data", "d"));
|
||||
|
||||
Func("b", ast::VariableList{}, ty.void_(),
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
Decl(var),
|
||||
Return(),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
|
|||
|
||||
Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr("a0")),
|
||||
Return("a0"),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
|
@ -64,10 +64,10 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
|
|||
ast::StatementList{
|
||||
Decl(Var("s0", s0, ast::StorageClass::kFunction)),
|
||||
Decl(Var("s1", s1, ast::StorageClass::kFunction)),
|
||||
create<ast::AssignmentStatement>(Expr("a1"), Call("func")),
|
||||
Assign("a1", Call("func")),
|
||||
},
|
||||
ast::DecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
Stage(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -24,7 +24,7 @@ using WgslGeneratorImplTest = TestHelper;
|
|||
TEST_F(WgslGeneratorImplTest, Emit_Loop) {
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block();
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* l = Loop(body, continuing);
|
||||
|
||||
WrapInFunction(l);
|
||||
|
||||
|
@ -42,7 +42,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
|
|||
TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||
auto* body = Block(create<ast::DiscardStatement>());
|
||||
auto* continuing = Block(Return());
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
auto* l = Loop(body, continuing);
|
||||
|
||||
WrapInFunction(l);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ TEST_P(WgslBuiltinConversionTest, Emit) {
|
|||
|
||||
auto* var = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(params.builtin),
|
||||
Builtin(params.builtin),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -275,9 +275,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointDecorations) {
|
|||
auto* s = Structure(
|
||||
"S",
|
||||
ast::StructMemberList{
|
||||
Member("a", ty.u32(),
|
||||
{create<ast::BuiltinDecoration>(ast::Builtin::kVertexIndex)}),
|
||||
Member("b", ty.f32(), {create<ast::LocationDecoration>(2u)})},
|
||||
Member("a", ty.u32(), {Builtin(ast::Builtin::kVertexIndex)}),
|
||||
Member("b", ty.f32(), {Location(2u)})},
|
||||
decos);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -25,7 +25,7 @@ using WgslGeneratorImplTest = TestHelper;
|
|||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction);
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -39,7 +39,7 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) {
|
||||
auto* var = Var("a", nullptr, ast::StorageClass::kFunction, Expr(123));
|
||||
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
auto* stmt = Decl(var);
|
||||
WrapInFunction(stmt);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
|
|
@ -45,7 +45,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
|
|||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
||||
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::LocationDecoration>(2),
|
||||
Location(2),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
@ -58,10 +58,10 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
|
|||
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
|
||||
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
|
||||
ast::DecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||
Builtin(ast::Builtin::kPosition),
|
||||
create<ast::BindingDecoration>(0),
|
||||
create<ast::GroupDecoration>(1),
|
||||
create<ast::LocationDecoration>(2),
|
||||
Location(2),
|
||||
create<ast::ConstantIdDecoration>(42),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue