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:
Ben Clayton 2021-04-22 13:50:53 +00:00 committed by Commit Bot service account
parent 261642e4e3
commit 43073d8aa3
61 changed files with 1050 additions and 1371 deletions

View File

@ -268,11 +268,11 @@ TEST_F(FunctionListTest, FindSymbolMissing) {
TEST_F(FunctionListTest, FindSymbolStage) { TEST_F(FunctionListTest, FindSymbolStage) {
auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), Stage(PipelineStage::kFragment),
}); });
auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{}, auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kVertex), Stage(PipelineStage::kVertex),
}); });
FunctionList list; FunctionList list;
list.Add(fs); list.Add(fs);
@ -286,7 +286,7 @@ TEST_F(FunctionListTest, FindSymbolStageMissing) {
FunctionList list; FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{}, list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), Stage(PipelineStage::kFragment),
})); }));
EXPECT_EQ(nullptr, EXPECT_EQ(nullptr,
list.Find(Symbols().Register("main"), PipelineStage::kVertex)); list.Find(Symbols().Register("main"), PipelineStage::kVertex));
@ -296,7 +296,7 @@ TEST_F(FunctionListTest, HasStage) {
FunctionList list; FunctionList list;
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{}, list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(PipelineStage::kFragment), Stage(PipelineStage::kFragment),
})); }));
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment)); EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));
EXPECT_FALSE(list.HasStage(PipelineStage::kVertex)); EXPECT_FALSE(list.HasStage(PipelineStage::kVertex));

File diff suppressed because it is too large Load Diff

View File

@ -1203,10 +1203,26 @@ class ProgramBuilder {
return func; 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 /// Creates an ast::ReturnStatement with no return value
/// @returns the return statement pointer /// @returns the return statement pointer
ast::ReturnStatement* Return() { return create<ast::ReturnStatement>(); } 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 /// Creates an ast::ReturnStatement with the given return value
/// @param val the return value /// @param val the return value
/// @returns the return statement pointer /// @returns the return statement pointer
@ -1330,6 +1346,20 @@ class ProgramBuilder {
std::forward<ELSE_STATEMENTS>(elseStatements)...}); 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 /// Creates a ast::AssignmentStatement with input lhs and rhs expressions
/// @param lhs the left hand side expression initializer /// @param lhs the left hand side expression initializer
/// @param rhs the right hand side expression initializer /// @param rhs the right hand side expression initializer
@ -1351,6 +1381,14 @@ class ProgramBuilder {
return create<ast::LoopStatement>(body, continuing); 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 /// Creates a ast::VariableDeclStatement for the input variable
/// @param var the variable to wrap in a decl statement /// @param var the variable to wrap in a decl statement
/// @returns the variable decl statement pointer /// @returns the variable decl statement pointer

View File

@ -115,8 +115,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
ast::DecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -140,8 +139,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
ast::DecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -165,8 +163,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
ast::DecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -187,8 +184,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
ast::DecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -225,8 +221,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
ast::DecorationList decos; ast::DecorationList decos;
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* s = Structure(Sym("S"), members, decos);
auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);

View File

@ -35,7 +35,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignIncompatibleTypes) {
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2.3f); 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); WrapInFunction(var, assign);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -57,7 +57,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); 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); WrapInFunction(var_a, var_b, assign);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -77,10 +77,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
WrapInFunction(body); WrapInFunction(body);
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -97,10 +94,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
WrapInFunction(block); WrapInFunction(block);
ASSERT_FALSE(r()->Resolve()); ASSERT_FALSE(r()->Resolve());
@ -123,14 +117,9 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* inner_block = create<ast::BlockStatement>(ast::StatementList{ auto* inner_block = Block(Decl(var), Assign(Source{{12, 34}}, lhs, rhs));
create<ast::VariableDeclStatement>(var),
create<ast::AssignmentStatement>(Source{{12, 34}}, lhs, rhs),
});
auto* outer_block = create<ast::BlockStatement>(ast::StatementList{ auto* outer_block = Block(inner_block);
inner_block,
});
WrapInFunction(outer_block); WrapInFunction(outer_block);
@ -149,7 +138,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToScalar_Fail) {
auto* lhs = Expr(1); auto* lhs = Expr(1);
auto* rhs = Expr("my_var"); 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); WrapInFunction(Decl(var), assign);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -166,8 +155,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignCompatibleTypes_Pass) {
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>( auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var), assign); WrapInFunction(Decl(var), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -184,8 +172,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>( auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var), assign); WrapInFunction(Decl(var), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -202,8 +189,7 @@ TEST_F(ResolverAssignmentValidationTest,
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr("b"); auto* rhs = Expr("b");
auto* assign = create<ast::AssignmentStatement>( auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var_a), Decl(var_b), assign); WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -220,8 +206,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignThroughPointer_Pass) {
auto* lhs = Expr("b"); auto* lhs = Expr("b");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>( auto* assign = Assign(Source{Source::Location{12, 34}}, lhs, rhs);
Source{Source::Location{12, 34}}, lhs, rhs);
WrapInFunction(Decl(var_a), Decl(var_b), assign); WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -237,11 +222,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignToConstant_Fail) {
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body =
create<ast::VariableDeclStatement>(var), Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
WrapInFunction(body); WrapInFunction(body);
@ -267,7 +249,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignFromPointer_Fail) {
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr("b"); 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); WrapInFunction(Decl(var_a), Decl(var_b), assign);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());

View File

@ -31,15 +31,13 @@ TEST_F(ResolverControlBlockValidationTest,
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f)); auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.14f));
ast::CaseStatementList body; ast::CaseStatementList body;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{}); auto* block_default = Block();
body.push_back( body.push_back(
create<ast::CaseStatement>(ast::CaseSelectorList{}, block_default)); create<ast::CaseStatement>(ast::CaseSelectorList{}, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(
create<ast::SwitchStatement>(Expr(Source{Source::Location{12, 34}}, "a"), Expr(Source{Source::Location{12, 34}}, "a"), body));
body),
});
WrapInFunction(block); WrapInFunction(block);
@ -60,14 +58,11 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithoutDefault_Fail) {
csl.push_back(Literal(1)); csl.push_back(Literal(1));
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>( body.push_back(create<ast::CaseStatement>(csl, Block()));
csl, create<ast::BlockStatement>(ast::StatementList{})));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(
create<ast::SwitchStatement>(Source{Source::Location{12, 34}}, Expr("a"), Source{Source::Location{12, 34}}, Expr("a"), body));
body),
});
WrapInFunction(block); WrapInFunction(block);
@ -87,24 +82,22 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithTwoDefault_Fail) {
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
ast::CaseSelectorList default_csl_1; ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>(ast::StatementList{}); auto* block_default_1 = Block();
switch_body.push_back( switch_body.push_back(
create<ast::CaseStatement>(default_csl_1, block_default_1)); create<ast::CaseStatement>(default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1; ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(Literal(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)); switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2; 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>( switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, default_csl_2, block_default_2)); Source{Source::Location{12, 34}}, default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
WrapInFunction(block); WrapInFunction(block);
@ -128,17 +121,14 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(ty.u32(), 1)); csl.push_back(create<ast::UintLiteral>(ty.u32(), 1));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl, Source{Source::Location{12, 34}}, csl, Block()));
create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList default_csl; 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)); switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -160,17 +150,14 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(Literal(-1)); csl.push_back(Literal(-1));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl, Source{Source::Location{12, 34}}, csl, Block()));
create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList default_csl; 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)); switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -192,24 +179,20 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(ty.u32(), 0)); csl_1.push_back(create<ast::UintLiteral>(ty.u32(), 0));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList csl_2; ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 2)); csl_2.push_back(create<ast::UintLiteral>(ty.u32(), 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>( switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2, Source{Source::Location{12, 34}}, csl_2, Block()));
create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList default_csl; 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)); switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -231,8 +214,7 @@ TEST_F(ResolverControlBlockValidationTest,
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(Literal(10)); csl_1.push_back(Literal(10));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(csl_1, Block()));
csl_1, create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList csl_2; ast::CaseSelectorList csl_2;
csl_2.push_back(Literal(0)); csl_2.push_back(Literal(0));
@ -240,17 +222,14 @@ TEST_F(ResolverControlBlockValidationTest,
csl_2.push_back(Literal(2)); csl_2.push_back(Literal(2));
csl_2.push_back(Literal(10)); csl_2.push_back(Literal(10));
switch_body.push_back(create<ast::CaseStatement>( switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, csl_2, Source{Source::Location{12, 34}}, csl_2, Block()));
create<ast::BlockStatement>(ast::StatementList{})));
ast::CaseSelectorList default_csl; 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)); switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block =
create<ast::VariableDeclStatement>(var), Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), switch_body));
create<ast::SwitchStatement>(Expr("a"), switch_body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -269,18 +248,12 @@ TEST_F(ResolverControlBlockValidationTest,
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>( auto* block_default = Block(
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
ast::StatementList{
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}),
});
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(default_csl, block_default)); body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -299,19 +272,16 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCase_Pass) {
auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{}); auto* block_default = Block();
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}}, body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default)); default_csl, block_default));
ast::CaseSelectorList case_csl; ast::CaseSelectorList case_csl;
case_csl.push_back(Literal(5)); 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)); body.push_back(create<ast::CaseStatement>(case_csl, block_case));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
WrapInFunction(block); WrapInFunction(block);
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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)); auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u));
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(ast::StatementList{}); auto* block_default = Block();
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}}, body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
default_csl, block_default)); default_csl, block_default));
auto* block = create<ast::BlockStatement>(ast::StatementList{ auto* block = Block(Decl(var), create<ast::SwitchStatement>(Expr("a"), body));
create<ast::VariableDeclStatement>(var),
create<ast::SwitchStatement>(Expr("a"), body),
});
AST().AddConstructedType(my_int); AST().AddConstructedType(my_int);
WrapInFunction(block); WrapInFunction(block);

View File

