reader/spirv: Test with WGSL writer intead of to_str()
This change replaces all the SPIR-V reader tests to their equivalent WGSL form. Bug: tint:1225 Change-Id: Idf0e6050f49fad0a8223b50bac89014dbdcf9b2b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/66444 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
1364f202da
commit
a5b3f07ec7
|
@ -741,7 +741,7 @@ if(${TINT_BUILD_TESTS})
|
|||
)
|
||||
endif()
|
||||
|
||||
if(${TINT_BUILD_SPV_READER})
|
||||
if(${TINT_BUILD_SPV_READER} AND ${TINT_BUILD_WGSL_WRITER})
|
||||
list(APPEND TINT_TEST_SRCS
|
||||
reader/spirv/enum_converter_test.cc
|
||||
reader/spirv/fail_stream_test.cc
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -51,33 +51,19 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
|
|||
OpFunctionEnd
|
||||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
const auto got = p->program().to_str(false);
|
||||
const char* expect = R"(Module{
|
||||
Function $1 -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
Function $2 -> __void
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{$1}
|
||||
(
|
||||
)
|
||||
}
|
||||
Return{}
|
||||
}
|
||||
Function $3 -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{$2}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
const auto got = test::ToString(p->program());
|
||||
const char* expect = R"(fn x_50() {
|
||||
return;
|
||||
}
|
||||
|
||||
fn x_100_1() {
|
||||
x_50();
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn x_100() {
|
||||
x_100_1();
|
||||
}
|
||||
)";
|
||||
EXPECT_EQ(expect, got);
|
||||
|
@ -103,37 +89,22 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
|
|||
OpFunctionEnd
|
||||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
ast::StatementList f100;
|
||||
{
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{x_50}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
f100 = fe.ast_body();
|
||||
}
|
||||
}
|
||||
Return{})"));
|
||||
}
|
||||
|
||||
ast::StatementList f50;
|
||||
{
|
||||
auto fe = p->function_emitter(50);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Return{
|
||||
{
|
||||
ScalarConstructor[not set]{42u}
|
||||
}
|
||||
})"));
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
f50 = fe.ast_body();
|
||||
}
|
||||
auto program = p->program();
|
||||
EXPECT_THAT(test::ToString(program, f100),
|
||||
HasSubstr("let x_1 : u32 = x_50();\nreturn;"));
|
||||
EXPECT_THAT(test::ToString(program, f50), HasSubstr("return 42u;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) {
|
||||
|
@ -160,55 +131,26 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) {
|
|||
OpFunctionEnd
|
||||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
ast::StatementList f100;
|
||||
{
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto got = ToString(p->builder(), fe.ast_body());
|
||||
const std::string expected =
|
||||
R"(VariableDeclStatement{
|
||||
Variable{
|
||||
x_10
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{x_50}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_10}
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_10}
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
Return{}
|
||||
)";
|
||||
EXPECT_EQ(got, expected);
|
||||
f100 = fe.ast_body();
|
||||
}
|
||||
ast::StatementList f50;
|
||||
{
|
||||
auto fe = p->function_emitter(50);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Return{
|
||||
{
|
||||
ScalarConstructor[not set]{42u}
|
||||
}
|
||||
})"));
|
||||
f50 = fe.ast_body();
|
||||
}
|
||||
auto program = p->program();
|
||||
EXPECT_EQ(test::ToString(program, f100), R"(var x_10 : u32;
|
||||
let x_1 : u32 = x_50();
|
||||
x_10 = x_1;
|
||||
x_10 = x_1;
|
||||
return;
|
||||
)");
|
||||
EXPECT_THAT(test::ToString(program, f50), HasSubstr("return 42u;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
||||
|
@ -236,66 +178,19 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
|
|||
)"));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto program_ast_str = p->program().to_str();
|
||||
const std::string expected = R"(Module{
|
||||
Function x_50 -> __u32
|
||||
(
|
||||
VariableConst{
|
||||
x_51
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
VariableConst{
|
||||
x_52
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
)
|
||||
{
|
||||
Return{
|
||||
{
|
||||
Binary[not set]{
|
||||
Identifier[not set]{x_51}
|
||||
add
|
||||
Identifier[not set]{x_52}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Function x_100_1 -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{x_50}
|
||||
(
|
||||
ScalarConstructor[not set]{42u}
|
||||
ScalarConstructor[not set]{84u}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Return{}
|
||||
}
|
||||
Function x_100 -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{x_100_1}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
const auto program_ast_str = test::ToString(p->program());
|
||||
const std::string expected = R"(fn x_50(x_51 : u32, x_52 : u32) -> u32 {
|
||||
return (x_51 + x_52);
|
||||
}
|
||||
|
||||
fn x_100_1() {
|
||||
let x_1 : u32 = x_50(42u, 84u);
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn x_100() {
|
||||
x_100_1();
|
||||
}
|
||||
)";
|
||||
EXPECT_EQ(program_ast_str, expected);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -83,18 +83,9 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Bitcast[not set]<__u32>{
|
||||
ScalarConstructor[not set]{50.000000}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : u32 = bitcast<u32>(50.0);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
|
||||
|
@ -109,22 +100,11 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
Bitcast[not set]<__vec_2__f32>{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__u32
|
||||
ScalarConstructor[not set]{10u}
|
||||
ScalarConstructor[not set]{20u}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(
|
||||
test::ToString(p->program(), ast_body),
|
||||
HasSubstr(
|
||||
"let x_1 : vec2<f32> = bitcast<vec2<f32>>(vec2<u32>(10u, 20u));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) {
|
||||
|
@ -239,18 +219,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__f32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : f32 = f32(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
|
||||
|
@ -266,20 +237,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__f32
|
||||
Bitcast[not set]<__i32>{
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : f32 = f32(bitcast<i32>(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
|
||||
|
@ -295,18 +255,9 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<f32> = vec2<f32>(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
|
||||
|
@ -322,20 +273,10 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
Bitcast[not set]<__vec_2__i32>{
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(
|
||||
test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<f32> = vec2<f32>(bitcast<vec2<i32>>(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) {
|
||||
|
@ -386,20 +327,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__f32
|
||||
Bitcast[not set]<__u32>{
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : f32 = f32(bitcast<u32>(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
|
||||
|
@ -415,18 +345,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__f32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : f32 = f32(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
|
||||
|
@ -442,20 +363,10 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
Bitcast[not set]<__vec_2__u32>{
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(
|
||||
test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<f32> = vec2<f32>(bitcast<vec2<u32>>(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
|
||||
|
@ -471,18 +382,9 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<f32> = vec2<f32>(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) {
|
||||
|
@ -534,18 +436,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__i32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : i32 = i32(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
|
||||
|
@ -561,20 +454,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Bitcast[not set]<__u32>{
|
||||
TypeConstructor[not set]{
|
||||
__i32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : u32 = bitcast<u32>(i32(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
|
||||
|
@ -590,18 +472,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__i32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__i32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<i32> = vec2<i32>(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
|
||||
|
@ -617,20 +490,10 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__u32
|
||||
{
|
||||
Bitcast[not set]<__vec_2__u32>{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__i32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(
|
||||
test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<u32> = bitcast<vec2<u32>>(vec2<i32>(x_30));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) {
|
||||
|
@ -698,18 +561,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__u32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : u32 = u32(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned_IsError) {
|
||||
|
@ -741,18 +595,9 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__vec_2__u32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__u32
|
||||
Identifier[not set]{x_30}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_1 : vec2<u32> = vec2<u32>(x_30);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvUnaryConversionTest, ConvertFToU_HoistedValue) {
|
||||
|
@ -792,18 +637,9 @@ OpFunctionEnd
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(VariableConst{
|
||||
x_82
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__u32
|
||||
Identifier[not set]{x_600}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_82 : u32 = u32(x_600);"));
|
||||
}
|
||||
|
||||
// TODO(dneto): OpSConvert // only if multiple widths
|
||||
|
|
|
@ -73,13 +73,9 @@ TEST_F(SpvParserTest, Emit_VoidFunctionWithoutParams) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
auto got = p->program().to_str();
|
||||
std::string expect = R"(Module{
|
||||
Function x_100 -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
auto got = test::ToString(p->program());
|
||||
std::string expect = R"(fn x_100() {
|
||||
return;
|
||||
}
|
||||
)";
|
||||
EXPECT_EQ(got, expect);
|
||||
|
@ -97,17 +93,9 @@ TEST_F(SpvParserTest, Emit_NonVoidResultType) {
|
|||
auto fe = p->function_emitter(200);
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->program().to_str();
|
||||
std::string expect = R"(Module{
|
||||
Function x_200 -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
{
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
auto got = test::ToString(p->program());
|
||||
std::string expect = R"(fn x_200() -> f32 {
|
||||
return 0.0;
|
||||
}
|
||||
)";
|
||||
EXPECT_THAT(got, HasSubstr(expect));
|
||||
|
@ -130,32 +118,9 @@ TEST_F(SpvParserTest, Emit_MixedParamTypes) {
|
|||
auto fe = p->function_emitter(200);
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->program().to_str();
|
||||
std::string expect = R"(Module{
|
||||
Function x_200 -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
VariableConst{
|
||||
b
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
}
|
||||
VariableConst{
|
||||
c
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
}
|
||||
)
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
auto got = test::ToString(p->program());
|
||||
std::string expect = R"(fn x_200(a : u32, b : f32, c : i32) {
|
||||
return;
|
||||
}
|
||||
)";
|
||||
EXPECT_THAT(got, HasSubstr(expect));
|
||||
|
@ -177,32 +142,9 @@ TEST_F(SpvParserTest, Emit_GenerateParamNames) {
|
|||
auto fe = p->function_emitter(200);
|
||||
EXPECT_TRUE(fe.Emit());
|
||||
|
||||
auto got = p->program().to_str();
|
||||
std::string expect = R"(Module{
|
||||
Function x_200 -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
VariableConst{
|
||||
x_15
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
}
|
||||
VariableConst{
|
||||
x_16
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
}
|
||||
)
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
auto got = test::ToString(p->program());
|
||||
std::string expect = R"(fn x_200(x_14 : u32, x_15 : f32, x_16 : i32) {
|
||||
return;
|
||||
}
|
||||
)";
|
||||
EXPECT_THAT(got, HasSubstr(expect));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -57,18 +57,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreBoolConst) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{true}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{false}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{false}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = true;
|
||||
x_1 = false;
|
||||
x_1 = false;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_StoreUintConst) {
|
||||
|
@ -90,14 +83,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreUintConst) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{42u}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{0u}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42u;
|
||||
x_1 = 0u;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_StoreIntConst) {
|
||||
|
@ -119,14 +108,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreIntConst) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{42}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{0}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42;
|
||||
x_1 = 0;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_StoreFloatConst) {
|
||||
|
@ -148,14 +133,10 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreFloatConst) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr(R"(x_1 = 42.0;
|
||||
x_1 = 0.0;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_LoadBool) {
|
||||
|
@ -177,16 +158,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_LoadBool) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__bool
|
||||
{
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_2 : bool = x_1;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_LoadScalar) {
|
||||
|
@ -207,29 +181,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_LoadScalar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_3
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_2 : u32 = x_1;
|
||||
let x_3 : u32 = x_1;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_UseLoadedScalarTwice) {
|
||||
|
@ -251,26 +207,11 @@ TEST_F(SpvParserMemoryTest, EmitStatement_UseLoadedScalarTwice) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
Identifier[not set]{x_2}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
Identifier[not set]{x_2}
|
||||
}
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_2 : u32 = x_1;
|
||||
x_1 = x_2;
|
||||
x_1 = x_2;
|
||||
)"));
|
||||
}
|
||||
|
||||
|
@ -291,10 +232,8 @@ TEST_F(SpvParserMemoryTest, EmitStatement_StoreToModuleScopeVar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
Identifier[not set]{x_1}
|
||||
ScalarConstructor[not set]{42u}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body), HasSubstr("x_1 = 42u;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest,
|
||||
|
@ -317,11 +256,9 @@ TEST_F(SpvParserMemoryTest,
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
const auto got = ToString(p->builder(), fe.ast_body());
|
||||
const auto* expected = R"(Assignment{
|
||||
Identifier[not set]{x_2}
|
||||
Identifier[not set]{x_1}
|
||||
})";
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto got = test::ToString(p->program(), ast_body);
|
||||
const auto* expected = "x_2 = x_1;";
|
||||
EXPECT_THAT(got, HasSubstr(expected));
|
||||
}
|
||||
|
||||
|
@ -386,13 +323,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorSwizzle) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{z}
|
||||
}
|
||||
ScalarConstructor[not set]{42u}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar.z = 42u;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorConstOutOfBounds) {
|
||||
|
@ -452,13 +385,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_VectorNonConstIndex) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{a_dynamic_index}
|
||||
}
|
||||
ScalarConstructor[not set]{42u}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar[a_dynamic_index] = 42u;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Matrix) {
|
||||
|
@ -489,19 +418,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Matrix) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
ScalarConstructor[not set]{2u}
|
||||
}
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar[2u] = vec4<f32>(42.0, 42.0, 42.0, 42.0);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Array) {
|
||||
|
@ -532,19 +451,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Array) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
ScalarConstructor[not set]{2u}
|
||||
}
|
||||
TypeConstructor[not set]{
|
||||
__vec_4__f32
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar[2u] = vec4<f32>(42.0, 42.0, 42.0, 42.0);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct) {
|
||||
|
@ -574,13 +483,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{age}
|
||||
}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar.age = 42.0;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest,
|
||||
|
@ -623,20 +528,11 @@ TEST_F(SpvParserMemoryTest,
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{age}
|
||||
}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
}
|
||||
Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar2}
|
||||
Identifier[not set]{ancientness}
|
||||
}
|
||||
ScalarConstructor[not set]{420.000000}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(myvar.age = 42.0;
|
||||
myvar2.ancientness = 420.0;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_StructNonConstIndex) {
|
||||
|
@ -741,16 +637,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Struct_RuntimeArray) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{age}
|
||||
}
|
||||
ScalarConstructor[not set]{2u}
|
||||
}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar.age[2u] = 42.0;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Compound_Matrix_Vector) {
|
||||
|
@ -781,16 +670,9 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_Compound_Matrix_Vector) {
|
|||
<< assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody());
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
ArrayAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
ScalarConstructor[not set]{2u}
|
||||
}
|
||||
Identifier[not set]{w}
|
||||
}
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar[2u].w = 42.0;"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_InvalidPointeeType) {
|
||||
|
@ -853,52 +735,19 @@ TEST_F(SpvParserMemoryTest, EmitStatement_AccessChain_DereferenceBase) {
|
|||
)";
|
||||
auto p = parser(test::Assemble(assembly));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
const auto got = p->program().to_str();
|
||||
const std::string expected = R"(Module{
|
||||
Function x_200 -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__ptr_private__vec_2__u32
|
||||
}
|
||||
)
|
||||
{
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_3
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
MemberAccessor[not set]{
|
||||
UnaryOp[not set]{
|
||||
indirection
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
Identifier[not set]{x}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Return{}
|
||||
}
|
||||
Function main_1 -> __void
|
||||
()
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
Function main -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{main_1}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
const auto got = test::ToString(p->program());
|
||||
const std::string expected = R"(fn x_200(x_1 : ptr<private, vec2<u32>>) {
|
||||
let x_3 : u32 = (*(x_1)).x;
|
||||
return;
|
||||
}
|
||||
|
||||
fn main_1() {
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
main_1();
|
||||
}
|
||||
)";
|
||||
EXPECT_EQ(got, expected) << got;
|
||||
|
@ -930,45 +779,16 @@ OpExecutionMode %main OriginUpperLeft
|
|||
)";
|
||||
auto p = parser(test::Assemble(assembly));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly;
|
||||
const auto got = p->program().to_str();
|
||||
const std::string expected = R"(Module{
|
||||
Function main_1 -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
Variable{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__ptr_function__u32
|
||||
{
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
Identifier[not set]{x_1}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Return{}
|
||||
}
|
||||
Function main -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{main_1}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
const auto got = test::ToString(p->program());
|
||||
const std::string expected = R"(fn main_1() {
|
||||
var x_1 : u32;
|
||||
let x_2 : ptr<function, u32> = &(x_1);
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
main_1();
|
||||
}
|
||||
)";
|
||||
EXPECT_EQ(got, expected) << got;
|
||||
|
@ -1016,24 +836,17 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_TypesAndVarDeclarations) {
|
|||
auto p = parser(test::Assemble(assembly));
|
||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
|
||||
<< assembly << p->error();
|
||||
const auto module_str = p->program().to_str();
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||
RTArr -> __array__u32_stride_4
|
||||
Struct S {
|
||||
[[block]]
|
||||
StructMember{[[ offset 0 ]] field0: __u32}
|
||||
StructMember{[[ offset 4 ]] field1: __type_name_RTArr}
|
||||
}
|
||||
Variable{
|
||||
Decorations{
|
||||
GroupDecoration{0}
|
||||
BindingDecoration{0}
|
||||
}
|
||||
myvar
|
||||
storage
|
||||
read_write
|
||||
__type_name_S
|
||||
})"));
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(type RTArr = [[stride(4)]] array<u32>;
|
||||
|
||||
[[block]]
|
||||
struct S {
|
||||
field0 : u32;
|
||||
field1 : RTArr;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<storage, read_write> myvar : S;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) {
|
||||
|
@ -1056,24 +869,11 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto got = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(got, HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field0}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field1}
|
||||
}
|
||||
ScalarConstructor[not set]{1u}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto got = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(got, HasSubstr(R"(myvar.field0 = 0u;
|
||||
myvar.field1[1u] = 0u;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest,
|
||||
|
@ -1098,25 +898,12 @@ TEST_F(SpvParserMemoryTest,
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto got = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(got, HasSubstr(R"(Assignment{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field0}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field1}
|
||||
}
|
||||
ScalarConstructor[not set]{1u}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
})")) << got
|
||||
<< p->error();
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto got = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(got, HasSubstr(R"(myvar.field0 = 0u;
|
||||
myvar.field1[1u] = 0u;
|
||||
)")) << got
|
||||
<< p->error();
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
|
||||
|
@ -1138,16 +925,10 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"(Assignment{
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field1}
|
||||
}
|
||||
ScalarConstructor[not set]{1u}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
})")) << p->error();
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("myvar.field1[1u] = 0u;"))
|
||||
<< p->error();
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest,
|
||||
|
@ -1171,34 +952,11 @@ TEST_F(SpvParserMemoryTest,
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__ptr_storage__u32
|
||||
{
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field1}
|
||||
}
|
||||
ScalarConstructor[not set]{1u}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assignment{
|
||||
UnaryOp[not set]{
|
||||
indirection
|
||||
Identifier[not set]{x_2}
|
||||
}
|
||||
ScalarConstructor[not set]{0u}
|
||||
})")) << p->error();
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_2 : ptr<storage, u32> = &(myvar.field1[1u]);
|
||||
*(x_2) = 0u;
|
||||
)")) << p->error();
|
||||
|
||||
p->SkipDumpingPending(
|
||||
"crbug.com/tint/1041 track access mode in spirv-reader parser type");
|
||||
|
@ -1240,45 +998,16 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_ThroughCopyObject_WithHoisting) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_EQ(ToString(p->builder(), fe.ast_body()),
|
||||
R"(VariableDeclStatement{
|
||||
Variable{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__ptr_storage__u32
|
||||
}
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_EQ(test::ToString(p->program(), ast_body),
|
||||
R"(var x_2 : ptr<storage, u32>;
|
||||
if (true) {
|
||||
x_2 = &(myvar.field1[1u]);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
If{
|
||||
(
|
||||
ScalarConstructor[not set]{true}
|
||||
)
|
||||
{
|
||||
Assignment{
|
||||
Identifier[not set]{x_2}
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
ArrayAccessor[not set]{
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{field1}
|
||||
}
|
||||
ScalarConstructor[not set]{1u}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Else{
|
||||
{
|
||||
Return{}
|
||||
}
|
||||
}
|
||||
Assignment{
|
||||
Identifier[not set]{x_2}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
Return{}
|
||||
x_2 = 0u;
|
||||
return;
|
||||
)") << p->error();
|
||||
p->SkipDumpingPending("crbug.com/tint/98");
|
||||
}
|
||||
|
@ -1340,30 +1069,11 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromVar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto body_str = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{arrayLength}
|
||||
(
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{rtarr}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)")) << body_str;
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto body_str = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(body_str,
|
||||
HasSubstr("let x_1 : u32 = arrayLength(&(myvar.rtarr));"))
|
||||
<< body_str;
|
||||
}
|
||||
|
||||
TEST_F(SpvParserMemoryTest, ArrayLength_FromCopyObject) {
|
||||
|
@ -1381,46 +1091,10 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromCopyObject) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto body_str = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_2
|
||||
none
|
||||
undefined
|
||||
__ptr_storage__type_name_S
|
||||
{
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
Identifier[not set]{myvar}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{arrayLength}
|
||||
(
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
MemberAccessor[not set]{
|
||||
UnaryOp[not set]{
|
||||
indirection
|
||||
Identifier[not set]{x_2}
|
||||
}
|
||||
Identifier[not set]{rtarr}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto body_str = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(body_str, HasSubstr(R"(let x_2 : ptr<storage, S> = &(myvar);
|
||||
let x_1 : u32 = arrayLength(&((*(x_2)).rtarr));
|
||||
)")) << body_str;
|
||||
|
||||
p->SkipDumpingPending(
|
||||
|
@ -1442,30 +1116,11 @@ TEST_F(SpvParserMemoryTest, ArrayLength_FromAccessChain) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto body_str = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(body_str, HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_1
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{arrayLength}
|
||||
(
|
||||
UnaryOp[not set]{
|
||||
address-of
|
||||
MemberAccessor[not set]{
|
||||
Identifier[not set]{myvar}
|
||||
Identifier[not set]{rtarr}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)")) << body_str;
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto body_str = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(body_str,
|
||||
HasSubstr("let x_1 : u32 = arrayLength(&(myvar.rtarr));"))
|
||||
<< body_str;
|
||||
}
|
||||
|
||||
std::string InvalidPointerPreamble() {
|
||||
|
|
|
@ -73,51 +73,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Scalar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__bool
|
||||
{
|
||||
ScalarConstructor[not set]{false}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_12
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_13
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
{
|
||||
ScalarConstructor[not set]{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_14
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_11 : bool = false;
|
||||
let x_12 : u32 = 0u;
|
||||
let x_13 : i32 = 0;
|
||||
let x_14 : f32 = 0.0;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) {
|
||||
|
@ -141,67 +103,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_BeforeFunction_Vector) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_14
|
||||
none
|
||||
undefined
|
||||
__vec_2__bool
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__bool
|
||||
ScalarConstructor[not set]{false}
|
||||
ScalarConstructor[not set]{false}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__vec_2__u32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__u32
|
||||
ScalarConstructor[not set]{0u}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_12
|
||||
none
|
||||
undefined
|
||||
__vec_2__i32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__i32
|
||||
ScalarConstructor[not set]{0}
|
||||
ScalarConstructor[not set]{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_13
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_14 : vec2<bool> = vec2<bool>(false, false);
|
||||
let x_11 : vec2<u32> = vec2<u32>(0u, 0u);
|
||||
let x_12 : vec2<i32> = vec2<i32>(0, 0);
|
||||
let x_13 : vec2<f32> = vec2<f32>(0.0, 0.0);
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) {
|
||||
|
@ -224,51 +132,13 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__bool
|
||||
{
|
||||
ScalarConstructor[not set]{false}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_12
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_13
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
{
|
||||
ScalarConstructor[not set]{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_14
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_11 : bool = false;
|
||||
let x_12 : u32 = 0u;
|
||||
let x_13 : i32 = 0;
|
||||
let x_14 : f32 = 0.0;
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
|
||||
|
@ -289,52 +159,12 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__vec_2__u32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__u32
|
||||
ScalarConstructor[not set]{0u}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_12
|
||||
none
|
||||
undefined
|
||||
__vec_2__i32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__i32
|
||||
ScalarConstructor[not set]{0}
|
||||
ScalarConstructor[not set]{0}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_13
|
||||
none
|
||||
undefined
|
||||
__vec_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr(R"(let x_11 : vec2<u32> = vec2<u32>(0u, 0u);
|
||||
let x_12 : vec2<i32> = vec2<i32>(0, 0);
|
||||
let x_13 : vec2<f32> = vec2<f32>(0.0, 0.0);
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
|
||||
|
@ -353,30 +183,11 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__mat_2_2__f32
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__mat_2_2__f32
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
TypeConstructor[not set]{
|
||||
__vec_2__f32
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_11 : mat2x2<f32> = mat2x2<f32>("
|
||||
"vec2<f32>(0.0, 0.0), "
|
||||
"vec2<f32>(0.0, 0.0));"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
|
||||
|
@ -396,22 +207,9 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__array__u32_2
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__array__u32_2
|
||||
ScalarConstructor[not set]{0u}
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_11 : array<u32, 2u> = array<u32, 2u>(0u, 0u);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
|
||||
|
@ -430,24 +228,9 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()),
|
||||
HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_11
|
||||
none
|
||||
undefined
|
||||
__type_name_S
|
||||
{
|
||||
TypeConstructor[not set]{
|
||||
__type_name_S
|
||||
ScalarConstructor[not set]{false}
|
||||
ScalarConstructor[not set]{0u}
|
||||
ScalarConstructor[not set]{0}
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_THAT(test::ToString(p->program(), ast_body),
|
||||
HasSubstr("let x_11 : S = S(false, 0u, 0, 0.0);"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTestMiscInstruction, OpNop) {
|
||||
|
@ -463,8 +246,8 @@ TEST_F(SpvParserTestMiscInstruction, OpNop) {
|
|||
<< p->error() << assembly;
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
EXPECT_THAT(ToString(p->builder(), fe.ast_body()), Eq(R"(Return{}
|
||||
)"));
|
||||
auto ast_body = fe.ast_body();
|
||||
EXPECT_EQ(test::ToString(p->program(), ast_body), "return;\n");
|
||||
}
|
||||
|
||||
// Test swizzle generation.
|
||||
|
@ -494,7 +277,7 @@ TEST_P(SpvParserSwizzleTest, Sample) {
|
|||
Program program(p->program());
|
||||
EXPECT_TRUE(fe.success());
|
||||
ASSERT_NE(result, nullptr);
|
||||
auto got = program.str(result);
|
||||
auto got = test::ToString(program, result);
|
||||
EXPECT_EQ(got, GetParam().expected_expr);
|
||||
} else {
|
||||
EXPECT_EQ(result, nullptr);
|
||||
|
@ -507,10 +290,10 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
ValidIndex,
|
||||
SpvParserSwizzleTest,
|
||||
::testing::ValuesIn(std::vector<SwizzleCase>{
|
||||
{0, "Identifier[not set]{x}\n", ""},
|
||||
{1, "Identifier[not set]{y}\n", ""},
|
||||
{2, "Identifier[not set]{z}\n", ""},
|
||||
{3, "Identifier[not set]{w}\n", ""},
|
||||
{0, "x", ""},
|
||||
{1, "y", ""},
|
||||
{2, "z", ""},
|
||||
{3, "w", ""},
|
||||
{4, "", "vector component index is larger than 3: 4"},
|
||||
{99999, "", "vector component index is larger than 3: 99999"}}));
|
||||
|
||||
|
@ -554,22 +337,9 @@ TEST_F(SpvParserTest, ValueFromBlockNotInBlockOrder) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||
auto fe = p->function_emitter(100);
|
||||
EXPECT_TRUE(fe.EmitBody()) << p->error();
|
||||
const auto got = ToString(p->builder(), fe.ast_body());
|
||||
EXPECT_THAT(got, HasSubstr(R"(VariableDeclStatement{
|
||||
VariableConst{
|
||||
x_81
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
{
|
||||
Binary[not set]{
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
multiply
|
||||
ScalarConstructor[not set]{42.000000}
|
||||
}
|
||||
}
|
||||
}
|
||||
})"));
|
||||
auto ast_body = fe.ast_body();
|
||||
const auto got = test::ToString(p->program(), ast_body);
|
||||
EXPECT_THAT(got, HasSubstr("let x_81 : f32 = (0.0 * 42.0);"));
|
||||
}
|
||||
|
||||
// TODO(dneto): OpSizeof : requires Kernel (OpenCL)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2131,8 +2131,8 @@ TypedExpression ParserImpl::RectifyOperandSignedness(
|
|||
}
|
||||
auto* type = expr.type;
|
||||
if (!type) {
|
||||
Fail() << "internal error: unmapped type for: " << builder_.str(expr.expr)
|
||||
<< "\n";
|
||||
Fail() << "internal error: unmapped type for: "
|
||||
<< expr.expr->TypeInfo().name << "\n";
|
||||
return {};
|
||||
}
|
||||
if (requires_unsigned) {
|
||||
|
|
|
@ -596,7 +596,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) {
|
|||
|
||||
auto* str = type->Build(p->builder());
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)"));
|
||||
EXPECT_EQ(test::ToString(program, str), "S");
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
|
||||
|
@ -614,7 +614,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) {
|
|||
|
||||
auto* str = type->Build(p->builder());
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)"));
|
||||
EXPECT_EQ(test::ToString(program, str), "S");
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
|
||||
|
@ -636,7 +636,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) {
|
|||
|
||||
auto* str = type->Build(p->builder());
|
||||
Program program = p->program();
|
||||
EXPECT_THAT(program.str(str), Eq(R"(__type_name_S)"));
|
||||
EXPECT_EQ(test::ToString(program, str), "S");
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, ConvertType_Struct_NoDeduplication) {
|
||||
|
|
|
@ -88,7 +88,7 @@ TEST_F(SpvParserTest, EmitFunctions_NoFunctions) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
|
||||
p->SkipDumpingPending("Not valid for Vulkan: needs an entry point");
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ TEST_F(SpvParserTest, EmitFunctions_FunctionWithoutBody) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, Not(HasSubstr("Function{")));
|
||||
p->SkipDumpingPending("Missing an entry point body requires Linkage");
|
||||
}
|
||||
|
@ -121,19 +121,18 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Struct $3 {
|
||||
StructMember{[[ BuiltinDecoration{position}
|
||||
]] $4: __vec_4__f32})"))
|
||||
<< program_ast;
|
||||
struct main_out {
|
||||
[[builtin(position)]]
|
||||
x_2_1 : vec4<f32>;
|
||||
};
|
||||
)")) << program_ast;
|
||||
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("main").to_str() +
|
||||
R"( -> __type_name_$3
|
||||
StageDecoration{vertex}
|
||||
()
|
||||
{)"));
|
||||
[[stage(vertex)]]
|
||||
fn main() -> main_out {
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_Fragment) {
|
||||
|
@ -147,13 +146,11 @@ TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_Fragment) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{)"));
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_GLCompute) {
|
||||
|
@ -167,18 +164,11 @@ TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_GLCompute) {
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{1}
|
||||
ScalarConstructor[not set]{1}
|
||||
ScalarConstructor[not set]{1}
|
||||
}
|
||||
()
|
||||
{)"));
|
||||
[[stage(compute), workgroup_size(1, 1, 1)]]
|
||||
fn main() {
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_Function_EntryPoint_MultipleEntryPoints) {
|
||||
|
@ -194,19 +184,15 @@ OpExecutionMode %main OriginUpperLeft
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("first_shader").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{)"));
|
||||
[[stage(fragment)]]
|
||||
fn first_shader() {
|
||||
)"));
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("second_shader").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{fragment}
|
||||
()
|
||||
{)"));
|
||||
[[stage(fragment)]]
|
||||
fn second_shader() {
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest,
|
||||
|
@ -225,19 +211,11 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{2}
|
||||
ScalarConstructor[not set]{4}
|
||||
ScalarConstructor[not set]{8}
|
||||
}
|
||||
()
|
||||
{)"))
|
||||
<< program_ast;
|
||||
[[stage(compute), workgroup_size(2, 4, 8)]]
|
||||
fn comp_main() {
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest,
|
||||
|
@ -259,19 +237,11 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{3}
|
||||
ScalarConstructor[not set]{5}
|
||||
ScalarConstructor[not set]{7}
|
||||
}
|
||||
()
|
||||
{)"))
|
||||
<< program_ast;
|
||||
[[stage(compute), workgroup_size(3, 5, 7)]]
|
||||
fn comp_main() {
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
|
@ -298,19 +268,11 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{3}
|
||||
ScalarConstructor[not set]{5}
|
||||
ScalarConstructor[not set]{7}
|
||||
}
|
||||
()
|
||||
{)"))
|
||||
<< program_ast;
|
||||
[[stage(compute), workgroup_size(3, 5, 7)]]
|
||||
fn comp_main() {
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
|
@ -336,19 +298,11 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{3}
|
||||
ScalarConstructor[not set]{5}
|
||||
ScalarConstructor[not set]{7}
|
||||
}
|
||||
()
|
||||
{)"))
|
||||
<< program_ast;
|
||||
[[stage(compute), workgroup_size(3, 5, 7)]]
|
||||
fn comp_main() {
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
|
@ -378,19 +332,11 @@ OpFunctionEnd)";
|
|||
ASSERT_TRUE(p->BuildAndParseInternalModule());
|
||||
ASSERT_TRUE(p->error().empty()) << p->error();
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("comp_main").to_str() +
|
||||
R"( -> __void
|
||||
StageDecoration{compute}
|
||||
WorkgroupDecoration{
|
||||
ScalarConstructor[not set]{3}
|
||||
ScalarConstructor[not set]{5}
|
||||
ScalarConstructor[not set]{7}
|
||||
}
|
||||
()
|
||||
{)"))
|
||||
<< program_ast;
|
||||
[[stage(compute), workgroup_size(3, 5, 7)]]
|
||||
fn comp_main() {
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
|
||||
|
@ -404,12 +350,9 @@ TEST_F(SpvParserTest, EmitFunctions_VoidFunctionWithoutParams) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str(false);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function )" + program.Symbols().Get("another_function").to_str() +
|
||||
R"( -> __void
|
||||
()
|
||||
{)"));
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(fn another_function() {
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
|
||||
|
@ -440,61 +383,21 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str();
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function leaf -> __u32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
{
|
||||
ScalarConstructor[not set]{0u}
|
||||
}
|
||||
}
|
||||
}
|
||||
Function branch -> __u32
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
leaf_result
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{leaf}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Return{
|
||||
{
|
||||
Identifier[not set]{leaf_result}
|
||||
}
|
||||
}
|
||||
}
|
||||
Function root -> __void
|
||||
()
|
||||
{
|
||||
VariableDeclStatement{
|
||||
VariableConst{
|
||||
branch_result
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
{
|
||||
Call[not set]{
|
||||
Identifier[not set]{branch}
|
||||
(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Return{}
|
||||
})")) << program_ast;
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(fn leaf() -> u32 {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
fn branch() -> u32 {
|
||||
let leaf_result : u32 = leaf();
|
||||
return leaf_result;
|
||||
}
|
||||
|
||||
fn root() {
|
||||
let branch_result : u32 = branch();
|
||||
return;
|
||||
}
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
|
||||
|
@ -511,18 +414,11 @@ TEST_F(SpvParserTest, EmitFunctions_NonVoidResultType) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str();
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function ret_float -> __f32
|
||||
()
|
||||
{
|
||||
Return{
|
||||
{
|
||||
ScalarConstructor[not set]{0.000000}
|
||||
}
|
||||
}
|
||||
})"))
|
||||
<< program_ast;
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(fn ret_float() -> f32 {
|
||||
return 0.0;
|
||||
}
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
|
||||
|
@ -541,32 +437,12 @@ TEST_F(SpvParserTest, EmitFunctions_MixedParamTypes) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str();
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function mixed_params -> __void
|
||||
(
|
||||
VariableConst{
|
||||
a
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
VariableConst{
|
||||
b
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
}
|
||||
VariableConst{
|
||||
c
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
}
|
||||
)
|
||||
{
|
||||
Return{}
|
||||
})"));
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast,
|
||||
HasSubstr(R"(fn mixed_params(a : u32, b : f32, c : i32) {
|
||||
return;
|
||||
}
|
||||
)"));
|
||||
}
|
||||
|
||||
TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
|
||||
|
@ -585,33 +461,12 @@ TEST_F(SpvParserTest, EmitFunctions_GenerateParamNames) {
|
|||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
Program program = p->program();
|
||||
const auto program_ast = program.to_str();
|
||||
EXPECT_THAT(program_ast, HasSubstr(R"(
|
||||
Function mixed_params -> __void
|
||||
(
|
||||
VariableConst{
|
||||
x_14
|
||||
none
|
||||
undefined
|
||||
__u32
|
||||
}
|
||||
VariableConst{
|
||||
x_15
|
||||
none
|
||||
undefined
|
||||
__f32
|
||||
}
|
||||
VariableConst{
|
||||
x_16
|
||||
none
|
||||
undefined
|
||||
__i32
|
||||
}
|
||||
)
|
||||
{
|
||||
Return{}
|
||||
})"))
|
||||
<< program_ast;
|
||||
const auto program_ast = test::ToString(program);
|
||||
EXPECT_THAT(program_ast,
|
||||
HasSubstr(R"(fn mixed_params(x_14 : u32, x_15 : f32, x_16 : i32) {
|
||||
return;
|
||||
}
|
||||
)")) << program_ast;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,7 +33,7 @@ TEST_F(SpvParserImportTest, Import_NoImport) {
|
|||
auto p = parser(test::Assemble("%1 = OpTypeVoid"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto program_ast = p->program().to_str();
|
||||
const auto program_ast = test::ToString(p->program());
|
||||
EXPECT_THAT(program_ast, Not(HasSubstr("Import")));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -29,7 +29,7 @@ TEST_F(SpvParserTest, NamedTypes_AnonStruct) {
|
|||
%s = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("Struct S"));
|
||||
EXPECT_THAT(test::ToString(p->program()), HasSubstr("struct S"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ TEST_F(SpvParserTest, NamedTypes_NamedStruct) {
|
|||
%s = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr("Struct mystruct"));
|
||||
EXPECT_THAT(test::ToString(p->program()), HasSubstr("struct mystruct"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -53,14 +53,15 @@ TEST_F(SpvParserTest, NamedTypes_Dup_EmitBoth) {
|
|||
%s2 = OpTypeStruct %uint %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||
EXPECT_THAT(p->program().to_str(), HasSubstr(R"(Struct S {
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __u32}
|
||||
}
|
||||
Struct S_1 {
|
||||
StructMember{field0: __u32}
|
||||
StructMember{field1: __u32}
|
||||
})"));
|
||||
EXPECT_THAT(test::ToString(p->program()), HasSubstr(R"(struct S {
|
||||
field0 : u32;
|
||||
field1 : u32;
|
||||
};
|
||||
|
||||
struct S_1 {
|
||||
field0 : u32;
|
||||
field1 : u32;
|
||||
})"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -76,8 +77,8 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArrayWithDecoration) {
|
|||
%arr = OpTypeRuntimeArray %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(),
|
||||
HasSubstr("RTArr -> __array__u32_stride_8\n"));
|
||||
EXPECT_THAT(test::ToString(p->program()),
|
||||
HasSubstr("RTArr = [[stride(8)]] array<u32>;\n"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -91,9 +92,11 @@ TEST_F(SpvParserTest, NamedTypes_AnonRTArray_Dup_EmitBoth) {
|
|||
%arr2 = OpTypeRuntimeArray %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(),
|
||||
HasSubstr("RTArr -> __array__u32_stride_8\n RTArr_1 -> "
|
||||
"__array__u32_stride_8\n"));
|
||||
EXPECT_THAT(test::ToString(p->program()),
|
||||
HasSubstr(R"(type RTArr = [[stride(8)]] array<u32>;
|
||||
|
||||
type RTArr_1 = [[stride(8)]] array<u32>;
|
||||
)"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -106,8 +109,8 @@ TEST_F(SpvParserTest, NamedTypes_NamedRTArray) {
|
|||
%arr = OpTypeRuntimeArray %uint
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(),
|
||||
HasSubstr("myrtarr -> __array__u32_stride_8\n"));
|
||||
EXPECT_THAT(test::ToString(p->program()),
|
||||
HasSubstr("myrtarr = [[stride(8)]] array<u32>;\n"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -122,8 +125,8 @@ TEST_F(SpvParserTest, NamedTypes_NamedArray) {
|
|||
%arr2 = OpTypeArray %uint %uint_5
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(),
|
||||
HasSubstr("myarr -> __array__u32_5_stride_8"));
|
||||
EXPECT_THAT(test::ToString(p->program()),
|
||||
HasSubstr("myarr = [[stride(8)]] array<u32, 5u>;"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
@ -138,9 +141,11 @@ TEST_F(SpvParserTest, NamedTypes_AnonArray_Dup_EmitBoth) {
|
|||
%arr2 = OpTypeArray %uint %uint_5
|
||||
)"));
|
||||
EXPECT_TRUE(p->BuildAndParseInternalModule());
|
||||
EXPECT_THAT(p->program().to_str(),
|
||||
HasSubstr("Arr -> __array__u32_5_stride_8\n Arr_1 -> "
|
||||
"__array__u32_5_stride_8"));
|
||||
EXPECT_THAT(test::ToString(p->program()),
|
||||
HasSubstr(R"(type Arr = [[stride(8)]] array<u32, 5u>;
|
||||
|
||||
type Arr_1 = [[stride(8)]] array<u32, 5u>;
|
||||
)"));
|
||||
|
||||
p->DeliberatelyInvalidSpirv();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
#include "src/reader/spirv/parser_impl_test_helper.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace reader {
|
||||
|
@ -35,6 +36,49 @@ ParserImplWrapperForTest::~ParserImplWrapperForTest() {
|
|||
}
|
||||
}
|
||||
|
||||
std::string ToString(const Program& program) {
|
||||
writer::wgsl::GeneratorImpl writer(&program);
|
||||
if (!writer.Generate()) {
|
||||
return "WGSL writer error: " + writer.error();
|
||||
}
|
||||
return writer.result();
|
||||
}
|
||||
|
||||
std::string ToString(const Program& program, const ast::StatementList& stmts) {
|
||||
writer::wgsl::GeneratorImpl writer(&program);
|
||||
for (const auto* stmt : stmts) {
|
||||
if (!writer.EmitStatement(const_cast<ast::Statement*>(stmt))) {
|
||||
return "WGSL writer error: " + writer.error();
|
||||
}
|
||||
}
|
||||
return writer.result();
|
||||
}
|
||||
|
||||
std::string ToString(const Program& program, const ast::Node* node) {
|
||||
writer::wgsl::GeneratorImpl writer(&program);
|
||||
if (auto* expr = node->As<ast::Expression>()) {
|
||||
std::stringstream out;
|
||||
if (!writer.EmitExpression(out, const_cast<ast::Expression*>(expr))) {
|
||||
return "WGSL writer error: " + writer.error();
|
||||
}
|
||||
return out.str();
|
||||
} else if (auto* stmt = node->As<ast::Statement>()) {
|
||||
if (!writer.EmitStatement(const_cast<ast::Statement*>(stmt))) {
|
||||
return "WGSL writer error: " + writer.error();
|
||||
}
|
||||
} else if (auto* ty = node->As<ast::Type>()) {
|
||||
std::stringstream out;
|
||||
if (!writer.EmitType(out, const_cast<ast::Type*>(ty))) {
|
||||
return "WGSL writer error: " + writer.error();
|
||||
}
|
||||
return out.str();
|
||||
} else {
|
||||
return "<unhandled AST node type " + std::string(node->TypeInfo().name) +
|
||||
">";
|
||||
}
|
||||
return writer.result();
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace spirv
|
||||
} // namespace reader
|
||||
|
|
|
@ -269,6 +269,23 @@ inline void DumpSuccessfullyConvertedSpirv() {
|
|||
ParserImplWrapperForTest::DumpSuccessfullyConvertedSpirv();
|
||||
}
|
||||
|
||||
/// Returns the WGSL printed string of a program.
|
||||
/// @param program the Program
|
||||
/// @returns the WGSL printed string the program.
|
||||
std::string ToString(const Program& program);
|
||||
|
||||
/// Returns the WGSL printed string of a statement list.
|
||||
/// @param program the Program
|
||||
/// @param stmts the statement list
|
||||
/// @returns the WGSL printed string of a statement list.
|
||||
std::string ToString(const Program& program, const ast::StatementList& stmts);
|
||||
|
||||
/// Returns the WGSL printed string of an AST node.
|
||||
/// @param program the Program
|
||||
/// @param node the AST node
|
||||
/// @returns the WGSL printed string of the AST node.
|
||||
std::string ToString(const Program& program, const ast::Node* node);
|
||||
|
||||
} // namespace test
|
||||
|
||||
/// SPIR-V Parser test class
|
||||
|
@ -295,32 +312,6 @@ class SpvParserTestBase : public T {
|
|||
// Use this form when you don't need to template any further.
|
||||
using SpvParserTest = SpvParserTestBase<::testing::Test>;
|
||||
|
||||
/// Returns the string dump of a statement list.
|
||||
/// @param program the Program
|
||||
/// @param stmts the statement list
|
||||
/// @returns the string dump of a statement list.
|
||||
inline std::string ToString(const Program& program,
|
||||
const ast::StatementList& stmts) {
|
||||
std::ostringstream outs;
|
||||
for (const auto* stmt : stmts) {
|
||||
program.to_str(stmt, outs, 0);
|
||||
}
|
||||
return Demangler().Demangle(program.Symbols(), outs.str());
|
||||
}
|
||||
|
||||
/// Returns the string dump of a statement list.
|
||||
/// @param builder the ProgramBuilder
|
||||
/// @param stmts the statement list
|
||||
/// @returns the string dump of a statement list.
|
||||
inline std::string ToString(ProgramBuilder& builder,
|
||||
const ast::StatementList& stmts) {
|
||||
std::ostringstream outs;
|
||||
for (const auto* stmt : stmts) {
|
||||
builder.to_str(stmt, outs, 0);
|
||||
}
|
||||
return Demangler().Demangle(builder.Symbols(), outs.str());
|
||||
}
|
||||
|
||||
} // namespace spirv
|
||||
} // namespace reader
|
||||
} // namespace tint
|
||||
|
|
Loading…
Reference in New Issue