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