@ -62,21 +62,19 @@ static ast::Decoration* createDecoration(const Source& source,
case DecorationKind::kBinding: case DecorationKind::kBinding:
return builder.create<ast::BindingDecoration>(source, 1); return builder.create<ast::BindingDecoration>(source, 1);
case DecorationKind::kBuiltin: case DecorationKind::kBuiltin:
return builder.create<ast::BuiltinDecoration>(source, return builder.Builtin(source, ast::Builtin::kPosition);
ast::Builtin::kPosition);
case DecorationKind::kConstantId: case DecorationKind::kConstantId:
return builder.create<ast::ConstantIdDecoration>(source, 0u); return builder.create<ast::ConstantIdDecoration>(source, 0u);
case DecorationKind::kGroup: case DecorationKind::kGroup:
return builder.create<ast::GroupDecoration>(source, 1u); return builder.create<ast::GroupDecoration>(source, 1u);
case DecorationKind::kLocation: case DecorationKind::kLocation:
return builder.create<ast::LocationDecoration>(source, 1); return builder.Location(source, 1);
case DecorationKind::kOffset: case DecorationKind::kOffset:
return builder.create<ast::StructMemberOffsetDecoration>(source, 4u); return builder.create<ast::StructMemberOffsetDecoration>(source, 4u);
case DecorationKind::kSize: case DecorationKind::kSize:
return builder.create<ast::StructMemberSizeDecoration>(source, 4u); return builder.create<ast::StructMemberSizeDecoration>(source, 4u);
case DecorationKind::kStage: case DecorationKind::kStage:
return builder.create<ast::StageDecoration>(source, return builder.Stage(source, ast::PipelineStage::kCompute);
ast::PipelineStage::kCompute);
case DecorationKind::kStride: case DecorationKind::kStride:
return builder.create<ast::StrideDecoration>(source, 4u); return builder.create<ast::StrideDecoration>(source, 4u);
case DecorationKind::kStructBlock: case DecorationKind::kStructBlock:
@ -91,10 +89,8 @@ using FunctionReturnTypeDecorationTest = TestWithParams;
TEST_P(FunctionReturnTypeDecorationTest, IsValid) { TEST_P(FunctionReturnTypeDecorationTest, IsValid) {
auto& params = GetParam(); auto& params = GetParam();
Func("main", ast::VariableList{}, ty.f32(), Func("main", ast::VariableList{}, ty.f32(), ast::StatementList{Return(1.f)},
ast::StatementList{create<ast::ReturnStatement>(Expr(1.f))}, ast::DecorationList{Stage(ast::PipelineStage::kCompute)},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute)},
ast::DecorationList{createDecoration({}, *this, params.kind)}); ast::DecorationList{createDecoration({}, *this, params.kind)});
if (params.should_pass) { if (params.should_pass) {
@ -126,15 +122,16 @@ using ArrayDecorationTest = TestWithParams;
TEST_P(ArrayDecorationTest, IsValid) { TEST_P(ArrayDecorationTest, IsValid) {
auto& params = GetParam(); auto& params = GetParam();
ast::StructMemberList members{Member( auto* arr = create<sem::ArrayType>(
"a", create<sem::ArrayType>(ty.f32(), 0, ty.f32(), 0,
ast::DecorationList{createDecoration( ast::DecorationList{
Source{{12, 34}}, *this, params.kind)}))}; createDecoration(Source{{12, 34}}, *this, params.kind),
auto* s = create<ast::Struct>( });
Sym("mystruct"), members, Structure("mystruct",
ast::DecorationList{create<ast::StructBlockDecoration>()}); {
auto* s_ty = ty.struct_(s); Member("a", arr),
AST().AddConstructedType(s_ty); },
{create<ast::StructBlockDecoration>()});
WrapInFunction(); WrapInFunction();
@ -167,11 +164,8 @@ using StructDecorationTest = TestWithParams;
TEST_P(StructDecorationTest, IsValid) { TEST_P(StructDecorationTest, IsValid) {
auto& params = GetParam(); auto& params = GetParam();
auto* s = create<ast::Struct>(Sym("mystruct"), ast::StructMemberList{}, Structure("mystruct", {},
ast::DecorationList{createDecoration( {createDecoration(Source{{12, 34}}, *this, params.kind)});
Source{{12, 34}}, *this, params.kind)});
auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty);
WrapInFunction(); WrapInFunction();
@ -208,10 +202,8 @@ TEST_P(StructMemberDecorationTest, IsValid) {
Member("a", ty.i32(), Member("a", ty.i32(),
ast::DecorationList{ ast::DecorationList{
createDecoration(Source{{12, 34}}, *this, params.kind)})}; createDecoration(Source{{12, 34}}, *this, params.kind)})};
auto* s =
create<ast::Struct>(Sym("mystruct"), members, ast::DecorationList{}); Structure("mystruct", members);
auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty);
WrapInFunction(); WrapInFunction();
@ -281,7 +273,7 @@ TEST_P(FunctionDecorationTest, IsValid) {
Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("foo", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
createDecoration(Source{{12, 34}}, *this, params.kind)}); createDecoration(Source{{12, 34}}, *this, params.kind)});
if (params.should_pass) { if (params.should_pass) {

View File

@ -31,7 +31,7 @@ class ResolverEntryPointValidationTest : public resolver::TestHelper,
TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Location) { TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Location) {
// [[stage(vertex)]] // [[stage(vertex)]]
// fn main() -> [[location(0)]] f32 { return 1.0; } // 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)}); {Stage(ast::PipelineStage::kFragment)}, {Location(0)});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();

View File

@ -30,13 +30,13 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
// fn func -> i32 { return 2; } // fn func -> i32 { return 2; }
Func("func", ast::VariableList{}, ty.i32(), Func("func", ast::VariableList{}, ty.i32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr(2)), Return(2),
}, },
ast::DecorationList{}); ast::DecorationList{});
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(), Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr(2)), Return(2),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -53,7 +53,7 @@ TEST_F(ResolverFunctionValidationTest,
Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{},
ty.void_(), ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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(), Func(Source{Source::Location{12, 34}}, "func", ast::VariableList{}, ty.i32(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -105,7 +105,7 @@ TEST_F(ResolverFunctionValidationTest,
Func("func", ast::VariableList{}, ty.void_(), Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -116,8 +116,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func { return 2; } // fn func { return 2; }
Func("func", ast::VariableList{}, ty.void_(), Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, Return(Source{Source::Location{12, 34}}, Expr(2)),
Expr(2)),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -132,8 +131,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func -> f32 { return 2.0; } // fn func -> f32 { return 2.0; }
Func("func", ast::VariableList{}, ty.f32(), Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, Return(Source{Source::Location{12, 34}}, Expr(2.f)),
Expr(2.f)),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -145,8 +143,7 @@ TEST_F(ResolverFunctionValidationTest,
// fn func -> f32 { return 2; } // fn func -> f32 { return 2; }
Func("func", ast::VariableList{}, ty.f32(), Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, Return(Source{Source::Location{12, 34}}, Expr(2)),
Expr(2)),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -163,8 +160,7 @@ TEST_F(ResolverFunctionValidationTest,
auto* myf32 = ty.alias("myf32", ty.f32()); auto* myf32 = ty.alias("myf32", ty.f32());
Func("func", ast::VariableList{}, myf32, Func("func", ast::VariableList{}, myf32,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, Return(Source{Source::Location{12, 34}}, Expr(2.f)),
Expr(2.f)),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -178,8 +174,7 @@ TEST_F(ResolverFunctionValidationTest,
auto* myf32 = ty.alias("myf32", ty.f32()); auto* myf32 = ty.alias("myf32", ty.f32());
Func("func", ast::VariableList{}, myf32, Func("func", ast::VariableList{}, myf32,
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Source{Source::Location{12, 34}}, Return(Source{Source::Location{12, 34}}, Expr(2u)),
Expr(2u)),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -196,11 +191,11 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{}, Func(Source{Source::Location{12, 34}}, "main", ast::VariableList{},
ty.void_(), ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), Stage(ast::PipelineStage::kVertex),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -212,7 +207,7 @@ TEST_F(ResolverFunctionValidationTest, PipelineStage_MustBeUnique_Fail) {
TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) { TEST_F(ResolverFunctionValidationTest, NoPipelineEntryPoints) {
Func("vtx_func", ast::VariableList{}, ty.void_(), Func("vtx_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});

View File

@ -59,7 +59,7 @@ TEST_F(ResolverTest, Stmt_Assign) {
auto* lhs = Expr("v"); auto* lhs = Expr("v");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs); auto* assign = Assign(lhs, rhs);
WrapInFunction(v, assign); WrapInFunction(v, assign);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -78,7 +78,7 @@ TEST_F(ResolverTest, Stmt_Case) {
auto* lhs = Expr("v"); auto* lhs = Expr("v");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs); auto* assign = Assign(lhs, rhs);
auto* block = Block(assign); auto* block = Block(assign);
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(ty.i32(), 3)); lit.push_back(create<ast::SintLiteral>(ty.i32(), 3));
@ -101,7 +101,7 @@ TEST_F(ResolverTest, Stmt_Block) {
auto* lhs = Expr("v"); auto* lhs = Expr("v");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs); auto* assign = Assign(lhs, rhs);
auto* block = Block(assign); auto* block = Block(assign);
WrapInFunction(v, block); WrapInFunction(v, block);
@ -123,7 +123,7 @@ TEST_F(ResolverTest, Stmt_If) {
auto* else_lhs = Expr("v"); auto* else_lhs = Expr("v");
auto* else_rhs = Expr(2.3f); 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_cond = Expr(3);
auto* else_stmt = create<ast::ElseStatement>(else_cond, else_body); auto* else_stmt = create<ast::ElseStatement>(else_cond, else_body);
@ -131,7 +131,7 @@ TEST_F(ResolverTest, Stmt_If) {
auto* lhs = Expr("v"); auto* lhs = Expr("v");
auto* rhs = Expr(2.3f); auto* rhs = Expr(2.3f);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs); auto* assign = Assign(lhs, rhs);
auto* body = Block(assign); auto* body = Block(assign);
auto* cond = Expr(true); auto* cond = Expr(true);
auto* stmt = auto* stmt =
@ -165,14 +165,12 @@ TEST_F(ResolverTest, Stmt_Loop) {
auto* body_lhs = Expr("v"); auto* body_lhs = Expr("v");
auto* body_rhs = Expr(2.3f); 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_lhs = Expr("v");
auto* continuing_rhs = Expr(2.3f); auto* continuing_rhs = Expr(2.3f);
auto* continuing = create<ast::BlockStatement>(ast::StatementList{ auto* continuing = Block(Assign(continuing_lhs, continuing_rhs));
create<ast::AssignmentStatement>(continuing_lhs, continuing_rhs), auto* stmt = Loop(body, continuing);
});
auto* stmt = create<ast::LoopStatement>(body, continuing);
WrapInFunction(v, stmt); WrapInFunction(v, stmt);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -194,7 +192,7 @@ TEST_F(ResolverTest, Stmt_Loop) {
TEST_F(ResolverTest, Stmt_Return) { TEST_F(ResolverTest, Stmt_Return) {
auto* cond = Expr(2); auto* cond = Expr(2);
auto* ret = create<ast::ReturnStatement>(cond); auto* ret = Return(cond);
Func("test", {}, ty.i32(), {ret}, {}); Func("test", {}, ty.i32(), {ret}, {});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -204,7 +202,7 @@ TEST_F(ResolverTest, Stmt_Return) {
} }
TEST_F(ResolverTest, Stmt_Return_WithoutValue) { TEST_F(ResolverTest, Stmt_Return_WithoutValue) {
auto* ret = create<ast::ReturnStatement>(); auto* ret = Return();
WrapInFunction(ret); WrapInFunction(ret);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -233,7 +231,7 @@ TEST_F(ResolverTest, Stmt_Switch) {
TEST_F(ResolverTest, Stmt_Call) { TEST_F(ResolverTest, Stmt_Call) {
ast::VariableList params; 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{}); ast::DecorationList{});
auto* expr = Call("my_func"); 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* var = Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(2));
auto* init = var->constructor(); auto* init = var->constructor();
auto* decl = create<ast::VariableDeclStatement>(var); auto* decl = Decl(var);
WrapInFunction(decl); WrapInFunction(decl);
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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* var = Var("my_var", my_int, ast::StorageClass::kNone, Expr(2));
auto* init = var->constructor(); auto* init = var->constructor();
auto* decl = create<ast::VariableDeclStatement>(var); auto* decl = Decl(var);
WrapInFunction(decl); WrapInFunction(decl);
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -301,25 +299,24 @@ TEST_F(ResolverTest, Stmt_VariableDecl_OuterScopeAfterInnerScope) {
// Declare i32 "foo" inside a block // Declare i32 "foo" inside a block
auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2)); auto* foo_i32 = Var("foo", ty.i32(), ast::StorageClass::kNone, Expr(2));
auto* foo_i32_init = foo_i32->constructor(); 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 // Reference "foo" inside the block
auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo")); auto* bar_i32 = Var("bar", ty.i32(), ast::StorageClass::kNone, Expr("foo"));
auto* bar_i32_init = bar_i32->constructor(); 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>( auto* inner = Block(foo_i32_decl, bar_i32_decl);
ast::StatementList{foo_i32_decl, bar_i32_decl});
// Declare f32 "foo" at function scope // Declare f32 "foo" at function scope
auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f)); auto* foo_f32 = Var("foo", ty.f32(), ast::StorageClass::kNone, Expr(2.f));
auto* foo_f32_init = foo_f32->constructor(); 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 // Reference "foo" at function scope
auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo")); auto* bar_f32 = Var("bar", ty.f32(), ast::StorageClass::kNone, Expr("foo"));
auto* bar_f32_init = bar_f32->constructor(); 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_(), Func("func", params, ty.void_(),
ast::StatementList{inner, foo_f32_decl, bar_f32_decl}, 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 // Declare i32 "foo" inside a function
auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kFunction, Expr(2)); auto* fn_i32 = Var("foo", ty.i32(), ast::StorageClass::kFunction, Expr(2));
auto* fn_i32_init = fn_i32->constructor(); 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}, Func("func_i32", params, ty.void_(), ast::StatementList{fn_i32_decl},
ast::DecorationList{}); ast::DecorationList{});
@ -373,7 +370,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl_ModuleScopeAfterFunctionScope) {
auto* fn_f32 = auto* fn_f32 =
Var("bar", ty.f32(), ast::StorageClass::kFunction, Expr("foo")); Var("bar", ty.f32(), ast::StorageClass::kFunction, Expr("foo"));
auto* fn_f32_init = fn_f32->constructor(); 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}, Func("func_f32", params, ty.void_(), ast::StatementList{fn_f32_decl},
ast::DecorationList{}); ast::DecorationList{});
@ -498,7 +495,7 @@ TEST_F(ResolverTest, Expr_Bitcast) {
TEST_F(ResolverTest, Expr_Call) { TEST_F(ResolverTest, Expr_Call) {
ast::VariableList params; 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{}); ast::DecorationList{});
auto* call = Call("my_func"); auto* call = Call("my_func");
@ -512,7 +509,7 @@ TEST_F(ResolverTest, Expr_Call) {
TEST_F(ResolverTest, Expr_Call_InBinaryOp) { TEST_F(ResolverTest, Expr_Call_InBinaryOp) {
ast::VariableList params; 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{}); ast::DecorationList{});
auto* expr = Add(Call("func"), Call("func")); 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_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
decl, decl,
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -664,13 +661,13 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable_Const) {
TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) { TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
auto* my_var_a = Expr("my_var"); auto* my_var_a = Expr("my_var");
auto* my_var_b = 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); auto* var = Var("my_var", ty.f32(), ast::StorageClass::kNone);
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
assign, assign,
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -695,13 +692,12 @@ TEST_F(ResolverTest, Expr_Identifier_FunctionVariable) {
TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) { TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
auto* my_var_a = Expr("my_var"); auto* my_var_a = Expr("my_var");
auto* my_var_b = 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_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>( Decl(Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction),
Var("my_var", ty.pointer<f32>(ast::StorageClass::kFunction), ast::StorageClass::kNone)),
ast::StorageClass::kNone)),
assign, assign,
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -720,7 +716,7 @@ TEST_F(ResolverTest, Expr_Identifier_Function_Ptr) {
TEST_F(ResolverTest, Expr_Call_Function) { TEST_F(ResolverTest, Expr_Call_Function) {
Func("my_func", ast::VariableList{}, ty.f32(), 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"); auto* call = Call("my_func");
WrapInFunction(call); WrapInFunction(call);
@ -775,15 +771,14 @@ TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup); auto* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate); auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
auto* func = Func( auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
"my_func", ast::VariableList{}, ty.void_(), ast::StatementList{
ast::StatementList{ Assign("out_var", "in_var"),
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")), Assign("wg_var", "wg_var"),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")), Assign("sb_var", "sb_var"),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")), Assign("priv_var", "priv_var"),
create<ast::AssignmentStatement>(Expr("priv_var"), Expr("priv_var")), },
}, ast::DecorationList{});
ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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* wg_var = Global("wg_var", ty.f32(), ast::StorageClass::kWorkgroup);
auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate); auto* priv_var = Global("priv_var", ty.f32(), ast::StorageClass::kPrivate);
Func("my_func", ast::VariableList{}, ty.f32(), Func(
ast::StatementList{ "my_func", ast::VariableList{}, ty.f32(),
create<ast::AssignmentStatement>(Expr("out_var"), Expr("in_var")), ast::StatementList{Assign("out_var", "in_var"),
create<ast::AssignmentStatement>(Expr("wg_var"), Expr("wg_var")), Assign("wg_var", "wg_var"), Assign("sb_var", "sb_var"),
create<ast::AssignmentStatement>(Expr("sb_var"), Expr("sb_var")), Assign("priv_var", "priv_var"), Return(0.0f)},
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")),
},
ast::DecorationList{}); 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(); EXPECT_TRUE(r()->Resolve()) << r()->error();
auto* func2_sem = Sem().Get(func2); 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); auto* var = Var("in_var", ty.f32(), ast::StorageClass::kFunction);
Global("var", ty.f32(), ast::StorageClass::kFunction); Global("var", ty.f32(), ast::StorageClass::kFunction);
auto* func = auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{
ast::StatementList{ Decl(var),
create<ast::VariableDeclStatement>(var), Assign("var", 1.f),
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), },
}, ast::DecorationList{});
ast::DecorationList{});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -865,13 +856,12 @@ TEST_F(ResolverTest, Function_NotRegisterFunctionVariable) {
TEST_F(ResolverTest, Function_ReturnStatements) { TEST_F(ResolverTest, Function_ReturnStatements) {
auto* var = Var("foo", ty.f32(), ast::StorageClass::kFunction); auto* var = Var("foo", ty.f32(), ast::StorageClass::kFunction);
auto* ret_1 = create<ast::ReturnStatement>(Expr(1.f)); auto* ret_1 = Return(1.f);
auto* ret_foo = create<ast::ReturnStatement>(Expr("foo")); auto* ret_foo = Return("foo");
auto* func = Func("my_func", ast::VariableList{}, ty.f32(), auto* func = Func("my_func", ast::VariableList{}, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
If(Expr(true), Block(ret_1)), If(true, Block(ret_1)),
ret_foo, ret_foo,
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -888,13 +878,8 @@ TEST_F(ResolverTest, Function_ReturnStatements) {
} }
TEST_F(ResolverTest, Expr_MemberAccessor_Struct) { TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
auto* strct = create<ast::Struct>( auto* st = Structure("S", {Member("first_member", ty.i32()),
Sym("S"), Member("second_member", ty.f32())});
ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
Global("my_struct", st, ast::StorageClass::kInput); Global("my_struct", st, ast::StorageClass::kInput);
auto* mem = MemberAccessor("my_struct", "second_member"); auto* mem = MemberAccessor("my_struct", "second_member");
@ -918,13 +903,8 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
} }
TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) { TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
auto* strct = create<ast::Struct>( auto* st = Structure("alias", {Member("first_member", ty.i32()),
Sym("alias"), Member("second_member", ty.f32())});
ast::StructMemberList{Member("first_member", ty.i32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
auto* alias = ty.alias("alias", st); auto* alias = ty.alias("alias", st);
Global("my_struct", alias, ast::StorageClass::kInput); Global("my_struct", alias, ast::StorageClass::kInput);
@ -1001,17 +981,11 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
// } // }
// //
auto* strctB = create<ast::Struct>( auto* stB = Structure("B", {Member("foo", ty.vec4<f32>())});
Sym("B"), ast::StructMemberList{Member("foo", ty.vec4<f32>())},
ast::DecorationList{});
auto* stB = ty.struct_(strctB);
sem::Vector vecB(stB, 3); 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); Global("c", stA, ast::StorageClass::kInput);
auto* mem = MemberAccessor( auto* mem = MemberAccessor(
@ -1029,13 +1003,8 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
} }
TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) { TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
auto* strct = create<ast::Struct>( auto* st = Structure("S", {Member("first_member", ty.f32()),
Sym("S"), Member("second_member", ty.f32())});
ast::StructMemberList{Member("first_member", ty.f32()),
Member("second_member", ty.f32())},
ast::DecorationList{});
auto* st = ty.struct_(strct);
Global("my_struct", st, ast::StorageClass::kInput); Global("my_struct", st, ast::StorageClass::kInput);
auto* expr = Add(MemberAccessor("my_struct", "first_member"), auto* expr = Add(MemberAccessor("my_struct", "first_member"),
@ -1470,7 +1439,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTest,
TEST_F(ResolverTest, StorageClass_SetsIfMissing) { TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
auto* var = Var("var", ty.i32(), ast::StorageClass::kNone); 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}, Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{}); ast::DecorationList{});
@ -1481,7 +1450,7 @@ TEST_F(ResolverTest, StorageClass_SetsIfMissing) {
TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) { TEST_F(ResolverTest, StorageClass_DoesNotSetOnConst) {
auto* var = Const("var", ty.i32()); 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}, Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{}); ast::DecorationList{});
@ -1510,39 +1479,34 @@ TEST_F(ResolverTest, Function_EntryPoints_StageDecoration) {
Global("call_c", ty.f32(), ast::StorageClass::kPrivate); Global("call_c", ty.f32(), ast::StorageClass::kPrivate);
ast::VariableList params; ast::VariableList params;
auto* func_b = auto* func_b = Func("b", params, ty.f32(), ast::StatementList{Return(0.0f)},
Func("b", params, ty.f32(), ast::StatementList{Return(Expr(0.0f))}, ast::DecorationList{});
auto* func_c =
Func("c", params, ty.f32(),
ast::StatementList{Assign("second", Call("b")), Return(0.0f)},
ast::DecorationList{}); 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(), auto* func_a =
ast::StatementList{create<ast::AssignmentStatement>( Func("a", params, ty.f32(),
Expr("first"), Call("c")), ast::StatementList{Assign("first", Call("c")), Return(0.0f)},
Return(Expr(0.0f))}, ast::DecorationList{});
ast::DecorationList{});
auto* ep_1 = auto* ep_1 = Func("ep_1", params, ty.void_(),
Func("ep_1", params, ty.void_(), ast::StatementList{
ast::StatementList{ Assign("call_a", Call("a")),
create<ast::AssignmentStatement>(Expr("call_a"), Call("a")), Assign("call_b", Call("b")),
create<ast::AssignmentStatement>(Expr("call_b"), Call("b")), },
}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kCompute),
create<ast::StageDecoration>(ast::PipelineStage::kCompute), });
});
auto* ep_2 = auto* ep_2 = Func("ep_2", params, ty.void_(),
Func("ep_2", params, ty.void_(), ast::StatementList{
ast::StatementList{ Assign("call_c", Call("c")),
create<ast::AssignmentStatement>(Expr("call_c"), Call("c")), },
}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kCompute),
create<ast::StageDecoration>(ast::PipelineStage::kCompute), });
});
ASSERT_TRUE(r()->Resolve()) << r()->error(); 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::CallStatement>(Call(fn_b(0))),
}, },
{ {
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@ -28,8 +28,7 @@ namespace {
using ResolverPipelineStageUseTest = ResolverTest; using ResolverPipelineStageUseTest = ResolverTest;
TEST_F(ResolverPipelineStageUseTest, UnusedStruct) { TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -39,8 +38,7 @@ TEST_F(ResolverPipelineStageUseTest, UnusedStruct) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
Func("foo", {Param("param", s)}, ty.void_(), {}, {}); Func("foo", {Param("param", s)}, ty.void_(), {}, {});
@ -52,8 +50,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointParam) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointReturnType) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsNonEntryPointReturnType) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
Func("foo", {}, s, {Return(Construct(s, Expr(0.f)))}, {}); Func("foo", {}, s, {Return(Construct(s, Expr(0.f)))}, {});
@ -96,11 +93,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderReturnType) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
Func("main", {Param("param", s)}, ty.void_(), {}, Func("main", {Param("param", s)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -111,11 +107,10 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderParam) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
Func("main", {}, s, {Return(Construct(s, Expr(0.f)))}, 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(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -126,12 +121,12 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) {
auto* s = Structure("S", {Member("a", ty.u32(), auto* s = Structure(
{create<ast::BuiltinDecoration>( "S",
ast::Builtin::kLocalInvocationIndex)})}); {Member("a", ty.u32(), {Builtin(ast::Builtin::kLocalInvocationIndex)})});
Func("main", {Param("param", s)}, ty.void_(), {}, Func("main", {Param("param", s)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)}); {Stage(ast::PipelineStage::kCompute)});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -162,12 +157,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s_alias = ty.alias("S_alias", s); auto* s_alias = ty.alias("S_alias", s);
Func("main", {Param("param", s_alias)}, ty.void_(), {}, Func("main", {Param("param", s_alias)}, ty.void_(), {},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(r()->Resolve()) << r()->error();
@ -178,12 +172,11 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) {
} }
TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderReturnTypeViaAlias) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderReturnTypeViaAlias) {
auto* s = Structure( auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})});
"S", {Member("a", ty.f32(), {create<ast::LocationDecoration>(0)})});
auto* s_alias = ty.alias("S_alias", s); auto* s_alias = ty.alias("S_alias", s);
Func("main", {}, s_alias, {Return(Construct(s_alias, Expr(0.f)))}, 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(); ASSERT_TRUE(r()->Resolve()) << r()->error();

View File

@ -38,11 +38,8 @@ TEST_F(ResolverTypeValidationTest, VariableDeclNoConstructor_Pass) {
auto* lhs = Expr("a"); auto* lhs = Expr("a");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body =
create<ast::VariableDeclStatement>(var), Block(Decl(var), Assign(Source{Source::Location{12, 34}}, lhs, rhs));
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
rhs),
});
WrapInFunction(body); WrapInFunction(body);
@ -133,7 +130,7 @@ TEST_F(ResolverTypeValidationTest,
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var), Decl(Source{{12, 34}}, var),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -152,8 +149,8 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifier_Fail) {
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float), Decl(Source{{12, 34}}, var_a_float),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -169,16 +166,13 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScope_Pass) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f)); auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true); auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Decl(var));
create<ast::VariableDeclStatement>(var),
});
auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f)); auto* var_a_float = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(3.1f));
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body =
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}), Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_a_float), Decl(Source{{12, 34}}, var_a_float));
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -198,14 +192,11 @@ TEST_F(ResolverTypeValidationTest,
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f)); auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true); auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Decl(Source{{12, 34}}, var));
create<ast::VariableDeclStatement>(Source{{12, 34}}, var),
});
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body =
create<ast::VariableDeclStatement>(var_a_float), Block(Decl(var_a_float),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}), create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -219,15 +210,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Pass) {
// var a : f32; // var a : f32;
// } // }
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone); auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* inner = create<ast::BlockStatement>(ast::StatementList{ auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
});
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone); auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body = Block(inner, Decl(var_outer));
inner,
create<ast::VariableDeclStatement>(var_outer),
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -240,15 +226,10 @@ TEST_F(ResolverTypeValidationTest, RedeclaredIdentifierInnerScopeBlock_Fail) {
// { var a : f32; } // { var a : f32; }
// } // }
auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone); auto* var_inner = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* inner = create<ast::BlockStatement>(ast::StatementList{ auto* inner = Block(Decl(Source{{12, 34}}, var_inner));
create<ast::VariableDeclStatement>(Source{{12, 34}}, var_inner),
});
auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone); auto* var_outer = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body = Block(Decl(var_outer), inner);
create<ast::VariableDeclStatement>(var_outer),
inner,
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -266,15 +247,15 @@ TEST_F(ResolverTypeValidationTest,
Func("func0", ast::VariableList{}, ty.void_(), Func("func0", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(Source{{12, 34}}, var0), Decl(Source{{12, 34}}, var0),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
Func("func1", ast::VariableList{}, ty.void_(), Func("func1", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(Source{{13, 34}}, var1), Decl(Source{{13, 34}}, var1),
create<ast::ReturnStatement>(), Return(),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -289,10 +270,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayInFunction_Fail) {
Func("func", ast::VariableList{}, ty.void_(), Func("func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), Stage(ast::PipelineStage::kVertex),
}); });
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -309,16 +290,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLast_Pass) {
// rt: array<f32>; // rt: array<f32>;
// }; // };
ast::DecorationList decos; Structure("Foo",
decos.push_back(create<ast::StructBlockDecoration>()); {
auto* st = Member("vf", ty.f32()),
create<ast::Struct>(Sym("Foo"), Member("rt", ty.array<f32>()),
ast::StructMemberList{Member("vf", ty.f32()), },
Member("rt", ty.array<f32>())}, {create<ast::StructBlockDecoration>()});
decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -331,15 +308,10 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLastNoBlock_Fail) {
// rt: array<f32>; // rt: array<f32>;
// }; // };
ast::DecorationList decos; Structure("Foo", {
auto* st = create<ast::Struct>( Member("vf", ty.f32()),
Sym("Foo"), Member(Source{{12, 34}}, "rt", ty.array<f32>()),
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);
WrapInFunction(); WrapInFunction();
@ -356,16 +328,12 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsNotLast_Fail) {
// vf: f32; // vf: f32;
// }; // };
ast::DecorationList decos; Structure("Foo",
decos.push_back(create<ast::StructBlockDecoration>()); {
Member(Source{{12, 34}}, "rt", ty.array<f32>()),
auto* rt = Member(Source{{12, 34}}, "rt", ty.array<f32>()); Member("vf", ty.f32()),
auto* st = create<ast::Struct>( },
Sym("Foo"), ast::StructMemberList{rt, Member("vf", ty.f32())}, decos); {create<ast::StructBlockDecoration>()});
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -405,16 +373,16 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayAsParameter_Fail) {
Func("func", ast::VariableList{param}, ty.void_(), Func("func", ast::VariableList{param}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), Stage(ast::PipelineStage::kVertex),
}); });
EXPECT_FALSE(r()->Resolve()) << r()->error(); EXPECT_FALSE(r()->Resolve()) << r()->error();
@ -434,16 +402,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsNotLast_Fail) {
auto* alias = ty.alias("RTArr", ty.array<u32>()); auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::DecorationList decos; Structure("s",
decos.push_back(create<ast::StructBlockDecoration>()); {
auto* st = create<ast::Struct>( Member(Source{{12, 34}}, "b", alias),
Sym("s"), Member("a", ty.u32()),
ast::StructMemberList{Member(Source{{12, 34}}, "b", alias), },
Member("a", ty.u32())}, {create<ast::StructBlockDecoration>()});
decos);
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -464,14 +428,12 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
auto* alias = ty.alias("RTArr", ty.array<u32>()); auto* alias = ty.alias("RTArr", ty.array<u32>());
ast::DecorationList decos; Structure("s",
decos.push_back(create<ast::StructBlockDecoration>()); {
auto* st = create<ast::Struct>( Member("a", ty.u32()),
Sym("s"), Member("b", alias),
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos); },
{create<ast::StructBlockDecoration>()});
auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();

View File

@ -95,13 +95,13 @@ TEST_F(ResolverValidationTest, Stmt_Call_undeclared) {
Func("main", params0, ty.f32(), Func("main", params0, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::CallStatement>(call_expr), create<ast::CallStatement>(call_expr),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
Func("func", params0, ty.f32(), Func("func", params0, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -123,7 +123,7 @@ TEST_F(ResolverValidationTest, Stmt_Call_recursive) {
create<ast::CallStatement>(call_expr), create<ast::CallStatement>(call_expr),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex), Stage(ast::PipelineStage::kVertex),
}); });
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -153,8 +153,7 @@ TEST_F(ResolverValidationTest,
auto* var = auto* var =
Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(unsigned_value)); Var("my_var", ty.i32(), ast::StorageClass::kNone, Expr(unsigned_value));
auto* decl = auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
WrapInFunction(decl); WrapInFunction(decl);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -170,8 +169,7 @@ TEST_F(ResolverValidationTest,
auto* var = auto* var =
Var("my_var", my_int, ast::StorageClass::kNone, Expr(unsigned_value)); Var("my_var", my_int, ast::StorageClass::kNone, Expr(unsigned_value));
auto* decl = auto* decl = Decl(Source{{{3, 3}, {3, 22}}}, var);
create<ast::VariableDeclStatement>(Source{{{3, 3}, {3, 22}}}, var);
WrapInFunction(decl); WrapInFunction(decl);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -216,7 +214,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariable_Fail) {
auto* lhs = Expr(Source{{12, 34}}, "b"); auto* lhs = Expr(Source{{12, 34}}, "b");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* assign = create<ast::AssignmentStatement>(lhs, rhs); auto* assign = Assign(lhs, rhs);
WrapInFunction(assign); WrapInFunction(assign);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -232,9 +230,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* lhs = Expr(Source{{12, 34}}, "b"); auto* lhs = Expr(Source{{12, 34}}, "b");
auto* rhs = Expr(2); auto* rhs = Expr(2);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Assign(lhs, rhs));
create<ast::AssignmentStatement>(lhs, rhs),
});
WrapInFunction(body); WrapInFunction(body);
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
@ -253,10 +249,9 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableGlobalVariableAfter_Fail) {
Func("my_func", ast::VariableList{}, ty.void_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(lhs, rhs), Assign(lhs, rhs),
}, },
ast::DecorationList{ ast::DecorationList{Stage(ast::PipelineStage::kVertex)});
create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
Global("global_var", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1f)); 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_(), Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, Assign(Expr(Source{Source::Location{12, 34}}, "global_var"), 3.14f),
Expr("global_var"), Expr(3.14f)), Return(),
create<ast::ReturnStatement>(),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); 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* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* cond = Expr(true); auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Decl(var));
create<ast::VariableDeclStatement>(var),
});
SetSource(Source{Source::Location{12, 34}}); SetSource(Source{Source::Location{12, 34}});
auto* lhs = Expr(Source{{12, 34}}, "a"); auto* lhs = Expr(Source{{12, 34}}, "a");
auto* rhs = Expr(3.14f); auto* rhs = Expr(3.14f);
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body =
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}), Block(create<ast::IfStatement>(cond, body, ast::ElseStatementList{}),
create<ast::AssignmentStatement>(lhs, rhs), Assign(lhs, rhs));
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -324,14 +315,11 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableOuterScope_Pass) {
auto* rhs = Expr(3.14f); auto* rhs = Expr(3.14f);
auto* cond = Expr(true); auto* cond = Expr(true);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Assign(lhs, rhs));
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body =
create<ast::VariableDeclStatement>(var), Block(Decl(var),
create<ast::IfStatement>(cond, body, ast::ElseStatementList{}), create<ast::IfStatement>(cond, body, ast::ElseStatementList{}));
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -344,20 +332,13 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
// { a = 3.14; } // { a = 3.14; }
// } // }
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f)); auto* var = Var("a", ty.f32(), ast::StorageClass::kNone, Expr(2.0f));
auto* first_body = create<ast::BlockStatement>(ast::StatementList{ auto* first_body = Block(Decl(var));
create<ast::VariableDeclStatement>(var),
});
auto* lhs = Expr(Source{{12, 34}}, "a"); auto* lhs = Expr(Source{{12, 34}}, "a");
auto* rhs = Expr(3.14f); auto* rhs = Expr(3.14f);
auto* second_body = create<ast::BlockStatement>(ast::StatementList{ auto* second_body = Block(Assign(lhs, rhs));
create<ast::AssignmentStatement>(lhs, rhs),
});
auto* outer_body = create<ast::BlockStatement>(ast::StatementList{ auto* outer_body = Block(first_body, second_body);
first_body,
second_body,
});
WrapInFunction(outer_body); WrapInFunction(outer_body);
@ -369,7 +350,7 @@ TEST_F(ResolverValidationTest, UsingUndefinedVariableDifferentScope_Fail) {
TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) { TEST_F(ResolverValidationTest, StorageClass_NonFunctionClassError) {
auto* var = Var("var", ty.i32(), ast::StorageClass::kWorkgroup); 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}, Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},
ast::DecorationList{}); ast::DecorationList{});
@ -436,7 +417,7 @@ TEST_F(ResolverValidationTest,
auto error_loc = Source{Source::Location{12, 34}}; auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(create<ast::ContinueStatement>(), auto* body = Block(create<ast::ContinueStatement>(),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -462,7 +443,7 @@ TEST_F(ResolverValidationTest,
auto* body = Block(create<ast::ContinueStatement>(), auto* body = Block(create<ast::ContinueStatement>(),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone)), Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
create<ast::ContinueStatement>()); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -487,7 +468,7 @@ TEST_F(ResolverValidationTest,
auto error_loc = Source{Source::Location{12, 34}}; auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())), auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -517,7 +498,7 @@ TEST_F(
Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); Decl(Var("z", ty.i32(), ast::StorageClass::kNone)));
auto* continuing = 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -545,7 +526,7 @@ TEST_F(ResolverValidationTest,
auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())), auto* body = Block(If(Expr(true), Block(create<ast::ContinueStatement>())),
Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -571,7 +552,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>())); auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body = auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -596,7 +577,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>())); auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body = auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -621,7 +602,7 @@ TEST_F(ResolverValidationTest,
auto* inner_loop = Loop(Block(create<ast::ContinueStatement>())); auto* inner_loop = Loop(Block(create<ast::ContinueStatement>()));
auto* body = auto* body =
Block(inner_loop, Decl(Var("z", ty.i32(), ast::StorageClass::kNone))); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);
@ -641,7 +622,7 @@ TEST_F(ResolverTest, Stmt_Loop_ContinueInLoopBodyAfterDecl_UsageInContinuing) {
auto error_loc = Source{Source::Location{12, 34}}; auto error_loc = Source{Source::Location{12, 34}};
auto* body = Block(Decl(Var("z", ty.i32(), ast::StorageClass::kNone)), auto* body = Block(Decl(Var("z", ty.i32(), ast::StorageClass::kNone)),
create<ast::ContinueStatement>()); 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); auto* loop_stmt = Loop(body, continuing);
WrapInFunction(loop_stmt); WrapInFunction(loop_stmt);

View File

@ -182,10 +182,9 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
// Construct the variable that'll hold the result of // Construct the variable that'll hold the result of
// RWByteAddressBuffer.GetDimensions() // RWByteAddressBuffer.GetDimensions()
auto* buffer_size_result = auto* buffer_size_result = ctx.dst->Decl(ctx.dst->Var(
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Var( ctx.dst->Symbols().New(), ctx.dst->ty.u32(),
ctx.dst->Symbols().New(), ctx.dst->ty.u32(), ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
// Call storage_buffer.GetDimensions(buffer_size_result) // Call storage_buffer.GetDimensions(buffer_size_result)
auto* call_get_dims = auto* call_get_dims =
@ -203,14 +202,12 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
auto name = ctx.dst->Symbols().New(); auto name = ctx.dst->Symbols().New();
uint32_t array_offset = array_member_sem->Offset(); uint32_t array_offset = array_member_sem->Offset();
uint32_t array_stride = array_member_sem->Size(); uint32_t array_stride = array_member_sem->Size();
auto* array_length_var = auto* array_length_var = ctx.dst->Decl(ctx.dst->Const(
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Const( name, ctx.dst->ty.u32(),
name, ctx.dst->ty.u32(), ctx.dst->Div(
ctx.dst->Div( ctx.dst->Sub(buffer_size_result->variable()->symbol(),
ctx.dst->Sub( array_offset),
buffer_size_result->variable()->symbol(), array_stride)));
array_offset),
array_stride)));
// Insert the array length calculations at the top of the block // Insert the array length calculations at the top of the block
ctx.InsertBefore(block->statements(), *block->begin(), ctx.InsertBefore(block->statements(), *block->begin(),

View File

@ -257,8 +257,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
ret_values.push_back(new_ret_value()); ret_values.push_back(new_ret_value());
} }
auto* new_ret = ctx.dst->create<ast::ReturnStatement>( auto* new_ret =
ctx.dst->Construct(new_ret_type, ret_values)); ctx.dst->Return(ctx.dst->Construct(new_ret_type, ret_values));
ctx.Replace(ret, new_ret); ctx.Replace(ret, new_ret);
} }
} }

View File

@ -356,10 +356,10 @@ sem::Type* UnwrapPtrAndAlias(sem::Type* ty) {
/// StorageBufferAccess describes a single storage buffer access /// StorageBufferAccess describes a single storage buffer access
struct StorageBufferAccess { struct StorageBufferAccess {
sem::Expression const* var = nullptr; // Storage buffer variable sem::Expression const* var = nullptr; // Storage buffer variable
std::unique_ptr<Offset> offset; // The byte offset on var std::unique_ptr<Offset> offset; // The byte offset on var
sem::Type* type = nullptr; // The type of the access sem::Type* type = nullptr; // The type of the access
operator bool() const { return var; } // Returns true if valid operator bool() const { return var; } // Returns true if valid
}; };
/// Store describes a single storage buffer write /// Store describes a single storage buffer write
@ -459,8 +459,8 @@ struct State {
} }
func = ctx.dst->create<ast::Function>( func = ctx.dst->create<ast::Function>(
ctx.dst->Symbols().New(), params, ctx.Clone(el_ty), ctx.dst->Symbols().New(), params, ctx.Clone(el_ty),
ctx.dst->Block(ctx.dst->create<ast::ReturnStatement>( ctx.dst->Block(
ctx.dst->create<ast::TypeConstructorExpression>( ctx.dst->Return(ctx.dst->create<ast::TypeConstructorExpression>(
ctx.Clone(el_ty), values))), ctx.Clone(el_ty), values))),
ast::DecorationList{}, ast::DecorationList{}); ast::DecorationList{}, ast::DecorationList{});
} }

