writer/spirv tests: Replace std::make_unique<T> -> create<T>
create() is currently just a simple forwarder to std::make_unique<>, but will be later replaced with a function that returns a raw pointer, and owned by the context. Bug: tint:322 Change-Id: I5321553847b6a7d47ac211ba093d219c7f3bb9bd Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32673 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
4c88cd93ec
commit
16b1b9438d
|
@ -56,9 +56,9 @@ TEST_F(BuilderTest, ArrayAccessor) {
|
|||
|
||||
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto idx_expr = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
auto ary = create<ast::IdentifierExpression>("ary");
|
||||
auto idx_expr = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
||||
|
||||
|
@ -98,8 +98,8 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
|
|||
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
|
||||
ast::Variable idx("idx", ast::StorageClass::kFunction, &i32);
|
||||
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto idx_expr = std::make_unique<ast::IdentifierExpression>("idx");
|
||||
auto ary = create<ast::IdentifierExpression>("ary");
|
||||
auto idx_expr = create<ast::IdentifierExpression>("idx");
|
||||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
|
||||
|
||||
|
@ -142,15 +142,15 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
|
|||
|
||||
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto ary = create<ast::IdentifierExpression>("ary");
|
||||
|
||||
ast::ArrayAccessorExpression expr(
|
||||
std::move(ary), std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
std::move(ary),
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -190,12 +190,12 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
|
|||
ast::Variable var("ary", ast::StorageClass::kFunction, &ary4);
|
||||
|
||||
ast::ArrayAccessorExpression expr(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ary"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
create<ast::ArrayAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ary"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -237,11 +237,11 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
|
|||
ast::Variable var("ary", ast::StorageClass::kFunction, &ary4);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ary"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||
std::make_unique<ast::IdentifierExpression>("xy"));
|
||||
create<ast::ArrayAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ary"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))),
|
||||
create<ast::IdentifierExpression>("xy"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -284,19 +284,16 @@ TEST_F(BuilderTest, MemberAccessor) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("b"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -337,27 +334,27 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
|
|||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList inner_members;
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
ast::type::StructType inner_struct(
|
||||
"Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
|
||||
"Inner", create<ast::Struct>(std::move(inner_members)));
|
||||
|
||||
ast::StructMemberList outer_members;
|
||||
outer_members.push_back(std::make_unique<ast::StructMember>(
|
||||
"inner", &inner_struct, std::move(decos)));
|
||||
outer_members.push_back(
|
||||
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
|
||||
|
||||
ast::type::StructType s_type(
|
||||
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
|
||||
ast::type::StructType s_type("my_struct",
|
||||
create<ast::Struct>(std::move(outer_members)));
|
||||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("inner")),
|
||||
create<ast::IdentifierExpression>("a"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -400,29 +397,29 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
|
|||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList inner_members;
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
ast::type::StructType inner_struct(
|
||||
"Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
|
||||
"Inner", create<ast::Struct>(std::move(inner_members)));
|
||||
|
||||
ast::type::AliasType alias("Inner", &inner_struct);
|
||||
|
||||
ast::StructMemberList outer_members;
|
||||
outer_members.push_back(
|
||||
std::make_unique<ast::StructMember>("inner", &alias, std::move(decos)));
|
||||
create<ast::StructMember>("inner", &alias, std::move(decos)));
|
||||
|
||||
ast::type::StructType s_type(
|
||||
"Outer", std::make_unique<ast::Struct>(std::move(outer_members)));
|
||||
ast::type::StructType s_type("Outer",
|
||||
create<ast::Struct>(std::move(outer_members)));
|
||||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("inner")),
|
||||
create<ast::IdentifierExpression>("a"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -465,30 +462,30 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
|
|||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList inner_members;
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
ast::type::StructType inner_struct(
|
||||
"Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
|
||||
"Inner", create<ast::Struct>(std::move(inner_members)));
|
||||
|
||||
ast::StructMemberList outer_members;
|
||||
outer_members.push_back(std::make_unique<ast::StructMember>(
|
||||
"inner", &inner_struct, std::move(decos)));
|
||||
outer_members.push_back(
|
||||
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
|
||||
|
||||
ast::type::StructType s_type(
|
||||
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
|
||||
ast::type::StructType s_type("my_struct",
|
||||
create<ast::Struct>(std::move(outer_members)));
|
||||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
|
||||
|
||||
auto lhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
auto lhs = create<ast::MemberAccessorExpression>(
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("inner")),
|
||||
create<ast::IdentifierExpression>("a"));
|
||||
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.f));
|
||||
|
||||
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -535,30 +532,30 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
|
|||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList inner_members;
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
inner_members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
ast::type::StructType inner_struct(
|
||||
"Inner", std::make_unique<ast::Struct>(std::move(inner_members)));
|
||||
"Inner", create<ast::Struct>(std::move(inner_members)));
|
||||
|
||||
ast::StructMemberList outer_members;
|
||||
outer_members.push_back(std::make_unique<ast::StructMember>(
|
||||
"inner", &inner_struct, std::move(decos)));
|
||||
outer_members.push_back(
|
||||
create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
|
||||
|
||||
ast::type::StructType s_type(
|
||||
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members)));
|
||||
ast::type::StructType s_type("my_struct",
|
||||
create<ast::Struct>(std::move(outer_members)));
|
||||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
|
||||
ast::Variable store("store", ast::StorageClass::kFunction, &f32);
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("store");
|
||||
auto lhs = create<ast::IdentifierExpression>("store");
|
||||
|
||||
auto rhs = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("inner")),
|
||||
std::make_unique<ast::IdentifierExpression>("a"));
|
||||
auto rhs = create<ast::MemberAccessorExpression>(
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("inner")),
|
||||
create<ast::IdentifierExpression>("a"));
|
||||
|
||||
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -601,9 +598,8 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
|
|||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("y"));
|
||||
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("y"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -637,9 +633,8 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
|
|||
|
||||
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("yx"));
|
||||
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("yx"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -673,10 +668,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
|
|||
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||
std::make_unique<ast::IdentifierExpression>("xz"));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("yxz")),
|
||||
create<ast::IdentifierExpression>("xz"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -711,10 +706,10 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
|
|||
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||
std::make_unique<ast::IdentifierExpression>("x"));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("yxz")),
|
||||
create<ast::IdentifierExpression>("x"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -749,11 +744,11 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
|
|||
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
|
||||
|
||||
ast::ArrayAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("yxz")),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("yxz")),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -799,21 +794,20 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("baz", &vec3, std::move(decos)));
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
members.push_back(create<ast::StructMember>("baz", &vec3, std::move(decos)));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType c_type("C", std::move(s));
|
||||
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("bar", &c_type, std::move(decos)));
|
||||
s = std::make_unique<ast::Struct>(std::move(members));
|
||||
create<ast::StructMember>("bar", &c_type, std::move(decos)));
|
||||
s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType b_type("B", std::move(s));
|
||||
|
||||
ast::type::ArrayType b_ary_type(&b_type, 3);
|
||||
|
||||
members.push_back(std::make_unique<ast::StructMember>("foo", &b_ary_type,
|
||||
std::move(decos)));
|
||||
s = std::make_unique<ast::Struct>(std::move(members));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("foo", &b_ary_type, std::move(decos)));
|
||||
s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType a_type("A", std::move(s));
|
||||
|
||||
ast::type::ArrayType a_ary_type(&a_type, 2);
|
||||
|
@ -821,20 +815,20 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
|
|||
ast::Variable var("index", ast::StorageClass::kFunction, &a_ary_type);
|
||||
|
||||
ast::MemberAccessorExpression expr(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("index"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 0))),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")),
|
||||
std::make_unique<ast::IdentifierExpression>("baz")),
|
||||
std::make_unique<ast::IdentifierExpression>("yx"));
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::ArrayAccessorExpression>(
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::ArrayAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("index"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 0))),
|
||||
create<ast::IdentifierExpression>("foo")),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))),
|
||||
create<ast::IdentifierExpression>("bar")),
|
||||
create<ast::IdentifierExpression>("baz")),
|
||||
create<ast::IdentifierExpression>("yx"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -888,36 +882,35 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
|||
ast::ExpressionList ary_params;
|
||||
|
||||
ast::ExpressionList vec_params;
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.0)));
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.5)));
|
||||
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vec_params)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 0.0)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 0.5)));
|
||||
ary_params.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
|
||||
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, -0.5)));
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, -0.5)));
|
||||
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vec_params)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, -0.5)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, -0.5)));
|
||||
ary_params.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
|
||||
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 0.5)));
|
||||
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, -0.5)));
|
||||
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(vec_params)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 0.5)));
|
||||
vec_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, -0.5)));
|
||||
ary_params.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
|
||||
|
||||
ast::Variable var("pos", ast::StorageClass::kPrivate, &arr);
|
||||
var.set_is_const(true);
|
||||
var.set_constructor(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&arr, std::move(ary_params)));
|
||||
var.set_constructor(
|
||||
create<ast::TypeConstructorExpression>(&arr, std::move(ary_params)));
|
||||
|
||||
ast::ArrayAccessorExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("pos"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
ast::ArrayAccessorExpression expr(create<ast::IdentifierExpression>("pos"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error();
|
||||
|
|
|
@ -47,9 +47,9 @@ TEST_F(BuilderTest, Assign_Var) {
|
|||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &f32);
|
||||
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f));
|
||||
auto ident = create<ast::IdentifierExpression>("var");
|
||||
auto val = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
@ -81,10 +81,9 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
|||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec);
|
||||
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto ident = create<ast::IdentifierExpression>("var");
|
||||
ast::ExpressionList vals;
|
||||
auto val =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto val = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
@ -116,24 +115,22 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
|||
ast::type::VectorType vec2(&f32, 2);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
auto first =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec2, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
auto first = create<ast::TypeConstructorExpression>(&vec2, std::move(vals));
|
||||
|
||||
vals.push_back(std::move(first));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
|
||||
|
||||
ast::AssignmentStatement assign(
|
||||
std::make_unique<ast::IdentifierExpression>("var"), std::move(init));
|
||||
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
|
||||
std::move(init));
|
||||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
@ -169,20 +166,19 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
|
||||
|
||||
ast::AssignmentStatement assign(
|
||||
std::make_unique<ast::IdentifierExpression>("var"), std::move(init));
|
||||
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
|
||||
std::move(init));
|
||||
|
||||
td.RegisterVariableForTesting(&v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
|
@ -220,22 +216,20 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
ast::Variable v("ident", ast::StorageClass::kFunction, &s_type);
|
||||
|
||||
auto ident = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("ident"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"));
|
||||
auto ident = create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("ident"),
|
||||
create<ast::IdentifierExpression>("b"));
|
||||
|
||||
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 4.0f));
|
||||
auto val = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 4.0f));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
@ -272,18 +266,17 @@ TEST_F(BuilderTest, Assign_Vector) {
|
|||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
|
||||
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto ident = create<ast::IdentifierExpression>("var");
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto val =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
auto val = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
@ -320,11 +313,11 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
|||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
|
||||
|
||||
auto ident = std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("var"),
|
||||
std::make_unique<ast::IdentifierExpression>("y"));
|
||||
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f));
|
||||
auto ident = create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("var"),
|
||||
create<ast::IdentifierExpression>("y"));
|
||||
auto val = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
@ -365,12 +358,12 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
|||
|
||||
ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
|
||||
|
||||
auto ident = std::make_unique<ast::ArrayAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("var"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
auto val = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f));
|
||||
auto ident = create<ast::ArrayAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("var"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
auto val = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f));
|
||||
|
||||
ast::AssignmentStatement assign(std::move(ident), std::move(val));
|
||||
|
||||
|
|
|
@ -57,10 +57,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
|||
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 4));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -83,23 +83,21 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
|||
ast::type::VectorType vec3(&i32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -123,8 +121,8 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
|
|||
|
||||
ast::Variable var("param", ast::StorageClass::kFunction, &i32);
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("param");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("param");
|
||||
auto lhs = create<ast::IdentifierExpression>("param");
|
||||
auto rhs = create<ast::IdentifierExpression>("param");
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -171,10 +169,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
|||
|
||||
ast::type::U32Type u32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 4));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -197,23 +195,21 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
|||
ast::type::VectorType vec3(&u32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -251,10 +247,10 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
|||
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 4.5f));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 4.5f));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -277,23 +273,21 @@ TEST_P(BinaryArithFloatTest, Vector) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -325,10 +319,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
|||
|
||||
ast::type::U32Type u32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 3));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 4));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -353,23 +347,21 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
|||
ast::type::VectorType vec3(&u32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::UintLiteral>(&u32, 1)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 1)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -405,10 +397,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
|||
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 4));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -433,23 +425,21 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
|||
ast::type::VectorType vec3(&i32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -485,10 +475,10 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
|
|||
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 4.5f));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 4.5f));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -513,23 +503,21 @@ TEST_P(BinaryCompareFloatTest, Vector) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
|
||||
|
||||
|
@ -564,17 +552,16 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f));
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
@ -597,18 +584,17 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f));
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
@ -631,11 +617,10 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat3(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto rhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = create<ast::IdentifierExpression>("mat");
|
||||
auto rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f));
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
|
@ -665,11 +650,10 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat3(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f));
|
||||
auto rhs = create<ast::IdentifierExpression>("mat");
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
|
@ -700,19 +684,17 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
ast::type::MatrixType mat3(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = create<ast::IdentifierExpression>("mat");
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
|
@ -744,20 +726,18 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
ast::type::MatrixType mat3(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto rhs = create<ast::IdentifierExpression>("mat");
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
|
@ -789,10 +769,9 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
ast::type::MatrixType mat3(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
|
||||
auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
|
||||
auto lhs = create<ast::IdentifierExpression>("mat");
|
||||
auto rhs = create<ast::IdentifierExpression>("mat");
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
||||
|
@ -821,19 +800,19 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
TEST_F(BuilderTest, Binary_LogicalAnd) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto rhs = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4)));
|
||||
auto rhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 4)));
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
@ -867,17 +846,17 @@ OpBranch %7
|
|||
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
||||
ast::type::BoolType bool_type;
|
||||
|
||||
auto a_var = std::make_unique<ast::Variable>(
|
||||
"a", ast::StorageClass::kFunction, &bool_type);
|
||||
a_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true)));
|
||||
auto b_var = std::make_unique<ast::Variable>(
|
||||
"b", ast::StorageClass::kFunction, &bool_type);
|
||||
b_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, false)));
|
||||
auto a_var =
|
||||
create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
|
||||
a_var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true)));
|
||||
auto b_var =
|
||||
create<ast::Variable>("b", ast::StorageClass::kFunction, &bool_type);
|
||||
b_var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, false)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("b");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto rhs = create<ast::IdentifierExpression>("b");
|
||||
|
||||
td.RegisterVariableForTesting(a_var.get());
|
||||
td.RegisterVariableForTesting(b_var.get());
|
||||
|
@ -917,19 +896,19 @@ OpBranch %9
|
|||
TEST_F(BuilderTest, Binary_LogicalOr) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lhs = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
auto lhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
auto rhs = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4)));
|
||||
auto rhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 4)));
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
@ -963,17 +942,17 @@ OpBranch %7
|
|||
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
||||
ast::type::BoolType bool_type;
|
||||
|
||||
auto a_var = std::make_unique<ast::Variable>(
|
||||
"a", ast::StorageClass::kFunction, &bool_type);
|
||||
a_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true)));
|
||||
auto b_var = std::make_unique<ast::Variable>(
|
||||
"b", ast::StorageClass::kFunction, &bool_type);
|
||||
b_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, false)));
|
||||
auto a_var =
|
||||
create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
|
||||
a_var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true)));
|
||||
auto b_var =
|
||||
create<ast::Variable>("b", ast::StorageClass::kFunction, &bool_type);
|
||||
b_var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, false)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("a");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("b");
|
||||
auto lhs = create<ast::IdentifierExpression>("a");
|
||||
auto rhs = create<ast::IdentifierExpression>("b");
|
||||
|
||||
td.RegisterVariableForTesting(a_var.get());
|
||||
td.RegisterVariableForTesting(b_var.get());
|
||||
|
|
|
@ -36,9 +36,9 @@ TEST_F(BuilderTest, Bitcast) {
|
|||
ast::type::U32Type u32;
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::BitcastExpression bitcast(
|
||||
&u32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
ast::BitcastExpression bitcast(&u32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
|
@ -57,9 +57,9 @@ TEST_F(BuilderTest, Bitcast) {
|
|||
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::BitcastExpression bitcast(
|
||||
&f32, std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
ast::BitcastExpression bitcast(&f32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
|
||||
|
|
|
@ -42,28 +42,26 @@ TEST_F(BuilderTest, Block) {
|
|||
// serves to prove the block code is pushing new scopes as needed.
|
||||
ast::BlockStatement outer;
|
||||
|
||||
outer.append(std::make_unique<ast::VariableDeclStatement>(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kFunction,
|
||||
&f32)));
|
||||
outer.append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("var"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))));
|
||||
outer.append(create<ast::VariableDeclStatement>(
|
||||
create<ast::Variable>("var", ast::StorageClass::kFunction, &f32)));
|
||||
outer.append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("var"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f))));
|
||||
|
||||
auto inner = std::make_unique<ast::BlockStatement>();
|
||||
inner->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kFunction,
|
||||
&f32)));
|
||||
inner->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("var"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))));
|
||||
auto inner = create<ast::BlockStatement>();
|
||||
inner->append(create<ast::VariableDeclStatement>(
|
||||
create<ast::Variable>("var", ast::StorageClass::kFunction, &f32)));
|
||||
inner->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("var"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f))));
|
||||
|
||||
outer.append(std::move(inner));
|
||||
outer.append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("var"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))));
|
||||
outer.append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("var"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f))));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error();
|
||||
|
||||
|
|
|
@ -45,30 +45,28 @@ TEST_F(BuilderTest, Expression_Call) {
|
|||
|
||||
ast::VariableList func_params;
|
||||
func_params.push_back(
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
|
||||
create<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
|
||||
func_params.push_back(
|
||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
|
||||
create<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
|
||||
|
||||
ast::Function a_func("a_func", std::move(func_params), &f32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("a"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
|
||||
create<ast::IdentifierExpression>("b"))));
|
||||
a_func.set_body(std::move(body));
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
|
||||
ast::ExpressionList call_params;
|
||||
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("a_func"),
|
||||
std::move(call_params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>("a_func"),
|
||||
std::move(call_params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
||||
|
@ -109,30 +107,28 @@ TEST_F(BuilderTest, Statement_Call) {
|
|||
|
||||
ast::VariableList func_params;
|
||||
func_params.push_back(
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
|
||||
create<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
|
||||
func_params.push_back(
|
||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
|
||||
create<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
|
||||
|
||||
ast::Function a_func("a_func", std::move(func_params), &void_type);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("a"),
|
||||
std::make_unique<ast::IdentifierExpression>("b"))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
|
||||
create<ast::IdentifierExpression>("b"))));
|
||||
a_func.set_body(std::move(body));
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
|
||||
ast::ExpressionList call_params;
|
||||
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
call_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
|
||||
ast::CallStatement expr(std::make_unique<ast::CallExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("a_func"),
|
||||
std::move(call_params)));
|
||||
ast::CallStatement expr(create<ast::CallExpression>(
|
||||
create<ast::IdentifierExpression>("a_func"), std::move(call_params)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -43,8 +43,8 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.entry_points()),
|
||||
|
@ -67,8 +67,7 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(
|
||||
std::make_unique<ast::StageDecoration>(params.stage, Source{}));
|
||||
func.add_decoration(create<ast::StageDecoration>(params.stage, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
|
||||
|
||||
|
@ -94,14 +93,13 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
auto v_in =
|
||||
std::make_unique<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
|
||||
auto v_out = std::make_unique<ast::Variable>(
|
||||
"my_out", ast::StorageClass::kOutput, &f32);
|
||||
auto v_wg = std::make_unique<ast::Variable>(
|
||||
"my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
func.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
auto v_in = create<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
|
||||
auto v_out =
|
||||
create<ast::Variable>("my_out", ast::StorageClass::kOutput, &f32);
|
||||
auto v_wg =
|
||||
create<ast::Variable>("my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_in.get())) << b.error();
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v_out.get())) << b.error();
|
||||
|
@ -138,28 +136,27 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
func.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("my_out"),
|
||||
std::make_unique<ast::IdentifierExpression>("my_in")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("my_wg"),
|
||||
std::make_unique<ast::IdentifierExpression>("my_wg")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("my_out"),
|
||||
create<ast::IdentifierExpression>("my_in")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("my_wg"),
|
||||
create<ast::IdentifierExpression>("my_wg")));
|
||||
// Add duplicate usages so we show they don't get output multiple times.
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("my_out"),
|
||||
std::make_unique<ast::IdentifierExpression>("my_in")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("my_out"),
|
||||
create<ast::IdentifierExpression>("my_in")));
|
||||
func.set_body(std::move(body));
|
||||
|
||||
auto v_in =
|
||||
std::make_unique<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
|
||||
auto v_out = std::make_unique<ast::Variable>(
|
||||
"my_out", ast::StorageClass::kOutput, &f32);
|
||||
auto v_wg = std::make_unique<ast::Variable>(
|
||||
"my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
auto v_in = create<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
|
||||
auto v_out =
|
||||
create<ast::Variable>("my_out", ast::StorageClass::kOutput, &f32);
|
||||
auto v_wg =
|
||||
create<ast::Variable>("my_wg", ast::StorageClass::kWorkgroup, &f32);
|
||||
|
||||
td.RegisterVariableForTesting(v_in.get());
|
||||
td.RegisterVariableForTesting(v_out.get());
|
||||
|
@ -201,8 +198,8 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
func.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -214,8 +211,8 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
func.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -227,10 +224,9 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func("main", {}, &void_type);
|
||||
func.add_decoration(create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}));
|
||||
func.add_decoration(
|
||||
std::make_unique<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}));
|
||||
func.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -242,12 +238,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
|
|||
ast::type::VoidType void_type;
|
||||
|
||||
ast::Function func1("main1", {}, &void_type);
|
||||
func1.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
func1.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
ast::Function func2("main2", {}, &void_type);
|
||||
func2.add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
func2.add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(&func1)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(&func2)) << b.error();
|
||||
|
|
|
@ -69,20 +69,18 @@ TEST_F(BuilderTest, Function_WithParams) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::VariableList params;
|
||||
auto var_a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
|
||||
auto var_a = create<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
|
||||
var_a->set_is_const(true);
|
||||
params.push_back(std::move(var_a));
|
||||
auto var_b =
|
||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &i32);
|
||||
auto var_b = create<ast::Variable>("b", ast::StorageClass::kFunction, &i32);
|
||||
var_b->set_is_const(true);
|
||||
params.push_back(std::move(var_b));
|
||||
|
||||
ast::Function func("a_func", std::move(params), &f32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("a")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::ReturnStatement>(create<ast::IdentifierExpression>("a")));
|
||||
func.set_body(std::move(body));
|
||||
|
||||
td.RegisterVariableForTesting(func.params()[0].get());
|
||||
|
@ -108,8 +106,8 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_WithBody) {
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::Function func("a_func", {}, &void_type);
|
||||
func.set_body(std::move(body));
|
||||
|
@ -169,27 +167,23 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
ast::StructMemberList members;
|
||||
ast::StructMemberDecorationList a_deco;
|
||||
a_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("d", &f32, std::move(a_deco)));
|
||||
a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
members.push_back(create<ast::StructMember>("d", &f32, std::move(a_deco)));
|
||||
|
||||
ast::StructDecorationList s_decos;
|
||||
s_decos.push_back(std::make_unique<ast::StructBlockDecoration>(Source{}));
|
||||
s_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
|
||||
|
||||
auto str =
|
||||
std::make_unique<ast::Struct>(std::move(s_decos), std::move(members));
|
||||
auto str = create<ast::Struct>(std::move(s_decos), std::move(members));
|
||||
|
||||
ast::type::StructType s("Data", std::move(str));
|
||||
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
|
||||
|
||||
auto data_var =
|
||||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"data", ast::StorageClass::kStorageBuffer, &ac));
|
||||
auto data_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &ac));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::BindingDecoration>(0, Source{}));
|
||||
decos.push_back(std::make_unique<ast::SetDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::BindingDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::SetDecoration>(0, Source{}));
|
||||
data_var->set_decorations(std::move(decos));
|
||||
|
||||
mod.AddConstructedType(&s);
|
||||
|
@ -199,20 +193,18 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
{
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("a", std::move(params), &void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
auto func = create<ast::Function>("a", std::move(params), &void_type);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"v", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("d")));
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("data"),
|
||||
create<ast::IdentifierExpression>("d")));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -220,20 +212,18 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
{
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("b", std::move(params), &void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
auto func = create<ast::Function>("b", std::move(params), &void_type);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"v", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("data"),
|
||||
std::make_unique<ast::IdentifierExpression>("d")));
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("data"),
|
||||
create<ast::IdentifierExpression>("d")));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
|
|
@ -70,15 +70,14 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -112,20 +111,19 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 2);
|
||||
|
||||
auto rel = std::make_unique<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kAdd,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
auto rel =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::move(rel));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -170,15 +168,14 @@ TEST_F(BuilderTest, FunctionVar_Const) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
|
|
@ -97,15 +97,14 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -133,15 +132,14 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -168,14 +166,13 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -202,19 +199,17 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
ast::type::VectorType vec2(&f32, 2);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
auto first =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec2, std::move(vals));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
auto first = create<ast::TypeConstructorExpression>(&vec2, std::move(vals));
|
||||
|
||||
vals.push_back(std::move(first));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -244,10 +239,9 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
||||
ast::type::F32Type f32;
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(5, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(5, Source{}));
|
||||
|
||||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
@ -266,11 +260,10 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
|
||||
ast::type::F32Type f32;
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::BindingDecoration>(2, Source{}));
|
||||
decos.push_back(std::make_unique<ast::SetDecoration>(3, Source{}));
|
||||
decos.push_back(create<ast::BindingDecoration>(2, Source{}));
|
||||
decos.push_back(create<ast::SetDecoration>(3, Source{}));
|
||||
|
||||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
@ -290,11 +283,10 @@ OpDecorate %1 DescriptorSet 3
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
||||
ast::type::F32Type f32;
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kPosition, Source{}));
|
||||
decos.push_back(
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
|
||||
|
||||
ast::DecoratedVariable dv(std::move(v));
|
||||
dv.set_decorations(std::move(decos));
|
||||
|
@ -315,13 +307,13 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
|||
ast::type::BoolType bool_type;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(1200, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(1200, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(std::make_unique<ast::Variable>(
|
||||
"var", ast::StorageClass::kNone, &bool_type));
|
||||
ast::DecoratedVariable v(
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &bool_type));
|
||||
v.set_decorations(std::move(decos));
|
||||
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true)));
|
||||
v.set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true)));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
|
@ -339,10 +331,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
|||
ast::type::BoolType bool_type;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(1200, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(1200, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(std::make_unique<ast::Variable>(
|
||||
"var", ast::StorageClass::kNone, &bool_type));
|
||||
ast::DecoratedVariable v(
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &bool_type));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
|
@ -361,13 +353,13 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &f32));
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &f32));
|
||||
v.set_decorations(std::move(decos));
|
||||
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0)));
|
||||
v.set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0)));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
|
||||
|
@ -385,10 +377,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &f32));
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &f32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
|
@ -407,10 +399,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &i32));
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &i32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
|
@ -429,10 +421,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
|||
ast::type::U32Type u32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
|
||||
|
||||
ast::DecoratedVariable v(
|
||||
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &u32));
|
||||
create<ast::Variable>("var", ast::StorageClass::kNone, &u32));
|
||||
v.set_decorations(std::move(decos));
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
|
||||
|
@ -491,13 +483,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &i32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("b", &i32, std::move(decos)));
|
||||
|
||||
ast::type::StructType A("A",
|
||||
std::make_unique<ast::Struct>(std::move(members)));
|
||||
ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
|
||||
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A};
|
||||
|
||||
ast::Variable var("b", ast::StorageClass::kStorageBuffer, &ac);
|
||||
|
@ -530,11 +519,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
|
||||
ast::type::StructType A("A",
|
||||
std::make_unique<ast::Struct>(std::move(members)));
|
||||
ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
|
||||
ast::type::AliasType B("B", &A);
|
||||
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &B};
|
||||
|
||||
|
@ -566,11 +553,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
|
||||
ast::type::StructType A("A",
|
||||
std::make_unique<ast::Struct>(std::move(members)));
|
||||
ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
|
||||
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A};
|
||||
ast::type::AliasType B("B", &ac);
|
||||
|
||||
|
@ -602,11 +587,9 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
|
||||
|
||||
ast::type::StructType A("A",
|
||||
std::make_unique<ast::Struct>(std::move(members)));
|
||||
ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
|
||||
ast::type::AccessControlType read{ast::AccessControl::kReadOnly, &A};
|
||||
ast::type::AccessControlType rw{ast::AccessControl::kReadWrite, &A};
|
||||
|
||||
|
|
|
@ -43,15 +43,14 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -103,15 +102,14 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto init =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
|
||||
|
||||
|
@ -167,8 +165,8 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
|
|||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto lhs = create<ast::IdentifierExpression>("var");
|
||||
auto rhs = create<ast::IdentifierExpression>("var");
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
@ -195,14 +193,14 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::Variable var("var", ast::StorageClass::kNone, &i32);
|
||||
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
var.set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
var.set_is_const(true);
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("var");
|
||||
auto lhs = create<ast::IdentifierExpression>("var");
|
||||
auto rhs = create<ast::IdentifierExpression>("var");
|
||||
|
||||
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
|
||||
std::move(rhs));
|
||||
|
|
|
@ -46,11 +46,10 @@ TEST_F(BuilderTest, If_Empty) {
|
|||
|
||||
// if (true) {
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(std::move(cond),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::IfStatement expr(std::move(cond), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -76,17 +75,16 @@ TEST_F(BuilderTest, If_WithStatements) {
|
|||
// if (true) {
|
||||
// v = 2;
|
||||
// }
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
|
||||
|
@ -124,27 +122,25 @@ TEST_F(BuilderTest, If_WithElse) {
|
|||
// } else {
|
||||
// v = 3;
|
||||
// }
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
|
||||
ast::ElseStatementList else_stmts;
|
||||
else_stmts.push_back(
|
||||
std::make_unique<ast::ElseStatement>(std::move(else_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
|
||||
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
@ -188,30 +184,29 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
|||
// } elseif (true) {
|
||||
// v = 3;
|
||||
// }
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
|
||||
auto else_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto else_cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::ElseStatementList else_stmts;
|
||||
else_stmts.push_back(std::make_unique<ast::ElseStatement>(
|
||||
std::move(else_cond), std::move(else_body)));
|
||||
else_stmts.push_back(
|
||||
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
|
||||
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
@ -264,45 +259,43 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
|||
// } else {
|
||||
// v = 5;
|
||||
// }
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto elseif_1_body = std::make_unique<ast::BlockStatement>();
|
||||
elseif_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto elseif_2_body = std::make_unique<ast::BlockStatement>();
|
||||
elseif_2_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 4))));
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 5))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
auto elseif_1_body = create<ast::BlockStatement>();
|
||||
elseif_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
auto elseif_2_body = create<ast::BlockStatement>();
|
||||
elseif_2_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 4))));
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 5))));
|
||||
|
||||
auto elseif_1_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto elseif_2_cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, false));
|
||||
auto elseif_1_cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto elseif_2_cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, false));
|
||||
|
||||
ast::ElseStatementList else_stmts;
|
||||
else_stmts.push_back(std::make_unique<ast::ElseStatement>(
|
||||
std::move(elseif_1_cond), std::move(elseif_1_body)));
|
||||
else_stmts.push_back(std::make_unique<ast::ElseStatement>(
|
||||
std::move(elseif_2_cond), std::move(elseif_2_body)));
|
||||
else_stmts.push_back(
|
||||
std::make_unique<ast::ElseStatement>(std::move(else_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(elseif_1_cond),
|
||||
std::move(elseif_1_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(elseif_2_cond),
|
||||
std::move(elseif_2_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
|
||||
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(body));
|
||||
expr.set_else_statements(std::move(else_stmts));
|
||||
|
@ -363,20 +356,18 @@ TEST_F(BuilderTest, If_WithBreak) {
|
|||
// break;
|
||||
// }
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
auto if_body = std::make_unique<ast::BlockStatement>();
|
||||
if_body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto if_body = create<ast::BlockStatement>();
|
||||
if_body->append(create<ast::BreakStatement>());
|
||||
|
||||
auto if_stmt =
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(if_body));
|
||||
auto if_stmt = create<ast::IfStatement>(std::move(cond), std::move(if_body));
|
||||
|
||||
auto loop_body = std::make_unique<ast::BlockStatement>();
|
||||
auto loop_body = create<ast::BlockStatement>();
|
||||
loop_body->append(std::move(if_stmt));
|
||||
|
||||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -412,25 +403,23 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
|||
// break;
|
||||
// }
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(create<ast::BreakStatement>());
|
||||
|
||||
ast::ElseStatementList else_stmts;
|
||||
else_stmts.push_back(
|
||||
std::make_unique<ast::ElseStatement>(std::move(else_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
|
||||
|
||||
auto if_stmt = std::make_unique<ast::IfStatement>(
|
||||
std::move(cond), std::make_unique<ast::BlockStatement>());
|
||||
auto if_stmt =
|
||||
create<ast::IfStatement>(std::move(cond), create<ast::BlockStatement>());
|
||||
if_stmt->set_else_statements(std::move(else_stmts));
|
||||
|
||||
auto loop_body = std::make_unique<ast::BlockStatement>();
|
||||
auto loop_body = create<ast::BlockStatement>();
|
||||
loop_body->append(std::move(if_stmt));
|
||||
|
||||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -467,20 +456,18 @@ TEST_F(BuilderTest, If_WithContinue) {
|
|||
// continue;
|
||||
// }
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
auto if_body = std::make_unique<ast::BlockStatement>();
|
||||
if_body->append(std::make_unique<ast::ContinueStatement>());
|
||||
auto if_body = create<ast::BlockStatement>();
|
||||
if_body->append(create<ast::ContinueStatement>());
|
||||
|
||||
auto if_stmt =
|
||||
std::make_unique<ast::IfStatement>(std::move(cond), std::move(if_body));
|
||||
auto if_stmt = create<ast::IfStatement>(std::move(cond), std::move(if_body));
|
||||
|
||||
auto loop_body = std::make_unique<ast::BlockStatement>();
|
||||
auto loop_body = create<ast::BlockStatement>();
|
||||
loop_body->append(std::move(if_stmt));
|
||||
|
||||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -516,25 +503,23 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
|||
// continue;
|
||||
// }
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::ContinueStatement>());
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(create<ast::ContinueStatement>());
|
||||
|
||||
ast::ElseStatementList else_stmts;
|
||||
else_stmts.push_back(
|
||||
std::make_unique<ast::ElseStatement>(std::move(else_body)));
|
||||
else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
|
||||
|
||||
auto if_stmt = std::make_unique<ast::IfStatement>(
|
||||
std::move(cond), std::make_unique<ast::BlockStatement>());
|
||||
auto if_stmt =
|
||||
create<ast::IfStatement>(std::move(cond), create<ast::BlockStatement>());
|
||||
if_stmt->set_else_statements(std::move(else_stmts));
|
||||
|
||||
auto loop_body = std::make_unique<ast::BlockStatement>();
|
||||
auto loop_body = create<ast::BlockStatement>();
|
||||
loop_body->append(std::move(if_stmt));
|
||||
|
||||
ast::LoopStatement expr(std::move(loop_body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -569,11 +554,11 @@ TEST_F(BuilderTest, If_WithReturn) {
|
|||
// if (true) {
|
||||
// return;
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
auto if_body = std::make_unique<ast::BlockStatement>();
|
||||
if_body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto if_body = create<ast::BlockStatement>();
|
||||
if_body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(if_body));
|
||||
|
||||
|
@ -599,13 +584,13 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
|||
// if (true) {
|
||||
// return false;
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond2 = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, false));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto cond2 = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, false));
|
||||
|
||||
auto if_body = std::make_unique<ast::BlockStatement>();
|
||||
if_body->append(std::make_unique<ast::ReturnStatement>(std::move(cond2)));
|
||||
auto if_body = create<ast::BlockStatement>();
|
||||
if_body->append(create<ast::ReturnStatement>(std::move(cond2)));
|
||||
|
||||
ast::IfStatement expr(std::move(cond), std::move(if_body));
|
||||
|
||||
|
|
|
@ -64,6 +64,13 @@ class IntrinsicBuilderTest : public ast::Builder, public testing::Test {
|
|||
return var;
|
||||
}
|
||||
|
||||
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
|
||||
/// @param args the arguments to forward to the constructor for `T`
|
||||
template <typename T, typename... ARGS>
|
||||
std::unique_ptr<T> create(ARGS&&... args) {
|
||||
return std::make_unique<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
Context ctx;
|
||||
ast::Module mod;
|
||||
TypeDeterminer td{&ctx, &mod};
|
||||
|
@ -1706,17 +1713,15 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
|
||||
|
||||
auto expr =
|
||||
call_expr("arrayLength", std::make_unique<ast::MemberAccessorExpression>(
|
||||
make_expr("b"), make_expr("a")));
|
||||
auto expr = call_expr("arrayLength", create<ast::MemberAccessorExpression>(
|
||||
make_expr("b"), make_expr("a")));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -1748,18 +1753,15 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("z", f32(), std::move(decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("z", f32(), std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
|
||||
auto expr =
|
||||
call_expr("arrayLength", std::make_unique<ast::MemberAccessorExpression>(
|
||||
make_expr("b"), make_expr("a")));
|
||||
auto expr = call_expr("arrayLength", create<ast::MemberAccessorExpression>(
|
||||
make_expr("b"), make_expr("a")));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -1793,19 +1795,17 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("z", f32(), std::move(decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("z", f32(), std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
|
||||
|
||||
auto ptr_var = make_var("ptr_var", ast::StorageClass::kPrivate, &ptr);
|
||||
ptr_var->set_constructor(std::make_unique<ast::MemberAccessorExpression>(
|
||||
make_expr("b"), make_expr("a")));
|
||||
ptr_var->set_constructor(
|
||||
create<ast::MemberAccessorExpression>(make_expr("b"), make_expr("a")));
|
||||
|
||||
auto expr = call_expr("arrayLength", "ptr_var");
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
|
|
@ -65,17 +65,15 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
|||
// loop {
|
||||
// v = 2;
|
||||
// }
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -113,20 +111,19 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto continuing = std::make_unique<ast::BlockStatement>();
|
||||
continuing->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto continuing = create<ast::BlockStatement>();
|
||||
continuing->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
ast::LoopStatement expr(std::move(body), std::move(continuing));
|
||||
|
||||
td.RegisterVariableForTesting(var.get());
|
||||
|
@ -162,11 +159,10 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
|||
// loop {
|
||||
// continue;
|
||||
// }
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ContinueStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ContinueStatement>());
|
||||
|
||||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -190,11 +186,10 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
|||
// loop {
|
||||
// break;
|
||||
// }
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::BreakStatement>());
|
||||
|
||||
ast::LoopStatement expr(std::move(body),
|
||||
std::make_unique<ast::BlockStatement>());
|
||||
ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
|
|
@ -51,15 +51,14 @@ TEST_F(BuilderTest, Return_WithValue) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto val =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
auto val = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
|
||||
|
||||
ast::ReturnStatement ret(std::move(val));
|
||||
|
||||
|
@ -85,8 +84,7 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
|
|||
|
||||
ast::Variable var("param", ast::StorageClass::kFunction, &f32);
|
||||
|
||||
ast::ReturnStatement ret(
|
||||
std::make_unique<ast::IdentifierExpression>("param"));
|
||||
ast::ReturnStatement ret(create<ast::IdentifierExpression>("param"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
|
||||
|
|
|
@ -45,8 +45,8 @@ TEST_F(BuilderTest, Switch_Empty) {
|
|||
|
||||
// switch (1) {
|
||||
// }
|
||||
auto cond = std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
auto cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::SwitchStatement expr(std::move(cond), ast::CaseStatementList{});
|
||||
|
||||
|
@ -77,36 +77,34 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
|||
// v = 2;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto case_1_body = std::make_unique<ast::BlockStatement>();
|
||||
case_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
auto case_1_body = create<ast::BlockStatement>();
|
||||
case_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
|
||||
auto case_2_body = std::make_unique<ast::BlockStatement>();
|
||||
case_2_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto case_2_body = create<ast::BlockStatement>();
|
||||
case_2_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::CaseSelectorList selector_2;
|
||||
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
@ -158,22 +156,19 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
|||
// v = 1;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto default_body = std::make_unique<ast::BlockStatement>();
|
||||
default_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
auto default_body = create<ast::BlockStatement>();
|
||||
default_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(
|
||||
std::make_unique<ast::CaseStatement>(std::move(default_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
@ -223,45 +218,42 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
// v = 3;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto case_1_body = std::make_unique<ast::BlockStatement>();
|
||||
case_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
auto case_1_body = create<ast::BlockStatement>();
|
||||
case_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
|
||||
auto case_2_body = std::make_unique<ast::BlockStatement>();
|
||||
case_2_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto case_2_body = create<ast::BlockStatement>();
|
||||
case_2_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto default_body = std::make_unique<ast::BlockStatement>();
|
||||
default_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto default_body = create<ast::BlockStatement>();
|
||||
default_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::CaseSelectorList selector_2;
|
||||
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 3));
|
||||
selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
|
||||
selector_2.push_back(create<ast::SintLiteral>(&i32, 3));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
cases.push_back(
|
||||
std::make_unique<ast::CaseStatement>(std::move(default_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
@ -320,45 +312,42 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
// v = 3;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto case_1_body = std::make_unique<ast::BlockStatement>();
|
||||
case_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
case_1_body->append(std::make_unique<ast::FallthroughStatement>());
|
||||
auto case_1_body = create<ast::BlockStatement>();
|
||||
case_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
case_1_body->append(create<ast::FallthroughStatement>());
|
||||
|
||||
auto case_2_body = std::make_unique<ast::BlockStatement>();
|
||||
case_2_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2))));
|
||||
auto case_2_body = create<ast::BlockStatement>();
|
||||
case_2_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2))));
|
||||
|
||||
auto default_body = std::make_unique<ast::BlockStatement>();
|
||||
default_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3))));
|
||||
auto default_body = create<ast::BlockStatement>();
|
||||
default_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3))));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::CaseSelectorList selector_2;
|
||||
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2));
|
||||
selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
cases.push_back(
|
||||
std::make_unique<ast::CaseStatement>(std::move(default_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
|
||||
std::move(case_2_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
@ -413,26 +402,24 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
|||
// fallthrough;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto case_1_body = std::make_unique<ast::BlockStatement>();
|
||||
case_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
case_1_body->append(std::make_unique<ast::FallthroughStatement>());
|
||||
auto case_1_body = create<ast::BlockStatement>();
|
||||
case_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
case_1_body->append(create<ast::FallthroughStatement>());
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
@ -461,33 +448,31 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
|||
// v = 1;
|
||||
// }
|
||||
|
||||
auto v =
|
||||
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
|
||||
|
||||
auto if_body = std::make_unique<ast::BlockStatement>();
|
||||
if_body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto if_body = create<ast::BlockStatement>();
|
||||
if_body->append(create<ast::BreakStatement>());
|
||||
|
||||
auto case_1_body = std::make_unique<ast::BlockStatement>();
|
||||
case_1_body->append(std::make_unique<ast::IfStatement>(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, true)),
|
||||
std::move(if_body)));
|
||||
auto case_1_body = create<ast::BlockStatement>();
|
||||
case_1_body->append(
|
||||
create<ast::IfStatement>(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true)),
|
||||
std::move(if_body)));
|
||||
|
||||
case_1_body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("v"),
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1))));
|
||||
case_1_body->append(
|
||||
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1))));
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1));
|
||||
selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
|
||||
std::move(case_1_body)));
|
||||
|
||||
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"),
|
||||
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
|
||||
std::move(cases));
|
||||
|
||||
td.RegisterVariableForTesting(v.get());
|
||||
|
|
|
@ -124,7 +124,7 @@ TEST_F(BuilderTest_Type, GenerateArray_WithStride) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::ArrayDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::StrideDecoration>(16u, Source{}));
|
||||
decos.push_back(create<ast::StrideDecoration>(16u, Source{}));
|
||||
|
||||
ast::type::ArrayType ary(&i32, 4);
|
||||
ary.set_decorations(std::move(decos));
|
||||
|
@ -279,7 +279,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
||||
auto s = std::make_unique<ast::Struct>();
|
||||
auto s = create<ast::Struct>();
|
||||
ast::type::StructType s_type("S", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -298,10 +298,9 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -321,15 +320,12 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
|
|||
|
||||
ast::StructMemberDecorationList decos;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
|
||||
|
||||
ast::StructDecorationList struct_decos;
|
||||
struct_decos.push_back(
|
||||
std::make_unique<ast::StructBlockDecoration>(Source{}));
|
||||
struct_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(struct_decos),
|
||||
std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(struct_decos), std::move(members));
|
||||
ast::type::StructType s_type("my_struct", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -350,19 +346,15 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberDecorationList a_decos;
|
||||
a_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
ast::StructMemberDecorationList b_decos;
|
||||
b_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(8, Source{}));
|
||||
b_decos.push_back(create<ast::StructMemberOffsetDecoration>(8, Source{}));
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("a", &f32, std::move(a_decos)));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(b_decos)));
|
||||
members.push_back(create<ast::StructMember>("a", &f32, std::move(a_decos)));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("S", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -392,14 +384,14 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
|
|||
ast::StructMemberDecorationList empty_b;
|
||||
ast::StructMemberDecorationList empty_c;
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2,
|
||||
std::move(empty_a)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3,
|
||||
std::move(empty_b)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4,
|
||||
std::move(empty_c)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &glsl_mat2x2, std::move(empty_a)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("b", &glsl_mat2x3, std::move(empty_b)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("c", &glsl_mat4x4, std::move(empty_c)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("S", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -431,24 +423,21 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
|
|||
ast::type::MatrixType glsl_mat4x4(&f32, 4, 4);
|
||||
|
||||
ast::StructMemberDecorationList a_decos;
|
||||
a_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
ast::StructMemberDecorationList b_decos;
|
||||
b_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
b_decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
ast::StructMemberDecorationList c_decos;
|
||||
c_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(48, Source{}));
|
||||
c_decos.push_back(create<ast::StructMemberOffsetDecoration>(48, Source{}));
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2,
|
||||
std::move(a_decos)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3,
|
||||
std::move(b_decos)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4,
|
||||
std::move(c_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &glsl_mat2x2, std::move(a_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("b", &glsl_mat2x3, std::move(b_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("c", &glsl_mat4x4, std::move(c_decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("S", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
@ -498,24 +487,21 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
|
|||
ast::type::ArrayType rtarr_mat4x4(&glsl_mat4x4); // Runtime array
|
||||
|
||||
ast::StructMemberDecorationList a_decos;
|
||||
a_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
ast::StructMemberDecorationList b_decos;
|
||||
b_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
b_decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
ast::StructMemberDecorationList c_decos;
|
||||
c_decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(48, Source{}));
|
||||
c_decos.push_back(create<ast::StructMemberOffsetDecoration>(48, Source{}));
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2,
|
||||
std::move(a_decos)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3,
|
||||
std::move(b_decos)));
|
||||
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4,
|
||||
std::move(c_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &glsl_mat2x2, std::move(a_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("b", &glsl_mat2x3, std::move(b_decos)));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("c", &glsl_mat4x4, std::move(c_decos)));
|
||||
|
||||
auto s = std::make_unique<ast::Struct>(std::move(members));
|
||||
auto s = create<ast::Struct>(std::move(members));
|
||||
ast::type::StructType s_type("S", std::move(s));
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&s_type);
|
||||
|
|
|
@ -41,10 +41,9 @@ using BuilderTest = TestHelper;
|
|||
TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
ast::UnaryOpExpression expr(
|
||||
ast::UnaryOp::kNegation,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -61,10 +60,9 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
|||
TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
ast::UnaryOpExpression expr(
|
||||
ast::UnaryOp::kNegation,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1)));
|
||||
ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -81,10 +79,9 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
|||
TEST_F(BuilderTest, UnaryOp_Not) {
|
||||
ast::type::BoolType bool_type;
|
||||
|
||||
ast::UnaryOpExpression expr(
|
||||
ast::UnaryOp::kNot,
|
||||
std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::BoolLiteral>(&bool_type, false)));
|
||||
ast::UnaryOpExpression expr(ast::UnaryOp::kNot,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, false)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
||||
|
@ -104,9 +101,8 @@ TEST_F(BuilderTest, UnaryOp_LoadRequired) {
|
|||
|
||||
ast::Variable var("param", ast::StorageClass::kFunction, &vec);
|
||||
|
||||
ast::UnaryOpExpression expr(
|
||||
ast::UnaryOp::kNegation,
|
||||
std::make_unique<ast::IdentifierExpression>("param"));
|
||||
ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
|
||||
create<ast::IdentifierExpression>("param"));
|
||||
|
||||
td.RegisterVariableForTesting(&var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#ifndef SRC_WRITER_SPIRV_TEST_HELPER_H_
|
||||
#define SRC_WRITER_SPIRV_TEST_HELPER_H_
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/module.h"
|
||||
#include "src/context.h"
|
||||
|
@ -26,12 +29,19 @@ namespace writer {
|
|||
namespace spirv {
|
||||
|
||||
/// Helper class for testing
|
||||
template <typename T>
|
||||
class TestHelperBase : public T {
|
||||
template <typename BASE>
|
||||
class TestHelperBase : public BASE {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), b(&ctx, &mod) {}
|
||||
~TestHelperBase() = default;
|
||||
|
||||
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
|
||||
/// @param args the arguments to forward to the constructor for `T`
|
||||
template <typename T, typename... ARGS>
|
||||
std::unique_ptr<T> create(ARGS&&... args) {
|
||||
return std::make_unique<T>(std::forward<ARGS>(args)...);
|
||||
}
|
||||
|
||||
/// The context
|
||||
Context ctx;
|
||||
/// The module
|
||||
|
|
Loading…
Reference in New Issue