writer/msl 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: I1756981b206c125d1dbf78ac178e0a7b60ec2941 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32672 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
bbc9b967a3
commit
4c88cd93ec
|
@ -54,16 +54,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &f32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &i32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("a", std::move(str));
|
||||
|
@ -81,16 +79,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &f32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &i32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("b", std::move(str));
|
||||
|
|
|
@ -33,9 +33,9 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||
ast::type::I32Type i32;
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, 5);
|
||||
auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit));
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto lit = create<ast::SintLiteral>(&i32, 5);
|
||||
auto idx = create<ast::ScalarConstructorExpression>(std::move(lit));
|
||||
auto ary = create<ast::IdentifierExpression>("ary");
|
||||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
|
@ -44,8 +44,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
|
||||
auto ary = std::make_unique<ast::IdentifierExpression>("ary");
|
||||
auto idx = std::make_unique<ast::IdentifierExpression>("idx");
|
||||
auto ary = create<ast::IdentifierExpression>("ary");
|
||||
auto idx = create<ast::IdentifierExpression>("idx");
|
||||
|
||||
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Assign) {
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
auto lhs = create<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = create<ast::IdentifierExpression>("rhs");
|
||||
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -38,8 +38,8 @@ using MslBinaryTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(MslBinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto left = std::make_unique<ast::IdentifierExpression>("left");
|
||||
auto right = std::make_unique<ast::IdentifierExpression>("right");
|
||||
auto left = create<ast::IdentifierExpression>("left");
|
||||
auto right = create<ast::IdentifierExpression>("right");
|
||||
|
||||
ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
ast::type::F32Type f32;
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("id");
|
||||
auto id = create<ast::IdentifierExpression>("id");
|
||||
ast::BitcastExpression bitcast(&f32, std::move(id));
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();
|
||||
|
|
|
@ -29,7 +29,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Block) {
|
||||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
b.append(create<ast::DiscardStatement>());
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
|
@ -42,7 +42,7 @@ TEST_F(MslGeneratorImplTest, Emit_Block) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
||||
ast::BlockStatement b;
|
||||
b.append(std::make_unique<ast::DiscardStatement>());
|
||||
b.append(create<ast::DiscardStatement>());
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
|
|
|
@ -34,11 +34,10 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
|
||||
auto id = create<ast::IdentifierExpression>("my_func");
|
||||
ast::CallExpression call(std::move(id), {});
|
||||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
|
@ -48,14 +47,13 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
|
|||
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
|
||||
auto id = create<ast::IdentifierExpression>("my_func");
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param2"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param2"));
|
||||
ast::CallExpression call(std::move(id), std::move(params));
|
||||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error();
|
||||
|
@ -65,15 +63,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
|
|||
TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto id = std::make_unique<ast::IdentifierExpression>("my_func");
|
||||
auto id = create<ast::IdentifierExpression>("my_func");
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param2"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param2"));
|
||||
ast::CallStatement call(
|
||||
std::make_unique<ast::CallExpression>(std::move(id), std::move(params)));
|
||||
create<ast::CallExpression>(std::move(id), std::move(params)));
|
||||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -35,11 +35,11 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
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::CaseSelectorList lit;
|
||||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -55,8 +55,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::make_unique<ast::BlockStatement>());
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), create<ast::BlockStatement>());
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
|
@ -70,11 +70,11 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::FallthroughStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::FallthroughStatement>());
|
||||
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -89,12 +89,12 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
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::CaseSelectorList lit;
|
||||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 6));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 6));
|
||||
ast::CaseStatement c(std::move(lit), std::move(body));
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -110,8 +110,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
||||
ast::CaseStatement c;
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::BreakStatement>());
|
||||
c.set_body(std::move(body));
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("id"));
|
||||
params.push_back(create<ast::IdentifierExpression>("id"));
|
||||
|
||||
ast::TypeConstructorExpression cast(&f32, std::move(params));
|
||||
|
||||
|
@ -47,7 +47,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
|||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("id"));
|
||||
params.push_back(create<ast::IdentifierExpression>("id"));
|
||||
|
||||
ast::TypeConstructorExpression cast(&vec3, std::move(params));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
|
||||
ast::type::BoolType bool_type;
|
||||
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false);
|
||||
auto lit = create<ast::BoolLiteral>(&bool_type, false);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
|
@ -48,7 +48,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
||||
ast::type::I32Type i32;
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
auto lit = create<ast::SintLiteral>(&i32, -12345);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
|
@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
||||
ast::type::U32Type u32;
|
||||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779);
|
||||
auto lit = create<ast::UintLiteral>(&u32, 56779);
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
|
@ -67,8 +67,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
|||
TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
||||
ast::type::F32Type f32;
|
||||
// Use a number close to 1<<30 but whose decimal representation ends in 0.
|
||||
auto lit = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>((1 << 30) - 4));
|
||||
auto lit = create<ast::FloatLiteral>(&f32, static_cast<float>((1 << 30) - 4));
|
||||
ast::ScalarConstructorExpression expr(std::move(lit));
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
|
@ -78,10 +77,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
|||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto lit = std::make_unique<ast::FloatLiteral>(&f32, -1.2e-5);
|
||||
auto lit = create<ast::FloatLiteral>(&f32, -1.2e-5);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
|
||||
ast::TypeConstructorExpression expr(&f32, std::move(values));
|
||||
|
||||
|
@ -92,10 +90,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
|||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
ast::type::BoolType b;
|
||||
|
||||
auto lit = std::make_unique<ast::BoolLiteral>(&b, true);
|
||||
auto lit = create<ast::BoolLiteral>(&b, true);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
|
||||
ast::TypeConstructorExpression expr(&b, std::move(values));
|
||||
|
||||
|
@ -106,10 +103,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
|||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345);
|
||||
auto lit = create<ast::SintLiteral>(&i32, -12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
|
||||
ast::TypeConstructorExpression expr(&i32, std::move(values));
|
||||
|
||||
|
@ -120,10 +116,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
|||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
ast::type::U32Type u32;
|
||||
|
||||
auto lit = std::make_unique<ast::UintLiteral>(&u32, 12345);
|
||||
auto lit = create<ast::UintLiteral>(&u32, 12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
|
||||
|
||||
ast::TypeConstructorExpression expr(&u32, std::move(values));
|
||||
|
||||
|
@ -135,16 +130,13 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f);
|
||||
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f);
|
||||
auto lit3 = std::make_unique<ast::FloatLiteral>(&f32, 3.f);
|
||||
auto lit1 = create<ast::FloatLiteral>(&f32, 1.f);
|
||||
auto lit2 = create<ast::FloatLiteral>(&f32, 2.f);
|
||||
auto lit3 = create<ast::FloatLiteral>(&f32, 3.f);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
|
||||
ast::TypeConstructorExpression expr(&vec, std::move(values));
|
||||
|
||||
|
@ -174,23 +166,20 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
ast::ExpressionList mat_values;
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
auto lit1 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(1 + (i * 2)));
|
||||
auto lit2 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(2 + (i * 2)));
|
||||
auto lit3 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(3 + (i * 2)));
|
||||
auto lit1 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(1 + (i * 2)));
|
||||
auto lit2 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(2 + (i * 2)));
|
||||
auto lit3 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 2)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
|
||||
mat_values.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(values)));
|
||||
mat_values.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
|
||||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
|
||||
|
@ -212,23 +201,20 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
|||
ast::ExpressionList ary_values;
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
auto lit1 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(1 + (i * 3)));
|
||||
auto lit2 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(2 + (i * 3)));
|
||||
auto lit3 = std::make_unique<ast::FloatLiteral>(
|
||||
&f32, static_cast<float>(3 + (i * 3)));
|
||||
auto lit1 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(1 + (i * 3)));
|
||||
auto lit2 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(2 + (i * 3)));
|
||||
auto lit3 =
|
||||
create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 3)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(
|
||||
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
|
||||
|
||||
ary_values.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(values)));
|
||||
ary_values.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(values)));
|
||||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(&ary, std::move(ary_values));
|
||||
|
|
|
@ -52,16 +52,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -71,19 +71,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("vtx_main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
auto func = create<ast::Function>("vtx_main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -111,16 +110,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -130,19 +129,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("vtx_main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kVertex, Source{}));
|
||||
auto func = create<ast::Function>("vtx_main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -170,16 +168,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -189,18 +187,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
auto func = create<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -228,16 +226,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -247,18 +245,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
auto func = create<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -283,16 +281,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -302,18 +300,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
auto func = create<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -333,16 +331,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::I32Type i32;
|
||||
|
||||
auto foo_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
auto foo_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::LocationDecoration>(0, Source{}));
|
||||
foo_var->set_decorations(std::move(decos));
|
||||
|
||||
auto bar_var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{}));
|
||||
auto bar_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
|
||||
decos.push_back(create<ast::LocationDecoration>(1, Source{}));
|
||||
bar_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(foo_var.get());
|
||||
|
@ -352,18 +350,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
mod.AddGlobalVariable(std::move(bar_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
auto func = create<ast::Function>("main", std::move(params), &f32);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("foo"),
|
||||
std::make_unique<ast::IdentifierExpression>("foo")));
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("bar"),
|
||||
std::make_unique<ast::IdentifierExpression>("bar")));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("foo"),
|
||||
create<ast::IdentifierExpression>("foo")));
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("bar"),
|
||||
create<ast::IdentifierExpression>("bar")));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
@ -389,20 +387,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
ast::type::VoidType void_type;
|
||||
ast::type::VectorType vec4(&f32, 4);
|
||||
|
||||
auto coord_var =
|
||||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"coord", ast::StorageClass::kInput, &vec4));
|
||||
auto coord_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kFragCoord, Source{}));
|
||||
decos.push_back(
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
|
||||
coord_var->set_decorations(std::move(decos));
|
||||
|
||||
auto depth_var =
|
||||
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||
"depth", ast::StorageClass::kOutput, &f32));
|
||||
decos.push_back(std::make_unique<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kFragDepth, Source{}));
|
||||
auto depth_var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
|
||||
decos.push_back(
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
|
||||
depth_var->set_decorations(std::move(decos));
|
||||
|
||||
td.RegisterVariableForTesting(coord_var.get());
|
||||
|
@ -412,18 +408,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
mod.AddGlobalVariable(std::move(depth_var));
|
||||
|
||||
ast::VariableList params;
|
||||
auto func =
|
||||
std::make_unique<ast::Function>("main", std::move(params), &void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kFragment, Source{}));
|
||||
auto func = create<ast::Function>("main", std::move(params), &void_type);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
|
||||
auto* func_ptr = func.get();
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::make_unique<ast::IdentifierExpression>("depth"),
|
||||
std::make_unique<ast::MemberAccessorExpression>(
|
||||
std::make_unique<ast::IdentifierExpression>("coord"),
|
||||
std::make_unique<ast::IdentifierExpression>("x"))));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::AssignmentStatement>(
|
||||
create<ast::IdentifierExpression>("depth"),
|
||||
create<ast::MemberAccessorExpression>(
|
||||
create<ast::IdentifierExpression>("coord"),
|
||||
create<ast::IdentifierExpression>("x"))));
|
||||
func->set_body(std::move(body));
|
||||
|
||||
mod.AddFunction(std::move(func));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,9 +29,9 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_If) {
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto cond = create<ast::IdentifierExpression>("cond");
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
|
||||
|
@ -45,17 +45,17 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
||||
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond");
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto else_cond = create<ast::IdentifierExpression>("else_cond");
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::ElseStatementList elses;
|
||||
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond),
|
||||
std::move(else_body)));
|
||||
elses.push_back(
|
||||
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto cond = create<ast::IdentifierExpression>("cond");
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
@ -72,15 +72,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::ElseStatementList elses;
|
||||
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body)));
|
||||
elses.push_back(create<ast::ElseStatement>(std::move(else_body)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto cond = create<ast::IdentifierExpression>("cond");
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
@ -97,22 +97,22 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond");
|
||||
auto else_cond = create<ast::IdentifierExpression>("else_cond");
|
||||
|
||||
auto else_body = std::make_unique<ast::BlockStatement>();
|
||||
else_body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto else_body = create<ast::BlockStatement>();
|
||||
else_body->append(create<ast::ReturnStatement>());
|
||||
|
||||
auto else_body_2 = std::make_unique<ast::BlockStatement>();
|
||||
else_body_2->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto else_body_2 = create<ast::BlockStatement>();
|
||||
else_body_2->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::ElseStatementList elses;
|
||||
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond),
|
||||
std::move(else_body)));
|
||||
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body_2)));
|
||||
elses.push_back(
|
||||
create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
|
||||
elses.push_back(create<ast::ElseStatement>(std::move(else_body_2)));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto cond = create<ast::IdentifierExpression>("cond");
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::IfStatement i(std::move(cond), std::move(body));
|
||||
i.set_else_statements(std::move(elses));
|
||||
|
|
|
@ -55,10 +55,10 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>(param.name);
|
||||
auto ident = create<ast::IdentifierExpression>(param.name);
|
||||
auto* ident_ptr = ident.get();
|
||||
|
||||
ast::CallExpression call(std::move(ident), std::move(params));
|
||||
|
@ -99,10 +99,10 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
|
||||
ast::CallExpression expr(std::make_unique<ast::IdentifierExpression>("abs"),
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>("abs"),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
|
@ -118,14 +118,13 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.f)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
|
@ -150,29 +149,28 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList type_params;
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.f)));
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.f)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.f)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.f)));
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(type_params)));
|
||||
params.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
|
||||
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 4.f)));
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 5.f)));
|
||||
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 6.f)));
|
||||
params.push_back(std::make_unique<ast::TypeConstructorExpression>(
|
||||
&vec, std::move(type_params)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 4.f)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 5.f)));
|
||||
type_params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 6.f)));
|
||||
params.push_back(
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
|
@ -191,14 +189,13 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
|
@ -216,16 +213,15 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.f)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.f)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.f)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
|
@ -248,16 +244,15 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
|
|||
ast::type::I32Type i32;
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 2)));
|
||||
params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::SintLiteral>(&i32, 3)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 1)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 2)));
|
||||
params.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(&i32, 3)));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
|
||||
std::move(params));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error();
|
||||
|
@ -273,15 +268,13 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat(&f32, 3, 3);
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"var", ast::StorageClass::kFunction, &mat);
|
||||
auto var = create<ast::Variable>("var", ast::StorageClass::kFunction, &mat);
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("var"));
|
||||
params.push_back(create<ast::IdentifierExpression>("var"));
|
||||
|
||||
ast::CallExpression expr(
|
||||
std::make_unique<ast::IdentifierExpression>("determinant"),
|
||||
std::move(params));
|
||||
ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"),
|
||||
std::move(params));
|
||||
|
||||
mod.AddGlobalVariable(std::move(var));
|
||||
|
||||
|
|
|
@ -71,18 +71,15 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
|
|||
ast::type::VectorType vec2(&f32, 2);
|
||||
ast::type::VectorType vec3(&f32, 3);
|
||||
|
||||
auto a =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &vec2);
|
||||
auto b =
|
||||
std::make_unique<ast::Variable>("b", ast::StorageClass::kNone, &vec3);
|
||||
auto a = create<ast::Variable>("a", ast::StorageClass::kNone, &vec2);
|
||||
auto b = create<ast::Variable>("b", ast::StorageClass::kNone, &vec3);
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("a"));
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("b"));
|
||||
params.push_back(create<ast::IdentifierExpression>("a"));
|
||||
params.push_back(create<ast::IdentifierExpression>("b"));
|
||||
|
||||
ast::CallExpression call(
|
||||
std::make_unique<ast::IdentifierExpression>("outer_product"),
|
||||
std::move(params));
|
||||
ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"),
|
||||
std::move(params));
|
||||
|
||||
td.RegisterVariableForTesting(a.get());
|
||||
td.RegisterVariableForTesting(b.get());
|
||||
|
@ -107,10 +104,10 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
|
|||
ast::type::VectorType vec(&f32, 3);
|
||||
|
||||
ast::ExpressionList params;
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(std::make_unique<ast::IdentifierExpression>("param2"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param1"));
|
||||
params.push_back(create<ast::IdentifierExpression>("param2"));
|
||||
|
||||
ast::CallExpression call(std::make_unique<ast::IdentifierExpression>("dot"),
|
||||
ast::CallExpression call(create<ast::IdentifierExpression>("dot"),
|
||||
std::move(params));
|
||||
|
||||
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);
|
||||
|
|
|
@ -36,8 +36,8 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::DiscardStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::DiscardStatement>());
|
||||
|
||||
ast::LoopStatement l(std::move(body), {});
|
||||
|
||||
|
@ -51,11 +51,11 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::DiscardStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::DiscardStatement>());
|
||||
|
||||
auto continuing = std::make_unique<ast::BlockStatement>();
|
||||
continuing->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto continuing = create<ast::BlockStatement>();
|
||||
continuing->append(create<ast::ReturnStatement>());
|
||||
|
||||
ast::LoopStatement l(std::move(body), std::move(continuing));
|
||||
|
||||
|
@ -79,24 +79,24 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::DiscardStatement>());
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::DiscardStatement>());
|
||||
|
||||
auto continuing = std::make_unique<ast::BlockStatement>();
|
||||
continuing->append(std::make_unique<ast::ReturnStatement>());
|
||||
auto continuing = create<ast::BlockStatement>();
|
||||
continuing->append(create<ast::ReturnStatement>());
|
||||
|
||||
auto inner = std::make_unique<ast::LoopStatement>(std::move(body),
|
||||
std::move(continuing));
|
||||
auto inner =
|
||||
create<ast::LoopStatement>(std::move(body), std::move(continuing));
|
||||
|
||||
body = std::make_unique<ast::BlockStatement>();
|
||||
body = create<ast::BlockStatement>();
|
||||
body->append(std::move(inner));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
auto lhs = create<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = create<ast::IdentifierExpression>("rhs");
|
||||
|
||||
continuing = std::make_unique<ast::BlockStatement>();
|
||||
continuing->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::move(lhs), std::move(rhs)));
|
||||
continuing = create<ast::BlockStatement>();
|
||||
continuing->append(
|
||||
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
|
||||
|
||||
ast::LoopStatement outer(std::move(body), std::move(continuing));
|
||||
|
||||
|
@ -151,23 +151,21 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
|||
|
||||
ast::type::F32Type f32;
|
||||
|
||||
auto var = std::make_unique<ast::Variable>(
|
||||
"lhs", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
|
||||
auto var = create<ast::Variable>("lhs", ast::StorageClass::kFunction, &f32);
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.4)));
|
||||
|
||||
auto body = std::make_unique<ast::BlockStatement>();
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(std::make_unique<ast::VariableDeclStatement>(
|
||||
std::make_unique<ast::Variable>("other", ast::StorageClass::kFunction,
|
||||
&f32)));
|
||||
auto body = create<ast::BlockStatement>();
|
||||
body->append(create<ast::VariableDeclStatement>(std::move(var)));
|
||||
body->append(create<ast::VariableDeclStatement>(
|
||||
create<ast::Variable>("other", ast::StorageClass::kFunction, &f32)));
|
||||
|
||||
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs");
|
||||
auto lhs = create<ast::IdentifierExpression>("lhs");
|
||||
auto rhs = create<ast::IdentifierExpression>("rhs");
|
||||
|
||||
auto continuing = std::make_unique<ast::BlockStatement>();
|
||||
continuing->append(std::make_unique<ast::AssignmentStatement>(
|
||||
std::move(lhs), std::move(rhs)));
|
||||
auto continuing = create<ast::BlockStatement>();
|
||||
continuing->append(
|
||||
create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
|
||||
auto str = std::make_unique<ast::IdentifierExpression>("str");
|
||||
auto mem = std::make_unique<ast::IdentifierExpression>("mem");
|
||||
auto str = create<ast::IdentifierExpression>("str");
|
||||
auto mem = create<ast::IdentifierExpression>("mem");
|
||||
|
||||
ast::MemberAccessorExpression expr(std::move(str), std::move(mem));
|
||||
|
||||
|
|
|
@ -40,18 +40,17 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
|||
ast::type::ArrayType ary(&f32, 3);
|
||||
|
||||
ast::ExpressionList exprs;
|
||||
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 1.0f)));
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 2.0f)));
|
||||
exprs.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
|
||||
auto var = create<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
|
||||
var->set_is_const(true);
|
||||
var->set_constructor(
|
||||
std::make_unique<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
|
||||
create<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error();
|
||||
EXPECT_EQ(
|
||||
|
@ -63,14 +62,14 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::VariableDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(23, Source{}));
|
||||
decos.push_back(create<ast::ConstantIdDecoration>(23, Source{}));
|
||||
|
||||
auto var = std::make_unique<ast::DecoratedVariable>(
|
||||
std::make_unique<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
|
||||
auto var = create<ast::DecoratedVariable>(
|
||||
create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
|
||||
var->set_decorations(std::move(decos));
|
||||
var->set_is_const(true);
|
||||
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
|
||||
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
var->set_constructor(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.0f)));
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "constant float pos [[function_constant(23)]];\n");
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST_F(MslGeneratorImplTest, Emit_Return) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
auto expr = create<ast::IdentifierExpression>("expr");
|
||||
ast::ReturnStatement r(std::move(expr));
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -33,26 +33,26 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
||||
auto def = std::make_unique<ast::CaseStatement>();
|
||||
auto def_body = std::make_unique<ast::BlockStatement>();
|
||||
def_body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto def = create<ast::CaseStatement>();
|
||||
auto def_body = create<ast::BlockStatement>();
|
||||
def_body->append(create<ast::BreakStatement>());
|
||||
def->set_body(std::move(def_body));
|
||||
|
||||
ast::type::I32Type i32;
|
||||
ast::CaseSelectorList case_val;
|
||||
case_val.push_back(std::make_unique<ast::SintLiteral>(&i32, 5));
|
||||
case_val.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
|
||||
auto case_body = std::make_unique<ast::BlockStatement>();
|
||||
case_body->append(std::make_unique<ast::BreakStatement>());
|
||||
auto case_body = create<ast::BlockStatement>();
|
||||
case_body->append(create<ast::BreakStatement>());
|
||||
|
||||
auto case_stmt = std::make_unique<ast::CaseStatement>(std::move(case_val),
|
||||
std::move(case_body));
|
||||
auto case_stmt =
|
||||
create<ast::CaseStatement>(std::move(case_val), std::move(case_body));
|
||||
|
||||
ast::CaseStatementList body;
|
||||
body.push_back(std::move(case_stmt));
|
||||
body.push_back(std::move(def));
|
||||
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
auto cond = create<ast::IdentifierExpression>("cond");
|
||||
ast::SwitchStatement s(std::move(cond), std::move(body));
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -50,10 +50,9 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, Generate) {
|
||||
ast::type::VoidType void_type;
|
||||
|
||||
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{},
|
||||
&void_type);
|
||||
func->add_decoration(std::make_unique<ast::StageDecoration>(
|
||||
ast::PipelineStage::kCompute, Source{}));
|
||||
auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
|
||||
func->add_decoration(
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
|
||||
mod.AddFunction(std::move(func));
|
||||
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
|
@ -157,24 +156,18 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberDecorationList decos;
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
|
||||
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)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
@ -188,44 +181,32 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
|||
ast::type::VectorType fvec(&f32, 3);
|
||||
|
||||
ast::StructMemberDecorationList decos;
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
|
||||
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)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &fvec, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &fvec, std::move(decos)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
|
||||
auto inner_str = std::make_unique<ast::Struct>();
|
||||
auto inner_str = create<ast::Struct>();
|
||||
inner_str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType inner_s("Inner", std::move(inner_str));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("d", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
|
||||
members.push_back(create<ast::StructMember>("d", &f32, std::move(decos)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("e", &inner_s, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(create<ast::StructMember>("e", &inner_s, std::move(decos)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(64, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("f", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(64, Source{}));
|
||||
members.push_back(create<ast::StructMember>("f", &f32, std::move(decos)));
|
||||
|
||||
auto outer_str = std::make_unique<ast::Struct>();
|
||||
auto outer_str = create<ast::Struct>();
|
||||
outer_str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType outer_s("Outer", std::move(outer_str));
|
||||
|
|
|
@ -176,16 +176,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &i32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
@ -199,16 +197,14 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &i32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
@ -226,24 +222,18 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberDecorationList decos;
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
|
||||
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)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
|
||||
|
||||
decos.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
|
||||
members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
@ -265,14 +255,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
members.push_back(create<ast::StructMember>(
|
||||
"main", &i32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("float", &f32, std::move(b_deco)));
|
||||
create<ast::StructMember>("float", &f32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
@ -291,19 +281,16 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &i32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(std::make_unique<ast::StructBlockDecoration>(Source{}));
|
||||
auto str =
|
||||
std::make_unique<ast::Struct>(std::move(decos), std::move(members));
|
||||
decos.push_back(create<ast::StructBlockDecoration>(Source{}));
|
||||
auto str = create<ast::Struct>(std::move(decos), std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
|||
TEST_P(MslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
auto expr = std::make_unique<ast::IdentifierExpression>("expr");
|
||||
auto expr = create<ast::IdentifierExpression>("expr");
|
||||
ast::UnaryOpExpression op(params.op, std::move(expr));
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();
|
||||
|
|
|
@ -42,8 +42,7 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -55,8 +54,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_is_const(true);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
@ -71,8 +69,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::ArrayType ary(&f32, 5);
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &ary);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &ary);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -86,21 +83,19 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
|||
ast::type::F32Type f32;
|
||||
|
||||
ast::StructMemberList members;
|
||||
members.push_back(std::make_unique<ast::StructMember>(
|
||||
"a", &f32, ast::StructMemberDecorationList{}));
|
||||
members.push_back(
|
||||
create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}));
|
||||
|
||||
ast::StructMemberDecorationList b_deco;
|
||||
b_deco.push_back(
|
||||
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(
|
||||
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
|
||||
members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
|
||||
|
||||
auto str = std::make_unique<ast::Struct>();
|
||||
auto str = create<ast::Struct>();
|
||||
str->set_members(std::move(members));
|
||||
|
||||
ast::type::StructType s("S", std::move(str));
|
||||
|
||||
auto var = std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &s);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &s);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -115,8 +110,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
|||
ast::type::F32Type f32;
|
||||
ast::type::VectorType vec(&f32, 2);
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &vec);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kFunction, &vec);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -129,8 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||
ast::type::F32Type f32;
|
||||
ast::type::MatrixType mat(&f32, 2, 3);
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &mat);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kFunction, &mat);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -142,8 +135,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
||||
|
@ -154,11 +146,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
||||
auto ident = std::make_unique<ast::IdentifierExpression>("initializer");
|
||||
auto ident = create<ast::IdentifierExpression>("initializer");
|
||||
|
||||
ast::type::F32Type f32;
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
|
||||
var->set_constructor(std::move(ident));
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
@ -174,10 +165,9 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
|||
|
||||
ast::ExpressionList values;
|
||||
auto zero_vec =
|
||||
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(values));
|
||||
create<ast::TypeConstructorExpression>(&vec, std::move(values));
|
||||
|
||||
auto var =
|
||||
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &vec);
|
||||
auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &vec);
|
||||
var->set_constructor(std::move(zero_vec));
|
||||
|
||||
ast::VariableDeclStatement stmt(std::move(var));
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
#ifndef SRC_WRITER_MSL_TEST_HELPER_H_
|
||||
#define SRC_WRITER_MSL_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 msl {
|
||||
|
||||
/// Helper class for testing
|
||||
template <typename T>
|
||||
class TestHelperBase : public T {
|
||||
template <typename BASE>
|
||||
class TestHelperBase : public BASE {
|
||||
public:
|
||||
TestHelperBase() : td(&ctx, &mod), gen(&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