View File

@ -40,7 +40,7 @@ Output EmitVertexPointSize::Run(const Program* in, const DataMap&) {
// Declare the pointsize builtin output variable. // Declare the pointsize builtin output variable.
out.Global(pointsize, out.ty.f32(), ast::StorageClass::kOutput, nullptr, out.Global(pointsize, out.ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ 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. // Add the pointsize assignment statement to the front of all vertex stages.

View File

@ -106,8 +106,7 @@ void Hlsl::PromoteInitializersToConstVar(CloneContext& ctx) const {
// Construct the constant that holds the hoisted initializer // Construct the constant that holds the hoisted initializer
auto* dst_var = ctx.dst->Const(dst_symbol, dst_ty, dst_init); auto* dst_var = ctx.dst->Const(dst_symbol, dst_ty, dst_init);
// Construct the variable declaration statement // Construct the variable declaration statement
auto* dst_var_decl = auto* dst_var_decl = ctx.dst->Decl(dst_var);
ctx.dst->create<ast::VariableDeclStatement>(dst_var);
// Construct the identifier for referencing the constant // Construct the identifier for referencing the constant
auto* dst_ident = ctx.dst->Expr(dst_symbol); auto* dst_ident = ctx.dst->Expr(dst_symbol);
@ -127,10 +126,9 @@ void Hlsl::AddEmptyEntryPoint(CloneContext& ctx) const {
return; return;
} }
} }
ctx.dst->Func( ctx.dst->Func(ctx.dst->Symbols().New("tint_unused_entry_point"), {},
ctx.dst->Symbols().New("tint_unused_entry_point"), {}, ctx.dst->ty.void_(), {},
ctx.dst->ty.void_(), {}, {ctx.dst->Stage(ast::PipelineStage::kCompute)});
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
} }
} // namespace transform } // namespace transform

View File

@ -176,7 +176,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
auto* call = ctx.dst->Call(return_func_symbol, ctx.Clone(ret->value())); auto* call = ctx.dst->Call(return_func_symbol, ctx.Clone(ret->value()));
ctx.InsertBefore(ret_sem->Block()->statements(), ret, ctx.InsertBefore(ret_sem->Block()->statements(), ret,
ctx.dst->create<ast::CallStatement>(call)); 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; return;
} }
} }
ctx.dst->Func( ctx.dst->Func("_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {},
"_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {}, {ctx.dst->Stage(ast::PipelineStage::kCompute)});
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
} }
Symbol Spirv::HoistToInputVariables( Symbol Spirv::HoistToInputVariables(

View File

@ -117,12 +117,11 @@ struct State {
static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index"; static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index";
vertex_index_name = ctx.dst->Symbols().New(kDefaultVertexIndexName); vertex_index_name = ctx.dst->Symbols().New(kDefaultVertexIndexName);
ctx.dst->Global( ctx.dst->Global(vertex_index_name, ctx.dst->ty.u32(),
vertex_index_name, ctx.dst->ty.u32(), ast::StorageClass::kInput, ast::StorageClass::kInput, nullptr,
nullptr, ast::DecorationList{
ast::DecorationList{ ctx.dst->Builtin(ast::Builtin::kVertexIndex),
ctx.dst->create<ast::BuiltinDecoration>(ast::Builtin::kVertexIndex), });
});
} }
/// Inserts instance_index binding, or finds the existing one /// 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(), ctx.dst->Global(instance_index_name, ctx.dst->ty.u32(),
ast::StorageClass::kInput, nullptr, ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
ctx.dst->create<ast::BuiltinDecoration>( ctx.dst->Builtin(ast::Builtin::kInstanceIndex),
ast::Builtin::kInstanceIndex),
}); });
} }
@ -230,9 +228,9 @@ struct State {
ast::StatementList stmts; ast::StatementList stmts;
// Declare the pulling position variable in the shader // Declare the pulling position variable in the shader
stmts.emplace_back(ctx.dst->create<ast::VariableDeclStatement>( stmts.emplace_back(
ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(), ctx.dst->Decl(ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(),
ast::StorageClass::kFunction))); ast::StorageClass::kFunction)));
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i]; const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i];

View File

