cleanup: Refactor tests to use ast::Builder helpers
Change-Id: I5bf1dac217c9c6192c0637d98c4a38196d41cbe8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36382 Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
dbfe2de982
commit
1637cbb868
|
@ -28,9 +28,7 @@ namespace {
|
|||
using ElseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(ElseStatementTest, Creation) {
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
|
@ -57,9 +55,7 @@ TEST_F(ElseStatementTest, IsElse) {
|
|||
}
|
||||
|
||||
TEST_F(ElseStatementTest, HasCondition) {
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
auto* cond = Expr(true);
|
||||
auto* e =
|
||||
create<ElseStatement>(cond, create<BlockStatement>(StatementList{}));
|
||||
EXPECT_TRUE(e->HasCondition());
|
||||
|
@ -113,9 +109,7 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
|
|||
}
|
||||
|
||||
TEST_F(ElseStatementTest, ToStr) {
|
||||
type::Bool bool_type;
|
||||
auto* cond = create<ScalarConstructorExpression>(
|
||||
create<BoolLiteral>(&bool_type, true));
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
|
|
|
@ -25,26 +25,20 @@ namespace {
|
|||
using ScalarConstructorExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, Creation) {
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
auto* b = create<BoolLiteral>(ty.bool_, true);
|
||||
auto* c = create<ScalarConstructorExpression>(b);
|
||||
EXPECT_EQ(c->literal(), b);
|
||||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) {
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
auto* c =
|
||||
create<ScalarConstructorExpression>(Source{Source::Location{20, 2}}, b);
|
||||
auto src = c->source();
|
||||
SetSource(Source{Source::Location{20, 2}});
|
||||
auto src = Expr(true)->source();
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, IsValid) {
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
auto* c = create<ScalarConstructorExpression>(b);
|
||||
auto* c = Expr(true);
|
||||
EXPECT_TRUE(c->IsValid());
|
||||
}
|
||||
|
||||
|
@ -54,9 +48,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) {
|
|||
}
|
||||
|
||||
TEST_F(ScalarConstructorExpressionTest, ToStr) {
|
||||
type::Bool bool_type;
|
||||
auto* b = create<BoolLiteral>(&bool_type, true);
|
||||
auto* c = create<ScalarConstructorExpression>(b);
|
||||
auto* c = Expr(true);
|
||||
std::ostringstream out;
|
||||
c->to_str(out, 2);
|
||||
EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true}
|
||||
|
|
|
@ -57,12 +57,11 @@ fn main() -> { # missing return type
|
|||
|
||||
TEST_F(ParserImplTest, GetRegisteredType) {
|
||||
auto p = parser("");
|
||||
ast::type::I32 i32;
|
||||
p->register_constructed("my_alias", &i32);
|
||||
p->register_constructed("my_alias", ty.i32);
|
||||
|
||||
auto* alias = p->get_constructed("my_alias");
|
||||
ASSERT_NE(alias, nullptr);
|
||||
ASSERT_EQ(alias, &i32);
|
||||
ASSERT_EQ(alias, ty.i32);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, GetUnregisteredType) {
|
||||
|
|
|
@ -755,9 +755,8 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) {
|
|||
auto p = parser("texture_sampled_cube<f32>");
|
||||
|
||||
auto& mod = p->get_module();
|
||||
ast::type::F32 f32;
|
||||
auto* type = mod.create<ast::type::SampledTexture>(
|
||||
ast::type::TextureDimension::kCube, &f32);
|
||||
ast::type::TextureDimension::kCube, ty.f32);
|
||||
|
||||
auto t = p->type_decl();
|
||||
EXPECT_TRUE(t.matched);
|
||||
|
@ -772,10 +771,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) {
|
|||
TEST_F(ParserImplTest, TypeDecl_Texture) {
|
||||
auto p = parser("texture_cube<f32>");
|
||||
|
||||
ast::type::F32 f32;
|
||||
auto& mod = p->get_module();
|
||||
auto* type = mod.create<ast::type::SampledTexture>(
|
||||
ast::type::TextureDimension::kCube, &f32);
|
||||
ast::type::TextureDimension::kCube, ty.f32);
|
||||
|
||||
auto t = p->type_decl();
|
||||
EXPECT_TRUE(t.matched);
|
||||
|
|
|
@ -139,8 +139,7 @@ TEST_F(VertexPullingTest, BasicModule) {
|
|||
TEST_F(VertexPullingTest, OneAttribute) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
|
||||
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
||||
|
||||
|
@ -225,8 +224,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
|
|||
TEST_F(VertexPullingTest, OneInstancedAttribute) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
|
||||
InitTransform(
|
||||
{{{4, InputStepMode::kInstance, {{VertexFormat::kF32, 0, 0}}}}});
|
||||
|
@ -312,8 +310,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
|
|||
TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
|
||||
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
||||
transform()->SetPullingBufferBindingSet(5);
|
||||
|
@ -550,11 +547,8 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
|
|||
TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
AddVertexInputVariable(0, "var_a", &f32);
|
||||
|
||||
ast::type::Array vec4_f32{&f32, 4u, ast::ArrayDecorationList{}};
|
||||
AddVertexInputVariable(1, "var_b", &vec4_f32);
|
||||
AddVertexInputVariable(0, "var_a", ty.f32);
|
||||
AddVertexInputVariable(1, "var_b", ty.array<f32, 4>());
|
||||
|
||||
InitTransform(
|
||||
{{{16,
|
||||
|
@ -732,16 +726,9 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
|
|||
|
||||
TEST_F(VertexPullingTest, FloatVectorAttributes) {
|
||||
InitBasicModule();
|
||||
|
||||
ast::type::F32 f32;
|
||||
ast::type::Array vec2_f32{&f32, 2u, ast::ArrayDecorationList{}};
|
||||
AddVertexInputVariable(0, "var_a", &vec2_f32);
|
||||
|
||||
ast::type::Array vec3_f32{&f32, 3u, ast::ArrayDecorationList{}};
|
||||
AddVertexInputVariable(1, "var_b", &vec3_f32);
|
||||
|
||||
ast::type::Array vec4_f32{&f32, 4u, ast::ArrayDecorationList{}};
|
||||
AddVertexInputVariable(2, "var_c", &vec4_f32);
|
||||
AddVertexInputVariable(0, "var_a", ty.array<f32, 2>());
|
||||
AddVertexInputVariable(1, "var_b", ty.array<f32, 3>());
|
||||
AddVertexInputVariable(2, "var_c", ty.array<f32, 4>());
|
||||
|
||||
InitTransform(
|
||||
{{{8, InputStepMode::kVertex, {{VertexFormat::kVec2F32, 0, 0}}},
|
||||
|
|
|
@ -365,10 +365,8 @@ TEST_F(TypeDeterminerTest, Expr_Error_Unknown) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
|
||||
auto* idx = Expr(2);
|
||||
auto* var = Var("my_var", ast::StorageClass::kFunction, &ary);
|
||||
auto* var = Var("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||
mod->AddGlobalVariable(var);
|
||||
|
||||
EXPECT_TRUE(td()->Determine());
|
||||
|
@ -383,8 +381,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
auto* aary = ty.alias("myarrty", &ary);
|
||||
auto* aary = ty.alias("myarrty", ty.array<f32, 3>());
|
||||
|
||||
mod->AddGlobalVariable(Var("my_var", ast::StorageClass::kFunction, aary));
|
||||
|
||||
|
@ -400,9 +397,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Alias_Array) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
|
||||
auto* var = Const("my_var", ast::StorageClass::kFunction, &ary);
|
||||
auto* var = Const("my_var", ast::StorageClass::kFunction, ty.array<f32, 3>());
|
||||
mod->AddGlobalVariable(var);
|
||||
|
||||
EXPECT_TRUE(td()->Determine());
|
||||
|
@ -415,9 +410,7 @@ TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Array_Constant) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_ArrayAccessor_Matrix) {
|
||||
ast::type::Matrix mat(ty.f32, 3, 2);
|
||||
|
||||
auto* var = Var("my_var", ast::StorageClass::kNone, &mat);
|
||||
auto* var = Var("my_var", ast::StorageClass::kNone, ty.mat2x3<f32>());
|
||||
mod->AddGlobalVariable(var);
|
||||
|
||||
EXPECT_TRUE(td()->Determine());
|
||||
|
@ -529,9 +522,7 @@ TEST_F(TypeDeterminerTest, Expr_Cast) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
|
||||
auto* s = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ty.f32, 1.0f));
|
||||
|
||||
auto* s = Expr(1.0f);
|
||||
EXPECT_TRUE(td()->DetermineResultType(s));
|
||||
ASSERT_NE(s->result_type(), nullptr);
|
||||
EXPECT_TRUE(s->result_type()->Is<ast::type::F32>());
|
||||
|
@ -746,9 +737,7 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) {
|
|||
Func("my_func", ast::VariableList{}, ty.f32,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::AssignmentStatement>(
|
||||
Expr("var"), create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ty.f32, 1.f))),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
|
@ -1104,10 +1093,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Vector) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
|
||||
ast::type::Matrix mat3x2(ty.f32, 3, 2);
|
||||
|
||||
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
|
||||
auto* matrix = Var("matrix", ast::StorageClass::kNone, &mat3x2);
|
||||
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
|
||||
mod->AddGlobalVariable(scalar);
|
||||
mod->AddGlobalVariable(matrix);
|
||||
|
||||
|
@ -1126,10 +1113,8 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Scalar) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Scalar_Matrix) {
|
||||
ast::type::Matrix mat3x2(ty.f32, 3, 2);
|
||||
|
||||
auto* scalar = Var("scalar", ast::StorageClass::kNone, ty.f32);
|
||||
auto* matrix = Var("matrix", ast::StorageClass::kNone, &mat3x2);
|
||||
auto* matrix = Var("matrix", ast::StorageClass::kNone, ty.mat2x3<f32>());
|
||||
mod->AddGlobalVariable(scalar);
|
||||
mod->AddGlobalVariable(matrix);
|
||||
|
||||
|
@ -1188,19 +1173,14 @@ TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Vector_Matrix) {
|
|||
}
|
||||
|
||||
TEST_F(TypeDeterminerTest, Expr_Binary_Multiply_Matrix_Matrix) {
|
||||
ast::type::Matrix mat4x3(ty.f32, 4, 3);
|
||||
ast::type::Matrix mat3x4(ty.f32, 3, 4);
|
||||
|
||||
auto* matrix1 = Var( // source
|
||||
"mat4x3", ast::StorageClass::kNone, &mat4x3);
|
||||
auto* matrix2 = Var( // source
|
||||
"mat3x4", ast::StorageClass::kNone, &mat3x4);
|
||||
auto* matrix1 = Var("mat3x4", ast::StorageClass::kNone, ty.mat3x4<f32>());
|
||||
auto* matrix2 = Var("mat4x3", ast::StorageClass::kNone, ty.mat4x3<f32>());
|
||||
mod->AddGlobalVariable(matrix1);
|
||||
mod->AddGlobalVariable(matrix2);
|
||||
|
||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||
|
||||
auto* expr = Mul("mat4x3", "mat3x4");
|
||||
auto* expr = Mul("mat3x4", "mat4x3");
|
||||
|
||||
ASSERT_TRUE(td()->DetermineResultType(expr)) << td()->error();
|
||||
ASSERT_NE(expr->result_type(), nullptr);
|
||||
|
@ -2821,9 +2801,7 @@ TEST_P(ImportData_Matrix_OneParam_Test, NoParams) {
|
|||
TEST_P(ImportData_Matrix_OneParam_Test, TooManyParams) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::Matrix mat(ty.f32, 3, 3);
|
||||
|
||||
auto* var = Var("var", ast::StorageClass::kFunction, &mat);
|
||||
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
mod->AddGlobalVariable(var);
|
||||
|
||||
ASSERT_TRUE(td()->Determine()) << td()->error();
|
||||
|
|
|
@ -169,9 +169,7 @@ TEST_F(ValidateControlBlockTest,
|
|||
// case -1: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(ty.u32, 2)),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32, Expr(2u),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
|
@ -203,9 +201,7 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
|
|||
// case 2, 2: {}
|
||||
// default: {}
|
||||
// }
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(ty.u32, 3)),
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.u32, Expr(3u),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::CaseStatementList switch_body;
|
||||
|
|
|
@ -301,7 +301,6 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
|
|||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::type::Bool bool_type;
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
|
@ -336,7 +335,6 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
|
|||
auto* lhs = Expr("a");
|
||||
auto* rhs = Expr(3.14f);
|
||||
|
||||
ast::type::Bool bool_type;
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Source{Source::Location{12, 34}}, lhs,
|
||||
|
@ -476,7 +474,6 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
|
|||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::type::Bool bool_type;
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
|
@ -508,7 +505,6 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
|
|||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr(2.0f),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ast::type::Bool bool_type;
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{Source::Location{12, 34}}, var),
|
||||
|
|
|
@ -874,15 +874,14 @@ void main() {
|
|||
}
|
||||
|
||||
TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) {
|
||||
ast::type::Array ary(ty.f32, 5, ast::ArrayDecorationList{});
|
||||
|
||||
auto* func = Func("my_func",
|
||||
ast::VariableList{Var("a", ast::StorageClass::kNone, &ary)},
|
||||
ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
auto* func = Func(
|
||||
"my_func",
|
||||
ast::VariableList{Var("a", ast::StorageClass::kNone, ty.array<f32, 5>())},
|
||||
ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
mod->AddFunction(func);
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -28,8 +28,7 @@ namespace {
|
|||
using HlslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(HlslGeneratorImplTest, Generate) {
|
||||
ast::type::Void void_type;
|
||||
auto* func = Func("my_func", ast::VariableList{}, &void_type,
|
||||
auto* func = Func("my_func", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
|
|
@ -33,13 +33,11 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -52,10 +50,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(
|
||||
lit, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
|
@ -69,13 +65,11 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::FallthroughStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
@ -88,14 +82,12 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 6));
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(ty.i32, 6));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
|
|
@ -31,20 +31,14 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
||||
ast::ExpressionList params;
|
||||
params.push_back(Expr("id"));
|
||||
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.f32, params);
|
||||
auto* cast = Construct<f32>("id");
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(id)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
||||
ast::ExpressionList params;
|
||||
params.push_back(Expr("id"));
|
||||
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.vec3<f32>(), params);
|
||||
auto* cast = vec3<f32>("id");
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(id)");
|
||||
|
|
|
@ -38,136 +38,76 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
|
||||
auto* lit = create<ast::BoolLiteral>(ty.bool_, false);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
auto* expr = Expr(false);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "false");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
||||
auto* lit = create<ast::SintLiteral>(ty.i32, -12345);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
auto* expr = Expr(-12345);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "-12345");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
||||
auto* lit = create<ast::UintLiteral>(ty.u32, 56779);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
auto* expr = Expr(56779u);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "56779u");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
||||
// Use a number close to 1<<30 but whose decimal representation ends in 0.
|
||||
auto* lit =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>((1 << 30) - 4));
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
auto* expr = Expr(static_cast<float>((1 << 30) - 4));
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "1073741824.0f");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
auto* lit = create<ast::FloatLiteral>(ty.f32, -1.2e-5);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.f32, values);
|
||||
|
||||
auto* expr = Construct<f32>(-1.2e-5f);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(-0.000012f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
auto* lit = create<ast::BoolLiteral>(ty.bool_, true);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.bool_, values);
|
||||
|
||||
auto* expr = Construct<bool>(true);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool(true)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
auto* lit = create<ast::SintLiteral>(ty.i32, -12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.i32, values);
|
||||
|
||||
auto* expr = Construct<i32>(-12345);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "int(-12345)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
auto* lit = create<ast::UintLiteral>(ty.u32, 12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.u32, values);
|
||||
|
||||
auto* expr = Construct<u32>(12345u);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "uint(12345u)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
auto* lit1 = create<ast::FloatLiteral>(ty.f32, 1.f);
|
||||
auto* lit2 = create<ast::FloatLiteral>(ty.f32, 2.f);
|
||||
auto* lit3 = create<ast::FloatLiteral>(ty.f32, 3.f);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&vec, values);
|
||||
|
||||
auto* expr = vec3<f32>(1.f, 2.f, 3.f);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(1.0f, 2.0f, 3.0f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
ast::ExpressionList values;
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&vec, values);
|
||||
|
||||
auto* expr = vec3<f32>();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(0.0f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||
ast::type::Matrix mat(ty.f32, 3, 2); // 3 ROWS, 2 COLUMNS
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
// WGSL matrix is mat2x3 (it flips for AST, sigh). With a type constructor
|
||||
// of <vec3, vec3>
|
||||
|
||||
ast::ExpressionList mat_values;
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
auto* lit1 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(1 + (i * 2)));
|
||||
auto* lit2 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(2 + (i * 2)));
|
||||
auto* lit3 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(3 + (i * 2)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
|
||||
mat_values.push_back(vec3<f32>(static_cast<float>(1 + (i * 2)),
|
||||
static_cast<float>(2 + (i * 2)),
|
||||
static_cast<float>(3 + (i * 2))));
|
||||
}
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&mat, mat_values);
|
||||
auto* expr = Construct(ty.mat2x3<f32>(), mat_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
|
||||
// A matrix of type T with n columns and m rows can also be constructed from
|
||||
|
@ -177,28 +117,17 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
ast::type::Array ary(&vec, 3, ast::ArrayDecorationList{});
|
||||
ast::type::Array ary(ty.vec3<f32>(), 3, ast::ArrayDecorationList{});
|
||||
|
||||
ast::ExpressionList ary_values;
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
auto* lit1 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(1 + (i * 3)));
|
||||
auto* lit2 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(2 + (i * 3)));
|
||||
auto* lit3 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(3 + (i * 3)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
|
||||
ary_values.push_back(vec3<f32>(static_cast<float>(1 + (i * 3)),
|
||||
static_cast<float>(2 + (i * 3)),
|
||||
static_cast<float>(3 + (i * 3))));
|
||||
}
|
||||
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&ary, ary_values);
|
||||
auto* expr = Construct(&ary, ary_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(),
|
||||
"{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), "
|
||||
|
|
|
@ -578,8 +578,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
mod->AddFunction(sub_func);
|
||||
|
||||
ast::ExpressionList expr;
|
||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ty.f32, 1.0f)));
|
||||
expr.push_back(Expr(1.0f));
|
||||
|
||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||
Call("sub_func", 1.0f), ast::VariableDecorationList{});
|
||||
|
@ -710,8 +709,7 @@ TEST_F(MslGeneratorImplTest,
|
|||
mod->AddFunction(sub_func);
|
||||
|
||||
ast::ExpressionList expr;
|
||||
expr.push_back(create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ty.f32, 1.0f)));
|
||||
expr.push_back(Expr(1.0f));
|
||||
|
||||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||
Call("sub_func", 1.0f), ast::VariableDecorationList{});
|
||||
|
@ -764,15 +762,9 @@ TEST_F(MslGeneratorImplTest,
|
|||
});
|
||||
|
||||
auto body = ast::StatementList{
|
||||
create<ast::AssignmentStatement>(
|
||||
Expr("bar"), create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(ty.f32, 1.f))),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr(1.f)),
|
||||
create<ast::IfStatement>(create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(ty.i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::SintLiteral>(ty.i32, 1))),
|
||||
ast::BinaryOp::kEqual, Expr(1), Expr(1)),
|
||||
list, ast::ElseStatementList{}),
|
||||
create<ast::ReturnStatement>(),
|
||||
};
|
||||
|
@ -825,10 +817,8 @@ kernel void main_tint_0() {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) {
|
||||
ast::type::Array ary(ty.f32, 5, ast::ArrayDecorationList{});
|
||||
|
||||
ast::VariableList params;
|
||||
params.push_back(Var("a", ast::StorageClass::kNone, &ary)); // decorations
|
||||
params.push_back(Var("a", ast::StorageClass::kNone, ty.array<f32, 5>()));
|
||||
|
||||
auto* func = Func("my_func", params, ty.void_,
|
||||
ast::StatementList{
|
||||
|
|
|
@ -117,8 +117,8 @@ using MslImportData_DualParam_VectorTest = TestParamHelper<MslImportData>;
|
|||
TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
|
||||
auto param = GetParam();
|
||||
|
||||
auto* expr = Call(param.name, Construct(ty.vec3<f32>(), 1.f, 2.f, 3.f),
|
||||
Construct(ty.vec3<f32>(), 4.f, 5.f, 6.f));
|
||||
auto* expr =
|
||||
Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
ASSERT_TRUE(gen.EmitCall(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string("metal::") + param.msl_name +
|
||||
|
@ -178,10 +178,7 @@ INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
|||
MslImportData{"clamp", "clamp"}));
|
||||
|
||||
TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Matrix mat(&f32, 3, 3);
|
||||
|
||||
auto* var = Var("var", ast::StorageClass::kFunction, &mat);
|
||||
auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
mod->AddGlobalVariable(var);
|
||||
|
||||
auto* expr = Call("determinant", "var");
|
||||
|
|
|
@ -35,12 +35,9 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
auto* var =
|
||||
Const("pos", ast::StorageClass::kNone, &ary,
|
||||
create<ast::TypeConstructorExpression>(
|
||||
&ary, ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)}),
|
||||
ast::VariableDecorationList{});
|
||||
Const("pos", ast::StorageClass::kNone, ty.array<f32, 3>(),
|
||||
array<f32, 3>(1.f, 2.f, 3.f), ast::VariableDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "constant float pos[3] = {1.0f, 2.0f, 3.0f};\n");
|
||||
|
|
|
@ -116,35 +116,27 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_alias) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_array) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Array ary(&f32, 4, ast::ArrayDecorationList{});
|
||||
EXPECT_EQ(4u * 4u, gen.calculate_alignment_size(&ary));
|
||||
EXPECT_EQ(4u * 4u, gen.calculate_alignment_size(ty.array<f32, 4>()));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_bool) {
|
||||
ast::type::Bool bool_type;
|
||||
EXPECT_EQ(1u, gen.calculate_alignment_size(&bool_type));
|
||||
EXPECT_EQ(1u, gen.calculate_alignment_size(ty.bool_));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_f32) {
|
||||
ast::type::F32 f32;
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&f32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(ty.f32));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_i32) {
|
||||
ast::type::I32 i32;
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&i32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(ty.i32));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_matrix) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Matrix mat(&f32, 3, 2);
|
||||
EXPECT_EQ(4u * 3u * 2u, gen.calculate_alignment_size(&mat));
|
||||
EXPECT_EQ(4u * 3u * 2u, gen.calculate_alignment_size(ty.mat3x2<f32>()));
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_pointer) {
|
||||
ast::type::Bool bool_type;
|
||||
ast::type::Pointer ptr(&bool_type, ast::StorageClass::kPrivate);
|
||||
ast::type::Pointer ptr(ty.bool_, ast::StorageClass::kPrivate);
|
||||
EXPECT_EQ(0u, gen.calculate_alignment_size(&ptr));
|
||||
}
|
||||
|
||||
|
@ -179,8 +171,7 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, calculate_alignment_size_u32) {
|
||||
ast::type::U32 u32;
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(&u32));
|
||||
EXPECT_EQ(4u, gen.calculate_alignment_size(ty.u32));
|
||||
}
|
||||
|
||||
struct MslVectorSizeData {
|
||||
|
@ -195,8 +186,7 @@ using MslVectorSizeBoolTest = TestParamHelper<MslVectorSizeData>;
|
|||
TEST_P(MslVectorSizeBoolTest, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::Bool bool_type;
|
||||
ast::type::Vector vec(&bool_type, param.elements);
|
||||
ast::type::Vector vec(ty.bool_, param.elements);
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
@ -209,8 +199,7 @@ using MslVectorSizeI32Test = TestParamHelper<MslVectorSizeData>;
|
|||
TEST_P(MslVectorSizeI32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32 i32;
|
||||
ast::type::Vector vec(&i32, param.elements);
|
||||
ast::type::Vector vec(ty.i32, param.elements);
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
@ -223,8 +212,7 @@ using MslVectorSizeU32Test = TestParamHelper<MslVectorSizeData>;
|
|||
TEST_P(MslVectorSizeU32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32 u32;
|
||||
ast::type::Vector vec(&u32, param.elements);
|
||||
ast::type::Vector vec(ty.u32, param.elements);
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
@ -237,8 +225,7 @@ using MslVectorSizeF32Test = TestParamHelper<MslVectorSizeData>;
|
|||
TEST_P(MslVectorSizeF32Test, calculate) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, param.elements);
|
||||
ast::type::Vector vec(ty.f32, param.elements);
|
||||
EXPECT_EQ(param.byte_size, gen.calculate_alignment_size(&vec));
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
|
|
@ -59,108 +59,78 @@ TEST_F(MslGeneratorImplTest, EmitType_Alias_NameCollision) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a, "ary")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.array<bool, 4>(), "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&c, "ary")) << gen.error();
|
||||
auto* a = ty.array<bool, 4>();
|
||||
auto* b = ty.array(a, 5);
|
||||
ASSERT_TRUE(gen.EmitType(b, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[5][4]");
|
||||
}
|
||||
|
||||
// TODO(dsinclair): Is this possible? What order should it output in?
|
||||
TEST_F(MslGeneratorImplTest, DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
|
||||
ast::type::Array d(&c, 0, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&c, "ary")) << gen.error();
|
||||
auto* a = ty.array<bool, 4>();
|
||||
auto* b = ty.array(a, 5);
|
||||
auto* c = ty.array(b, 0);
|
||||
ASSERT_TRUE(gen.EmitType(c, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[5][4][1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
|
||||
ast::type::Array d(&c, 6, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&d, "ary")) << gen.error();
|
||||
auto* a = ty.array<bool, 4>();
|
||||
auto* b = ty.array(a, 5);
|
||||
auto* c = ty.array(b, 6);
|
||||
ASSERT_TRUE(gen.EmitType(c, "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[6][5][4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array_NameCollision) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a, "bool")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.array<bool, 4>(), "bool")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool bool_tint_0[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.array<bool, 4>(), "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool[4]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 0, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a, "ary")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.array<bool, 1>(), "ary")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool ary[1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray_NameCollision) {
|
||||
ast::type::Bool b;
|
||||
ast::type::Array a(&b, 0, ast::ArrayDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&a, "discard_fragment")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.array<bool, 1>(), "discard_fragment"))
|
||||
<< gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool discard_fragment_tint_0[1]");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Bool) {
|
||||
ast::type::Bool b;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&b, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.bool_, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_F32) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&f32, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.f32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_I32) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&i32, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.i32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "int");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Matrix) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Matrix m(&f32, 3, 2);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&m, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.mat2x3<f32>(), "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float2x3");
|
||||
}
|
||||
|
||||
// TODO(dsinclair): How to annotate as workgroup?
|
||||
TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Pointer) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Pointer p(&f32, ast::StorageClass::kWorkgroup);
|
||||
ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&p, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float*");
|
||||
|
@ -247,24 +217,17 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_U32) {
|
||||
ast::type::U32 u32;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&u32, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.u32, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "uint");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Vector) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector v(&f32, 3);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&v, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.vec3<f32>(), "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
||||
ast::type::Void v;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&v, "")) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.void_, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "void");
|
||||
}
|
||||
|
||||
|
@ -324,8 +287,7 @@ using MslSampledtexturesTest = TestParamHelper<MslTextureData>;
|
|||
TEST_P(MslSampledtexturesTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
ast::type::SampledTexture s(params.dim, &f32);
|
||||
ast::type::SampledTexture s(params.dim, ty.f32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
|
@ -350,8 +312,7 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
"texturecube_array<float, access::sample>"}));
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) {
|
||||
ast::type::U32 u32;
|
||||
ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, &u32);
|
||||
ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, ty.u32);
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&s, "")) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "texture2d_ms<uint, access::sample>");
|
||||
|
|
|
@ -131,9 +131,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
||||
ast::ExpressionList values;
|
||||
auto* zero_vec =
|
||||
create<ast::TypeConstructorExpression>(ty.vec3<f32>(), values);
|
||||
auto* zero_vec = vec3<f32>();
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.vec3<f32>(), zero_vec,
|
||||
ast::VariableDecorationList{});
|
||||
|
|
|
@ -718,7 +718,6 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
|
|||
// vec2<f32>(0.5, -0.5));
|
||||
// pos[1]
|
||||
|
||||
ast::type::U32 u32;
|
||||
ast::type::Array arr(ty.vec2<f32>(), 3, ast::ArrayDecorationList{});
|
||||
|
||||
auto* var = Const("pos", ast::StorageClass::kPrivate, &arr,
|
||||
|
|
|
@ -88,8 +88,7 @@ TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
|||
TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
auto* val = create<ast::TypeConstructorExpression>(ty.vec3<f32>(),
|
||||
ast::ExpressionList{});
|
||||
auto* val = vec3<f32>();
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
@ -115,11 +114,7 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||
auto* first = create<ast::TypeConstructorExpression>(
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
|
@ -154,8 +149,7 @@ OpStore %1 %13
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 2.f, 3.f);
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
|
@ -231,8 +225,7 @@ OpStore %8 %9
|
|||
TEST_F(BuilderTest, Assign_Vector) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
auto* val = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* val = vec3<f32>(1.f, 1.f, 3.f);
|
||||
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
|
|
@ -140,12 +140,8 @@ using BinaryArithUnsignedIntegerTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32 u32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
auto* lhs = Expr(3u);
|
||||
auto* rhs = Expr(4u);
|
||||
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
|
@ -201,12 +197,8 @@ using BinaryArithFloatTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryArithFloatTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::FloatLiteral>(&f32, 4.5f));
|
||||
auto* lhs = Expr(3.2f);
|
||||
auto* rhs = Expr(4.5f);
|
||||
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
|
@ -256,12 +248,8 @@ using BinaryCompareUnsignedIntegerTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32 u32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
auto* lhs = Expr(3u);
|
||||
auto* rhs = Expr(4u);
|
||||
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
|
@ -522,8 +510,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
|
||||
TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
|
@ -552,8 +539,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
|||
|
||||
TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
|
@ -643,8 +629,6 @@ OpBranch %7
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
||||
ast::type::Bool bool_type;
|
||||
|
||||
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_, Expr(true),
|
||||
ast::VariableDecorationList{});
|
||||
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_, Expr(false),
|
||||
|
@ -686,24 +670,15 @@ OpBranch %9
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
|
||||
ast::type::Bool bool_ty;
|
||||
|
||||
// Test an expression like
|
||||
// a || (b && c)
|
||||
// From: crbug.com/tint/355
|
||||
|
||||
auto* logical_and_expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalAnd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, false)));
|
||||
ast::BinaryOp::kLogicalAnd, Expr(true), Expr(false));
|
||||
|
||||
auto* expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalOr,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
logical_and_expr);
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||
Expr(true), logical_and_expr);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
|
@ -733,24 +708,15 @@ OpBranch %4
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
|
||||
ast::type::Bool bool_ty;
|
||||
|
||||
// Test an expression like
|
||||
// a && (b || c)
|
||||
// From: crbug.com/tint/355
|
||||
|
||||
auto* logical_or_expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalOr,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, false)));
|
||||
ast::BinaryOp::kLogicalOr, Expr(true), Expr(false));
|
||||
|
||||
auto* expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalAnd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
logical_or_expr);
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
||||
Expr(true), logical_or_expr);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
|
@ -816,8 +782,6 @@ OpBranch %7
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
||||
ast::type::Bool bool_type;
|
||||
|
||||
auto* a_var = Var("a", ast::StorageClass::kFunction, ty.bool_, Expr(true),
|
||||
ast::VariableDecorationList{});
|
||||
auto* b_var = Var("b", ast::StorageClass::kFunction, ty.bool_, Expr(false),
|
||||
|
|
|
@ -49,8 +49,6 @@ TEST_F(BuilderTest, Bitcast) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
auto* bitcast = create<ast::BitcastExpression>(ty.f32, Expr(2.4f));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
|
||||
|
|
|
@ -35,8 +35,6 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Block) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
// Note, this test uses shadow variables which aren't allowed in WGSL but
|
||||
// serves to prove the block code is pushing new scopes as needed.
|
||||
auto* inner = create<ast::BlockStatement>(ast::StatementList{
|
||||
|
|
|
@ -40,9 +40,6 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Expression_Call) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Void void_type;
|
||||
|
||||
ast::VariableList func_params;
|
||||
func_params.push_back(Var("a", ast::StorageClass::kFunction, ty.f32));
|
||||
func_params.push_back(Var("b", ast::StorageClass::kFunction, ty.f32));
|
||||
|
|
|
@ -115,7 +115,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
|
|||
// cast<Int>(2.3f)
|
||||
|
||||
auto* alias = ty.alias("Int", ty.i32);
|
||||
auto* cast = create<ast::TypeConstructorExpression>(alias, ExprList(2.3f));
|
||||
auto* cast = Construct(alias, 2.3f);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -197,7 +197,7 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.bool_, ExprList(true));
|
||||
auto* cast = Construct<bool>(true);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -213,7 +213,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.i32, ExprList(2));
|
||||
auto* cast = Construct<i32>(2);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -227,7 +227,7 @@ TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.u32, ExprList(2u));
|
||||
auto* cast = Construct<u32>(2u);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -241,7 +241,7 @@ TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.f32, ExprList(2.0f));
|
||||
auto* cast = Construct<f32>(2.0f);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -993,7 +993,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_F32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
|
||||
auto* t = Construct(ty.i32);
|
||||
auto* t = Construct<i32>();
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
||||
|
||||
|
@ -1008,7 +1008,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_I32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_U32) {
|
||||
auto* t = Construct(ty.u32);
|
||||
auto* t = Construct<u32>();
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(t)) << td.error();
|
||||
|
||||
|
@ -1110,7 +1110,7 @@ TEST_F(SpvBuilderConstructorTest, Type_ZeroInit_Struct) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
|
||||
auto* cast = Construct(ty.i32, 2u);
|
||||
auto* cast = Construct<i32>(2u);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1127,7 +1127,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_I32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
|
||||
auto* cast = Construct(ty.u32, 2);
|
||||
auto* cast = Construct<u32>(2);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1144,7 +1144,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_U32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
|
||||
auto* cast = Construct(ty.i32, 2.4f);
|
||||
auto* cast = Construct<i32>(2.4f);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1161,7 +1161,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_I32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
|
||||
auto* cast = Construct(ty.u32, 2.4f);
|
||||
auto* cast = Construct<u32>(2.4f);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1178,7 +1178,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_F32_To_U32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
|
||||
auto* cast = Construct(ty.f32, 2);
|
||||
auto* cast = Construct<f32>(2);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1195,7 +1195,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_I32_To_F32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
|
||||
auto* cast = Construct(ty.f32, 2u);
|
||||
auto* cast = Construct<f32>(2u);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1214,7 +1214,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_U32_To_F32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_I32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<i32>(), "i");
|
||||
auto* cast = vec3<i32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1239,7 +1239,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_I32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_I32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<i32>(), "i");
|
||||
auto* cast = vec3<i32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1264,7 +1264,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_I32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_U32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<u32>(), "i");
|
||||
auto* cast = vec3<u32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1289,7 +1289,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_U32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_U32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<f32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<u32>(), "i");
|
||||
auto* cast = vec3<u32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_F32_to_U32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_F32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<i32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<f32>(), "i");
|
||||
auto* cast = vec3<f32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
@ -1339,7 +1339,7 @@ TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_I32_to_F32) {
|
|||
TEST_F(SpvBuilderConstructorTest, Type_Convert_Vectors_U32_to_F32) {
|
||||
auto* var = Var("i", ast::StorageClass::kPrivate, ty.vec3<u32>());
|
||||
|
||||
auto* cast = Construct(ty.vec3<f32>(), "i");
|
||||
auto* cast = vec3<f32>("i");
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#include "src/ast/identifier_expression.h"
|
||||
#include "src/ast/pipeline_stage.h"
|
||||
#include "src/ast/stage_decoration.h"
|
||||
#include "src/ast/type/f32_type.h"
|
||||
#include "src/ast/type/void_type.h"
|
||||
#include "src/ast/variable.h"
|
||||
#include "src/ast/workgroup_decoration.h"
|
||||
#include "src/type_determiner.h"
|
||||
|
@ -88,9 +86,6 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
SpvExecutionModelGLCompute}));
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Void void_type;
|
||||
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
|
|
|
@ -63,8 +63,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -93,8 +92,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Add(3.f, 3.f)});
|
||||
auto* init = vec2<f32>(1.f, Add(3.f, 3.f));
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
|
||||
|
@ -203,8 +201,7 @@ OpStore %7 %6
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionVar_Const) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
|
|
@ -85,8 +85,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -109,8 +108,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_Const) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -131,8 +129,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -152,11 +149,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||
auto* first = create<ast::TypeConstructorExpression>(
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
auto* init = vec3<f32>(vec2<f32>(1.f, 2.f), 3.f);
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -81,8 +80,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* init = vec3<f32>(1.f, 1.f, 3.f);
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
|
|
@ -41,12 +41,9 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, If_Empty) {
|
||||
ast::type::Bool bool_type;
|
||||
|
||||
// if (true) {
|
||||
// }
|
||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto* cond = Expr(true);
|
||||
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
cond, create<ast::BlockStatement>(ast::StatementList{}),
|
||||
|
@ -70,13 +67,10 @@ OpBranch %3
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, If_Empty_OutsideFunction_IsError) {
|
||||
ast::type::Bool bool_type;
|
||||
|
||||
// Outside a function.
|
||||
// if (true) {
|
||||
// }
|
||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
auto* cond = Expr(true);
|
||||
|
||||
ast::ElseStatementList elses;
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{});
|
||||
|
|
|
@ -100,7 +100,6 @@ OpBranch %5
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Loop_WithContinuing) {
|
||||
ast::type::I32 i32;
|
||||
// loop {
|
||||
// a = 2;
|
||||
// continuing {
|
||||
|
|
|
@ -46,8 +46,7 @@ TEST_F(BuilderTest, Return) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Return_WithValue) {
|
||||
auto* val = create<ast::TypeConstructorExpression>(
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
auto* val = vec3<f32>(1.f, 1.f, 3.f);
|
||||
|
||||
auto* ret = create<ast::ReturnStatement>(val);
|
||||
|
||||
|
|
|
@ -31,8 +31,7 @@ namespace {
|
|||
using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitExpression_ArrayAccessor) {
|
||||
auto* lit = create<ast::SintLiteral>(ty.i32, 5);
|
||||
auto* idx = create<ast::ScalarConstructorExpression>(lit);
|
||||
auto* idx = Expr(5);
|
||||
auto* ary = Expr("ary");
|
||||
|
||||
auto* expr = create<ast::ArrayAccessorExpression>(ary, idx);
|
||||
|
|
|
@ -30,9 +30,7 @@ namespace {
|
|||
using WgslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, Generate) {
|
||||
ast::type::Void void_type;
|
||||
|
||||
mod->AddFunction(Func("my_func", ast::VariableList{}, &void_type,
|
||||
mod->AddFunction(Func("my_func", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{}, ast::FunctionDecorationList{}));
|
||||
|
||||
ASSERT_TRUE(gen.Generate(*mod)) << gen.error();
|
||||
|
|
|
@ -202,9 +202,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector) {
|
|||
}
|
||||
|
||||
TEST_F(WgslGeneratorImplTest, EmitType_Void) {
|
||||
ast::type::Void v;
|
||||
|
||||
ASSERT_TRUE(gen.EmitType(&v)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitType(ty.void_)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "void");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue