Remove all Source{} smell from tests
Switch all remaining AST stack allocations in tests to using create<T>() which will automatically inject the current Source as the first parameter. Most remaining uses of Source{} in the codebase are places where we need to fix. Bug: tint:396 Change-Id: I24655800b50d6ad52e682a7339022972e9b354d9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36380 Commit-Queue: Ben Clayton <bclayton@google.com> Commit-Queue: David Neto <dneto@google.com> Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
9a644c7903
commit
e6e704145b
|
@ -21,6 +21,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/builder.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
|
||||
namespace tint {
|
||||
|
@ -28,7 +29,7 @@ namespace reader {
|
|||
namespace wgsl {
|
||||
|
||||
/// WGSL Parser test class
|
||||
class ParserImplTest : public testing::Test {
|
||||
class ParserImplTest : public testing::Test, public ast::BuilderWithModule {
|
||||
public:
|
||||
/// Constructor
|
||||
ParserImplTest();
|
||||
|
@ -50,7 +51,8 @@ class ParserImplTest : public testing::Test {
|
|||
|
||||
/// WGSL Parser test class with param
|
||||
template <typename T>
|
||||
class ParserImplTestWithParam : public testing::TestWithParam<T> {
|
||||
class ParserImplTestWithParam : public testing::TestWithParam<T>,
|
||||
public ast::BuilderWithModule {
|
||||
public:
|
||||
/// Constructor
|
||||
ParserImplTestWithParam() = default;
|
||||
|
|
|
@ -83,23 +83,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_InvalidType) {
|
|||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -111,23 +108,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
|
|||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_FALSE(p->has_error()) << p->error();
|
||||
|
@ -139,23 +133,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
|
|||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read), access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -164,23 +155,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
|
|||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[access(read)]][[access(read_write)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
@ -205,23 +193,20 @@ TEST_F(ParserImplTest, VariableIdentDecl_AccessDecoIllegalValue) {
|
|||
}
|
||||
|
||||
TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto p = parser("my_var : [[stride(1)]] S");
|
||||
|
||||
ast::StructMember mem(Source{}, p->get_module().RegisterSymbol("a"), "a",
|
||||
&i32, ast::StructMemberDecorationList{});
|
||||
auto* mem = Member("a", ty.i32, ast::StructMemberDecorationList{});
|
||||
ast::StructMemberList members;
|
||||
members.push_back(&mem);
|
||||
members.push_back(mem);
|
||||
|
||||
ast::StructBlockDecoration block_deco(Source{});
|
||||
auto* block_deco = create<ast::StructBlockDecoration>();
|
||||
ast::StructDecorationList decos;
|
||||
decos.push_back(&block_deco);
|
||||
decos.push_back(block_deco);
|
||||
|
||||
ast::Struct str(Source{}, members, decos);
|
||||
ast::type::Struct s(p->get_module().RegisterSymbol("S"), "S", &str);
|
||||
auto* str = create<ast::Struct>(members, decos);
|
||||
auto* s = ty.struct_("S", str);
|
||||
|
||||
p->register_constructed("S", &s);
|
||||
p->register_constructed("S", s);
|
||||
|
||||
auto decl = p->expect_variable_ident_decl("test");
|
||||
ASSERT_TRUE(p->has_error());
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Assign) {
|
||||
ast::AssignmentStatement assign(Source{}, Expr("lhs"), Expr("rhs"));
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs"));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&assign)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(assign)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " lhs = rhs;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -38,8 +38,9 @@ using MslBinaryTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(MslBinaryTest, Emit) {
|
||||
auto params = GetParam();
|
||||
|
||||
ast::BinaryExpression expr(Source{}, params.op, Expr("left"), Expr("right"));
|
||||
ASSERT_TRUE(gen.EmitExpression(&expr)) << gen.error();
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(params.op, Expr("left"), Expr("right"));
|
||||
ASSERT_TRUE(gen.EmitExpression(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), params.result);
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
|
||||
ast::BitcastExpression bitcast(Source{}, ty.f32, Expr("id"));
|
||||
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();
|
||||
auto* bitcast = create<ast::BitcastExpression>(ty.f32, Expr("id"));
|
||||
ASSERT_TRUE(gen.EmitExpression(bitcast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "as_type<float>(id)");
|
||||
}
|
||||
|
||||
|
|
|
@ -28,12 +28,12 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Block) {
|
||||
ast::BlockStatement b(Source{}, ast::StatementList{
|
||||
create<ast::DiscardStatement>(Source{}),
|
||||
});
|
||||
auto* b = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
discard_fragment();
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ TEST_F(MslGeneratorImplTest, Emit_Block) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) {
|
||||
ast::BlockStatement b(Source{}, ast::StatementList{
|
||||
create<ast::DiscardStatement>(Source{}),
|
||||
});
|
||||
auto* b = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitBlock(b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"({
|
||||
discard_fragment();
|
||||
})");
|
||||
|
|
|
@ -29,11 +29,11 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Break) {
|
||||
ast::BreakStatement b(Source{});
|
||||
auto* b = create<ast::BreakStatement>();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(b)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " break;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -57,10 +57,10 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
|
|||
ast::StatementList{}, ast::FunctionDecorationList{});
|
||||
mod->AddFunction(func);
|
||||
|
||||
ast::CallStatement expr(Source{}, call);
|
||||
auto* expr = create<ast::CallStatement>(call);
|
||||
|
||||
gen.increment_indent();
|
||||
ASSERT_TRUE(gen.EmitStatement(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " my_func(param1, param2);\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -35,17 +35,16 @@ using MslGeneratorImplTest = TestHelper;
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||
ast::CaseStatement c(Source{}, lit, body);
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -56,14 +55,13 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
ast::type::I32 i32;
|
||||
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||
ast::CaseStatement c(
|
||||
Source{}, lit,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(
|
||||
lit, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
break;
|
||||
}
|
||||
|
@ -73,17 +71,16 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::FallthroughStatement>(Source{}),
|
||||
});
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::FallthroughStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||
ast::CaseStatement c(Source{}, lit, body);
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5: {
|
||||
/* fallthrough */
|
||||
}
|
||||
|
@ -93,18 +90,17 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
ast::CaseSelectorList lit;
|
||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6));
|
||||
ast::CaseStatement c(Source{}, lit, body);
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 5));
|
||||
lit.push_back(create<ast::SintLiteral>(&i32, 6));
|
||||
auto* c = create<ast::CaseStatement>(lit, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( case 5:
|
||||
case 6: {
|
||||
break;
|
||||
|
@ -113,15 +109,14 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
auto* c = create<ast::CaseStatement>(ast::CaseSelectorList{}, body);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitCase(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitCase(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( default: {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
|
|||
ast::ExpressionList params;
|
||||
params.push_back(Expr("id"));
|
||||
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.f32, params);
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.f32, params);
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(id)");
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,9 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
|
|||
ast::ExpressionList params;
|
||||
params.push_back(Expr("id"));
|
||||
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.vec3<f32>(), params);
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.vec3<f32>(), params);
|
||||
|
||||
ASSERT_TRUE(gen.EmitExpression(&cast)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitExpression(cast)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(id)");
|
||||
}
|
||||
|
||||
|
|
|
@ -38,128 +38,113 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) {
|
||||
ast::type::Bool bool_type;
|
||||
auto* lit = create<ast::BoolLiteral>(Source{}, &bool_type, false);
|
||||
ast::ScalarConstructorExpression expr(Source{}, lit);
|
||||
auto* lit = create<ast::BoolLiteral>(ty.bool_, false);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "false");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Int) {
|
||||
ast::type::I32 i32;
|
||||
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
|
||||
ast::ScalarConstructorExpression expr(Source{}, lit);
|
||||
auto* lit = create<ast::SintLiteral>(ty.i32, -12345);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "-12345");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) {
|
||||
ast::type::U32 u32;
|
||||
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 56779);
|
||||
ast::ScalarConstructorExpression expr(Source{}, lit);
|
||||
auto* lit = create<ast::UintLiteral>(ty.u32, 56779);
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "56779u");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Float) {
|
||||
ast::type::F32 f32;
|
||||
// Use a number close to 1<<30 but whose decimal representation ends in 0.
|
||||
auto* lit = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>((1 << 30) - 4));
|
||||
ast::ScalarConstructorExpression expr(Source{}, lit);
|
||||
auto* lit =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>((1 << 30) - 4));
|
||||
auto* expr = create<ast::ScalarConstructorExpression>(lit);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "1073741824.0f");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
auto* lit = create<ast::FloatLiteral>(Source{}, &f32, -1.2e-5);
|
||||
auto* lit = create<ast::FloatLiteral>(ty.f32, -1.2e-5);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &f32, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.f32, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float(-0.000012f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) {
|
||||
ast::type::Bool b;
|
||||
|
||||
auto* lit = create<ast::BoolLiteral>(Source{}, &b, true);
|
||||
auto* lit = create<ast::BoolLiteral>(ty.bool_, true);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &b, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.bool_, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "bool(true)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) {
|
||||
ast::type::I32 i32;
|
||||
|
||||
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
|
||||
auto* lit = create<ast::SintLiteral>(ty.i32, -12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &i32, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.i32, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "int(-12345)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) {
|
||||
ast::type::U32 u32;
|
||||
|
||||
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 12345);
|
||||
auto* lit = create<ast::UintLiteral>(ty.u32, 12345);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit));
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &u32, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(ty.u32, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "uint(12345u)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, 3);
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32, 1.f);
|
||||
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
|
||||
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
|
||||
auto* lit1 = create<ast::FloatLiteral>(ty.f32, 1.f);
|
||||
auto* lit2 = create<ast::FloatLiteral>(ty.f32, 2.f);
|
||||
auto* lit3 = create<ast::FloatLiteral>(ty.f32, 3.f);
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &vec, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&vec, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(1.0f, 2.0f, 3.0f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec_Empty) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, 3);
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
ast::ExpressionList values;
|
||||
ast::TypeConstructorExpression expr(Source{}, &vec, values);
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&vec, values);
|
||||
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "float3(0.0f)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Matrix mat(&f32, 3, 2); // 3 ROWS, 2 COLUMNS
|
||||
ast::type::Vector vec(&f32, 3);
|
||||
ast::type::Matrix mat(ty.f32, 3, 2); // 3 ROWS, 2 COLUMNS
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
|
||||
// WGSL matrix is mat2x3 (it flips for AST, sigh). With a type constructor
|
||||
// of <vec3, vec3>
|
||||
|
@ -167,24 +152,23 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
ast::ExpressionList mat_values;
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(1 + (i * 2)));
|
||||
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(2 + (i * 2)));
|
||||
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(3 + (i * 2)));
|
||||
auto* lit1 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(1 + (i * 2)));
|
||||
auto* lit2 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(2 + (i * 2)));
|
||||
auto* lit3 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(3 + (i * 2)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
mat_values.push_back(
|
||||
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
|
||||
mat_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
|
||||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &mat, mat_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&mat, mat_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
|
||||
// A matrix of type T with n columns and m rows can also be constructed from
|
||||
// n vectors of type T with m components.
|
||||
|
@ -193,31 +177,29 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec(&f32, 3);
|
||||
ast::type::Vector vec(ty.f32, 3);
|
||||
ast::type::Array ary(&vec, 3, ast::ArrayDecorationList{});
|
||||
|
||||
ast::ExpressionList ary_values;
|
||||
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(1 + (i * 3)));
|
||||
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(2 + (i * 3)));
|
||||
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32,
|
||||
static_cast<float>(3 + (i * 3)));
|
||||
auto* lit1 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(1 + (i * 3)));
|
||||
auto* lit2 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(2 + (i * 3)));
|
||||
auto* lit3 =
|
||||
create<ast::FloatLiteral>(ty.f32, static_cast<float>(3 + (i * 3)));
|
||||
|
||||
ast::ExpressionList values;
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit1));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit2));
|
||||
values.push_back(create<ast::ScalarConstructorExpression>(lit3));
|
||||
|
||||
ary_values.push_back(
|
||||
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
|
||||
ary_values.push_back(create<ast::TypeConstructorExpression>(&vec, values));
|
||||
}
|
||||
|
||||
ast::TypeConstructorExpression expr(Source{}, &ary, ary_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error();
|
||||
auto* expr = create<ast::TypeConstructorExpression>(&ary, ary_values);
|
||||
ASSERT_TRUE(gen.EmitConstructor(expr)) << gen.error();
|
||||
EXPECT_EQ(gen.result(),
|
||||
"{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), "
|
||||
"float3(7.0f, 8.0f, 9.0f)}");
|
||||
|
|
|
@ -29,11 +29,11 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Continue) {
|
||||
ast::ContinueStatement c(Source{});
|
||||
auto* c = create<ast::ContinueStatement>();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&c)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(c)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " continue;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,11 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Discard) {
|
||||
ast::DiscardStatement stmt(Source{});
|
||||
auto* stmt = create<ast::DiscardStatement>();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " discard_fragment();\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -65,11 +65,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"vtx_main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func("vtx_main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -111,11 +111,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"vtx_main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func("vtx_main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -157,11 +157,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -203,11 +203,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -246,11 +246,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -284,11 +284,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
|
|||
create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
|
||||
create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
|
||||
};
|
||||
auto* func = Func(
|
||||
"main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.f32, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
@ -327,11 +327,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
|
|||
|
||||
auto body = ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Expr("depth"), MemberAccessor("coord", "x"))};
|
||||
auto* func = Func(
|
||||
"main", ast::VariableList{}, ty.void_, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", ast::VariableList{}, ty.void_, body,
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
|
||||
|
|
|
@ -33,11 +33,11 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
|
|||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
|
||||
auto* i = create<ast::IfStatement>(cond, body, ast::ElseStatementList{});
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
}
|
||||
|
@ -54,12 +54,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
|
|||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
ast::IfStatement i(Source{}, cond, body,
|
||||
{create<ast::ElseStatement>(else_cond, else_body)});
|
||||
auto* i = create<ast::IfStatement>(
|
||||
cond, body,
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(else_cond, else_body),
|
||||
});
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else if (else_cond) {
|
||||
|
@ -77,12 +80,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
|||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
ast::IfStatement i(Source{}, cond, body,
|
||||
{create<ast::ElseStatement>(nullptr, else_body)});
|
||||
auto* i = create<ast::IfStatement>(
|
||||
cond, body,
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(nullptr, else_body),
|
||||
});
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else {
|
||||
|
@ -94,30 +100,28 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
|
||||
auto* else_cond = Expr("else_cond");
|
||||
|
||||
auto* else_body =
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
auto* else_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
|
||||
auto* else_body_2 =
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
auto* else_body_2 = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
|
||||
auto* cond = Expr("cond");
|
||||
auto* body =
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
ast::IfStatement i(Source{}, cond, body,
|
||||
{
|
||||
create<ast::ElseStatement>(else_cond, else_body),
|
||||
create<ast::ElseStatement>(nullptr, else_body_2),
|
||||
});
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
auto* i = create<ast::IfStatement>(
|
||||
cond, body,
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(else_cond, else_body),
|
||||
create<ast::ElseStatement>(nullptr, else_body_2),
|
||||
});
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&i)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(i)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( if (cond) {
|
||||
return;
|
||||
} else if (else_cond) {
|
||||
|
|
|
@ -39,11 +39,11 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) {
|
|||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::DiscardStatement>(),
|
||||
});
|
||||
ast::LoopStatement l(Source{}, body, {});
|
||||
auto* l = create<ast::LoopStatement>(body, nullptr);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&l)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( for(;;) {
|
||||
discard_fragment();
|
||||
}
|
||||
|
@ -57,11 +57,11 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) {
|
|||
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
ast::LoopStatement l(Source{}, body, continuing);
|
||||
auto* l = create<ast::LoopStatement>(body, continuing);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&l)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(l)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
for(;;) {
|
||||
|
@ -93,11 +93,11 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
|
|||
create<ast::AssignmentStatement>(Expr("lhs"), Expr("rhs")),
|
||||
});
|
||||
|
||||
ast::LoopStatement outer(Source{}, body, continuing);
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
for(;;) {
|
||||
|
@ -157,9 +157,9 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
|
|||
});
|
||||
gen.increment_indent();
|
||||
|
||||
ast::LoopStatement outer(Source{}, body, continuing);
|
||||
auto* outer = create<ast::LoopStatement>(body, continuing);
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&outer)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(outer)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
bool tint_msl_is_first_1 = true;
|
||||
float lhs;
|
||||
|
|
|
@ -36,11 +36,11 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
||||
ast::type::Array ary(ty.f32, 3, ast::ArrayDecorationList{});
|
||||
auto* var = Const(
|
||||
"pos", ast::StorageClass::kNone, &ary,
|
||||
create<ast::TypeConstructorExpression>(
|
||||
Source{}, &ary, ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)}),
|
||||
ast::VariableDecorationList{});
|
||||
auto* var =
|
||||
Const("pos", ast::StorageClass::kNone, &ary,
|
||||
create<ast::TypeConstructorExpression>(
|
||||
&ary, ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)}),
|
||||
ast::VariableDecorationList{});
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), "constant float pos[3] = {1.0f, 2.0f, 3.0f};\n");
|
||||
|
@ -49,7 +49,7 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_SpecConstant) {
|
||||
auto* var = Const("pos", ast::StorageClass::kNone, ty.f32, Expr(3.f),
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 23),
|
||||
create<ast::ConstantIdDecoration>(23),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.error();
|
||||
|
|
|
@ -30,18 +30,18 @@ namespace {
|
|||
using MslGeneratorImplTest = TestHelper;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Return) {
|
||||
ast::ReturnStatement r(Source{});
|
||||
auto* r = create<ast::ReturnStatement>();
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&r)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(r)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " return;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
|
||||
ast::ReturnStatement r(Source{}, Expr("expr"));
|
||||
auto* r = create<ast::ReturnStatement>(Expr("expr"));
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&r)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(r)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " return expr;\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -51,10 +51,10 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
|
|||
body.push_back(case_stmt);
|
||||
body.push_back(def);
|
||||
|
||||
ast::SwitchStatement s(Source{}, Expr("cond"), body);
|
||||
auto* s = create<ast::SwitchStatement>(Expr("cond"), body);
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&s)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(s)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( switch(cond) {
|
||||
case 5: {
|
||||
break;
|
||||
|
|
|
@ -38,8 +38,8 @@ inline std::ostream& operator<<(std::ostream& out, UnaryOpData data) {
|
|||
using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
|
||||
TEST_P(MslUnaryOpTest, Emit) {
|
||||
auto params = GetParam();
|
||||
ast::UnaryOpExpression op(Source{}, params.op, Expr("expr"));
|
||||
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();
|
||||
auto* op = create<ast::UnaryOpExpression>(params.op, Expr("expr"));
|
||||
ASSERT_TRUE(gen.EmitExpression(op)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), std::string(params.name) + "(expr)");
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(MslGeneratorImplTest,
|
||||
|
|
|
@ -42,21 +42,21 @@ using MslGeneratorImplTest = TestHelper;
|
|||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) {
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32);
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) {
|
||||
auto* var = Const("a", ast::StorageClass::kNone, ty.f32);
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " const float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
|
@ -64,11 +64,11 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) {
|
|||
ast::type::Array ary(ty.f32, 5, ast::ArrayDecorationList{});
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, &ary);
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a[5] = {0.0f};\n");
|
||||
}
|
||||
|
||||
|
@ -80,52 +80,52 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) {
|
|||
|
||||
auto* s = ty.struct_("S", str);
|
||||
auto* var = Var("a", ast::StorageClass::kNone, s);
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( S a = {};
|
||||
)");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) {
|
||||
auto* var = Var("a", ast::StorageClass::kFunction, ty.vec2<f32>());
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float2 a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) {
|
||||
auto* var = Var("a", ast::StorageClass::kFunction, ty.mat3x2<f32>());
|
||||
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float3x2 a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||
auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32);
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), " float a = 0.0f;\n");
|
||||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr("initializer"),
|
||||
ast::VariableDecorationList{});
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(float a = initializer;
|
||||
)");
|
||||
}
|
||||
|
@ -133,13 +133,13 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
|
|||
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) {
|
||||
ast::ExpressionList values;
|
||||
auto* zero_vec =
|
||||
create<ast::TypeConstructorExpression>(Source{}, ty.vec3<f32>(), values);
|
||||
create<ast::TypeConstructorExpression>(ty.vec3<f32>(), values);
|
||||
|
||||
auto* var = Var("a", ast::StorageClass::kNone, ty.vec3<f32>(), zero_vec,
|
||||
ast::VariableDecorationList{});
|
||||
ast::VariableDeclStatement stmt(Source{}, var);
|
||||
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(&stmt)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(float3 a = float3(0.0f);
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -44,16 +44,16 @@ using BuilderTest = TestHelper;
|
|||
TEST_F(BuilderTest, Assign_Var) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32);
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), Expr(1.f));
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
|
@ -70,15 +70,15 @@ TEST_F(BuilderTest, Assign_Var) {
|
|||
TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32);
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), Expr(1.f));
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), Expr(1.f));
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_FALSE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_FALSE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_TRUE(b.has_error());
|
||||
EXPECT_EQ(
|
||||
b.error(),
|
||||
|
@ -88,19 +88,19 @@ TEST_F(BuilderTest, Assign_Var_OutsideFunction_IsError) {
|
|||
TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
auto* val = create<ast::TypeConstructorExpression>(Source{}, ty.vec3<f32>(),
|
||||
auto* val = create<ast::TypeConstructorExpression>(ty.vec3<f32>(),
|
||||
ast::ExpressionList{});
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), val);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -116,22 +116,22 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
|
|||
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
|
||||
auto* first = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), init);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -155,20 +155,19 @@ OpStore %1 %13
|
|||
|
||||
TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), init);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), init);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -200,17 +199,17 @@ TEST_F(BuilderTest, Assign_StructMember) {
|
|||
auto* s_type = ty.struct_("my_struct", s);
|
||||
auto* v = Var("ident", ast::StorageClass::kFunction, s_type);
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, MemberAccessor("ident", "b"),
|
||||
Expr(4.f));
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(MemberAccessor("ident", "b"), Expr(4.f));
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -233,19 +232,18 @@ TEST_F(BuilderTest, Assign_Vector) {
|
|||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
auto* val = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, Expr("var"), val);
|
||||
auto* assign = create<ast::AssignmentStatement>(Expr("var"), val);
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -267,17 +265,17 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
|
|||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, MemberAccessor("var", "y"),
|
||||
Expr(1.f));
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(MemberAccessor("var", "y"), Expr(1.f));
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
@ -302,16 +300,17 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
|
|||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.vec3<f32>());
|
||||
|
||||
ast::AssignmentStatement assign(Source{}, IndexAccessor("var", 1), Expr(1.f));
|
||||
auto* assign =
|
||||
create<ast::AssignmentStatement>(IndexAccessor("var", 1), Expr(1.f));
|
||||
td.RegisterVariableForTesting(v);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(assign)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
|
|
@ -54,20 +54,16 @@ using BinaryArithSignedIntegerTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32 i32;
|
||||
auto* lhs = Expr(3);
|
||||
auto* rhs = Expr(4);
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4));
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
|
||||
%2 = OpConstant %1 3
|
||||
%3 = OpConstant %1 4
|
||||
|
@ -78,38 +74,16 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
|
|||
TEST_P(BinaryArithSignedIntegerTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32 i32;
|
||||
ast::type::Vector vec3(&i32, 3);
|
||||
auto* lhs = vec3<i32>(1, 1, 1);
|
||||
auto* rhs = vec3<i32>(1, 1, 1);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -122,14 +96,15 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
|
|||
auto param = GetParam();
|
||||
|
||||
auto* var = Var("param", ast::StorageClass::kFunction, ty.i32);
|
||||
ast::BinaryExpression expr(Source{}, param.op, Expr("param"), Expr("param"));
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(param.op, Expr("param"), Expr("param"));
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 7u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 7u) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
|
@ -168,17 +143,17 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
|||
ast::type::U32 u32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 3));
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 4));
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
|
||||
%2 = OpConstant %1 3
|
||||
%3 = OpConstant %1 4
|
||||
|
@ -189,38 +164,16 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
|
|||
TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32 u32;
|
||||
ast::type::Vector vec3(&u32, 3);
|
||||
auto* lhs = vec3<u32>(1u, 1u, 1u);
|
||||
auto* rhs = vec3<u32>(1u, 1u, 1u);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -251,16 +204,16 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
|||
ast::type::F32 f32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.2f));
|
||||
create<ast::FloatLiteral>(&f32, 3.2f));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.5f));
|
||||
create<ast::FloatLiteral>(&f32, 4.5f));
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
%2 = OpConstant %1 3.20000005
|
||||
%3 = OpConstant %1 4.5
|
||||
|
@ -272,38 +225,16 @@ TEST_P(BinaryArithFloatTest, Scalar) {
|
|||
TEST_P(BinaryArithFloatTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec3(&f32, 3);
|
||||
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -328,17 +259,17 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
|||
ast::type::U32 u32;
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 3));
|
||||
create<ast::UintLiteral>(&u32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 4));
|
||||
create<ast::UintLiteral>(&u32, 4));
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
|
||||
%2 = OpConstant %1 3
|
||||
%3 = OpConstant %1 4
|
||||
|
@ -351,38 +282,16 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
|
|||
TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::U32 u32;
|
||||
ast::type::Vector vec3(&u32, 3);
|
||||
auto* lhs = vec3<u32>(1u, 1u, 1u);
|
||||
auto* rhs = vec3<u32>(1u, 1u, 1u);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::UintLiteral>(Source{}, &u32, 1)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -408,20 +317,16 @@ using BinaryCompareSignedIntegerTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32 i32;
|
||||
auto* lhs = Expr(3);
|
||||
auto* rhs = Expr(4);
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4));
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
|
||||
%2 = OpConstant %1 3
|
||||
%3 = OpConstant %1 4
|
||||
|
@ -434,38 +339,16 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
|
|||
TEST_P(BinaryCompareSignedIntegerTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::I32 i32;
|
||||
ast::type::Vector vec3(&i32, 3);
|
||||
auto* lhs = vec3<i32>(1, 1, 1);
|
||||
auto* rhs = vec3<i32>(1, 1, 1);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -491,20 +374,16 @@ using BinaryCompareFloatTest = TestParamHelper<BinaryData>;
|
|||
TEST_P(BinaryCompareFloatTest, Scalar) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
auto* lhs = Expr(3.2f);
|
||||
auto* rhs = Expr(4.5f);
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.2f));
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.5f));
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 4u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
%2 = OpConstant %1 3.20000005
|
||||
%3 = OpConstant %1 4.5
|
||||
|
@ -517,38 +396,16 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
|
|||
TEST_P(BinaryCompareFloatTest, Vector) {
|
||||
auto param = GetParam();
|
||||
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec3(&f32, 3);
|
||||
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
});
|
||||
auto* expr = create<ast::BinaryExpression>(param.op, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
});
|
||||
|
||||
ast::BinaryExpression expr(Source{}, param.op, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -571,30 +428,17 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BinaryData{ast::BinaryOp::kNotEqual, "OpFOrdNotEqual"}));
|
||||
|
||||
TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec3(&f32, 3);
|
||||
auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
auto* rhs = Expr(1.f);
|
||||
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, &vec3,
|
||||
ast::ExpressionList{
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
|
||||
});
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||
|
||||
auto* rhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%1 = OpTypeVector %2 3
|
||||
%3 = OpConstant %2 1
|
||||
|
@ -605,28 +449,17 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
|
||||
ast::type::F32 f32;
|
||||
ast::type::Vector vec3(&f32, 3);
|
||||
auto* lhs = Expr(1.f);
|
||||
auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
|
||||
|
||||
auto* lhs = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
|
||||
|
||||
ast::ExpressionList vals;
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
|
||||
vals.push_back(create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 5u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
%2 = OpConstant %1 1
|
||||
%3 = OpTypeVector %1 3
|
||||
|
@ -640,14 +473,14 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
|
|||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, Expr("mat"),
|
||||
Expr(1.f));
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||
Expr("mat"), Expr(1.f));
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 8u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
|
||||
%4 = OpTypeVector %5 3
|
||||
%3 = OpTypeMatrix %4 3
|
||||
|
@ -665,15 +498,15 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, Expr(1.f),
|
||||
Expr("mat"));
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||
Expr(1.f), Expr("mat"));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 8u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
|
||||
%4 = OpTypeVector %5 3
|
||||
%3 = OpTypeMatrix %4 3
|
||||
|
@ -690,20 +523,19 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
|
|||
TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
auto* rhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, Expr("mat"),
|
||||
rhs);
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, Expr("mat"), rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 9u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
|
||||
%4 = OpTypeVector %5 3
|
||||
%3 = OpTypeMatrix %4 3
|
||||
|
@ -721,20 +553,19 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
|
|||
TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
|
||||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
auto* lhs = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(1.f)});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs,
|
||||
Expr("mat"));
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, Expr("mat"));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 9u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
|
||||
%4 = OpTypeVector %5 3
|
||||
%3 = OpTypeMatrix %4 3
|
||||
|
@ -753,15 +584,15 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, Expr("mat"),
|
||||
Expr("mat"));
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kMultiply,
|
||||
Expr("mat"), Expr("mat"));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 8u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 8u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
|
||||
%4 = OpTypeVector %5 3
|
||||
%3 = OpTypeMatrix %4 3
|
||||
|
@ -776,30 +607,21 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_LogicalAnd) {
|
||||
ast::type::I32 i32;
|
||||
auto* lhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, Expr(1), Expr(2));
|
||||
|
||||
auto* lhs = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
|
||||
auto* rhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, Expr(3), Expr(4));
|
||||
|
||||
auto* rhs = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4)));
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, lhs, rhs);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalAnd, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 12u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpConstant %2 1
|
||||
%4 = OpConstant %2 2
|
||||
|
@ -831,10 +653,10 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
|||
td.RegisterVariableForTesting(a_var);
|
||||
td.RegisterVariableForTesting(b_var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalAnd, Expr("a"),
|
||||
Expr("b"));
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
|
||||
Expr("a"), Expr("b"));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
@ -842,7 +664,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a_var)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(b_var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 12u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%5 = OpTypePointer Function %2
|
||||
|
@ -871,24 +693,24 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
|
|||
// From: crbug.com/tint/355
|
||||
|
||||
auto* logical_and_expr = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kLogicalAnd,
|
||||
ast::BinaryOp::kLogicalAnd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, true)),
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, false)));
|
||||
create<ast::BoolLiteral>(&bool_ty, false)));
|
||||
|
||||
ast::BinaryExpression expr(
|
||||
Source{}, ast::BinaryOp::kLogicalOr,
|
||||
auto* expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalOr,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, true)),
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
logical_and_expr);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 10u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
|
@ -918,24 +740,24 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
|
|||
// From: crbug.com/tint/355
|
||||
|
||||
auto* logical_or_expr = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kLogicalOr,
|
||||
ast::BinaryOp::kLogicalOr,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, true)),
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, false)));
|
||||
create<ast::BoolLiteral>(&bool_ty, false)));
|
||||
|
||||
ast::BinaryExpression expr(
|
||||
Source{}, ast::BinaryOp::kLogicalAnd,
|
||||
auto* expr = create<ast::BinaryExpression>(
|
||||
ast::BinaryOp::kLogicalAnd,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_ty, true)),
|
||||
create<ast::BoolLiteral>(&bool_ty, true)),
|
||||
logical_or_expr);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 10u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%8 = OpConstantFalse %2
|
||||
|
@ -958,30 +780,21 @@ OpBranch %4
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Binary_LogicalOr) {
|
||||
ast::type::I32 i32;
|
||||
auto* lhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, Expr(1), Expr(2));
|
||||
|
||||
auto* lhs = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
|
||||
auto* rhs =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kEqual, Expr(3), Expr(4));
|
||||
|
||||
auto* rhs = create<ast::BinaryExpression>(
|
||||
Source{}, ast::BinaryOp::kEqual,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)),
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::SintLiteral>(Source{}, &i32, 4)));
|
||||
auto* expr =
|
||||
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, lhs, rhs);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalOr, lhs, rhs);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 12u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpConstant %2 1
|
||||
%4 = OpConstant %2 2
|
||||
|
@ -1013,10 +826,10 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
|||
td.RegisterVariableForTesting(a_var);
|
||||
td.RegisterVariableForTesting(b_var);
|
||||
|
||||
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalOr, Expr("a"),
|
||||
Expr("b"));
|
||||
auto* expr = create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
|
||||
Expr("a"), Expr("b"));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
b.GenerateLabel(b.next_id());
|
||||
|
@ -1024,7 +837,7 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a_var)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(b_var)) << b.error();
|
||||
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(&expr), 12u) << b.error();
|
||||
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantTrue %2
|
||||
%5 = OpTypePointer Function %2
|
||||
|
|
|
@ -32,18 +32,12 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Bitcast) {
|
||||
ast::type::U32 u32;
|
||||
ast::type::F32 f32;
|
||||
auto* bitcast = create<ast::BitcastExpression>(ty.u32, Expr(2.4f));
|
||||
|
||||
ast::BitcastExpression bitcast(
|
||||
Source{}, &u32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.4)));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(bitcast), 1u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%3 = OpTypeFloat 32
|
||||
|
@ -57,15 +51,12 @@ TEST_F(BuilderTest, Bitcast) {
|
|||
TEST_F(BuilderTest, Bitcast_DuplicateType) {
|
||||
ast::type::F32 f32;
|
||||
|
||||
ast::BitcastExpression bitcast(
|
||||
Source{}, &f32,
|
||||
create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.4)));
|
||||
auto* bitcast = create<ast::BitcastExpression>(ty.f32, Expr(2.4f));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(bitcast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(&bitcast), 1u);
|
||||
EXPECT_EQ(b.GenerateBitcastExpression(bitcast), 1u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%3 = OpConstant %2 2.4000001
|
||||
|
|
|
@ -39,27 +39,22 @@ TEST_F(BuilderTest, Block) {
|
|||
|
||||
// Note, this test uses shadow variables which aren't allowed in WGSL but
|
||||
// serves to prove the block code is pushing new scopes as needed.
|
||||
auto* inner = create<ast::BlockStatement>(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{}, Var("var", ast::StorageClass::kFunction, ty.f32)),
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("var"), Expr(2.f))});
|
||||
ast::BlockStatement outer(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Source{}, Var("var", ast::StorageClass::kFunction, ty.f32)),
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("var"), Expr(1.f)),
|
||||
inner,
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("var"), Expr(3.f))});
|
||||
auto* inner = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("var", ast::StorageClass::kFunction, ty.f32)),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(2.f))});
|
||||
auto* outer = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(
|
||||
Var("var", ast::StorageClass::kFunction, ty.f32)),
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(1.f)), inner,
|
||||
create<ast::AssignmentStatement>(Expr("var"), Expr(3.f))});
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(outer)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateStatement(&outer)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateStatement(outer)) << b.error();
|
||||
EXPECT_FALSE(b.has_error());
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
|
|
|
@ -47,10 +47,10 @@ TEST_F(BuilderTest, Expression_Call) {
|
|||
func_params.push_back(Var("a", ast::StorageClass::kFunction, ty.f32));
|
||||
func_params.push_back(Var("b", ast::StorageClass::kFunction, ty.f32));
|
||||
|
||||
auto* a_func = Func(
|
||||
"a_func", func_params, ty.f32,
|
||||
ast::StatementList{create<ast::ReturnStatement>(Source{}, Add("a", "b"))},
|
||||
ast::FunctionDecorationList{});
|
||||
auto* a_func =
|
||||
Func("a_func", func_params, ty.f32,
|
||||
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
auto* func = Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -95,24 +95,24 @@ TEST_F(BuilderTest, Statement_Call) {
|
|||
func_params.push_back(Var("a", ast::StorageClass::kFunction, ty.f32));
|
||||
func_params.push_back(Var("b", ast::StorageClass::kFunction, ty.f32));
|
||||
|
||||
auto* a_func = Func(
|
||||
"a_func", func_params, ty.void_,
|
||||
ast::StatementList{create<ast::ReturnStatement>(Source{}, Add("a", "b"))},
|
||||
ast::FunctionDecorationList{});
|
||||
auto* a_func =
|
||||
Func("a_func", func_params, ty.void_,
|
||||
ast::StatementList{create<ast::ReturnStatement>(Add("a", "b"))},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
auto* func = Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
ast::CallStatement expr(Source{}, Call("a_func", 1.f, 1.f));
|
||||
auto* expr = create<ast::CallStatement>(Call("a_func", 1.f, 1.f));
|
||||
|
||||
ASSERT_TRUE(td.DetermineFunction(func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineFunction(a_func)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(a_func)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %4 "a_func"
|
||||
OpName %5 "a"
|
||||
OpName %6 "b"
|
||||
|
|
|
@ -115,12 +115,12 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) {
|
|||
// cast<Int>(2.3f)
|
||||
|
||||
auto* alias = ty.alias("Int", ty.i32);
|
||||
ast::TypeConstructorExpression cast(Source{}, alias, ExprList(2.3f));
|
||||
auto* cast = create<ast::TypeConstructorExpression>(alias, ExprList(2.3f));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 1u);
|
||||
EXPECT_EQ(b.GenerateExpression(cast), 1u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpTypeFloat 32
|
||||
|
@ -184,8 +184,8 @@ TEST_F(SpvBuilderConstructorTest, Vector_Bitcast_Params) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
|
||||
auto* rel = create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kAdd,
|
||||
Expr(3.0f), Expr(3.0f));
|
||||
auto* rel = create<ast::BinaryExpression>(ast::BinaryOp::kAdd, Expr(3.0f),
|
||||
Expr(3.0f));
|
||||
|
||||
auto* t = vec2<f32>(1.0f, rel);
|
||||
|
||||
|
@ -197,13 +197,13 @@ TEST_F(SpvBuilderConstructorTest, Type_NonConst_Value_Fails) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.bool_, ExprList(true));
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.bool_, ExprList(true));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 3u);
|
||||
EXPECT_EQ(b.GenerateExpression(cast), 3u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
|
@ -213,12 +213,12 @@ TEST_F(SpvBuilderConstructorTest, Type_Bool_With_Bool) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.i32, ExprList(2));
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.i32, ExprList(2));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 3u);
|
||||
EXPECT_EQ(b.GenerateExpression(cast), 3u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpConstant %2 2
|
||||
|
@ -227,12 +227,12 @@ TEST_F(SpvBuilderConstructorTest, Type_I32_With_I32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.u32, ExprList(2u));
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.u32, ExprList(2u));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 3u);
|
||||
EXPECT_EQ(b.GenerateExpression(cast), 3u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
|
||||
%3 = OpConstant %2 2
|
||||
|
@ -241,12 +241,12 @@ TEST_F(SpvBuilderConstructorTest, Type_U32_With_U32) {
|
|||
}
|
||||
|
||||
TEST_F(SpvBuilderConstructorTest, Type_F32_With_F32) {
|
||||
ast::TypeConstructorExpression cast(Source{}, ty.f32, ExprList(2.0f));
|
||||
auto* cast = create<ast::TypeConstructorExpression>(ty.f32, ExprList(2.0f));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&cast)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(cast)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateExpression(&cast), 3u);
|
||||
EXPECT_EQ(b.GenerateExpression(cast), 3u);
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%3 = OpConstant %2 2
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Discard) {
|
||||
ast::DiscardStatement expr(Source{});
|
||||
auto* expr = create<ast::DiscardStatement>();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateStatement(&expr), 1u) << b.error();
|
||||
EXPECT_EQ(b.GenerateStatement(expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpKill
|
||||
)");
|
||||
}
|
||||
|
|
|
@ -39,11 +39,11 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_Stage) {
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.entry_points()),
|
||||
|
@ -65,7 +65,7 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
|
|||
|
||||
auto* func = Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, params.stage),
|
||||
create<ast::StageDecoration>(params.stage),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
@ -91,11 +91,11 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
|
|||
ast::type::F32 f32;
|
||||
ast::type::Void void_type;
|
||||
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32);
|
||||
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32);
|
||||
|
@ -132,19 +132,17 @@ OpName %11 "main"
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_,
|
||||
ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("my_out"), Expr("my_in")),
|
||||
create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("my_wg"), Expr("my_wg")),
|
||||
// Add duplicate usages so we show they don't get
|
||||
// output multiple times.
|
||||
create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("my_out"), Expr("my_in"))},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in")),
|
||||
create<ast::AssignmentStatement>(Expr("my_wg"), Expr("my_wg")),
|
||||
// Add duplicate usages so we show they don't get
|
||||
// output multiple times.
|
||||
create<ast::AssignmentStatement>(Expr("my_out"), Expr("my_in"))},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
|
||||
});
|
||||
|
||||
auto* v_in = Var("my_in", ast::StorageClass::kInput, ty.f32);
|
||||
auto* v_out = Var("my_out", ast::StorageClass::kOutput, ty.f32);
|
||||
|
@ -187,11 +185,11 @@ OpName %11 "main"
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -200,11 +198,11 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_WorkgroupSize_Default) {
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -213,12 +211,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_WorkgroupSize_Default) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_WorkgroupSize) {
|
||||
auto* func = Func(
|
||||
"main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::WorkgroupDecoration>(Source{}, 2u, 4u, 6u),
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("main", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::WorkgroupDecoration>(2u, 4u, 6u),
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.execution_modes()),
|
||||
|
@ -227,17 +225,17 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_WorkgroupSize) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
|
||||
auto* func1 = Func(
|
||||
"main1", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func1 =
|
||||
Func("main1", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
auto* func2 = Func(
|
||||
"main2", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment),
|
||||
});
|
||||
auto* func2 =
|
||||
Func("main2", {}, ty.void_, ast::StatementList{},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kFragment),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(b.GenerateFunction(func1)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func2)) << b.error();
|
||||
|
|
|
@ -63,7 +63,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_Terminator_Return) {
|
||||
auto* func = Func("a_func", {}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{}),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
|
@ -108,7 +108,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_Terminator_Discard) {
|
||||
auto* func = Func("a_func", {}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::DiscardStatement>(Source{}),
|
||||
create<ast::DiscardStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
|
@ -155,7 +155,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, Function_WithBody) {
|
||||
auto* func = Func("a_func", {}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{}),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{});
|
||||
|
||||
|
@ -211,7 +211,7 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
// }
|
||||
|
||||
ast::StructDecorationList s_decos;
|
||||
s_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
|
||||
s_decos.push_back(create<ast::StructBlockDecoration>());
|
||||
|
||||
auto* str = create<ast::Struct>(
|
||||
ast::StructMemberList{Member("d", ty.f32, {MemberOffset(0)})}, s_decos);
|
||||
|
@ -221,8 +221,8 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
|
||||
auto* data_var = Var("data", ast::StorageClass::kStorageBuffer, &ac, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BindingDecoration>(Source{}, 0),
|
||||
create<ast::SetDecoration>(Source{}, 0),
|
||||
create<ast::BindingDecoration>(0),
|
||||
create<ast::SetDecoration>(0),
|
||||
});
|
||||
|
||||
mod->AddConstructedType(s);
|
||||
|
@ -234,15 +234,15 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func("a", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{}, var),
|
||||
create<ast::ReturnStatement>(Source{}),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(
|
||||
Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("a", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
}
|
||||
|
@ -251,15 +251,15 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
|
|||
auto* var = Var("v", ast::StorageClass::kFunction, ty.f32,
|
||||
MemberAccessor("data", "d"), ast::VariableDecorationList{});
|
||||
|
||||
auto* func = Func("b", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(Source{}, var),
|
||||
create<ast::ReturnStatement>(Source{}),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(
|
||||
Source{}, ast::PipelineStage::kCompute),
|
||||
});
|
||||
auto* func =
|
||||
Func("b", ast::VariableList{}, ty.void_,
|
||||
ast::StatementList{
|
||||
create<ast::VariableDeclStatement>(var),
|
||||
create<ast::ReturnStatement>(),
|
||||
},
|
||||
ast::FunctionDecorationList{
|
||||
create<ast::StageDecoration>(ast::PipelineStage::kCompute),
|
||||
});
|
||||
|
||||
mod->AddFunction(func);
|
||||
}
|
||||
|
|
|
@ -64,8 +64,7 @@ TEST_F(BuilderTest, FunctionVar_NoStorageClass) {
|
|||
|
||||
TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -95,7 +94,7 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
|
|||
|
||||
TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Add(3.f, 3.f)});
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Add(3.f, 3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kFunction, ty.vec2<f32>(), init,
|
||||
|
@ -205,8 +204,7 @@ OpStore %7 %6
|
|||
|
||||
TEST_F(BuilderTest, FunctionVar_Const) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
|
|
@ -86,8 +86,7 @@ TEST_F(BuilderTest, GlobalVar_WithStorageClass_Input) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -111,8 +110,7 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_Const) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -134,8 +132,7 @@ TEST_F(BuilderTest, GlobalVar_Const) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -156,10 +153,10 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
|
|||
|
||||
TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
||||
auto* first = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
ty.vec2<f32>(), ast::ExpressionList{Expr(1.f), Expr(2.f)});
|
||||
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{first, Expr(3.f)});
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
|
@ -189,7 +186,7 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
|
|||
TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::LocationDecoration>(Source{}, 5),
|
||||
create<ast::LocationDecoration>(5),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -207,8 +204,8 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
|
|||
TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BindingDecoration>(Source{}, 2),
|
||||
create<ast::SetDecoration>(Source{}, 3),
|
||||
create<ast::BindingDecoration>(2),
|
||||
create<ast::SetDecoration>(3),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -225,11 +222,10 @@ OpDecorate %1 DescriptorSet 3
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
||||
auto* v =
|
||||
Var("var", ast::StorageClass::kOutput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kPosition),
|
||||
});
|
||||
auto* v = Var("var", ast::StorageClass::kOutput, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::BuiltinDecoration>(ast::Builtin::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
|
||||
|
@ -246,7 +242,7 @@ TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_, Expr(true),
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 1200),
|
||||
create<ast::ConstantIdDecoration>(1200),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -264,7 +260,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.bool_, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 1200),
|
||||
create<ast::ConstantIdDecoration>(1200),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -282,7 +278,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32, Expr(2.f),
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 0),
|
||||
create<ast::ConstantIdDecoration>(0),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -300,7 +296,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.f32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 0),
|
||||
create<ast::ConstantIdDecoration>(0),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -318,7 +314,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.i32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 0),
|
||||
create<ast::ConstantIdDecoration>(0),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
@ -336,7 +332,7 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
|
|||
TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
|
||||
auto* v = Var("var", ast::StorageClass::kNone, ty.u32, nullptr,
|
||||
ast::VariableDecorationList{
|
||||
create<ast::ConstantIdDecoration>(Source{}, 0),
|
||||
create<ast::ConstantIdDecoration>(0),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
|
||||
|
|
|
@ -39,8 +39,7 @@ using BuilderTest = TestHelper;
|
|||
|
||||
TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
@ -83,8 +82,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
|
|||
|
||||
TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
|
||||
auto* init = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
EXPECT_TRUE(td.DetermineResultType(init)) << td.error();
|
||||
|
||||
auto* v = Const("var", ast::StorageClass::kOutput, ty.f32, init,
|
||||
|
|
|
@ -46,18 +46,17 @@ TEST_F(BuilderTest, If_Empty) {
|
|||
// if (true) {
|
||||
// }
|
||||
auto* cond = create<ast::ScalarConstructorExpression>(
|
||||
Source{}, create<ast::BoolLiteral>(Source{}, &bool_type, true));
|
||||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::IfStatement expr(
|
||||
Source{}, cond,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
cond, create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::ElseStatementList{});
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
)");
|
||||
|
@ -80,12 +79,12 @@ TEST_F(BuilderTest, If_Empty_OutsideFunction_IsError) {
|
|||
create<ast::BoolLiteral>(&bool_type, true));
|
||||
|
||||
ast::ElseStatementList elses;
|
||||
auto* block = create<ast::BlockStatement>(Source{}, ast::StatementList{});
|
||||
ast::IfStatement expr(Source{}, cond, block, elses);
|
||||
auto* block = create<ast::BlockStatement>(ast::StatementList{});
|
||||
auto* expr = create<ast::IfStatement>(cond, block, elses);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
EXPECT_FALSE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_FALSE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_TRUE(b.has_error());
|
||||
EXPECT_EQ(b.error(),
|
||||
"Internal error: trying to add SPIR-V instruction 247 outside a "
|
||||
|
@ -99,17 +98,17 @@ TEST_F(BuilderTest, If_WithStatements) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::IfStatement expr(Source{}, Expr(true), body, ast::ElseStatementList{});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* expr =
|
||||
create<ast::IfStatement>(Expr(true), body, ast::ElseStatementList{});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -137,24 +136,22 @@ TEST_F(BuilderTest, If_WithElse) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
|
||||
ast::IfStatement expr(
|
||||
Source{}, Expr(true), body,
|
||||
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -186,24 +183,24 @@ TEST_F(BuilderTest, If_WithElseIf) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
|
||||
ast::IfStatement expr(
|
||||
Source{}, Expr(true), body,
|
||||
{create<ast::ElseStatement>(Source{}, Expr(true), else_body)});
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(Expr(true), else_body),
|
||||
});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -244,34 +241,30 @@ TEST_F(BuilderTest, If_WithMultiple) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* elseif_1_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
auto* elseif_2_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(4))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(4))});
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(5))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(5))});
|
||||
|
||||
ast::IfStatement expr(
|
||||
Source{}, Expr(true), body,
|
||||
{
|
||||
create<ast::ElseStatement>(Source{}, Expr(true), elseif_1_body),
|
||||
create<ast::ElseStatement>(Source{}, Expr(false), elseif_2_body),
|
||||
create<ast::ElseStatement>(Source{}, nullptr, else_body),
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr(true), body,
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(Expr(true), elseif_1_body),
|
||||
create<ast::ElseStatement>(Expr(false), elseif_2_body),
|
||||
create<ast::ElseStatement>(nullptr, else_body),
|
||||
});
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -320,27 +313,25 @@ TEST_F(BuilderTest, If_WithBreak) {
|
|||
// }
|
||||
// }
|
||||
|
||||
auto* if_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
|
||||
auto* if_stmt = create<ast::IfStatement>(Source{}, Expr(true), if_body,
|
||||
ast::ElseStatementList{});
|
||||
auto* if_stmt =
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||
|
||||
auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
auto* loop_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
|
||||
ast::LoopStatement expr(
|
||||
Source{}, loop_body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* expr = create<ast::LoopStatement>(
|
||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
|
||||
%6 = OpConstantTrue %5
|
||||
)");
|
||||
|
@ -369,30 +360,26 @@ TEST_F(BuilderTest, If_WithElseBreak) {
|
|||
// break;
|
||||
// }
|
||||
// }
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
auto* else_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
|
||||
auto* if_stmt = create<ast::IfStatement>(
|
||||
Source{}, Expr(true),
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||
Expr(true), create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
|
||||
|
||||
auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
auto* loop_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
|
||||
ast::LoopStatement expr(
|
||||
Source{}, loop_body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* expr = create<ast::LoopStatement>(
|
||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
|
||||
%6 = OpConstantTrue %5
|
||||
)");
|
||||
|
@ -422,27 +409,25 @@ TEST_F(BuilderTest, If_WithContinue) {
|
|||
// continue;
|
||||
// }
|
||||
// }
|
||||
auto* if_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::ContinueStatement>(Source{}),
|
||||
});
|
||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ContinueStatement>(),
|
||||
});
|
||||
|
||||
auto* if_stmt = create<ast::IfStatement>(Source{}, Expr(true), if_body,
|
||||
ast::ElseStatementList{});
|
||||
auto* if_stmt =
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||
|
||||
auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
auto* loop_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
|
||||
ast::LoopStatement expr(
|
||||
Source{}, loop_body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* expr = create<ast::LoopStatement>(
|
||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
|
||||
%6 = OpConstantTrue %5
|
||||
)");
|
||||
|
@ -471,30 +456,26 @@ TEST_F(BuilderTest, If_WithElseContinue) {
|
|||
// continue;
|
||||
// }
|
||||
// }
|
||||
auto* else_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::ContinueStatement>(Source{}),
|
||||
});
|
||||
auto* else_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ContinueStatement>(),
|
||||
});
|
||||
|
||||
auto* if_stmt = create<ast::IfStatement>(
|
||||
Source{}, Expr(true),
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
ast::ElseStatementList{
|
||||
create<ast::ElseStatement>(Source{}, nullptr, else_body)});
|
||||
Expr(true), create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
|
||||
|
||||
auto* loop_body = create<ast::BlockStatement>(Source{}, ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
auto* loop_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
if_stmt,
|
||||
});
|
||||
|
||||
ast::LoopStatement expr(
|
||||
Source{}, loop_body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* expr = create<ast::LoopStatement>(
|
||||
loop_body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
|
||||
%6 = OpConstantTrue %5
|
||||
)");
|
||||
|
@ -522,18 +503,17 @@ TEST_F(BuilderTest, If_WithReturn) {
|
|||
// if (true) {
|
||||
// return;
|
||||
// }
|
||||
auto* if_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{}),
|
||||
});
|
||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(),
|
||||
});
|
||||
|
||||
ast::IfStatement expr(Source{}, Expr(true), if_body,
|
||||
ast::ElseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr =
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
)");
|
||||
|
@ -550,18 +530,17 @@ TEST_F(BuilderTest, If_WithReturnValue) {
|
|||
// if (true) {
|
||||
// return false;
|
||||
// }
|
||||
auto* if_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::ReturnStatement>(Source{}, Expr(false)),
|
||||
});
|
||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ReturnStatement>(Expr(false)),
|
||||
});
|
||||
|
||||
ast::IfStatement expr(Source{}, Expr(true), if_body,
|
||||
ast::ElseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr =
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
%2 = OpConstantTrue %1
|
||||
%5 = OpConstantFalse %1
|
||||
|
@ -583,17 +562,16 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
|
|||
auto* var = Var("a", ast::StorageClass::kFunction, ty.bool_);
|
||||
td.RegisterVariableForTesting(var);
|
||||
|
||||
ast::IfStatement expr(
|
||||
Source{}, Expr("a"),
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
auto* expr = create<ast::IfStatement>(
|
||||
Expr("a"), create<ast::BlockStatement>(ast::StatementList{}),
|
||||
ast::ElseStatementList{});
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateIfStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeBool
|
||||
%2 = OpTypePointer Function %3
|
||||
%1 = OpVariable %2 Function
|
||||
|
|
|
@ -2793,10 +2793,11 @@ TEST_P(IntrinsicTextureTest, OutsideFunction_IsError) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(tex)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error();
|
||||
|
||||
ast::CallExpression call{Source{}, Expr(param.function), param.args(this)};
|
||||
auto* call =
|
||||
create<ast::CallExpression>(Expr(param.function), param.args(this));
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(&call)) << td.error();
|
||||
EXPECT_EQ(b.GenerateExpression(&call), 0u);
|
||||
EXPECT_TRUE(td.DetermineResultType(call)) << td.error();
|
||||
EXPECT_EQ(b.GenerateExpression(call), 0u);
|
||||
EXPECT_THAT(b.error(),
|
||||
::testing::StartsWith(
|
||||
"Internal error: trying to add SPIR-V instruction "));
|
||||
|
|
|
@ -34,10 +34,9 @@ namespace spirv {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Literal_Bool_True) {
|
||||
ast::type::Bool bool_type;
|
||||
ast::BoolLiteral b_true(Source{}, &bool_type, true);
|
||||
auto* b_true = create<ast::BoolLiteral>(ty.bool_, true);
|
||||
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &b_true);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, b_true);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
||||
|
@ -47,10 +46,9 @@ TEST_F(BuilderTest, Literal_Bool_True) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_Bool_False) {
|
||||
ast::type::Bool bool_type;
|
||||
ast::BoolLiteral b_false(Source{}, &bool_type, false);
|
||||
auto* b_false = create<ast::BoolLiteral>(ty.bool_, false);
|
||||
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &b_false);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, b_false);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
||||
|
@ -60,15 +58,14 @@ TEST_F(BuilderTest, Literal_Bool_False) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_Bool_Dedup) {
|
||||
ast::type::Bool bool_type;
|
||||
ast::BoolLiteral b_true(Source{}, &bool_type, true);
|
||||
ast::BoolLiteral b_false(Source{}, &bool_type, false);
|
||||
auto* b_true = create<ast::BoolLiteral>(ty.bool_, true);
|
||||
auto* b_false = create<ast::BoolLiteral>(ty.bool_, false);
|
||||
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &b_true), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, b_true), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &b_false), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, b_false), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &b_true), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, b_true), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
|
||||
|
@ -78,10 +75,9 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_I32) {
|
||||
ast::type::I32 i32;
|
||||
ast::SintLiteral i(Source{}, &i32, -23);
|
||||
auto* i = create<ast::SintLiteral>(ty.i32, -23);
|
||||
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
||||
|
@ -91,12 +87,11 @@ TEST_F(BuilderTest, Literal_I32) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_I32_Dedup) {
|
||||
ast::type::I32 i32;
|
||||
ast::SintLiteral i1(Source{}, &i32, -23);
|
||||
ast::SintLiteral i2(Source{}, &i32, -23);
|
||||
auto* i1 = create<ast::SintLiteral>(ty.i32, -23);
|
||||
auto* i2 = create<ast::SintLiteral>(ty.i32, -23);
|
||||
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
|
||||
|
@ -105,10 +100,9 @@ TEST_F(BuilderTest, Literal_I32_Dedup) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_U32) {
|
||||
ast::type::U32 u32;
|
||||
ast::UintLiteral i(Source{}, &u32, 23);
|
||||
auto* i = create<ast::UintLiteral>(ty.u32, 23);
|
||||
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
||||
|
@ -118,12 +112,11 @@ TEST_F(BuilderTest, Literal_U32) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_U32_Dedup) {
|
||||
ast::type::U32 u32;
|
||||
ast::UintLiteral i1(Source{}, &u32, 23);
|
||||
ast::UintLiteral i2(Source{}, &u32, 23);
|
||||
auto* i1 = create<ast::UintLiteral>(ty.u32, 23);
|
||||
auto* i2 = create<ast::UintLiteral>(ty.u32, 23);
|
||||
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
|
||||
|
@ -132,10 +125,9 @@ TEST_F(BuilderTest, Literal_U32_Dedup) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_F32) {
|
||||
ast::type::F32 f32;
|
||||
ast::FloatLiteral i(Source{}, &f32, 23.245f);
|
||||
auto* i = create<ast::FloatLiteral>(ty.f32, 23.245f);
|
||||
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, &i);
|
||||
auto id = b.GenerateLiteralIfNeeded(nullptr, i);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
EXPECT_EQ(2u, id);
|
||||
|
||||
|
@ -145,12 +137,11 @@ TEST_F(BuilderTest, Literal_F32) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, Literal_F32_Dedup) {
|
||||
ast::type::F32 f32;
|
||||
ast::FloatLiteral i1(Source{}, &f32, 23.245f);
|
||||
ast::FloatLiteral i2(Source{}, &f32, 23.245f);
|
||||
auto* i1 = create<ast::FloatLiteral>(ty.f32, 23.245f);
|
||||
auto* i2 = create<ast::FloatLiteral>(ty.f32, 23.245f);
|
||||
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, &i2), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i1), 0u);
|
||||
ASSERT_NE(b.GenerateLiteralIfNeeded(nullptr, i2), 0u);
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
|
||||
|
|
|
@ -39,14 +39,14 @@ TEST_F(BuilderTest, Loop_Empty) {
|
|||
// loop {
|
||||
// }
|
||||
|
||||
ast::LoopStatement loop(
|
||||
Source{}, create<ast::BlockStatement>(Source{}, ast::StatementList{}),
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
create<ast::BlockStatement>(ast::StatementList{}),
|
||||
create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(OpBranch %1
|
||||
%1 = OpLabel
|
||||
|
@ -67,20 +67,18 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
|
||||
ast::LoopStatement loop(
|
||||
Source{}, body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -112,21 +110,19 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
|
|||
|
||||
auto* var = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
auto* continuing = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
|
||||
ast::LoopStatement loop(Source{}, body, continuing);
|
||||
auto* loop = create<ast::LoopStatement>(body, continuing);
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
|
||||
%2 = OpTypePointer Private %3
|
||||
%4 = OpConstantNull %3
|
||||
|
@ -153,19 +149,17 @@ TEST_F(BuilderTest, Loop_WithContinue) {
|
|||
// loop {
|
||||
// continue;
|
||||
// }
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::ContinueStatement>(Source{}),
|
||||
});
|
||||
ast::LoopStatement loop(
|
||||
Source{}, body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::ContinueStatement>(),
|
||||
});
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(OpBranch %1
|
||||
%1 = OpLabel
|
||||
|
@ -183,19 +177,17 @@ TEST_F(BuilderTest, Loop_WithBreak) {
|
|||
// loop {
|
||||
// break;
|
||||
// }
|
||||
auto* body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
ast::LoopStatement loop(
|
||||
Source{}, body,
|
||||
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
|
||||
auto* body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
auto* loop = create<ast::LoopStatement>(
|
||||
body, create<ast::BlockStatement>(ast::StatementList{}));
|
||||
|
||||
ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(loop)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(&loop)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
|
||||
R"(OpBranch %1
|
||||
%1 = OpLabel
|
||||
|
|
|
@ -35,10 +35,10 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, Return) {
|
||||
ast::ReturnStatement ret(Source{});
|
||||
auto* ret = create<ast::ReturnStatement>();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret));
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(ret));
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
|
||||
|
@ -47,15 +47,14 @@ TEST_F(BuilderTest, Return) {
|
|||
|
||||
TEST_F(BuilderTest, Return_WithValue) {
|
||||
auto* val = create<ast::TypeConstructorExpression>(
|
||||
Source{}, ty.vec3<f32>(),
|
||||
ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
ty.vec3<f32>(), ast::ExpressionList{Expr(1.f), Expr(1.f), Expr(3.f)});
|
||||
|
||||
ast::ReturnStatement ret(Source{}, val);
|
||||
auto* ret = create<ast::ReturnStatement>(val);
|
||||
|
||||
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
|
||||
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret));
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(ret));
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
|
@ -72,14 +71,14 @@ TEST_F(BuilderTest, Return_WithValue) {
|
|||
TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
|
||||
auto* var = Var("param", ast::StorageClass::kFunction, ty.f32);
|
||||
|
||||
ast::ReturnStatement ret(Source{}, Expr("param"));
|
||||
auto* ret = create<ast::ReturnStatement>(Expr("param"));
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();
|
||||
EXPECT_TRUE(td.DetermineResultType(ret)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(&ret)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateReturnStatement(ret)) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
|
||||
|
|
|
@ -43,12 +43,12 @@ TEST_F(BuilderTest, Switch_Empty) {
|
|||
// switch (1) {
|
||||
// }
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr(1), ast::CaseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr = create<ast::SwitchStatement>(Expr(1), ast::CaseStatementList{});
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpConstant %2 1
|
||||
)");
|
||||
|
@ -73,12 +73,10 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
|||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(1))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
|
||||
auto* case_2_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
@ -87,16 +85,14 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
|||
selector_2.push_back(Literal(2));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -105,7 +101,7 @@ TEST_F(BuilderTest, Switch_WithCase) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
|
@ -147,18 +143,17 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
|||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(1))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
|
||||
default_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(ast::CaseSelectorList{}, default_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -167,7 +162,7 @@ TEST_F(BuilderTest, Switch_WithDefault) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
|
@ -207,16 +202,13 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(1))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
|
||||
auto* case_2_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
@ -226,18 +218,16 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
selector_2.push_back(Literal(3));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
|
||||
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
|
||||
default_body));
|
||||
create<ast::CaseStatement>(ast::CaseSelectorList{}, default_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -246,7 +236,7 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
|
@ -295,18 +285,14 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("v"), Expr(1)),
|
||||
create<ast::FallthroughStatement>(Source{})});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
|
||||
create<ast::FallthroughStatement>()});
|
||||
|
||||
auto* case_2_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(2))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(2))});
|
||||
|
||||
auto* default_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{create<ast::AssignmentStatement>(
|
||||
Source{}, Expr("v"), Expr(3))});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(3))});
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
@ -315,18 +301,16 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
selector_2.push_back(Literal(2));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_2, case_2_body));
|
||||
cases.push_back(create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{},
|
||||
default_body));
|
||||
create<ast::CaseStatement>(ast::CaseSelectorList{}, default_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -335,7 +319,7 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
|
@ -380,23 +364,20 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
|||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("v"), Expr(1)),
|
||||
create<ast::FallthroughStatement>(Source{})});
|
||||
ast::StatementList{create<ast::AssignmentStatement>(Expr("v"), Expr(1)),
|
||||
create<ast::FallthroughStatement>()});
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -405,7 +386,7 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_FALSE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_FALSE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
EXPECT_EQ(b.error(), "fallthrough of last case statement is disallowed");
|
||||
}
|
||||
|
||||
|
@ -421,30 +402,25 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
|||
auto* v = Var("v", ast::StorageClass::kPrivate, ty.i32);
|
||||
auto* a = Var("a", ast::StorageClass::kPrivate, ty.i32);
|
||||
|
||||
auto* if_body = create<ast::BlockStatement>(
|
||||
Source{}, ast::StatementList{
|
||||
create<ast::BreakStatement>(Source{}),
|
||||
});
|
||||
auto* if_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::BreakStatement>(),
|
||||
});
|
||||
|
||||
auto* case_1_body = create<ast::BlockStatement>(
|
||||
Source{},
|
||||
ast::StatementList{
|
||||
create<ast::IfStatement>(Source{}, Expr(true), if_body,
|
||||
ast::ElseStatementList{}),
|
||||
create<ast::AssignmentStatement>(Source{}, Expr("v"), Expr(1))});
|
||||
auto* case_1_body = create<ast::BlockStatement>(ast::StatementList{
|
||||
create<ast::IfStatement>(Expr(true), if_body, ast::ElseStatementList{}),
|
||||
create<ast::AssignmentStatement>(Expr("v"), Expr(1))});
|
||||
|
||||
ast::CaseSelectorList selector_1;
|
||||
selector_1.push_back(Literal(1));
|
||||
|
||||
ast::CaseStatementList cases;
|
||||
cases.push_back(
|
||||
create<ast::CaseStatement>(Source{}, selector_1, case_1_body));
|
||||
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
|
||||
|
||||
ast::SwitchStatement expr(Source{}, Expr("a"), cases);
|
||||
auto* expr = create<ast::SwitchStatement>(Expr("a"), cases);
|
||||
|
||||
td.RegisterVariableForTesting(v);
|
||||
td.RegisterVariableForTesting(a);
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
auto* func = Func("a_func", {}, ty.i32, ast::StatementList{},
|
||||
ast::FunctionDecorationList{});
|
||||
|
@ -453,7 +429,7 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
|
|||
ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error();
|
||||
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
|
||||
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(&expr)) << b.error();
|
||||
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpBuilder(b), R"(OpName %1 "v"
|
||||
OpName %5 "a"
|
||||
|
|
|
@ -114,7 +114,7 @@ TEST_F(BuilderTest_Type, GenerateArray) {
|
|||
TEST_F(BuilderTest_Type, GenerateArray_WithStride) {
|
||||
ast::type::Array ary(ty.i32, 4,
|
||||
ast::ArrayDecorationList{
|
||||
create<ast::StrideDecoration>(Source{}, 16u),
|
||||
create<ast::StrideDecoration>(16u),
|
||||
});
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(&ary);
|
||||
|
@ -242,8 +242,8 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
|
||||
auto* s = create<ast::Struct>(Source{}, ast::StructMemberList{},
|
||||
ast::StructDecorationList{});
|
||||
auto* s =
|
||||
create<ast::Struct>(ast::StructMemberList{}, ast::StructDecorationList{});
|
||||
auto* s_type = ty.struct_("S", s);
|
||||
|
||||
auto id = b.GenerateTypeIfNeeded(s_type);
|
||||
|
@ -276,7 +276,7 @@ OpMemberName %1 0 "a"
|
|||
|
||||
TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
|
||||
ast::StructDecorationList struct_decos;
|
||||
struct_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
|
||||
struct_decos.push_back(create<ast::StructBlockDecoration>());
|
||||
|
||||
auto* s = create<ast::Struct>(ast::StructMemberList{Member("a", ty.f32)},
|
||||
struct_decos);
|
||||
|
|
|
@ -38,11 +38,11 @@ namespace {
|
|||
using BuilderTest = TestHelper;
|
||||
|
||||
TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
||||
ast::UnaryOpExpression expr(Source{}, ast::UnaryOp::kNegation, Expr(1));
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1));
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error();
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
|
||||
%3 = OpConstant %2 1
|
||||
)");
|
||||
|
@ -52,11 +52,12 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
||||
ast::UnaryOpExpression expr(Source{}, ast::UnaryOp::kNegation, Expr(1.f));
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr(1.f));
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error();
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
|
||||
%3 = OpConstant %2 1
|
||||
)");
|
||||
|
@ -66,11 +67,11 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
|
|||
}
|
||||
|
||||
TEST_F(BuilderTest, UnaryOp_Not) {
|
||||
ast::UnaryOpExpression expr(Source{}, ast::UnaryOp::kNot, Expr(false));
|
||||
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
auto* expr = create<ast::UnaryOpExpression>(ast::UnaryOp::kNot, Expr(false));
|
||||
ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 1u) << b.error();
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
|
||||
%3 = OpConstantFalse %2
|
||||
)");
|
||||
|
@ -82,14 +83,15 @@ TEST_F(BuilderTest, UnaryOp_Not) {
|
|||
TEST_F(BuilderTest, UnaryOp_LoadRequired) {
|
||||
auto* var = Var("param", ast::StorageClass::kFunction, ty.vec3<f32>());
|
||||
|
||||
ast::UnaryOpExpression expr(Source{}, ast::UnaryOp::kNegation, Expr("param"));
|
||||
auto* expr =
|
||||
create<ast::UnaryOpExpression>(ast::UnaryOp::kNegation, Expr("param"));
|
||||
|
||||
td.RegisterVariableForTesting(var);
|
||||
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();
|
||||
EXPECT_TRUE(td.DetermineResultType(expr)) << td.error();
|
||||
|
||||
b.push_function(Function{});
|
||||
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(&expr), 6u) << b.error();
|
||||
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 6u) << b.error();
|
||||
ASSERT_FALSE(b.has_error()) << b.error();
|
||||
|
||||
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
|
||||
|
|
Loading…
Reference in New Issue