@ -24,7 +24,7 @@ using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) { TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
Global("lhs", ty.i32(), ast::StorageClass::kPrivate); Global("lhs", ty.i32(), ast::StorageClass::kPrivate);
Global("rhs", 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); WrapInFunction(assign);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -315,22 +315,16 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
Global("b", ty.bool_(), ast::StorageClass::kPrivate); Global("b", ty.bool_(), ast::StorageClass::kPrivate);
Global("c", ty.bool_(), ast::StorageClass::kPrivate); Global("c", ty.bool_(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(Return(3));
Return(Expr(3)),
});
auto* else_stmt = create<ast::ElseStatement>(nullptr, body); auto* else_stmt = create<ast::ElseStatement>(nullptr, body);
body = create<ast::BlockStatement>(ast::StatementList{ body = Block(Return(2));
Return(Expr(2)),
});
auto* else_if_stmt = create<ast::ElseStatement>( auto* else_if_stmt = create<ast::ElseStatement>(
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"), create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"),
Expr("c")), Expr("c")),
body); body);
body = create<ast::BlockStatement>(ast::StatementList{ body = Block(Return(1));
Return(Expr(1)),
});
auto* expr = create<ast::IfStatement>( auto* expr = create<ast::IfStatement>(
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("a"), 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("c", ty.bool_(), ast::StorageClass::kPrivate);
Global("d", 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>( Expr("a"), create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,

View File

@ -34,18 +34,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(), Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(),
ast::StatementList{ ast::StatementList{
Assign(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
Assign(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
Return(Construct(ty.vec4<f32>())), Return(Construct(ty.vec4<f32>())),
}, },
{Stage(ast::PipelineStage::kVertex)}, {Stage(ast::PipelineStage::kVertex)},
@ -77,18 +77,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(), Func("vtx_main", ast::VariableList{}, ty.vec4<f32>(),
ast::StatementList{ ast::StatementList{
Assign(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
Assign(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
Return(Construct(ty.vec4<f32>())), Return(Construct(ty.vec4<f32>())),
}, },
{Stage(ast::PipelineStage::kVertex)}, {Stage(ast::PipelineStage::kVertex)},
@ -120,21 +120,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -163,21 +163,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -203,21 +203,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -239,21 +239,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(1), Location(1),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;
@ -281,21 +281,20 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition), Builtin(ast::Builtin::kPosition),
}); });
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), Builtin(ast::Builtin::kFragDepth),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Assign("depth", MemberAccessor("coord", "x")),
MemberAccessor("coord", "x")),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
std::unordered_set<Symbol> globals; std::unordered_set<Symbol> globals;

View File

@ -106,10 +106,9 @@ TEST_F(HlslGeneratorImplTest_Function,
// fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 { // fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 {
// return foo; // return foo;
// } // }
auto* foo_in = Param("foo", ty.f32(), {create<ast::LocationDecoration>(0)}); auto* foo_in = Param("foo", ty.f32(), {Location(0)});
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return(Expr("foo"))}, Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return("foo")},
{Stage(ast::PipelineStage::kFragment)}, {Stage(ast::PipelineStage::kFragment)}, {Location(1)});
{create<ast::LocationDecoration>(1)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -138,12 +137,11 @@ TEST_F(HlslGeneratorImplTest_Function,
// return coord.x; // return coord.x;
// } // }
auto* coord_in = auto* coord_in =
Param("coord", ty.vec4<f32>(), Param("coord", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)});
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Func("frag_main", ast::VariableList{coord_in}, ty.f32(), Func("frag_main", ast::VariableList{coord_in}, ty.f32(),
{Return(MemberAccessor("coord", "x"))}, {Return(MemberAccessor("coord", "x"))},
{Stage(ast::PipelineStage::kFragment)}, {Stage(ast::PipelineStage::kFragment)},
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); {Builtin(ast::Builtin::kFragDepth)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -196,10 +194,9 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", {Param("inputs", interface_struct)}, ty.void_(), Func("frag_main", {Param("inputs", interface_struct)}, ty.void_(),
{ {
Decl(Const("r", ty.f32(), MemberAccessor(Expr("inputs"), "col1"))), Decl(Const("r", ty.f32(), MemberAccessor("inputs", "col1"))),
Decl(Const("g", ty.f32(), MemberAccessor(Expr("inputs"), "col2"))), Decl(Const("g", ty.f32(), MemberAccessor("inputs", "col2"))),
Decl(Const("p", ty.vec4<f32>(), Decl(Const("p", ty.vec4<f32>(), MemberAccessor("inputs", "pos"))),
MemberAccessor(Expr("inputs"), "pos"))),
}, },
{Stage(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
@ -257,13 +254,11 @@ TEST_F(HlslGeneratorImplTest_Function,
// } // }
auto* vertex_output_struct = Structure( auto* vertex_output_struct = Structure(
"VertexOutput", "VertexOutput",
{Member("pos", ty.vec4<f32>(), {Member("pos", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)})});
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)})});
Func("foo", {Param("x", ty.f32())}, vertex_output_struct, Func("foo", {Param("x", ty.f32())}, vertex_output_struct,
{Return(Construct(vertex_output_struct, {Return(Construct(vertex_output_struct,
Construct(ty.vec4<f32>(), Expr("x"), Expr("x"), Construct(ty.vec4<f32>(), "x", "x", "x", Expr(1.f))))},
Expr("x"), Expr(1.f))))},
{}); {});
Func("vert_main1", {}, vertex_output_struct, Func("vert_main1", {}, vertex_output_struct,
@ -374,12 +369,11 @@ TEST_F(HlslGeneratorImplTest_Function,
}); });
auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction, auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
create<ast::MemberAccessorExpression>( MemberAccessor(MemberAccessor("uniforms", "coord"), "x"));
MemberAccessor("uniforms", "coord"), Expr("x")));
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -427,7 +421,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -473,7 +467,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -516,8 +510,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"), Assign(MemberAccessor("coord", "b"), Expr(2.0f)),
Expr(2.0f)),
Return(), Return(),
}, },
{ {
@ -560,8 +553,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::AssignmentStatement>(MemberAccessor("coord", "b"), Assign(MemberAccessor("coord", "b"), Expr(2.0f)),
Expr(2.0f)),
Return(), Return(),
}, },
{ {
@ -591,35 +583,34 @@ TEST_F(
Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr,
{ {
create<ast::LocationDecoration>(0), Location(0),
}); });
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
{ {
create<ast::LocationDecoration>(1), Location(1),
}); });
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, 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(), Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
{ {
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), Assign("bar", "foo"),
create<ast::AssignmentStatement>(Expr("val"), Expr("param")), Assign("val", "param"),
Return(Expr("foo")), Return("foo"),
}); });
Func( Func("ep_1", ast::VariableList{}, ty.void_(),
"ep_1", ast::VariableList{}, ty.void_(), {
{ Assign("bar", Call("sub_func", 1.0f)),
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)), Return(),
Return(), },
}, {
{ Stage(ast::PipelineStage::kFragment),
Stage(ast::PipelineStage::kFragment), });
});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -654,18 +645,17 @@ TEST_F(HlslGeneratorImplTest_Function,
Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) { Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, 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(), Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
{ {
Return(Expr("param")), Return("param"),
}); });
Func("ep_1", ast::VariableList{}, ty.void_(), Func("ep_1", ast::VariableList{}, ty.void_(),
{ {
create<ast::AssignmentStatement>(Expr("depth"), Assign("depth", Call("sub_func", 1.0f)),
Call("sub_func", 1.0f)),
Return(), Return(),
}, },
{ {
@ -700,25 +690,23 @@ TEST_F(
Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, 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, 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(), Func("sub_func", ast::VariableList{Param("param", ty.f32())}, ty.f32(),
{ {
create<ast::AssignmentStatement>(Expr("depth"), Assign("depth", MemberAccessor("coord", "x")),
MemberAccessor("coord", "x")), Return("param"),
Return(Expr("param")),
}); });
Func("ep_1", ast::VariableList{}, ty.void_(), Func("ep_1", ast::VariableList{}, ty.void_(),
{ {
create<ast::AssignmentStatement>(Expr("depth"), Assign("depth", Call("sub_func", 1.0f)),
Call("sub_func", 1.0f)),
Return(), Return(),
}, },
{ {
@ -772,7 +760,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -823,7 +811,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -855,13 +843,13 @@ TEST_F(HlslGeneratorImplTest_Function,
Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) { Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr,
{ {
create<ast::LocationDecoration>(1), Location(1),
}); });
Func( Func(
"ep_1", ast::VariableList{}, ty.void_(), "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>( create<ast::IfStatement>(create<ast::BinaryExpression>(
ast::BinaryOp::kEqual, Expr(1), Expr(1)), ast::BinaryOp::kEqual, Expr(1), Expr(1)),
Block(Return()), ast::ElseStatementList{}), Block(Return()), ast::ElseStatementList{}),
@ -1010,7 +998,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("a", ast::VariableList{}, ty.void_(), Func("a", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -1024,7 +1012,7 @@ TEST_F(HlslGeneratorImplTest_Function,
Func("b", ast::VariableList{}, ty.void_(), Func("b", ast::VariableList{}, ty.void_(),
{ {
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {

View File

@ -416,7 +416,7 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Unpack2x16Float) {
TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) { TEST_F(HlslGeneratorImplTest_Intrinsic, StorageBarrier) {
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{create<ast::CallStatement>(Call("storageBarrier"))}, {create<ast::CallStatement>(Call("storageBarrier"))},
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)}); {Stage(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -435,7 +435,7 @@ void main() {
TEST_F(HlslGeneratorImplTest_Intrinsic, WorkgroupBarrier) { TEST_F(HlslGeneratorImplTest_Intrinsic, WorkgroupBarrier) {
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{create<ast::CallStatement>(Call("workgroupBarrier"))}, {create<ast::CallStatement>(Call("workgroupBarrier"))},
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)}); {Stage(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -364,7 +364,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
create<ast::CallStatement>(call), create<ast::CallStatement>(call),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();

View File

@ -25,7 +25,7 @@ using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(create<ast::DiscardStatement>());
auto* continuing = Block(); auto* continuing = Block();
auto* l = create<ast::LoopStatement>(body, continuing); auto* l = Loop(body, continuing);
WrapInFunction(l); WrapInFunction(l);
@ -43,7 +43,7 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(create<ast::DiscardStatement>());
auto* continuing = Block(Return()); auto* continuing = Block(Return());
auto* l = create<ast::LoopStatement>(body, continuing); auto* l = Loop(body, continuing);
WrapInFunction(l); WrapInFunction(l);
@ -72,16 +72,16 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(create<ast::DiscardStatement>());
auto* continuing = Block(Return()); auto* continuing = Block(Return());
auto* inner = create<ast::LoopStatement>(body, continuing); auto* inner = Loop(body, continuing);
body = Block(inner); body = Block(inner);
auto* lhs = Expr("lhs"); auto* lhs = Expr("lhs");
auto* rhs = Expr("rhs"); 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); WrapInFunction(outer);
GeneratorImpl& gen = Build(); 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* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f));
auto* body = Block(create<ast::VariableDeclStatement>(var), auto* body = Block(
create<ast::VariableDeclStatement>( Decl(var), Decl(Var("other", ty.f32(), ast::StorageClass::kFunction)));
Var("other", ty.f32(), ast::StorageClass::kFunction)));
auto* lhs = Expr("lhs"); auto* lhs = Expr("lhs");
auto* rhs = Expr("rhs"); auto* rhs = Expr("rhs");
auto* continuing = Block(create<ast::AssignmentStatement>(lhs, rhs)); auto* continuing = Block(Assign(lhs, rhs));
auto* outer = create<ast::LoopStatement>(body, continuing); auto* outer = Loop(body, continuing);
WrapInFunction(outer); WrapInFunction(outer);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -113,7 +113,7 @@ class HlslGeneratorImplTest_MemberAccessorBase : public BASE {
ProgramBuilder& b = *this; ProgramBuilder& b = *this;
b.Func("main", ast::VariableList{}, b.ty.void_(), statements, b.Func("main", ast::VariableList{}, b.ty.void_(), statements,
ast::DecorationList{ 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({ SetupFunction({
create<ast::VariableDeclStatement>(Var("x", nullptr, Decl(Var("x", nullptr, ast::StorageClass::kFunction,
ast::StorageClass::kFunction, MemberAccessor("data", "b"))),
MemberAccessor("data", "b"))),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -256,8 +255,7 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) {
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(Var("value", type, ast::StorageClass::kFunction, Construct(type))),
Var("value", type, ast::StorageClass::kFunction, Construct(type))),
Assign(MemberAccessor("data", "b"), Expr("value")), Assign(MemberAccessor("data", "b"), Expr("value")),
}); });
@ -386,7 +384,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(
Var("x", nullptr, ast::StorageClass::kFunction, Var("x", nullptr, ast::StorageClass::kFunction,
IndexAccessor(IndexAccessor(MemberAccessor("data", "a"), 2), 1))), IndexAccessor(IndexAccessor(MemberAccessor("data", "a"), 2), 1))),
}); });
@ -423,9 +421,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(Var("x", nullptr, ast::StorageClass::kFunction,
Var("x", nullptr, ast::StorageClass::kFunction, IndexAccessor(MemberAccessor("data", "a"), 2))),
IndexAccessor(MemberAccessor("data", "a"), 2))),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -458,10 +455,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(Var("x", nullptr, ast::StorageClass::kFunction,
Var("x", nullptr, ast::StorageClass::kFunction, IndexAccessor(MemberAccessor("data", "a"),
IndexAccessor(MemberAccessor("data", "a"), Sub(Add(2, Expr(4)), Expr(3))))),
Sub(Add(2, Expr(4)), Expr(3))))),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -534,7 +530,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) {
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>(Var( Decl(Var(
"x", nullptr, ast::StorageClass::kFunction, "x", nullptr, ast::StorageClass::kFunction,
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2), "b"))), MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2), "b"))),
}); });
@ -580,12 +576,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(Var("x", nullptr, ast::StorageClass::kFunction,
Var("x", nullptr, ast::StorageClass::kFunction, MemberAccessor(
MemberAccessor( MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2), "b"),
"b"), "xy"))),
"xy"))),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -629,12 +624,11 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>( Decl(Var("x", nullptr, ast::StorageClass::kFunction,
Var("x", nullptr, ast::StorageClass::kFunction, MemberAccessor(
MemberAccessor( MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2),
MemberAccessor(IndexAccessor(MemberAccessor("data", "c"), 2), "b"),
"b"), "g"))),
"g"))),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -678,7 +672,7 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
}); });
SetupFunction({ SetupFunction({
create<ast::VariableDeclStatement>(Var( Decl(Var(
"x", nullptr, ast::StorageClass::kFunction, "x", nullptr, ast::StorageClass::kFunction,
IndexAccessor(MemberAccessor( IndexAccessor(MemberAccessor(
IndexAccessor(MemberAccessor("data", "c"), 2), "b"), IndexAccessor(MemberAccessor("data", "c"), 2), "b"),

View File

@ -45,12 +45,11 @@ TEST_F(HlslSanitizerTest, ArrayLength) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>( Decl(Var("len", ty.u32(), ast::StorageClass::kFunction,
Var("len", ty.u32(), ast::StorageClass::kFunction, Call("arrayLength", MemberAccessor("sb", "arr")))),
Call("arrayLength", MemberAccessor("sb", "arr")))),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -80,10 +79,10 @@ TEST_F(HlslSanitizerTest, PromoteArrayInitializerToConstVar) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(pos), Decl(pos),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -114,10 +113,10 @@ TEST_F(HlslSanitizerTest, PromoteStructInitializerToConstVar) {
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(pos), Decl(pos),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();

View File

@ -336,7 +336,7 @@ TEST_P(HlslDepthTexturesTest, Emit) {
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{create<ast::CallStatement>(Call("textureDimensions", "tex"))}, {create<ast::CallStatement>(Call("textureDimensions", "tex"))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -395,7 +395,7 @@ TEST_P(HlslSampledTexturesTest, Emit) {
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{create<ast::CallStatement>(Call("textureDimensions", "tex"))}, {create<ast::CallStatement>(Call("textureDimensions", "tex"))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -539,7 +539,7 @@ TEST_P(HlslStorageTexturesTest, Emit) {
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(),
{create<ast::CallStatement>(Call("textureDimensions", "tex"))}, {create<ast::CallStatement>(Call("textureDimensions", "tex"))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -27,7 +27,7 @@ using HlslGeneratorImplTest_VariableDecl = TestHelper;
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction); auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ty.f32()); auto* var = Const("a", ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -96,7 +96,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
auto* var = auto* var =
Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, vec3<f32>()); Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, vec3<f32>());
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -111,7 +111,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
auto* var = auto* var =
Var("a", ty.mat2x3<f32>(), ast::StorageClass::kFunction, mat2x3<f32>()); Var("a", ty.mat2x3<f32>(), ast::StorageClass::kFunction, mat2x3<f32>());
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -28,9 +28,8 @@ using HlslGeneratorImplTest_WorkgroupVar = TestHelper;
TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) { TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) {
Global("wg", ty.f32(), ast::StorageClass::kWorkgroup); Global("wg", ty.f32(), ast::StorageClass::kWorkgroup);
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
{create<ast::AssignmentStatement>(Expr("wg"), Expr(1.2f))}, {Stage(ast::PipelineStage::kCompute)});
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
@ -45,9 +44,8 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) {
Global("wg", alias, ast::StorageClass::kWorkgroup); Global("wg", alias, ast::StorageClass::kWorkgroup);
Func("main", {}, ty.void_(), Func("main", {}, ty.void_(), {Assign("wg", 1.2f)},
{create<ast::AssignmentStatement>(Expr("wg"), Expr(1.2f))}, {Stage(ast::PipelineStage::kCompute)});
{create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();

View File

@ -24,7 +24,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Assign) { TEST_F(MslGeneratorImplTest, Emit_Assign) {
auto* lhs = Var("lhs", ty.i32(), ast::StorageClass::kFunction); auto* lhs = Var("lhs", ty.i32(), ast::StorageClass::kFunction);
auto* rhs = Var("rhs", 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); WrapInFunction(lhs, rhs, assign);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -32,14 +32,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, 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, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
Assign(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
Assign(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
Return(Construct(ty.vec4<f32>())), 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, 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, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
Assign(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
Assign(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
Return(Construct(ty.vec4<f32>())), 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, 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, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}; };
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -143,19 +143,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
// }; // };
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, 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, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}; };
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -177,19 +177,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
// -> Error, not allowed // -> Error, not allowed
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, 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, Global("bar", ty.i32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}; };
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -207,19 +207,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
// -> Error not allowed // -> Error not allowed
Global("foo", ty.f32(), ast::StorageClass::kOutput, nullptr, 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, Global("bar", ty.i32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{create<ast::LocationDecoration>(1)}); ast::DecorationList{Location(1)});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")), Assign("foo", "foo"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")), Assign("bar", "bar"),
}; };
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -242,19 +242,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
// }; // };
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{Builtin(ast::Builtin::kPosition)});
create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{Builtin(ast::Builtin::kFragDepth)});
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)});
auto body = ast::StatementList{create<ast::AssignmentStatement>( auto body = ast::StatementList{Assign("depth", MemberAccessor("coord", "x"))};
Expr("depth"), MemberAccessor("coord", "x"))};
Func("main", ast::VariableList{}, ty.void_(), body, Func("main", ast::VariableList{}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -95,10 +95,9 @@ TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOutVars) {
// fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 { // fn frag_main([[location(0)]] foo : f32) -> [[location(1)]] f32 {
// return foo; // return foo;
// } // }
auto* foo_in = Param("foo", ty.f32(), {create<ast::LocationDecoration>(0)}); auto* foo_in = Param("foo", ty.f32(), {Location(0)});
Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return(Expr("foo"))}, Func("frag_main", ast::VariableList{foo_in}, ty.f32(), {Return("foo")},
{Stage(ast::PipelineStage::kFragment)}, {Stage(ast::PipelineStage::kFragment)}, {Location(1)});
{create<ast::LocationDecoration>(1)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -128,12 +127,11 @@ TEST_F(MslGeneratorImplTest, Emit_Decoration_EntryPoint_WithInOut_Builtins) {
// return coord.x; // return coord.x;
// } // }
auto* coord_in = auto* coord_in =
Param("coord", ty.vec4<f32>(), Param("coord", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)});
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
Func("frag_main", ast::VariableList{coord_in}, ty.f32(), Func("frag_main", ast::VariableList{coord_in}, ty.f32(),
{Return(MemberAccessor("coord", "x"))}, {Return(MemberAccessor("coord", "x"))},
{Stage(ast::PipelineStage::kFragment)}, {Stage(ast::PipelineStage::kFragment)},
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); {Builtin(ast::Builtin::kFragDepth)});
GeneratorImpl& gen = SanitizeAndBuild(); GeneratorImpl& gen = SanitizeAndBuild();
@ -188,9 +186,9 @@ TEST_F(MslGeneratorImplTest,
Func("frag_main", {Param("colors", interface_struct)}, ty.void_(), Func("frag_main", {Param("colors", interface_struct)}, ty.void_(),
{ {
WrapInStatement( WrapInStatement(
Const("r", ty.f32(), MemberAccessor(Expr("colors"), "col1"))), Const("r", ty.f32(), MemberAccessor("colors", "col1"))),
WrapInStatement( WrapInStatement(
Const("g", ty.f32(), MemberAccessor(Expr("colors"), "col2"))), Const("g", ty.f32(), MemberAccessor("colors", "col2"))),
}, },
{Stage(ast::PipelineStage::kFragment)}); {Stage(ast::PipelineStage::kFragment)});
@ -249,13 +247,11 @@ TEST_F(MslGeneratorImplTest,
// } // }
auto* vertex_output_struct = Structure( auto* vertex_output_struct = Structure(
"VertexOutput", "VertexOutput",
{Member("pos", ty.vec4<f32>(), {Member("pos", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)})});
{create<ast::BuiltinDecoration>(ast::Builtin::kPosition)})});
Func("foo", {Param("x", ty.f32())}, vertex_output_struct, Func("foo", {Param("x", ty.f32())}, vertex_output_struct,
{Return(Construct(vertex_output_struct, {Return(Construct(vertex_output_struct,
Construct(ty.vec4<f32>(), Expr("x"), Expr("x"), Construct(ty.vec4<f32>(), "x", "x", "x", Expr(1.f))))},
Expr("x"), Expr(1.f))))},
{}); {});
Func("vert_main1", {}, vertex_output_struct, Func("vert_main1", {}, vertex_output_struct,
@ -321,7 +317,7 @@ TEST_F(MslGeneratorImplTest,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -366,7 +362,7 @@ TEST_F(MslGeneratorImplTest,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -396,27 +392,22 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
TEST_F( TEST_F(
MslGeneratorImplTest, MslGeneratorImplTest,
Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithLocationGlobals_And_Params) { // NOLINT
Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, Global("foo", ty.f32(), ast::StorageClass::kInput, nullptr, {Location(0)});
{create<ast::LocationDecoration>(0)});
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(1)});
{create<ast::LocationDecoration>(1)});
Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("val", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(0)});
{create<ast::LocationDecoration>(0)});
ast::VariableList params; ast::VariableList params;
params.push_back(Param("param", ty.f32())); params.push_back(Param("param", ty.f32()));
auto body = ast::StatementList{ auto body = ast::StatementList{Assign("bar", "foo"), Assign("val", "param"),
create<ast::AssignmentStatement>(Expr("bar"), Expr("foo")), Return("foo")};
create<ast::AssignmentStatement>(Expr("val"), Expr("param")),
Return(Expr("foo"))};
Func("sub_func", params, ty.f32(), body, {}); Func("sub_func", params, ty.f32(), body, {});
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Call("sub_func", 1.0f)), Assign("bar", Call("sub_func", 1.0f)),
Return(), Return(),
}; };
@ -459,19 +450,19 @@ fragment ep_1_out ep_1(ep_1_in _tint_in [[stage_in]]) {
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) { Emit_Decoration_Called_By_EntryPoints_NoUsedGlobals) {
Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); {Builtin(ast::Builtin::kFragDepth)});
ast::VariableList params; ast::VariableList params;
params.push_back(Param("param", ty.f32())); params.push_back(Param("param", ty.f32()));
Func("sub_func", params, ty.f32(), Func("sub_func", params, ty.f32(),
ast::StatementList{ ast::StatementList{
Return(Expr("param")), Return("param"),
}, },
{}); {});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), Assign("depth", Call("sub_func", 1.0f)),
Return(), Return(),
}; };
@ -508,24 +499,23 @@ TEST_F(
MslGeneratorImplTest, MslGeneratorImplTest,
Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT Emit_Decoration_Called_By_EntryPoints_WithBuiltinGlobals_And_Params) { // NOLINT
Global("coord", ty.vec4<f32>(), ast::StorageClass::kInput, nullptr, 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, Global("depth", ty.f32(), ast::StorageClass::kOutput, nullptr,
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); {Builtin(ast::Builtin::kFragDepth)});
ast::VariableList params; ast::VariableList params;
params.push_back(Param("param", ty.f32())); params.push_back(Param("param", ty.f32()));
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Assign("depth", MemberAccessor("coord", "x")),
MemberAccessor("coord", "x")), Return("param"),
Return(Expr("param")),
}; };
Func("sub_func", params, ty.f32(), body, {}); Func("sub_func", params, ty.f32(), body, {});
body = ast::StatementList{ body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("depth"), Call("sub_func", 1.0f)), Assign("depth", Call("sub_func", 1.0f)),
Return(), Return(),
}; };
@ -635,7 +625,7 @@ TEST_F(MslGeneratorImplTest,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -691,7 +681,7 @@ TEST_F(MslGeneratorImplTest,
Func("frag_main", ast::VariableList{}, ty.void_(), Func("frag_main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -724,15 +714,12 @@ fragment void frag_main(const device Data& coord [[buffer(0)]]) {
// TODO(crbug.com/tint/697): Remove this test // TODO(crbug.com/tint/697): Remove this test
TEST_F(MslGeneratorImplTest, TEST_F(MslGeneratorImplTest,
Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) { Emit_Decoration_EntryPoints_WithGlobal_Nested_Return) {
Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("bar", ty.f32(), ast::StorageClass::kOutput, nullptr, {Location(1)});
{create<ast::LocationDecoration>(1)});
auto* list = create<ast::BlockStatement>(ast::StatementList{ auto* list = Block(Return());
Return(),
});
auto body = ast::StatementList{ auto body = ast::StatementList{
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.f)), Assign("bar", Expr(1.f)),
create<ast::IfStatement>(create<ast::BinaryExpression>( create<ast::IfStatement>(create<ast::BinaryExpression>(
ast::BinaryOp::kEqual, Expr(1), Expr(1)), ast::BinaryOp::kEqual, Expr(1), Expr(1)),
list, ast::ElseStatementList{}), list, ast::ElseStatementList{}),
@ -823,7 +810,7 @@ TEST_F(MslGeneratorImplTest,
Func("a", ast::VariableList{}, ty.void_(), Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
Return(), Return(),
}, },
{ {
@ -836,7 +823,7 @@ TEST_F(MslGeneratorImplTest,
MemberAccessor("data", "d")); MemberAccessor("data", "d"));
Func("b", ast::VariableList{}, ty.void_(), Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{create<ast::VariableDeclStatement>(var), Return()}, ast::StatementList{Decl(var), Return()},
{Stage(ast::PipelineStage::kCompute)}); {Stage(ast::PipelineStage::kCompute)});
} }

View File

@ -23,11 +23,9 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Loop) { TEST_F(MslGeneratorImplTest, Emit_Loop) {
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(create<ast::DiscardStatement>());
create<ast::DiscardStatement>(), auto* continuing = Block();
}); auto* l = Loop(body, continuing);
auto* continuing = create<ast::BlockStatement>(ast::StatementList{});
auto* l = create<ast::LoopStatement>(body, continuing);
WrapInFunction(l); WrapInFunction(l);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -42,13 +40,9 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
} }
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(create<ast::DiscardStatement>());
create<ast::DiscardStatement>(), auto* continuing = Block(Return());
}); auto* l = Loop(body, continuing);
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* l = create<ast::LoopStatement>(body, continuing);
WrapInFunction(l); WrapInFunction(l);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -74,23 +68,15 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
Global("lhs", ty.f32(), ast::StorageClass::kInput); Global("lhs", ty.f32(), ast::StorageClass::kInput);
Global("rhs", ty.f32(), ast::StorageClass::kInput); Global("rhs", ty.f32(), ast::StorageClass::kInput);
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(create<ast::DiscardStatement>());
create<ast::DiscardStatement>(), auto* continuing = Block(Return());
}); auto* inner = Loop(body, continuing);
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* inner = create<ast::LoopStatement>(body, continuing);
body = create<ast::BlockStatement>(ast::StatementList{ body = Block(inner);
inner,
});
continuing = create<ast::BlockStatement>(ast::StatementList{ continuing = Block(Assign("lhs", "rhs"));
create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")),
});
auto* outer = create<ast::LoopStatement>(body, continuing); auto* outer = Loop(body, continuing);
WrapInFunction(outer); WrapInFunction(outer);
GeneratorImpl& gen = Build(); 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* var = Var("lhs", ty.f32(), ast::StorageClass::kFunction, Expr(2.4f));
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(
create<ast::VariableDeclStatement>(var), Decl(var), Decl(Var("other", ty.f32(), ast::StorageClass::kFunction)));
create<ast::VariableDeclStatement>(
Var("other", ty.f32(), ast::StorageClass::kFunction))});
auto* continuing = create<ast::BlockStatement>(ast::StatementList{ auto* continuing = Block(Assign("lhs", "rhs"));
create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")),
});
auto* outer = create<ast::LoopStatement>(body, continuing); auto* outer = Loop(body, continuing);
WrapInFunction(outer); WrapInFunction(outer);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -25,7 +25,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Generate) { TEST_F(MslGeneratorImplTest, Generate) {
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -27,7 +27,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kNone); auto* var = Var("a", ty.f32(), ast::StorageClass::kNone);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -40,7 +40,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
auto* var = Const("a", ty.f32()); auto* var = Const("a", ty.f32());
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -55,7 +55,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
sem::ArrayType ary(ty.f32(), 5, ast::DecorationList{}); sem::ArrayType ary(ty.f32(), 5, ast::DecorationList{});
auto* var = Var("a", &ary, ast::StorageClass::kNone); auto* var = Var("a", &ary, ast::StorageClass::kNone);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -73,7 +73,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
}); });
auto* var = Var("a", s, ast::StorageClass::kNone); auto* var = Var("a", s, ast::StorageClass::kNone);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -87,7 +87,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
auto* var = Var("a", ty.vec2<f32>(), ast::StorageClass::kFunction); auto* var = Var("a", ty.vec2<f32>(), ast::StorageClass::kFunction);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -101,7 +101,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
auto* var = Var("a", ty.mat3x2<f32>(), ast::StorageClass::kFunction); auto* var = Var("a", ty.mat3x2<f32>(), ast::StorageClass::kFunction);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -146,7 +146,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
auto* zero_vec = vec3<f32>(); auto* zero_vec = vec3<f32>();
auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, zero_vec); auto* var = Var("a", ty.vec3<f32>(), ast::StorageClass::kFunction, zero_vec);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -442,8 +442,8 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
auto* s_type = Structure("my_struct", {Member("inner", inner_struct)}); auto* s_type = Structure("my_struct", {Member("inner", inner_struct)});
auto* var = Global("ident", s_type, ast::StorageClass::kFunction); auto* var = Global("ident", s_type, ast::StorageClass::kFunction);
auto* expr = create<ast::AssignmentStatement>( auto* expr =
MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f)); Assign(MemberAccessor(MemberAccessor("ident", "inner"), "a"), Expr(2.0f));
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); 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* store = Global("store", ty.f32(), ast::StorageClass::kFunction);
auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a"); auto* rhs = MemberAccessor(MemberAccessor("ident", "inner"), "a");
auto* expr = create<ast::AssignmentStatement>(Expr("store"), rhs); auto* expr = Assign("store", rhs);
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -25,7 +25,7 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, Assign_Var) { TEST_F(BuilderTest, Assign_Var) {
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput); 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); WrapInFunction(assign);
@ -53,7 +53,7 @@ TEST_F(BuilderTest, Assign_Var) {
TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) { TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput); 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); WrapInFunction(assign);
@ -73,7 +73,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
auto* val = vec3<f32>(); auto* val = vec3<f32>();
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val); auto* assign = Assign("var", val);
WrapInFunction(assign); WrapInFunction(assign);
@ -103,7 +103,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); 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); WrapInFunction(assign);
@ -140,7 +140,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); 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); WrapInFunction(assign);
@ -183,8 +183,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
auto* v = Global("ident", s, ast::StorageClass::kFunction); auto* v = Global("ident", s, ast::StorageClass::kFunction);
auto* assign = auto* assign = Assign(MemberAccessor("ident", "b"), Expr(4.f));
create<ast::AssignmentStatement>(MemberAccessor("ident", "b"), Expr(4.f));
WrapInFunction(assign); WrapInFunction(assign);
@ -217,7 +216,7 @@ TEST_F(BuilderTest, Assign_Vector) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
auto* val = vec3<f32>(1.f, 1.f, 3.f); 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); WrapInFunction(assign);
@ -250,8 +249,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
auto* assign = auto* assign = Assign(MemberAccessor("var", "y"), Expr(1.f));
create<ast::AssignmentStatement>(MemberAccessor("var", "y"), Expr(1.f));
WrapInFunction(assign); WrapInFunction(assign);
@ -286,8 +284,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput); auto* v = Global("var", ty.vec3<f32>(), ast::StorageClass::kOutput);
auto* assign = auto* assign = Assign(IndexAccessor("var", 1), Expr(1.f));
create<ast::AssignmentStatement>(IndexAccessor("var", 1), Expr(1.f));
WrapInFunction(assign); WrapInFunction(assign);

