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