View File

@ -27,15 +27,10 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, DISABLED_Block) { TEST_F(BuilderTest, DISABLED_Block) {
// Note, this test uses shadow variables which aren't allowed in WGSL but // 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. // serves to prove the block code is pushing new scopes as needed.
auto* inner = create<ast::BlockStatement>(ast::StatementList{ auto* inner = Block(Decl(Var("var", ty.f32(), ast::StorageClass::kFunction)),
create<ast::VariableDeclStatement>( Assign("var", 2.f));
Var("var", ty.f32(), ast::StorageClass::kFunction)), auto* outer = Block(Decl(Var("var", ty.f32(), ast::StorageClass::kFunction)),
create<ast::AssignmentStatement>(Expr("var"), Expr(2.f))}); Assign("var", 1.f), inner, Assign("var", 3.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))});
WrapInFunction(outer); WrapInFunction(outer);

View File

@ -31,8 +31,7 @@ TEST_F(BuilderTest, Expression_Call) {
auto* a_func = auto* a_func =
Func("a_func", func_params, ty.f32(), Func("a_func", func_params, ty.f32(),
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))}, ast::StatementList{Return(Add("a", "b"))}, ast::DecorationList{});
ast::DecorationList{});
auto* func = auto* func =
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{}); Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});
@ -78,8 +77,7 @@ TEST_F(BuilderTest, Statement_Call) {
auto* a_func = auto* a_func =
Func("a_func", func_params, ty.f32(), Func("a_func", func_params, ty.f32(),
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))}, ast::StatementList{Return(Add("a", "b"))}, ast::DecorationList{});
ast::DecorationList{});
auto* func = auto* func =
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{}); Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{});

View File

@ -44,15 +44,14 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
// } // }
auto f32 = ty.f32(); auto f32 = ty.f32();
auto* vec4 = ty.vec4<float>(); auto* vec4 = ty.vec4<float>();
auto* coord = Param( auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
"coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}); auto* loc1 = Param("loc1", f32, {Location(1u)});
auto* loc1 = Param("loc1", f32, {create<ast::LocationDecoration>(1u)});
auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1")); auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1"));
auto* col = Var("col", f32, ast::StorageClass::kFunction, mul, {}); auto* col = Var("col", f32, ast::StorageClass::kFunction, mul, {});
Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
ast::StatementList{WrapInStatement(col)}, ast::StatementList{WrapInStatement(col)},
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = SanitizeAndBuild(); spirv::Builder& b = SanitizeAndBuild();
@ -108,18 +107,18 @@ TEST_F(BuilderTest, EntryPoint_ReturnValue) {
// } // }
auto f32 = ty.f32(); auto f32 = ty.f32();
auto u32 = ty.u32(); 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, auto* cond = create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThan,
Expr("loc_in"), Expr(10u)); Expr("loc_in"), Expr(10u));
Func("frag_main", ast::VariableList{loc_in}, f32, Func("frag_main", ast::VariableList{loc_in}, f32,
ast::StatementList{ ast::StatementList{
If(cond, Block(create<ast::ReturnStatement>(Expr(0.5f)))), If(cond, Block(Return(0.5f))),
create<ast::ReturnStatement>(Expr(1.0f)), Return(1.0f),
}, },
ast::DecorationList{ 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(); spirv::Builder& b = SanitizeAndBuild();
@ -201,15 +200,14 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) {
}); });
auto* vert_retval = Construct(interface, 42.f, Construct(ty.vec4<f32>())); auto* vert_retval = Construct(interface, 42.f, Construct(ty.vec4<f32>()));
Func("vert_main", ast::VariableList{}, interface, Func("vert_main", ast::VariableList{}, interface, {Return(vert_retval)},
{create<ast::ReturnStatement>(vert_retval)}, {Stage(ast::PipelineStage::kVertex)});
{create<ast::StageDecoration>(ast::PipelineStage::kVertex)});
auto* frag_inputs = Param("inputs", interface); auto* frag_inputs = Param("inputs", interface);
Func("frag_main", ast::VariableList{frag_inputs}, ty.f32(), Func("frag_main", ast::VariableList{frag_inputs}, ty.f32(),
{create<ast::ReturnStatement>(MemberAccessor(Expr("inputs"), "value"))}, {Return(MemberAccessor(Expr("inputs"), "value"))},
{create<ast::StageDecoration>(ast::PipelineStage::kFragment)}, {Stage(ast::PipelineStage::kFragment)},
{create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth)}); {Builtin(ast::Builtin::kFragDepth)});
spirv::Builder& b = SanitizeAndBuild(); spirv::Builder& b = SanitizeAndBuild();

View File

@ -25,11 +25,10 @@ namespace {
using BuilderTest = TestHelper; using BuilderTest = TestHelper;
TEST_F(BuilderTest, Decoration_Stage) { TEST_F(BuilderTest, Decoration_Stage) {
auto* func = auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -61,7 +60,7 @@ TEST_P(Decoration_StageTest, Emit) {
auto* func = Func("main", {}, ty.void_(), body, auto* func = Func("main", {}, ty.void_(), body,
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(params.stage), Stage(params.stage),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -90,11 +89,10 @@ INSTANTIATE_TEST_SUITE_P(
SpvExecutionModelGLCompute})); SpvExecutionModelGLCompute}));
TEST_F(BuilderTest, Decoration_Stage_WithUnusedInterfaceIds) { TEST_F(BuilderTest, Decoration_Stage_WithUnusedInterfaceIds) {
auto* func = auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
auto* v_in = Global("my_in", ty.f32(), ast::StorageClass::kInput); auto* v_in = Global("my_in", ty.f32(), ast::StorageClass::kInput);
auto* v_out = Global("my_out", ty.f32(), ast::StorageClass::kOutput); 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_out = Global("my_out", ty.f32(), ast::StorageClass::kOutput);
auto* v_wg = Global("my_wg", ty.f32(), ast::StorageClass::kWorkgroup); auto* v_wg = Global("my_wg", ty.f32(), ast::StorageClass::kWorkgroup);
auto* func = auto* func = Func(
Func("main", {}, ty.void_(), "main", {}, ty.void_(),
ast::StatementList{ ast::StatementList{Assign("my_out", "my_in"), Assign("my_wg", "my_wg"),
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in")), // Add duplicate usages so we show they
create<ast::AssignmentStatement>(Expr("my_wg"), Expr("my_wg")), // don't get output multiple times.
// Add duplicate usages so we show they don't get Assign("my_out", "my_in")},
// output multiple times. ast::DecorationList{
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in"))}, Stage(ast::PipelineStage::kFragment),
ast::DecorationList{ });
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -174,11 +170,10 @@ OpName %11 "main"
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) { TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) {
auto* func = auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -189,11 +184,10 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) {
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) { TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) {
auto* func = auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kCompute),
create<ast::StageDecoration>(ast::PipelineStage::kCompute), });
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -204,12 +198,11 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) {
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize) { TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize) {
auto* func = auto* func = Func("main", {}, ty.void_(), ast::StatementList{},
Func("main", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ create<ast::WorkgroupDecoration>(2u, 4u, 6u),
create<ast::WorkgroupDecoration>(2u, 4u, 6u), Stage(ast::PipelineStage::kCompute),
create<ast::StageDecoration>(ast::PipelineStage::kCompute), });
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -220,17 +213,15 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize) {
} }
TEST_F(BuilderTest, Decoration_ExecutionMode_MultipleFragment) { TEST_F(BuilderTest, Decoration_ExecutionMode_MultipleFragment) {
auto* func1 = auto* func1 = Func("main1", {}, ty.void_(), ast::StatementList{},
Func("main1", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
auto* func2 = auto* func2 = Func("main2", {}, ty.void_(), ast::StatementList{},
Func("main2", {}, ty.void_(), ast::StatementList{}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -259,15 +250,14 @@ OpFunctionEnd
TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) { TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) {
Global("fragdepth", ty.f32(), ast::StorageClass::kOutput, nullptr, Global("fragdepth", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth), Builtin(ast::Builtin::kFragDepth),
}); });
auto* func = auto* func = Func("main", ast::VariableList{}, ty.void_(),
Func("main", ast::VariableList{}, ty.void_(), ast::StatementList{
ast::StatementList{ Assign("fragdepth", Expr(1.f)),
create<ast::AssignmentStatement>(Expr("fragdepth"), Expr(1.f)), },
}, ast::DecorationList{});
ast::DecorationList{});
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -44,7 +44,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_Return) { TEST_F(BuilderTest, Function_Terminator_Return) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -65,8 +65,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_Terminator_ReturnValue) { TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
Global("a", ty.f32(), ast::StorageClass::kPrivate); Global("a", ty.f32(), ast::StorageClass::kPrivate);
Func("a_func", {}, ty.f32(), Func("a_func", {}, ty.f32(), ast::StatementList{Return("a")},
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
ast::DecorationList{}); ast::DecorationList{});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -115,8 +114,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_WithParams) { TEST_F(BuilderTest, Function_WithParams) {
ast::VariableList params = {Param("a", ty.f32()), Param("b", ty.i32())}; ast::VariableList params = {Param("a", ty.f32()), Param("b", ty.i32())};
Func("a_func", params, ty.f32(), Func("a_func", params, ty.f32(), ast::StatementList{Return("a")},
ast::StatementList{create<ast::ReturnStatement>(Expr("a"))},
ast::DecorationList{}); ast::DecorationList{});
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -141,7 +139,7 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_WithBody) { TEST_F(BuilderTest, Function_WithBody) {
Func("a_func", {}, ty.void_(), Func("a_func", {}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -220,11 +218,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
Func("a", ast::VariableList{}, ty.void_(), Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ 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_(), Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
} }

View File

@ -144,7 +144,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
TEST_F(BuilderTest, GlobalVar_WithLocation) { TEST_F(BuilderTest, GlobalVar_WithLocation) {
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr, auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(5), Location(5),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -186,7 +186,7 @@ OpDecorate %1 DescriptorSet 3
TEST_F(BuilderTest, GlobalVar_WithBuiltin) { TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr, auto* v = Global("var", ty.f32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition), Builtin(ast::Builtin::kPosition),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -621,7 +621,7 @@ TEST_F(BuilderTest, SampleIndex) {
auto* var = auto* var =
Global("sample_index", ty.u32(), ast::StorageClass::kInput, nullptr, Global("sample_index", ty.u32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kSampleIndex), Builtin(ast::Builtin::kSampleIndex),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -655,18 +655,18 @@ TEST_F(BuilderTest, SampleMask) {
Global("mask_in", ty.u32(), ast::StorageClass::kInput, nullptr, Global("mask_in", ty.u32(), ast::StorageClass::kInput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kSampleMask), Builtin(ast::Builtin::kSampleMask),
}); });
Global("mask_out", ty.u32(), ast::StorageClass::kOutput, nullptr, Global("mask_out", ty.u32(), ast::StorageClass::kOutput, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kSampleMask), Builtin(ast::Builtin::kSampleMask),
}); });
Func("main", ast::VariableList{}, ty.void_(), Func("main", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::AssignmentStatement>(Expr("mask_out"), Expr("mask_in")), Assign("mask_out", "mask_in"),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
spirv::Builder& b = SanitizeAndBuild(); spirv::Builder& b = SanitizeAndBuild();

View File

@ -74,8 +74,7 @@ TEST_F(BuilderTest, If_WithStatements) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* expr = auto* expr =
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{}); create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
WrapInFunction(expr); WrapInFunction(expr);
@ -112,10 +111,8 @@ TEST_F(BuilderTest, If_WithElse) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))}); auto* else_body = Block(Assign("v", 3));
auto* else_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
auto* expr = create<ast::IfStatement>( auto* expr = create<ast::IfStatement>(
Expr(true), body, Expr(true), body,
@ -158,10 +155,8 @@ TEST_F(BuilderTest, If_WithElseIf) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))}); auto* else_body = Block(Assign("v", 3));
auto* else_body = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
auto* expr = create<ast::IfStatement>( auto* expr = create<ast::IfStatement>(
Expr(true), body, Expr(true), body,
@ -215,14 +210,10 @@ TEST_F(BuilderTest, If_WithMultiple) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))}); auto* elseif_1_body = Block(Assign("v", 3));
auto* elseif_1_body = create<ast::BlockStatement>( auto* elseif_2_body = Block(Assign("v", 4));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))}); auto* else_body = Block(Assign("v", 5));
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* expr = create<ast::IfStatement>( auto* expr = create<ast::IfStatement>(
Expr(true), body, Expr(true), body,
@ -294,7 +285,7 @@ TEST_F(BuilderTest, If_WithBreak) {
auto* loop_body = Block(if_stmt); auto* loop_body = Block(if_stmt);
auto* expr = create<ast::LoopStatement>(loop_body, Block()); auto* expr = Loop(loop_body, Block());
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -338,7 +329,7 @@ TEST_F(BuilderTest, If_WithElseBreak) {
auto* loop_body = Block(if_stmt); auto* loop_body = Block(if_stmt);
auto* expr = create<ast::LoopStatement>(loop_body, Block()); auto* expr = Loop(loop_body, Block());
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -382,7 +373,7 @@ TEST_F(BuilderTest, If_WithContinue) {
auto* loop_body = Block(if_stmt); auto* loop_body = Block(if_stmt);
auto* expr = create<ast::LoopStatement>(loop_body, Block()); auto* expr = Loop(loop_body, Block());
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -426,7 +417,7 @@ TEST_F(BuilderTest, If_WithElseContinue) {
auto* loop_body = Block(if_stmt); auto* loop_body = Block(if_stmt);
auto* expr = create<ast::LoopStatement>(loop_body, Block()); auto* expr = Loop(loop_body, Block());
WrapInFunction(expr); WrapInFunction(expr);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -461,7 +452,7 @@ TEST_F(BuilderTest, If_WithReturn) {
// if (true) { // if (true) {
// return; // return;
// } // }
auto* if_body = Block(create<ast::ReturnStatement>()); auto* if_body = Block(Return());
auto* expr = auto* expr =
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{}); create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
@ -489,9 +480,9 @@ TEST_F(BuilderTest, If_WithReturnValue) {
// return false; // return false;
// } // }
// return true; // return true;
auto* if_body = Block(Return(Expr(false))); auto* if_body = Block(Return(false));
auto* expr = If(Expr(true), if_body); 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(); spirv::Builder& b = Build();
b.push_function(Function{}); b.push_function(Function{});

View File

@ -1257,11 +1257,11 @@ TEST_F(IntrinsicBuilderTest, Call_Modf) {
auto* expr = Call("modf", vec2<f32>(1.0f, 2.0f), "out"); auto* expr = Call("modf", vec2<f32>(1.0f, 2.0f), "out");
Func("a_func", ast::VariableList{}, ty.void_(), Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(out), Decl(out),
create<ast::CallStatement>(expr), create<ast::CallStatement>(expr),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -1301,11 +1301,11 @@ TEST_F(IntrinsicBuilderTest, Call_Frexp) {
auto* expr = Call("frexp", vec2<f32>(1.0f, 2.0f), "out"); auto* expr = Call("frexp", vec2<f32>(1.0f, 2.0f), "out");
Func("a_func", ast::VariableList{}, ty.void_(), Func("a_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(out), Decl(out),
create<ast::CallStatement>(expr), create<ast::CallStatement>(expr),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -1395,7 +1395,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
create<ast::CallStatement>(expr), create<ast::CallStatement>(expr),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -1445,7 +1445,7 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
create<ast::CallStatement>(expr), create<ast::CallStatement>(expr),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -1605,7 +1605,7 @@ TEST_F(IntrinsicBuilderTest, Call_WorkgroupBarrier) {
create<ast::CallStatement>(Call("workgroupBarrier")), create<ast::CallStatement>(Call("workgroupBarrier")),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -1637,7 +1637,7 @@ TEST_F(IntrinsicBuilderTest, Call_StorageBarrier) {
create<ast::CallStatement>(Call("storageBarrier")), create<ast::CallStatement>(Call("storageBarrier")),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -3494,7 +3494,7 @@ TEST_P(IntrinsicTextureTest, ValidateSPIRV) {
create<ast::CallStatement>(call), create<ast::CallStatement>(call),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kFragment), Stage(ast::PipelineStage::kFragment),
}); });
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -26,9 +26,7 @@ TEST_F(BuilderTest, Loop_Empty) {
// loop { // loop {
// } // }
auto* loop = create<ast::LoopStatement>( auto* loop = Loop(Block(), Block());
create<ast::BlockStatement>(ast::StatementList{}),
create<ast::BlockStatement>(ast::StatementList{}));
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -55,11 +53,9 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* loop = create<ast::LoopStatement>( auto* loop = Loop(body, Block());
body, create<ast::BlockStatement>(ast::StatementList{}));
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -97,12 +93,10 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
// } // }
auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* var = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* body = create<ast::BlockStatement>( auto* body = Block(Assign("v", 2));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))}); auto* continuing = Block(Assign("v", 3));
auto* continuing = create<ast::BlockStatement>(
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
auto* loop = create<ast::LoopStatement>(body, continuing); auto* loop = Loop(body, continuing);
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -143,11 +137,10 @@ TEST_F(BuilderTest, Loop_WithBodyVariableAccessInContinuing) {
auto* var = Var("a", ty.i32(), ast::StorageClass::kFunction); auto* var = Var("a", ty.i32(), ast::StorageClass::kFunction);
auto* var_decl = WrapInStatement(var); auto* var_decl = WrapInStatement(var);
auto* body = create<ast::BlockStatement>(ast::StatementList{var_decl}); auto* body = Block(var_decl);
auto* continuing = create<ast::BlockStatement>( auto* continuing = Block(Assign("a", 3));
ast::StatementList{create<ast::AssignmentStatement>(Expr("a"), Expr(3))});
auto* loop = create<ast::LoopStatement>(body, continuing); auto* loop = Loop(body, continuing);
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -178,11 +171,8 @@ TEST_F(BuilderTest, Loop_WithContinue) {
// loop { // loop {
// continue; // continue;
// } // }
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(create<ast::ContinueStatement>());
create<ast::ContinueStatement>(), auto* loop = Loop(body, Block());
});
auto* loop = create<ast::LoopStatement>(
body, create<ast::BlockStatement>(ast::StatementList{}));
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();
@ -207,11 +197,8 @@ TEST_F(BuilderTest, Loop_WithBreak) {
// loop { // loop {
// break; // break;
// } // }
auto* body = create<ast::BlockStatement>(ast::StatementList{ auto* body = Block(create<ast::BreakStatement>());
create<ast::BreakStatement>(), auto* loop = Loop(body, Block());
});
auto* loop = create<ast::LoopStatement>(
body, create<ast::BlockStatement>(ast::StatementList{}));
WrapInFunction(loop); WrapInFunction(loop);
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -62,7 +62,7 @@ TEST_F(BuilderTest, Return_WithValue) {
TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) { TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
auto* var = Global("param", ty.f32(), ast::StorageClass::kFunction); auto* var = Global("param", ty.f32(), ast::StorageClass::kFunction);
auto* ret = Return(Expr("param")); auto* ret = Return(var);
Func("test", {}, ty.f32(), {ret}, {}); Func("test", {}, ty.f32(), {ret}, {});
spirv::Builder& b = Build(); spirv::Builder& b = Build();

View File

@ -178,8 +178,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate); auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
auto* default_body = create<ast::BlockStatement>( auto* default_body = Block(Assign("v", 1));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back( cases.push_back(
@ -238,14 +237,11 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate); auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
auto* case_1_body = create<ast::BlockStatement>( auto* case_1_body = Block(Assign("v", Expr(1)));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
auto* case_2_body = create<ast::BlockStatement>( auto* case_2_body = Block(Assign("v", Expr(2)));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* default_body = create<ast::BlockStatement>( auto* default_body = Block(Assign("v", Expr(3)));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(Literal(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* v = Global("v", ty.i32(), ast::StorageClass::kPrivate);
auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate); auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate);
auto* case_1_body = create<ast::BlockStatement>( auto* case_1_body =
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)), Block(Assign("v", Expr(1)), create<ast::FallthroughStatement>());
create<ast::FallthroughStatement>()});
auto* case_2_body = create<ast::BlockStatement>( auto* case_2_body = Block(Assign("v", Expr(2)));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
auto* default_body = create<ast::BlockStatement>( auto* default_body = Block(Assign("v", Expr(3)));
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(Literal(1)); selector_1.push_back(Literal(1));

View File

@ -22,9 +22,9 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Assign) { TEST_F(WgslGeneratorImplTest, Emit_Assign) {
Global("lhs", ty.i32(), ast::StorageClass::kPrivate); auto* lhs = Global("lhs", ty.i32(), ast::StorageClass::kPrivate);
Global("rhs", ty.i32(), ast::StorageClass::kPrivate); auto* rhs = Global("rhs", ty.i32(), ast::StorageClass::kPrivate);
auto* assign = create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")); auto* assign = Assign(lhs, rhs);
WrapInFunction(assign); WrapInFunction(assign);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -38,7 +38,7 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedFunction) {
create<ast::CallStatement>(call_func), create<ast::CallStatement>(call_func),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -65,10 +65,10 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_UnusedVariable) {
Func("main", {}, ty.void_(), 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(); GeneratorImpl& gen = Build();
@ -105,10 +105,10 @@ TEST_F(WgslGeneratorImplTest, Emit_EntryPoint_GlobalsInterleaved) {
{ {
Decl(Var("s0", s0, ast::StorageClass::kFunction)), Decl(Var("s0", s0, ast::StorageClass::kFunction)),
Decl(Var("s1", s1, 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(); GeneratorImpl& gen = Build();

View File

@ -30,7 +30,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(), auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::DiscardStatement>(), create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -52,7 +52,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) {
ty.void_(), ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::DiscardStatement>(), create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -72,7 +72,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
auto* func = Func("my_func", ast::VariableList{}, ty.void_(), auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::DiscardStatement>(), create<ast::DiscardStatement>(),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::WorkgroupDecoration>(2u, 4u, 6u), create<ast::WorkgroupDecoration>(2u, 4u, 6u),
@ -92,15 +92,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
auto* func = auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{
ast::StatementList{ create<ast::DiscardStatement>(),
create<ast::DiscardStatement>(), Return(),
create<ast::ReturnStatement>(), },
}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), });
});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -116,16 +115,15 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
auto* func = auto* func = Func("my_func", ast::VariableList{}, ty.void_(),
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{
ast::StatementList{ create<ast::DiscardStatement>(),
create<ast::DiscardStatement>(), Return(),
create<ast::ReturnStatement>(), },
}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), create<ast::WorkgroupDecoration>(2u, 4u, 6u),
create<ast::WorkgroupDecoration>(2u, 4u, 6u), });
});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -143,15 +141,13 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) {
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
auto* vec4 = ty.vec4<f32>(); auto* vec4 = ty.vec4<f32>();
auto* coord = Param( auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)});
"coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)}); auto* loc1 = Param("loc1", ty.f32(), {Location(1u)});
auto* loc1 = Param("loc1", ty.f32(), {create<ast::LocationDecoration>(1u)}); auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(),
auto* func = ast::StatementList{},
Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), ast::DecorationList{
ast::StatementList{}, Stage(ast::PipelineStage::kFragment),
ast::DecorationList{ });
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -165,17 +161,16 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) { TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_ReturnValue) {
auto* func = auto* func = Func("frag_main", ast::VariableList{}, ty.f32(),
Func("frag_main", ast::VariableList{}, ty.f32(), ast::StatementList{
ast::StatementList{ Return(1.f),
create<ast::ReturnStatement>(Expr(1.f)), },
}, ast::DecorationList{
ast::DecorationList{ Stage(ast::PipelineStage::kFragment),
create<ast::StageDecoration>(ast::PipelineStage::kFragment), },
}, ast::DecorationList{
ast::DecorationList{ Location(1u),
create<ast::LocationDecoration>(1u), });
});
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -219,32 +214,30 @@ TEST_F(WgslGeneratorImplTest,
}); });
{ {
auto* var = auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
Var("v", ty.f32(), ast::StorageClass::kFunction, MemberAccessor("data", "d"));
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")));
Func("a", ast::VariableList{}, ty.void_(), Func("a", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
} }
{ {
auto* var = auto* var = Var("v", ty.f32(), ast::StorageClass::kFunction,
Var("v", ty.f32(), ast::StorageClass::kFunction, MemberAccessor("data", "d"));
create<ast::MemberAccessorExpression>(Expr("data"), Expr("d")));
Func("b", ast::VariableList{}, ty.void_(), Func("b", ast::VariableList{}, ty.void_(),
ast::StatementList{ ast::StatementList{
create<ast::VariableDeclStatement>(var), Decl(var),
create<ast::ReturnStatement>(), Return(),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
} }

View File

@ -52,7 +52,7 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
Func("func", ast::VariableList{}, ty.f32(), Func("func", ast::VariableList{}, ty.f32(),
ast::StatementList{ ast::StatementList{
create<ast::ReturnStatement>(Expr("a0")), Return("a0"),
}, },
ast::DecorationList{}); ast::DecorationList{});
@ -64,10 +64,10 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalsInterleaved) {
ast::StatementList{ ast::StatementList{
Decl(Var("s0", s0, ast::StorageClass::kFunction)), Decl(Var("s0", s0, ast::StorageClass::kFunction)),
Decl(Var("s1", s1, ast::StorageClass::kFunction)), Decl(Var("s1", s1, ast::StorageClass::kFunction)),
create<ast::AssignmentStatement>(Expr("a1"), Call("func")), Assign("a1", Call("func")),
}, },
ast::DecorationList{ ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kCompute), Stage(ast::PipelineStage::kCompute),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -24,7 +24,7 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Loop) { TEST_F(WgslGeneratorImplTest, Emit_Loop) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(create<ast::DiscardStatement>());
auto* continuing = Block(); auto* continuing = Block();
auto* l = create<ast::LoopStatement>(body, continuing); auto* l = Loop(body, continuing);
WrapInFunction(l); WrapInFunction(l);
@ -42,7 +42,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) {
TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) {
auto* body = Block(create<ast::DiscardStatement>()); auto* body = Block(create<ast::DiscardStatement>());
auto* continuing = Block(Return()); auto* continuing = Block(Return());
auto* l = create<ast::LoopStatement>(body, continuing); auto* l = Loop(body, continuing);
WrapInFunction(l); WrapInFunction(l);

View File

@ -48,7 +48,7 @@ TEST_P(WgslBuiltinConversionTest, Emit) {
auto* var = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr, auto* var = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(params.builtin), Builtin(params.builtin),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -275,9 +275,8 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointDecorations) {
auto* s = Structure( auto* s = Structure(
"S", "S",
ast::StructMemberList{ ast::StructMemberList{
Member("a", ty.u32(), Member("a", ty.u32(), {Builtin(ast::Builtin::kVertexIndex)}),
{create<ast::BuiltinDecoration>(ast::Builtin::kVertexIndex)}), Member("b", ty.f32(), {Location(2u)})},
Member("b", ty.f32(), {create<ast::LocationDecoration>(2u)})},
decos); decos);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -25,7 +25,7 @@ using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) { TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction); auto* var = Var("a", ty.f32(), ast::StorageClass::kFunction);
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -39,7 +39,7 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement) {
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) { TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) {
auto* var = Var("a", nullptr, ast::StorageClass::kFunction, Expr(123)); auto* var = Var("a", nullptr, ast::StorageClass::kFunction, Expr(123));
auto* stmt = create<ast::VariableDeclStatement>(var); auto* stmt = Decl(var);
WrapInFunction(stmt); WrapInFunction(stmt);
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();

View File

@ -45,7 +45,7 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_StorageClass) {
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) { TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr, auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::LocationDecoration>(2), Location(2),
}); });
GeneratorImpl& gen = Build(); GeneratorImpl& gen = Build();
@ -58,10 +58,10 @@ TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated) {
TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) { TEST_F(WgslGeneratorImplTest, EmitVariable_Decorated_Multiple) {
auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr, auto* v = Global("a", ty.f32(), ast::StorageClass::kPrivate, nullptr,
ast::DecorationList{ ast::DecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kPosition), Builtin(ast::Builtin::kPosition),
create<ast::BindingDecoration>(0), create<ast::BindingDecoration>(0),
create<ast::GroupDecoration>(1), create<ast::GroupDecoration>(1),
create<ast::LocationDecoration>(2), Location(2),
create<ast::ConstantIdDecoration>(42), create<ast::ConstantIdDecoration>(42),
}); });