Add a symbol to the Identifier AST node

This CL adds a Symbol to the identifier to represent the name. The name
still exists but will be removed in a future CL when the namers are in
place.

Change-Id: Ic3cc8ad0d99e3bea6eb1ff1ce212e7de67991aec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35460
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2020-12-11 19:16:13 +00:00 committed by Commit Bot service account
parent 5b3c9f1c62
commit 6b59bf45aa
113 changed files with 2525 additions and 1750 deletions

View File

@ -24,8 +24,8 @@ namespace {
using ArrayAccessorExpressionTest = TestHelper; using ArrayAccessorExpressionTest = TestHelper;
TEST_F(ArrayAccessorExpressionTest, Create) { TEST_F(ArrayAccessorExpressionTest, Create) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
ASSERT_EQ(exp.array(), ary); ASSERT_EQ(exp.array(), ary);
@ -33,8 +33,8 @@ TEST_F(ArrayAccessorExpressionTest, Create) {
} }
TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, ary, idx); ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, ary, idx);
auto src = exp.source(); auto src = exp.source();
@ -43,58 +43,58 @@ TEST_F(ArrayAccessorExpressionTest, CreateWithSource) {
} }
TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) { TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
EXPECT_TRUE(exp.Is<ArrayAccessorExpression>()); EXPECT_TRUE(exp.Is<ArrayAccessorExpression>());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid) { TEST_F(ArrayAccessorExpressionTest, IsValid) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
EXPECT_TRUE(exp.IsValid()); EXPECT_TRUE(exp.IsValid());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) { TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) {
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(nullptr, idx); ArrayAccessorExpression exp(nullptr, idx);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) { TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
ArrayAccessorExpression exp(ary, nullptr); ArrayAccessorExpression exp(ary, nullptr);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) { TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) {
auto* ary = create<IdentifierExpression>(""); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) { TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>(""); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
} }
TEST_F(ArrayAccessorExpressionTest, ToStr) { TEST_F(ArrayAccessorExpressionTest, ToStr) {
auto* ary = create<IdentifierExpression>("ary"); auto* ary = create<IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx = create<IdentifierExpression>("idx"); auto* idx = create<IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ArrayAccessorExpression exp(ary, idx); ArrayAccessorExpression exp(ary, idx);
std::ostringstream out; std::ostringstream out;
exp.to_str(out, 2); exp.to_str(out, 2);
EXPECT_EQ(out.str(), R"( ArrayAccessor[not set]{ EXPECT_EQ(demangle(out.str()), R"( ArrayAccessor[not set]{
Identifier[not set]{ary} Identifier[not set]{ary}
Identifier[not set]{idx} Identifier[not set]{idx}
} }

View File

@ -24,8 +24,8 @@ namespace {
using AssignmentStatementTest = TestHelper; using AssignmentStatementTest = TestHelper;
TEST_F(AssignmentStatementTest, Creation) { TEST_F(AssignmentStatementTest, Creation) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_EQ(stmt.lhs(), lhs); EXPECT_EQ(stmt.lhs(), lhs);
@ -33,8 +33,8 @@ TEST_F(AssignmentStatementTest, Creation) {
} }
TEST_F(AssignmentStatementTest, CreationWithSource) { TEST_F(AssignmentStatementTest, CreationWithSource) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs); AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs);
auto src = stmt.source(); auto src = stmt.source();
@ -43,58 +43,58 @@ TEST_F(AssignmentStatementTest, CreationWithSource) {
} }
TEST_F(AssignmentStatementTest, IsAssign) { TEST_F(AssignmentStatementTest, IsAssign) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.Is<AssignmentStatement>()); EXPECT_TRUE(stmt.Is<AssignmentStatement>());
} }
TEST_F(AssignmentStatementTest, IsValid) { TEST_F(AssignmentStatementTest, IsValid) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { TEST_F(AssignmentStatementTest, IsValid_MissingLHS) {
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(nullptr, rhs); AssignmentStatement stmt(nullptr, rhs);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { TEST_F(AssignmentStatementTest, IsValid_MissingRHS) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
AssignmentStatement stmt(lhs, nullptr); AssignmentStatement stmt(lhs, nullptr);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) { TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) {
auto* lhs = create<IdentifierExpression>(""); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) { TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(""); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(AssignmentStatementTest, ToStr) { TEST_F(AssignmentStatementTest, ToStr) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
AssignmentStatement stmt(lhs, rhs); AssignmentStatement stmt(lhs, rhs);
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Assignment{ EXPECT_EQ(demangle(out.str()), R"( Assignment{
Identifier[not set]{lhs} Identifier[not set]{lhs}
Identifier[not set]{rhs} Identifier[not set]{rhs}
} }

View File

@ -26,8 +26,8 @@ namespace {
using BinaryExpressionTest = TestHelper; using BinaryExpressionTest = TestHelper;
TEST_F(BinaryExpressionTest, Creation) { TEST_F(BinaryExpressionTest, Creation) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_EQ(r.lhs(), lhs); EXPECT_EQ(r.lhs(), lhs);
@ -36,8 +36,8 @@ TEST_F(BinaryExpressionTest, Creation) {
} }
TEST_F(BinaryExpressionTest, Creation_WithSource) { TEST_F(BinaryExpressionTest, Creation_WithSource) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs, BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs,
rhs); rhs);
@ -47,67 +47,67 @@ TEST_F(BinaryExpressionTest, Creation_WithSource) {
} }
TEST_F(BinaryExpressionTest, IsBinary) { TEST_F(BinaryExpressionTest, IsBinary) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_TRUE(r.Is<BinaryExpression>()); EXPECT_TRUE(r.Is<BinaryExpression>());
} }
TEST_F(BinaryExpressionTest, IsValid) { TEST_F(BinaryExpressionTest, IsValid) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_TRUE(r.IsValid()); EXPECT_TRUE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, IsValid_Null_LHS) { TEST_F(BinaryExpressionTest, IsValid_Null_LHS) {
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, nullptr, rhs); BinaryExpression r(BinaryOp::kEqual, nullptr, rhs);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) { TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) {
auto* lhs = create<IdentifierExpression>(""); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, IsValid_Null_RHS) { TEST_F(BinaryExpressionTest, IsValid_Null_RHS) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
BinaryExpression r(BinaryOp::kEqual, lhs, nullptr); BinaryExpression r(BinaryOp::kEqual, lhs, nullptr);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) { TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>(""); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, IsValid_Binary_None) { TEST_F(BinaryExpressionTest, IsValid_Binary_None) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kNone, lhs, rhs); BinaryExpression r(BinaryOp::kNone, lhs, rhs);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(BinaryExpressionTest, ToStr) { TEST_F(BinaryExpressionTest, ToStr) {
auto* lhs = create<IdentifierExpression>("lhs"); auto* lhs = create<IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs = create<IdentifierExpression>("rhs"); auto* rhs = create<IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
BinaryExpression r(BinaryOp::kEqual, lhs, rhs); BinaryExpression r(BinaryOp::kEqual, lhs, rhs);
std::ostringstream out; std::ostringstream out;
r.to_str(out, 2); r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Binary[not set]{ EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{
Identifier[not set]{lhs} Identifier[not set]{lhs}
equal equal
Identifier[not set]{rhs} Identifier[not set]{rhs}

View File

@ -26,7 +26,7 @@ using BitcastExpressionTest = TestHelper;
TEST_F(BitcastExpressionTest, Create) { TEST_F(BitcastExpressionTest, Create) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
ASSERT_EQ(exp.type(), &f32); ASSERT_EQ(exp.type(), &f32);
@ -35,7 +35,7 @@ TEST_F(BitcastExpressionTest, Create) {
TEST_F(BitcastExpressionTest, CreateWithSource) { TEST_F(BitcastExpressionTest, CreateWithSource) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr); BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr);
auto src = exp.source(); auto src = exp.source();
@ -45,7 +45,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) {
TEST_F(BitcastExpressionTest, IsBitcast) { TEST_F(BitcastExpressionTest, IsBitcast) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
EXPECT_TRUE(exp.Is<BitcastExpression>()); EXPECT_TRUE(exp.Is<BitcastExpression>());
@ -53,14 +53,14 @@ TEST_F(BitcastExpressionTest, IsBitcast) {
TEST_F(BitcastExpressionTest, IsValid) { TEST_F(BitcastExpressionTest, IsValid) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
EXPECT_TRUE(exp.IsValid()); EXPECT_TRUE(exp.IsValid());
} }
TEST_F(BitcastExpressionTest, IsValid_MissingType) { TEST_F(BitcastExpressionTest, IsValid_MissingType) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(nullptr, expr); BitcastExpression exp(nullptr, expr);
EXPECT_FALSE(exp.IsValid()); EXPECT_FALSE(exp.IsValid());
@ -75,20 +75,20 @@ TEST_F(BitcastExpressionTest, IsValid_MissingExpr) {
TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) { TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>(""); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
BitcastExpression e(&f32, expr); BitcastExpression e(&f32, expr);
EXPECT_FALSE(e.IsValid()); EXPECT_FALSE(e.IsValid());
} }
TEST_F(BitcastExpressionTest, ToStr) { TEST_F(BitcastExpressionTest, ToStr) {
type::F32 f32; type::F32 f32;
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
BitcastExpression exp(&f32, expr); BitcastExpression exp(&f32, expr);
std::ostringstream out; std::ostringstream out;
exp.to_str(out, 2); exp.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Bitcast[not set]<__f32>{ EXPECT_EQ(demangle(out.str()), R"( Bitcast[not set]<__f32>{
Identifier[not set]{expr} Identifier[not set]{expr}
} }
)"); )");

View File

@ -206,13 +206,13 @@ class Builder {
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const std::string& name) { IdentifierExpression* Expr(const std::string& name) {
return create<IdentifierExpression>(name); return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
} }
/// @param name the identifier name /// @param name the identifier name
/// @return an IdentifierExpression with the given name /// @return an IdentifierExpression with the given name
IdentifierExpression* Expr(const char* name) { IdentifierExpression* Expr(const char* name) {
return create<IdentifierExpression>(name); return create<IdentifierExpression>(mod->RegisterSymbol(name), name);
} }
/// @param value the boolean value /// @param value the boolean value

View File

@ -24,10 +24,12 @@ namespace {
using CallExpressionTest = TestHelper; using CallExpressionTest = TestHelper;
TEST_F(CallExpressionTest, Creation) { TEST_F(CallExpressionTest, Creation) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
ExpressionList params; ExpressionList params;
params.push_back(create<IdentifierExpression>("param1")); params.push_back(
params.push_back(create<IdentifierExpression>("param2")); create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params); CallExpression stmt(func, params);
EXPECT_EQ(stmt.func(), func); EXPECT_EQ(stmt.func(), func);
@ -39,7 +41,7 @@ TEST_F(CallExpressionTest, Creation) {
} }
TEST_F(CallExpressionTest, Creation_WithSource) { TEST_F(CallExpressionTest, Creation_WithSource) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(Source{Source::Location{20, 2}}, func, {}); CallExpression stmt(Source{Source::Location{20, 2}}, func, {});
auto src = stmt.source(); auto src = stmt.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
@ -47,13 +49,13 @@ TEST_F(CallExpressionTest, Creation_WithSource) {
} }
TEST_F(CallExpressionTest, IsCall) { TEST_F(CallExpressionTest, IsCall) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {}); CallExpression stmt(func, {});
EXPECT_TRUE(stmt.Is<CallExpression>()); EXPECT_TRUE(stmt.Is<CallExpression>());
} }
TEST_F(CallExpressionTest, IsValid) { TEST_F(CallExpressionTest, IsValid) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {}); CallExpression stmt(func, {});
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
@ -64,40 +66,43 @@ TEST_F(CallExpressionTest, IsValid_MissingFunction) {
} }
TEST_F(CallExpressionTest, IsValid_NullParam) { TEST_F(CallExpressionTest, IsValid_NullParam) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
ExpressionList params; ExpressionList params;
params.push_back(create<IdentifierExpression>("param1")); params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(nullptr); params.push_back(nullptr);
params.push_back(create<IdentifierExpression>("param2")); params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params); CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(CallExpressionTest, IsValid_InvalidFunction) { TEST_F(CallExpressionTest, IsValid_InvalidFunction) {
auto* func = create<IdentifierExpression>(""); auto* func = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
ExpressionList params; ExpressionList params;
params.push_back(create<IdentifierExpression>("param1")); params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
CallExpression stmt(func, params); CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(CallExpressionTest, IsValid_InvalidParam) { TEST_F(CallExpressionTest, IsValid_InvalidParam) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
ExpressionList params; ExpressionList params;
params.push_back(create<IdentifierExpression>("")); params.push_back(create<IdentifierExpression>(mod.RegisterSymbol(""), ""));
CallExpression stmt(func, params); CallExpression stmt(func, params);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(CallExpressionTest, ToStr_NoParams) { TEST_F(CallExpressionTest, ToStr_NoParams) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
CallExpression stmt(func, {}); CallExpression stmt(func, {});
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Call[not set]{ EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func} Identifier[not set]{func}
( (
) )
@ -106,15 +111,17 @@ TEST_F(CallExpressionTest, ToStr_NoParams) {
} }
TEST_F(CallExpressionTest, ToStr_WithParams) { TEST_F(CallExpressionTest, ToStr_WithParams) {
auto* func = create<IdentifierExpression>("func"); auto* func = create<IdentifierExpression>(mod.RegisterSymbol("func"), "func");
ExpressionList params; ExpressionList params;
params.push_back(create<IdentifierExpression>("param1")); params.push_back(
params.push_back(create<IdentifierExpression>("param2")); create<IdentifierExpression>(mod.RegisterSymbol("param1"), "param1"));
params.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("param2"), "param2"));
CallExpression stmt(func, params); CallExpression stmt(func, params);
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Call[not set]{ EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func} Identifier[not set]{func}
( (
Identifier[not set]{param1} Identifier[not set]{param1}

View File

@ -25,7 +25,8 @@ namespace {
using CallStatementTest = TestHelper; using CallStatementTest = TestHelper;
TEST_F(CallStatementTest, Creation) { TEST_F(CallStatementTest, Creation) {
auto* expr = create<CallExpression>(create<IdentifierExpression>("func"), auto* expr = create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{}); ExpressionList{});
CallStatement c(expr); CallStatement c(expr);
@ -38,7 +39,8 @@ TEST_F(CallStatementTest, IsCall) {
} }
TEST_F(CallStatementTest, IsValid) { TEST_F(CallStatementTest, IsValid) {
CallStatement c(create<CallExpression>(create<IdentifierExpression>("func"), CallStatement c(create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{})); ExpressionList{}));
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
} }
@ -55,12 +57,13 @@ TEST_F(CallStatementTest, IsValid_InvalidExpr) {
} }
TEST_F(CallStatementTest, ToStr) { TEST_F(CallStatementTest, ToStr) {
CallStatement c(create<CallExpression>(create<IdentifierExpression>("func"), CallStatement c(create<CallExpression>(
create<IdentifierExpression>(mod.RegisterSymbol("func"), "func"),
ExpressionList{})); ExpressionList{}));
std::ostringstream out; std::ostringstream out;
c.to_str(out, 2); c.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Call[not set]{ EXPECT_EQ(demangle(out.str()), R"( Call[not set]{
Identifier[not set]{func} Identifier[not set]{func}
( (
) )

View File

@ -22,28 +22,30 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::IdentifierExpression);
namespace tint { namespace tint {
namespace ast { namespace ast {
IdentifierExpression::IdentifierExpression(const std::string& name) IdentifierExpression::IdentifierExpression(Symbol sym, const std::string& name)
: Base(), name_(name) {} : Base(), sym_(sym), name_(name) {}
IdentifierExpression::IdentifierExpression(const Source& source, IdentifierExpression::IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name) const std::string& name)
: Base(source), name_(name) {} : Base(source), sym_(sym), name_(name) {}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default; IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
IdentifierExpression::~IdentifierExpression() = default; IdentifierExpression::~IdentifierExpression() = default;
IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const { IdentifierExpression* IdentifierExpression::Clone(CloneContext* ctx) const {
return ctx->mod->create<IdentifierExpression>(ctx->Clone(source()), name_); return ctx->mod->create<IdentifierExpression>(ctx->Clone(source()), sym_,
name_);
} }
bool IdentifierExpression::IsValid() const { bool IdentifierExpression::IsValid() const {
return !name_.empty(); return sym_.IsValid();
} }
void IdentifierExpression::to_str(std::ostream& out, size_t indent) const { void IdentifierExpression::to_str(std::ostream& out, size_t indent) const {
make_indent(out, indent); make_indent(out, indent);
out << "Identifier[" << result_type_str() << "]{" << name_ << "}" out << "Identifier[" << result_type_str() << "]{" << sym_.to_str() << "}"
<< std::endl; << std::endl;
} }

View File

@ -21,6 +21,7 @@
#include "src/ast/expression.h" #include "src/ast/expression.h"
#include "src/ast/intrinsic.h" #include "src/ast/intrinsic.h"
#include "src/symbol.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -29,16 +30,22 @@ namespace ast {
class IdentifierExpression : public Castable<IdentifierExpression, Expression> { class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
public: public:
/// Constructor /// Constructor
/// @param sym the symbol for the identifier
/// @param name the name /// @param name the name
explicit IdentifierExpression(const std::string& name); explicit IdentifierExpression(Symbol sym, const std::string& name);
/// Constructor /// Constructor
/// @param source the source /// @param source the source
/// @param sym the symbol for the identifier
/// @param name the name /// @param name the name
IdentifierExpression(const Source& source, const std::string& name); IdentifierExpression(const Source& source,
Symbol sym,
const std::string& name);
/// Move constructor /// Move constructor
IdentifierExpression(IdentifierExpression&&); IdentifierExpression(IdentifierExpression&&);
~IdentifierExpression() override; ~IdentifierExpression() override;
/// @returns the symbol for the identifier
Symbol symbol() const { return sym_; }
/// @returns the name part of the identifier /// @returns the name part of the identifier
std::string name() const { return name_; } std::string name() const { return name_; }
@ -82,6 +89,7 @@ class IdentifierExpression : public Castable<IdentifierExpression, Expression> {
Intrinsic intrinsic_ = Intrinsic::kNone; Intrinsic intrinsic_ = Intrinsic::kNone;
std::unique_ptr<intrinsic::Signature> intrinsic_sig_; std::unique_ptr<intrinsic::Signature> intrinsic_sig_;
Symbol sym_;
std::string name_; std::string name_;
}; };

View File

@ -23,12 +23,15 @@ namespace {
using IdentifierExpressionTest = TestHelper; using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) { TEST_F(IdentifierExpressionTest, Creation) {
IdentifierExpression i("ident"); IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
EXPECT_EQ(i.symbol(), Symbol(1));
EXPECT_EQ(i.name(), "ident"); EXPECT_EQ(i.name(), "ident");
} }
TEST_F(IdentifierExpressionTest, Creation_WithSource) { TEST_F(IdentifierExpressionTest, Creation_WithSource) {
IdentifierExpression i(Source{Source::Location{20, 2}}, "ident"); IdentifierExpression i(Source{Source::Location{20, 2}},
mod.RegisterSymbol("ident"), "ident");
EXPECT_EQ(i.symbol(), Symbol(1));
EXPECT_EQ(i.name(), "ident"); EXPECT_EQ(i.name(), "ident");
auto src = i.source(); auto src = i.source();
@ -37,25 +40,20 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) {
} }
TEST_F(IdentifierExpressionTest, IsIdentifier) { TEST_F(IdentifierExpressionTest, IsIdentifier) {
IdentifierExpression i("ident"); IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
EXPECT_TRUE(i.Is<IdentifierExpression>()); EXPECT_TRUE(i.Is<IdentifierExpression>());
} }
TEST_F(IdentifierExpressionTest, IsValid) { TEST_F(IdentifierExpressionTest, IsValid) {
IdentifierExpression i("ident"); IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
EXPECT_TRUE(i.IsValid()); EXPECT_TRUE(i.IsValid());
} }
TEST_F(IdentifierExpressionTest, IsValid_BlankName) {
IdentifierExpression i("");
EXPECT_FALSE(i.IsValid());
}
TEST_F(IdentifierExpressionTest, ToStr) { TEST_F(IdentifierExpressionTest, ToStr) {
IdentifierExpression i("ident"); IdentifierExpression i(mod.RegisterSymbol("ident"), "ident");
std::ostringstream out; std::ostringstream out;
i.to_str(out, 2); i.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Identifier[not set]{ident} EXPECT_EQ(demangle(out.str()), R"( Identifier[not set]{ident}
)"); )");
} }

View File

@ -25,7 +25,7 @@ namespace {
using IfStatementTest = TestHelper; using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -43,7 +43,7 @@ TEST_F(IfStatementTest, IsIf) {
} }
TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -52,14 +52,15 @@ TEST_F(IfStatementTest, IsValid) {
} }
TEST_F(IfStatementTest, IsValid_WithElseStatements) { TEST_F(IfStatementTest, IsValid_WithElseStatements) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt( IfStatement stmt(
Source{}, cond, body, Source{}, cond, body,
{ {
create<ElseStatement>(create<IdentifierExpression>("Ident"), create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>()), create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()), create<ElseStatement>(create<BlockStatement>()),
}); });
@ -75,7 +76,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
} }
TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto* cond = create<IdentifierExpression>(""); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -84,7 +85,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
} }
TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
body->append(nullptr); body->append(nullptr);
@ -94,7 +95,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
} }
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(), body->append(create<IfStatement>(Source{}, nullptr, create<BlockStatement>(),
@ -105,14 +106,15 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
} }
TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt( IfStatement stmt(
Source{}, cond, body, Source{}, cond, body,
{ {
create<ElseStatement>(create<IdentifierExpression>("Ident"), create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>()), create<BlockStatement>()),
create<ElseStatement>(create<BlockStatement>()), create<ElseStatement>(create<BlockStatement>()),
nullptr, nullptr,
@ -121,20 +123,21 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
} }
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
IfStatement stmt(Source{}, cond, body, IfStatement stmt(Source{}, cond, body,
{ {
create<ElseStatement>(create<IdentifierExpression>(""), create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol(""), ""),
create<BlockStatement>()), create<BlockStatement>()),
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -147,7 +150,7 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
} }
TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -155,14 +158,15 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
Source{}, cond, body, Source{}, cond, body,
{ {
create<ElseStatement>(create<BlockStatement>()), create<ElseStatement>(create<BlockStatement>()),
create<ElseStatement>(create<IdentifierExpression>("ident"), create<ElseStatement>(create<IdentifierExpression>(
mod.RegisterSymbol("ident"), "ident"),
create<BlockStatement>()), create<BlockStatement>()),
}); });
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -170,7 +174,7 @@ TEST_F(IfStatementTest, ToStr) {
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( If{ EXPECT_EQ(demangle(out.str()), R"( If{
( (
Identifier[not set]{cond} Identifier[not set]{cond}
) )
@ -182,7 +186,7 @@ TEST_F(IfStatementTest, ToStr) {
} }
TEST_F(IfStatementTest, ToStr_WithElseStatements) { TEST_F(IfStatementTest, ToStr_WithElseStatements) {
auto* cond = create<IdentifierExpression>("cond"); auto* cond = create<IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(); auto* body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
@ -193,16 +197,18 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
else_body->append(create<DiscardStatement>()); else_body->append(create<DiscardStatement>());
else_body->append(create<DiscardStatement>()); else_body->append(create<DiscardStatement>());
IfStatement stmt(Source{}, cond, body, IfStatement stmt(
Source{}, cond, body,
{ {
create<ElseStatement>( create<ElseStatement>(create<IdentifierExpression>(
create<IdentifierExpression>("ident"), else_if_body), mod.RegisterSymbol("ident"), "ident"),
else_if_body),
create<ElseStatement>(else_body), create<ElseStatement>(else_body),
}); });
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( If{ EXPECT_EQ(demangle(out.str()), R"( If{
( (
Identifier[not set]{cond} Identifier[not set]{cond}
) )

View File

@ -26,8 +26,10 @@ namespace {
using MemberAccessorExpressionTest = TestHelper; using MemberAccessorExpressionTest = TestHelper;
TEST_F(MemberAccessorExpressionTest, Creation) { TEST_F(MemberAccessorExpressionTest, Creation) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>("member"); "structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
EXPECT_EQ(stmt.structure(), str); EXPECT_EQ(stmt.structure(), str);
@ -35,8 +37,10 @@ TEST_F(MemberAccessorExpressionTest, Creation) {
} }
TEST_F(MemberAccessorExpressionTest, Creation_WithSource) { TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>("member"); "structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, str, mem); MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, str, mem);
auto src = stmt.source(); auto src = stmt.source();
@ -45,59 +49,69 @@ TEST_F(MemberAccessorExpressionTest, Creation_WithSource) {
} }
TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) { TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>("member"); "structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
EXPECT_TRUE(stmt.Is<MemberAccessorExpression>()); EXPECT_TRUE(stmt.Is<MemberAccessorExpression>());
} }
TEST_F(MemberAccessorExpressionTest, IsValid) { TEST_F(MemberAccessorExpressionTest, IsValid) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>("member"); "structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
} }
TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) { TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) {
auto* mem = create<IdentifierExpression>("member"); auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(nullptr, mem); MemberAccessorExpression stmt(nullptr, mem);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) { TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) {
auto* str = create<IdentifierExpression>(""); auto* str = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
auto* mem = create<IdentifierExpression>("member"); auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) { TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
"structure");
MemberAccessorExpression stmt(str, nullptr); MemberAccessorExpression stmt(str, nullptr);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) { TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>(""); "structure");
auto* mem = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
} }
TEST_F(MemberAccessorExpressionTest, ToStr) { TEST_F(MemberAccessorExpressionTest, ToStr) {
auto* str = create<IdentifierExpression>("structure"); auto* str = create<IdentifierExpression>(mod.RegisterSymbol("structure"),
auto* mem = create<IdentifierExpression>("member"); "structure");
auto* mem =
create<IdentifierExpression>(mod.RegisterSymbol("member"), "member");
MemberAccessorExpression stmt(str, mem); MemberAccessorExpression stmt(str, mem);
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( MemberAccessor[not set]{ EXPECT_EQ(demangle(out.str()), R"( MemberAccessor[not set]{
Identifier[not set]{structure} Identifier[not set]{structure}
Identifier[not set]{member} Identifier[not set]{member}
} }

View File

@ -38,6 +38,10 @@ Module Module::Clone() {
} }
void Module::Clone(CloneContext* ctx) { void Module::Clone(CloneContext* ctx) {
// Symbol table must be cloned first so that the resulting module has the
// symbols before we start the tree mutations.
ctx->mod->symbol_table_ = symbol_table_;
for (auto* ty : constructed_types_) { for (auto* ty : constructed_types_) {
ctx->mod->constructed_types_.emplace_back(ctx->Clone(ty)); ctx->mod->constructed_types_.emplace_back(ctx->Clone(ty));
} }
@ -47,8 +51,6 @@ void Module::Clone(CloneContext* ctx) {
for (auto* func : functions_) { for (auto* func : functions_) {
ctx->mod->functions_.emplace_back(ctx->Clone(func)); ctx->mod->functions_.emplace_back(ctx->Clone(func));
} }
ctx->mod->symbol_table_ = symbol_table_;
} }
Function* Module::FindFunctionBySymbol(Symbol sym) const { Function* Module::FindFunctionBySymbol(Symbol sym) const {

View File

@ -26,7 +26,7 @@ namespace {
using ReturnStatementTest = TestHelper; using ReturnStatementTest = TestHelper;
TEST_F(ReturnStatementTest, Creation) { TEST_F(ReturnStatementTest, Creation) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr); ReturnStatement r(Source{}, expr);
EXPECT_EQ(r.value(), expr); EXPECT_EQ(r.value(), expr);
@ -50,7 +50,7 @@ TEST_F(ReturnStatementTest, HasValue_WithoutValue) {
} }
TEST_F(ReturnStatementTest, HasValue_WithValue) { TEST_F(ReturnStatementTest, HasValue_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr); ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.has_value()); EXPECT_TRUE(r.has_value());
} }
@ -61,23 +61,23 @@ TEST_F(ReturnStatementTest, IsValid_WithoutValue) {
} }
TEST_F(ReturnStatementTest, IsValid_WithValue) { TEST_F(ReturnStatementTest, IsValid_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr); ReturnStatement r(Source{}, expr);
EXPECT_TRUE(r.IsValid()); EXPECT_TRUE(r.IsValid());
} }
TEST_F(ReturnStatementTest, IsValid_InvalidValue) { TEST_F(ReturnStatementTest, IsValid_InvalidValue) {
auto* expr = create<IdentifierExpression>(""); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
ReturnStatement r(Source{}, expr); ReturnStatement r(Source{}, expr);
EXPECT_FALSE(r.IsValid()); EXPECT_FALSE(r.IsValid());
} }
TEST_F(ReturnStatementTest, ToStr_WithValue) { TEST_F(ReturnStatementTest, ToStr_WithValue) {
auto* expr = create<IdentifierExpression>("expr"); auto* expr = create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ReturnStatement r(Source{}, expr); ReturnStatement r(Source{}, expr);
std::ostringstream out; std::ostringstream out;
r.to_str(out, 2); r.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Return{ EXPECT_EQ(demangle(out.str()), R"( Return{
{ {
Identifier[not set]{expr} Identifier[not set]{expr}
} }

View File

@ -34,7 +34,8 @@ TEST_F(SwitchStatementTest, Creation) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 1)); lit.push_back(create<SintLiteral>(&i32, 1));
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>()); auto* case_stmt = create<CaseStatement>(lit, create<BlockStatement>());
body.push_back(case_stmt); body.push_back(case_stmt);
@ -46,7 +47,8 @@ TEST_F(SwitchStatementTest, Creation) {
} }
TEST_F(SwitchStatementTest, Creation_WithSource) { TEST_F(SwitchStatementTest, Creation_WithSource) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
SwitchStatement stmt(Source{Source::Location{20, 2}}, ident, SwitchStatement stmt(Source{Source::Location{20, 2}}, ident,
CaseStatementList()); CaseStatementList());
@ -61,7 +63,8 @@ TEST_F(SwitchStatementTest, IsSwitch) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -75,7 +78,8 @@ TEST_F(SwitchStatementTest, IsValid) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -102,7 +106,7 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>(""); auto* ident = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
@ -116,7 +120,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
body.push_back(nullptr); body.push_back(nullptr);
@ -126,7 +131,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
} }
TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
auto* case_body = create<BlockStatement>(); auto* case_body = create<BlockStatement>();
case_body->append(nullptr); case_body->append(nullptr);
@ -139,12 +145,13 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
} }
TEST_F(SwitchStatementTest, ToStr_Empty) { TEST_F(SwitchStatementTest, ToStr_Empty) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
SwitchStatement stmt(ident, {}); SwitchStatement stmt(ident, {});
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Switch{ EXPECT_EQ(demangle(out.str()), R"( Switch{
Identifier[not set]{ident} Identifier[not set]{ident}
{ {
} }
@ -158,14 +165,15 @@ TEST_F(SwitchStatementTest, ToStr) {
CaseSelectorList lit; CaseSelectorList lit;
lit.push_back(create<SintLiteral>(&i32, 2)); lit.push_back(create<SintLiteral>(&i32, 2));
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
CaseStatementList body; CaseStatementList body;
body.push_back(create<CaseStatement>(lit, create<BlockStatement>())); body.push_back(create<CaseStatement>(lit, create<BlockStatement>()));
SwitchStatement stmt(ident, body); SwitchStatement stmt(ident, body);
std::ostringstream out; std::ostringstream out;
stmt.to_str(out, 2); stmt.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Switch{ EXPECT_EQ(demangle(out.str()), R"( Switch{
Identifier[not set]{ident} Identifier[not set]{ident}
{ {
Case 2{ Case 2{

View File

@ -32,7 +32,8 @@ using TypeConstructorExpressionTest = TestHelper;
TEST_F(TypeConstructorExpressionTest, Creation) { TEST_F(TypeConstructorExpressionTest, Creation) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
EXPECT_EQ(t.type(), &f32); EXPECT_EQ(t.type(), &f32);
@ -43,7 +44,8 @@ TEST_F(TypeConstructorExpressionTest, Creation) {
TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, expr); TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, expr);
auto src = t.source(); auto src = t.source();
@ -54,7 +56,8 @@ TEST_F(TypeConstructorExpressionTest, Creation_WithSource) {
TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
EXPECT_TRUE(t.Is<TypeConstructorExpression>()); EXPECT_TRUE(t.Is<TypeConstructorExpression>());
@ -63,7 +66,8 @@ TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) {
TEST_F(TypeConstructorExpressionTest, IsValid) { TEST_F(TypeConstructorExpressionTest, IsValid) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
EXPECT_TRUE(t.IsValid()); EXPECT_TRUE(t.IsValid());
@ -79,7 +83,8 @@ TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) {
TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
TypeConstructorExpression t(nullptr, expr); TypeConstructorExpression t(nullptr, expr);
EXPECT_FALSE(t.IsValid()); EXPECT_FALSE(t.IsValid());
@ -88,7 +93,8 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) {
TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"));
expr.push_back(nullptr); expr.push_back(nullptr);
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
@ -98,7 +104,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) {
TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) {
type::F32 f32; type::F32 f32;
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("")); expr.push_back(create<IdentifierExpression>(mod.RegisterSymbol(""), ""));
TypeConstructorExpression t(&f32, expr); TypeConstructorExpression t(&f32, expr);
EXPECT_FALSE(t.IsValid()); EXPECT_FALSE(t.IsValid());
@ -108,14 +114,17 @@ TEST_F(TypeConstructorExpressionTest, ToStr) {
type::F32 f32; type::F32 f32;
type::Vector vec(&f32, 3); type::Vector vec(&f32, 3);
ExpressionList expr; ExpressionList expr;
expr.push_back(create<IdentifierExpression>("expr_1")); expr.push_back(
expr.push_back(create<IdentifierExpression>("expr_2")); create<IdentifierExpression>(mod.RegisterSymbol("expr_1"), "expr_1"));
expr.push_back(create<IdentifierExpression>("expr_3")); expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr_2"), "expr_2"));
expr.push_back(
create<IdentifierExpression>(mod.RegisterSymbol("expr_3"), "expr_3"));
TypeConstructorExpression t(&vec, expr); TypeConstructorExpression t(&vec, expr);
std::ostringstream out; std::ostringstream out;
t.to_str(out, 2); t.to_str(out, 2);
EXPECT_EQ(out.str(), R"( TypeConstructor[not set]{ EXPECT_EQ(demangle(out.str()), R"( TypeConstructor[not set]{
__vec_3__f32 __vec_3__f32
Identifier[not set]{expr_1} Identifier[not set]{expr_1}
Identifier[not set]{expr_2} Identifier[not set]{expr_2}

View File

@ -26,7 +26,8 @@ namespace {
using UnaryOpExpressionTest = TestHelper; using UnaryOpExpressionTest = TestHelper;
TEST_F(UnaryOpExpressionTest, Creation) { TEST_F(UnaryOpExpressionTest, Creation) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident); UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_EQ(u.op(), UnaryOp::kNot); EXPECT_EQ(u.op(), UnaryOp::kNot);
@ -34,7 +35,8 @@ TEST_F(UnaryOpExpressionTest, Creation) {
} }
TEST_F(UnaryOpExpressionTest, Creation_WithSource) { TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident); UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident);
auto src = u.source(); auto src = u.source();
EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.line, 20u);
@ -42,13 +44,15 @@ TEST_F(UnaryOpExpressionTest, Creation_WithSource) {
} }
TEST_F(UnaryOpExpressionTest, IsUnaryOp) { TEST_F(UnaryOpExpressionTest, IsUnaryOp) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident); UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_TRUE(u.Is<UnaryOpExpression>()); EXPECT_TRUE(u.Is<UnaryOpExpression>());
} }
TEST_F(UnaryOpExpressionTest, IsValid) { TEST_F(UnaryOpExpressionTest, IsValid) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident); UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_TRUE(u.IsValid()); EXPECT_TRUE(u.IsValid());
} }
@ -59,17 +63,18 @@ TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) {
} }
TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) { TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) {
auto* ident = create<IdentifierExpression>(""); auto* ident = create<IdentifierExpression>(mod.RegisterSymbol(""), "");
UnaryOpExpression u(UnaryOp::kNot, ident); UnaryOpExpression u(UnaryOp::kNot, ident);
EXPECT_FALSE(u.IsValid()); EXPECT_FALSE(u.IsValid());
} }
TEST_F(UnaryOpExpressionTest, ToStr) { TEST_F(UnaryOpExpressionTest, ToStr) {
auto* ident = create<IdentifierExpression>("ident"); auto* ident =
create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident");
UnaryOpExpression u(UnaryOp::kNot, ident); UnaryOpExpression u(UnaryOp::kNot, ident);
std::ostringstream out; std::ostringstream out;
u.to_str(out, 2); u.to_str(out, 2);
EXPECT_EQ(out.str(), R"( UnaryOp[not set]{ EXPECT_EQ(demangle(out.str()), R"( UnaryOp[not set]{
not not
Identifier[not set]{ident} Identifier[not set]{ident}
} }

View File

@ -84,7 +84,7 @@ TEST_F(VariableTest, IsValid_WithConstructor) {
StorageClass::kNone, StorageClass::kNone,
&t, &t,
false, false,
create<IdentifierExpression>("ident"), create<IdentifierExpression>(mod.RegisterSymbol("ident"), "ident"),
ast::VariableDecorationList{}}; ast::VariableDecorationList{}};
EXPECT_TRUE(v.IsValid()); EXPECT_TRUE(v.IsValid());
} }
@ -115,7 +115,7 @@ TEST_F(VariableTest, IsValid_InvalidConstructor) {
StorageClass::kNone, StorageClass::kNone,
&t, &t,
false, false,
create<IdentifierExpression>(""), create<IdentifierExpression>(mod.RegisterSymbol(""), ""),
ast::VariableDecorationList{}}; ast::VariableDecorationList{}};
EXPECT_FALSE(v.IsValid()); EXPECT_FALSE(v.IsValid());
} }
@ -162,8 +162,9 @@ TEST_F(VariableTest, ConstantId) {
TEST_F(VariableTest, Decorated_to_str) { TEST_F(VariableTest, Decorated_to_str) {
type::F32 t; type::F32 t;
auto* var = create<Variable>(Source{}, "my_var", StorageClass::kFunction, &t, auto* var = create<Variable>(
false, create<IdentifierExpression>("expr"), Source{}, "my_var", StorageClass::kFunction, &t, false,
create<IdentifierExpression>(mod.RegisterSymbol("expr"), "expr"),
VariableDecorationList{ VariableDecorationList{
create<BindingDecoration>(2, Source{}), create<BindingDecoration>(2, Source{}),
create<SetDecoration>(1, Source{}), create<SetDecoration>(1, Source{}),
@ -171,7 +172,7 @@ TEST_F(VariableTest, Decorated_to_str) {
std::ostringstream out; std::ostringstream out;
var->to_str(out, 2); var->to_str(out, 2);
EXPECT_EQ(out.str(), R"( Variable{ EXPECT_EQ(demangle(out.str()), R"( Variable{
Decorations{ Decorations{
BindingDecoration{2} BindingDecoration{2}
SetDecoration{1} SetDecoration{1}

View File

@ -98,7 +98,8 @@ class InspectorHelper {
std::string callee, std::string callee,
ast::FunctionDecorationList decorations = {}) { ast::FunctionDecorationList decorations = {}) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
auto* ident_expr = create<ast::IdentifierExpression>(callee); auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
@ -152,8 +153,8 @@ class InspectorHelper {
std::string in, out; std::string in, out;
std::tie(in, out) = inout; std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(out), create<ast::IdentifierExpression>(mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(in))); create<ast::IdentifierExpression>(mod()->RegisterSymbol(in), in)));
} }
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name, return create<ast::Function>(Source{}, mod()->RegisterSymbol(name), name,
@ -179,10 +180,11 @@ class InspectorHelper {
std::string in, out; std::string in, out;
std::tie(in, out) = inout; std::tie(in, out) = inout;
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(out), create<ast::IdentifierExpression>(mod()->RegisterSymbol(out), out),
create<ast::IdentifierExpression>(in))); create<ast::IdentifierExpression>(mod()->RegisterSymbol(in), in)));
} }
auto* ident_expr = create<ast::IdentifierExpression>(callee); auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
@ -442,10 +444,14 @@ class InspectorHelper {
std::tie(member_idx, member_type) = member; std::tie(member_idx, member_type) = member;
std::string member_name = StructMemberName(member_idx, member_type); std::string member_name = StructMemberName(member_idx, member_type);
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("local" + member_name), create<ast::IdentifierExpression>(
mod()->RegisterSymbol("local" + member_name),
"local" + member_name),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>(struct_name), create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(member_name)))); mod()->RegisterSymbol(struct_name), struct_name),
create<ast::IdentifierExpression>(
mod()->RegisterSymbol(member_name), member_name))));
} }
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -581,14 +587,21 @@ class InspectorHelper {
body->append(create<ast::VariableDeclStatement>(call_result)); body->append(create<ast::VariableDeclStatement>(call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(texture_name)); call_params.push_back(create<ast::IdentifierExpression>(
call_params.push_back(create<ast::IdentifierExpression>(sampler_name)); mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(coords_name)); call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
auto* call_expr = create<ast::CallExpression>( auto* call_expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("textureSample"), call_params); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params);
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
@ -628,15 +641,23 @@ class InspectorHelper {
body->append(create<ast::VariableDeclStatement>(call_result)); body->append(create<ast::VariableDeclStatement>(call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(texture_name)); call_params.push_back(create<ast::IdentifierExpression>(
call_params.push_back(create<ast::IdentifierExpression>(sampler_name)); mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(coords_name)); call_params.push_back(create<ast::IdentifierExpression>(
call_params.push_back(create<ast::IdentifierExpression>(array_index)); mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(array_index), array_index));
auto* call_expr = create<ast::CallExpression>( auto* call_expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("textureSample"), call_params); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSample"), "textureSample"),
call_params);
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
@ -677,15 +698,24 @@ class InspectorHelper {
body->append(create<ast::VariableDeclStatement>(call_result)); body->append(create<ast::VariableDeclStatement>(call_result));
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(create<ast::IdentifierExpression>(texture_name)); call_params.push_back(create<ast::IdentifierExpression>(
call_params.push_back(create<ast::IdentifierExpression>(sampler_name)); mod()->RegisterSymbol(texture_name), texture_name));
call_params.push_back(create<ast::IdentifierExpression>(coords_name)); call_params.push_back(create<ast::IdentifierExpression>(
call_params.push_back(create<ast::IdentifierExpression>(depth_name)); mod()->RegisterSymbol(sampler_name), sampler_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(coords_name), coords_name));
call_params.push_back(create<ast::IdentifierExpression>(
mod()->RegisterSymbol(depth_name), depth_name));
auto* call_expr = create<ast::CallExpression>( auto* call_expr = create<ast::CallExpression>(
create<ast::IdentifierExpression>("textureSampleCompare"), call_params); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("textureSampleCompare"),
"textureSampleCompare"),
call_params);
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("sampler_result"), call_expr)); create<ast::IdentifierExpression>(
mod()->RegisterSymbol("sampler_result"), "sampler_result"),
call_expr));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name), return create<ast::Function>(Source{}, mod()->RegisterSymbol(func_name),
@ -1507,7 +1537,8 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) {
AddReferenceFunc("ub_baz_func", "ub_baz"); AddReferenceFunc("ub_baz_func", "ub_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee); auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
@ -1654,7 +1685,8 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) {
AddReferenceFunc("sb_baz_func", "sb_baz"); AddReferenceFunc("sb_baz_func", "sb_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee); auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));
@ -1828,7 +1860,8 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest,
AddReferenceFunc("sb_baz_func", "sb_baz"); AddReferenceFunc("sb_baz_func", "sb_baz");
auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) {
auto* ident_expr = create<ast::IdentifierExpression>(callee); auto* ident_expr = create<ast::IdentifierExpression>(
mod()->RegisterSymbol(callee), callee);
auto* call_expr = auto* call_expr =
create<ast::CallExpression>(ident_expr, ast::ExpressionList()); create<ast::CallExpression>(ident_expr, ast::ExpressionList());
body->append(create<ast::CallStatement>(call_expr)); body->append(create<ast::CallStatement>(call_expr));

View File

@ -689,7 +689,8 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
// as the statement block at the top of the stack. // as the statement block at the top of the stack.
const auto& top = statements_stack_.back(); const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>(guard_name); auto* cond = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(guard_name), guard_name);
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
AddStatement( AddStatement(
create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{})); create<ast::IfStatement>(Source{}, cond, body, ast::ElseStatementList{}));
@ -1891,9 +1892,11 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
return {}; return {};
} }
if (identifier_values_.count(id) || parser_impl_.IsScalarSpecConstant(id)) { if (identifier_values_.count(id) || parser_impl_.IsScalarSpecConstant(id)) {
auto name = namer_.Name(id);
return TypedExpression{ return TypedExpression{
parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()), parser_impl_.ConvertType(def_use_mgr_->GetDef(id)->type_id()),
create<ast::IdentifierExpression>(namer_.Name(id))}; create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name),
name)};
} }
if (singly_used_values_.count(id)) { if (singly_used_values_.count(id)) {
auto expr = std::move(singly_used_values_[id]); auto expr = std::move(singly_used_values_[id]);
@ -1910,11 +1913,13 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) {
return {}; return {};
} }
switch (inst->opcode()) { switch (inst->opcode()) {
case SpvOpVariable: case SpvOpVariable: {
// This occurs for module-scope variables. // This occurs for module-scope variables.
return TypedExpression{ auto name = namer_.Name(inst->result_id());
parser_impl_.ConvertType(inst->type_id()), return TypedExpression{parser_impl_.ConvertType(inst->type_id()),
create<ast::IdentifierExpression>(namer_.Name(inst->result_id()))}; create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name)};
}
default: default:
break; break;
} }
@ -2579,7 +2584,9 @@ ast::Statement* FunctionEmitter::MakeBranchDetailed(
} }
// Signal an exit from the branch. // Signal an exit from the branch.
return create<ast::AssignmentStatement>( return create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(flow_guard), MakeFalse()); create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(flow_guard), flow_guard),
MakeFalse());
} }
// For an unconditional branch, the break out to an if-selection // For an unconditional branch, the break out to an if-selection
@ -2733,7 +2740,9 @@ bool FunctionEmitter::EmitStatementsInBasicBlock(const BlockInfo& block_info,
const auto var_name = GetDefInfo(assignment.phi_id)->phi_var; const auto var_name = GetDefInfo(assignment.phi_id)->phi_var;
auto expr = MakeExpression(assignment.value); auto expr = MakeExpression(assignment.value);
AddStatement(create<ast::AssignmentStatement>( AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(var_name), expr.expr)); create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(var_name), var_name),
expr.expr));
} }
} }
@ -2766,10 +2775,11 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
const auto result_id = inst.result_id(); const auto result_id = inst.result_id();
const auto* def_info = GetDefInfo(result_id); const auto* def_info = GetDefInfo(result_id);
if (def_info && def_info->requires_hoisted_def) { if (def_info && def_info->requires_hoisted_def) {
auto name = namer_.Name(result_id);
// Emit an assignment of the expression to the hoisted variable. // Emit an assignment of the expression to the hoisted variable.
AddStatementForInstruction( AddStatementForInstruction(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>( create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(namer_.Name(result_id)), ast_module_.RegisterSymbol(name), name),
ast_expr.expr), ast_expr.expr),
inst); inst);
return true; return true;
@ -2861,9 +2871,10 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
} }
case SpvOpPhi: { case SpvOpPhi: {
// Emit a read from the associated state variable. // Emit a read from the associated state variable.
TypedExpression expr{ TypedExpression expr{parser_impl_.ConvertType(inst.type_id()),
parser_impl_.ConvertType(inst.type_id()), create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(def_info->phi_var)}; ast_module_.RegisterSymbol(def_info->phi_var),
def_info->phi_var)};
return EmitConstDefOrWriteToHoistedVar(inst, expr); return EmitConstDefOrWriteToHoistedVar(inst, expr);
} }
case SpvOpFunctionCall: case SpvOpFunctionCall:
@ -2916,7 +2927,9 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue(
ast::ExpressionList params; ast::ExpressionList params;
params.emplace_back(MakeOperand(inst, 0).expr); params.emplace_back(MakeOperand(inst, 0).expr);
return {ast_type, create<ast::CallExpression>( return {ast_type, create<ast::CallExpression>(
create<ast::IdentifierExpression>(unary_builtin_name), create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(unary_builtin_name),
unary_builtin_name),
std::move(params))}; std::move(params))};
} }
@ -3017,7 +3030,8 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(
return {}; return {};
} }
auto* func = create<ast::IdentifierExpression>(name); auto* func =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
ast::ExpressionList operands; ast::ExpressionList operands;
ast::type::Type* first_operand_type = nullptr; ast::type::Type* first_operand_type = nullptr;
// All parameters to GLSL.std.450 extended instructions are IDs. // All parameters to GLSL.std.450 extended instructions are IDs.
@ -3042,17 +3056,21 @@ ast::IdentifierExpression* FunctionEmitter::Swizzle(uint32_t i) {
return nullptr; return nullptr;
} }
const char* names[] = {"x", "y", "z", "w"}; const char* names[] = {"x", "y", "z", "w"};
return create<ast::IdentifierExpression>(names[i & 3]); return create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(names[i & 3]), names[i & 3]);
} }
ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) { ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) {
switch (n) { switch (n) {
case 1: case 1:
return create<ast::IdentifierExpression>("x"); return create<ast::IdentifierExpression>(ast_module_.RegisterSymbol("x"),
"x");
case 2: case 2:
return create<ast::IdentifierExpression>("xy"); return create<ast::IdentifierExpression>(ast_module_.RegisterSymbol("xy"),
"xy");
case 3: case 3:
return create<ast::IdentifierExpression>("xyz"); return create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol("xyz"), "xyz");
default: default:
break; break;
} }
@ -3121,8 +3139,10 @@ TypedExpression FunctionEmitter::MakeAccessChain(
first_index = first_index + 1; first_index = first_index + 1;
// Replace the gl_PerVertex reference with the gl_Position reference // Replace the gl_PerVertex reference with the gl_Position reference
ptr_ty_id = builtin_position_info.member_pointer_type_id; ptr_ty_id = builtin_position_info.member_pointer_type_id;
current_expr.expr =
create<ast::IdentifierExpression>(namer_.Name(base_id)); auto name = namer_.Name(base_id);
current_expr.expr = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name);
current_expr.type = parser_impl_.ConvertType(ptr_ty_id); current_expr.type = parser_impl_.ConvertType(ptr_ty_id);
} }
} }
@ -3212,8 +3232,10 @@ TypedExpression FunctionEmitter::MakeAccessChain(
<< pointee_type_id << " having " << num_members << " members"; << pointee_type_id << " having " << num_members << " members";
return {}; return {};
} }
auto name =
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(pointee_type_id, uint32_t(index_const_val))); ast_module_.RegisterSymbol(name), name);
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr, next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access); member_access);
@ -3331,8 +3353,9 @@ TypedExpression FunctionEmitter::MakeCompositeExtract(
<< current_type_id << " having " << num_members << " members"; << current_type_id << " having " << num_members << " members";
return {}; return {};
} }
auto name = namer_.GetMemberName(current_type_id, uint32_t(index_val));
auto* member_access = create<ast::IdentifierExpression>( auto* member_access = create<ast::IdentifierExpression>(
namer_.GetMemberName(current_type_id, uint32_t(index_val))); ast_module_.RegisterSymbol(name), name);
next_expr = create<ast::MemberAccessorExpression>(current_expr.expr, next_expr = create<ast::MemberAccessorExpression>(current_expr.expr,
member_access); member_access);
@ -3712,8 +3735,9 @@ TypedExpression FunctionEmitter::MakeNumericConversion(
bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) { bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
// We ignore function attributes such as Inline, DontInline, Pure, Const. // We ignore function attributes such as Inline, DontInline, Pure, Const.
auto* function = create<ast::IdentifierExpression>( auto name = namer_.Name(inst.GetSingleWordInOperand(0));
namer_.Name(inst.GetSingleWordInOperand(0))); auto* function =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
ast::ExpressionList params; ast::ExpressionList params;
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) { for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
@ -3739,7 +3763,9 @@ TypedExpression FunctionEmitter::MakeIntrinsicCall(
const auto intrinsic = GetIntrinsic(inst.opcode()); const auto intrinsic = GetIntrinsic(inst.opcode());
std::ostringstream ss; std::ostringstream ss;
ss << intrinsic; ss << intrinsic;
auto* ident = create<ast::IdentifierExpression>(ss.str()); auto name = ss.str();
auto* ident =
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name), name);
ident->set_intrinsic(intrinsic); ident->set_intrinsic(intrinsic);
ast::ExpressionList params; ast::ExpressionList params;
@ -3781,8 +3807,10 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
params.push_back(operand2.expr); params.push_back(operand2.expr);
// The condition goes last. // The condition goes last.
params.push_back(condition.expr); params.push_back(condition.expr);
return {operand1.type, create<ast::CallExpression>( return {operand1.type,
create<ast::IdentifierExpression>("select"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol("select"), "select"),
std::move(params))}; std::move(params))};
} }
return {}; return {};
@ -3813,8 +3841,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
return Fail() << "internal error: couldn't find image for " return Fail() << "internal error: couldn't find image for "
<< inst.PrettyPrint(); << inst.PrettyPrint();
} }
params.push_back( auto name = namer_.Name(image->result_id());
create<ast::IdentifierExpression>(namer_.Name(image->result_id()))); params.push_back(create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name));
if (IsSampledImageAccess(inst.opcode())) { if (IsSampledImageAccess(inst.opcode())) {
// Form the sampler operand. // Form the sampler operand.
@ -3824,8 +3853,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
return Fail() << "internal error: couldn't find sampler for " return Fail() << "internal error: couldn't find sampler for "
<< inst.PrettyPrint(); << inst.PrettyPrint();
} }
params.push_back( auto param_name = namer_.Name(sampler->result_id());
create<ast::IdentifierExpression>(namer_.Name(sampler->result_id()))); params.push_back(create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(param_name), param_name));
} }
ast::type::Pointer* texture_ptr_type = ast::type::Pointer* texture_ptr_type =
@ -3964,7 +3994,8 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
<< "): " << inst.PrettyPrint(); << "): " << inst.PrettyPrint();
} }
auto* ident = create<ast::IdentifierExpression>(builtin_name); auto* ident = create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(builtin_name), builtin_name);
auto* call_expr = create<ast::CallExpression>(ident, std::move(params)); auto* call_expr = create<ast::CallExpression>(ident, std::move(params));
if (inst.type_id() != 0) { if (inst.type_id() != 0) {

View File

@ -135,7 +135,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -147,7 +147,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Int) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) { TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
@ -162,7 +162,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -176,7 +176,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Int_Uint) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) { TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
@ -191,7 +191,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -205,7 +205,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Int) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) { TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
@ -220,7 +220,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -236,7 +236,7 @@ TEST_F(SpvUnaryArithTest, SNegate_Uint_Uint) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) { TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
@ -251,7 +251,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -267,7 +267,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_SignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) { TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
@ -282,7 +282,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -300,7 +300,7 @@ TEST_F(SpvUnaryArithTest, SNegate_SignedVec_UnsignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) { TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
@ -315,7 +315,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -333,7 +333,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_SignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) { TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
@ -348,7 +348,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -368,7 +368,7 @@ TEST_F(SpvUnaryArithTest, SNegate_UnsignedVec_UnsignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, FNegate_Scalar) { TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
@ -383,7 +383,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -395,7 +395,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryArithTest, FNegate_Vector) { TEST_F(SpvUnaryArithTest, FNegate_Vector) {
@ -410,7 +410,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -426,7 +426,7 @@ TEST_F(SpvUnaryArithTest, FNegate_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
struct BinaryData { struct BinaryData {
@ -474,7 +474,8 @@ TEST_P(SpvBinaryArithTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{" << GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs; << "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(ss.str())) << assembly; EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str()))
<< assembly;
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -696,7 +697,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Scalar_UnsignedResult) {
<< assembly; << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -731,7 +732,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) {
<< assembly; << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -754,7 +755,7 @@ TEST_F(SpvBinaryArithTestBasic, SDiv_Vector_UnsignedResult) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -842,7 +843,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Scalar_UnsignedResult) {
<< assembly; << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -877,7 +878,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) {
<< assembly; << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -900,7 +901,7 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -930,7 +931,8 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__vec_2__f32 __vec_2__f32
@ -942,7 +944,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) { TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
@ -959,7 +961,8 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__mat_2_2__f32 __mat_2_2__f32
@ -971,7 +974,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesScalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) { TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
@ -988,7 +991,8 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__mat_2_2__f32 __mat_2_2__f32
@ -1000,7 +1004,7 @@ TEST_F(SpvBinaryArithTestBasic, VectorTimesMatrix) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) { TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
@ -1017,7 +1021,8 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__mat_2_2__f32 __mat_2_2__f32
@ -1029,7 +1034,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesVector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) { TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
@ -1046,7 +1051,8 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__mat_2_2__f32 __mat_2_2__f32
@ -1058,7 +1064,7 @@ TEST_F(SpvBinaryArithTestBasic, MatrixTimesMatrix) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, Dot) { TEST_F(SpvBinaryArithTestBasic, Dot) {
@ -1075,7 +1081,8 @@ TEST_F(SpvBinaryArithTestBasic, Dot) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_3 x_3
none none
__f32 __f32
@ -1089,7 +1096,7 @@ TEST_F(SpvBinaryArithTestBasic, Dot) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvBinaryArithTestBasic, OuterProduct) { TEST_F(SpvBinaryArithTestBasic, OuterProduct) {
@ -1106,7 +1113,8 @@ TEST_F(SpvBinaryArithTestBasic, OuterProduct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_3 x_3
none none
__mat_2_2__f32 __mat_2_2__f32
@ -1120,7 +1128,7 @@ TEST_F(SpvBinaryArithTestBasic, OuterProduct) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
// TODO(dneto): OpSRem. Missing from WGSL // TODO(dneto): OpSRem. Missing from WGSL

View File

@ -163,7 +163,8 @@ TEST_P(SpvBinaryBitTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{" << GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs; << "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(ss.str())) << assembly; EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str()))
<< assembly;
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -400,7 +401,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -412,7 +413,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Int) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_Int_Uint) { TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
@ -427,7 +428,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -441,7 +442,7 @@ TEST_F(SpvUnaryBitTest, Not_Int_Uint) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_Uint_Int) { TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
@ -456,7 +457,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -470,7 +471,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Int) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_Uint_Uint) { TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
@ -485,7 +486,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -497,7 +498,7 @@ TEST_F(SpvUnaryBitTest, Not_Uint_Uint) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) { TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
@ -512,7 +513,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -528,7 +529,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_SignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) { TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
@ -543,7 +544,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -561,7 +562,7 @@ TEST_F(SpvUnaryBitTest, Not_SignedVec_UnsignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) { TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
@ -576,7 +577,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -594,7 +595,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_SignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) { TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
const auto assembly = CommonTypes() + R"( const auto assembly = CommonTypes() + R"(
@ -608,7 +609,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -624,7 +625,7 @@ TEST_F(SpvUnaryBitTest, Not_UnsignedVec_UnsignedVec) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
std::string BitTestPreamble() { std::string BitTestPreamble() {
@ -663,7 +664,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -691,7 +692,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -721,7 +722,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -751,7 +752,7 @@ TEST_F(SpvUnaryBitTest, BitCount_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -779,7 +780,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -807,7 +808,7 @@ TEST_F(SpvUnaryBitTest, BitCount_UintVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -837,7 +838,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -867,7 +868,7 @@ TEST_F(SpvUnaryBitTest, BitCount_IntVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -895,7 +896,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -923,7 +924,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Uint_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -953,7 +954,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Uint) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -983,7 +984,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_Int_Int) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1011,7 +1012,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1039,7 +1040,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_UintVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1069,7 +1070,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_UintVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1099,7 +1100,7 @@ TEST_F(SpvUnaryBitTest, BitReverse_IntVector_IntVector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
const auto body = ToString(fe.ast_body()); const auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1

View File

@ -48,18 +48,16 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
const auto module_ast_str = p->get_module().to_str(); const auto module_ast_str = p->get_module().to_str();
EXPECT_THAT(module_ast_str, Eq(R"(Module{ EXPECT_THAT(module_ast_str, Eq(R"(Module{
Function )" + p->get_module().GetSymbol("x_50").to_str() + Function tint_symbol_1 -> __void
R"( -> __void
() ()
{ {
Return{} Return{}
} }
Function )" + p->get_module().GetSymbol("x_100").to_str() + Function tint_symbol_2 -> __void
R"( -> __void
() ()
{ {
Call[not set]{ Call[not set]{
Identifier[not set]{x_50} Identifier[not set]{tint_symbol_1}
( (
) )
} }
@ -92,7 +90,8 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
{ {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -107,17 +106,17 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
} }
} }
Return{})")) Return{})"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
{ {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Return{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Return{
{ {
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
} }
@ -148,7 +147,8 @@ TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParamsUsedTwice) {
{ {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_10 x_10
function function
@ -178,16 +178,16 @@ Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
} }
Return{})")) Return{})"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
{ {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 50));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Return{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Return{
{ {
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
} }
@ -218,8 +218,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_ast_str = p->get_module().to_str(); const auto module_ast_str = p->get_module().to_str();
EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{ EXPECT_THAT(module_ast_str, HasSubstr(R"(Module{
Function )" + p->get_module().GetSymbol("x_50").to_str() + Function tint_symbol_3 -> __u32
R"( -> __u32
( (
VariableConst{ VariableConst{
x_51 x_51
@ -236,9 +235,9 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
Return{ Return{
{ {
Binary[not set]{ Binary[not set]{
Identifier[not set]{x_51} Identifier[not set]{tint_symbol_1}
add add
Identifier[not set]{x_52} Identifier[not set]{tint_symbol_2}
} }
} }
} }
@ -254,7 +253,7 @@ TEST_F(SpvParserTest, EmitStatement_CallWithParams) {
__u32 __u32
{ {
Call[not set]{ Call[not set]{
Identifier[not set]{x_50} Identifier[not set]{tint_symbol_3}
( (
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
ScalarConstructor[not set]{84} ScalarConstructor[not set]{84}

View File

@ -7361,7 +7361,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromThen_ForwardWithinThen) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -7473,7 +7473,7 @@ TEST_F(SpvParserTest, EmitBody_IfBreak_FromElse_ForwardWithinElse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -7600,7 +7600,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly; EXPECT_TRUE(fe.EmitBody()) << p->error() << assembly;
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -7791,7 +7791,7 @@ TEST_F(SpvParserTest, EmitBody_If_Empty) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -7827,7 +7827,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_NoElse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -7875,7 +7875,7 @@ TEST_F(SpvParserTest, EmitBody_If_NoThen_Else) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -7931,7 +7931,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -7998,7 +7998,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Else_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8070,7 +8070,7 @@ TEST_F(SpvParserTest, EmitBody_If_Then_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8134,7 +8134,7 @@ TEST_F(SpvParserTest, EmitBody_If_Else_Premerge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8219,7 +8219,7 @@ TEST_F(SpvParserTest, EmitBody_If_Nest_If) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8309,7 +8309,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_TrueBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8364,7 +8364,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_FalseBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8415,7 +8415,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_BothBackedge) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8458,7 +8458,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_SingleBlock_UnconditionalBackege) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8509,7 +8509,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_SingleBlockContinue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8574,7 +8574,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_MultiBlockContinue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8648,7 +8648,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Unconditional_Body_ContinueNestIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8720,7 +8720,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_MultiBlockContinueIsEntireLoop) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -8778,7 +8778,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_Never) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -8838,7 +8838,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_TrueToBody_FalseBreaks) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -8905,7 +8905,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_FalseToBody_TrueBreaks) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -8979,7 +8979,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_NestedIfContinue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
If{ If{
( (
@ -9037,7 +9037,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyAlwaysBreaks) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -9086,7 +9086,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -9142,7 +9142,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -9204,7 +9204,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromTrue_Early) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -9266,7 +9266,7 @@ TEST_F(SpvParserTest, EmitBody_Loop_BodyConditionallyBreaks_FromFalse_Early) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -9319,7 +9319,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_NoCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9364,7 +9364,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_OneCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9418,7 +9418,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_TwoCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9478,7 +9478,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsMerge_CasesWithDup) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9544,7 +9544,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_NoDupCases) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9615,7 +9615,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_DefaultIsCase_WithDupCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9687,7 +9687,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_SintValue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9757,7 +9757,7 @@ TEST_F(SpvParserTest, EmitBody_Switch_Case_UintValue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -9809,7 +9809,7 @@ TEST_F(SpvParserTest, EmitBody_Return_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Return{} auto* expect = R"(Return{}
)"; )";
ASSERT_EQ(expect, got); ASSERT_EQ(expect, got);
@ -9835,7 +9835,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -9875,7 +9875,7 @@ TEST_F(SpvParserTest, EmitBody_Return_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Return{} Return{}
} }
@ -9905,7 +9905,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Return{ auto* expect = R"(Return{
{ {
ScalarConstructor[not set]{2} ScalarConstructor[not set]{2}
@ -9944,7 +9944,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -10001,7 +10001,7 @@ TEST_F(SpvParserTest, EmitBody_ReturnValue_Loop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Return{ Return{
{ {
@ -10031,7 +10031,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Discard{} auto* expect = R"(Discard{}
)"; )";
ASSERT_EQ(expect, got); ASSERT_EQ(expect, got);
@ -10057,7 +10057,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -10097,7 +10097,7 @@ TEST_F(SpvParserTest, EmitBody_Kill_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Discard{} Discard{}
} }
@ -10119,7 +10119,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_TopLevel) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Return{} auto* expect = R"(Return{}
)"; )";
ASSERT_EQ(expect, got); ASSERT_EQ(expect, got);
@ -10145,7 +10145,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideIf) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -10185,7 +10185,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InsideLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Return{} Return{}
} }
@ -10215,7 +10215,7 @@ TEST_F(SpvParserTest, EmitBody_Unreachable_InNonVoidFunction) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 200));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Return{ auto* expect = R"(Return{
{ {
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -10249,7 +10249,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_MultiBlockLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
continuing { continuing {
Assignment{ Assignment{
@ -10284,7 +10284,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_BackEdge_SingleBlockLoop) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -10321,7 +10321,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_LastInCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -10381,7 +10381,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_SwitchBreak_NotLastInCase) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -10452,7 +10452,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopBreak_MultiBlockLoop_FromBody) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -10534,7 +10534,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
continuing { continuing {
Assignment{ Assignment{
@ -10576,7 +10576,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_LastInLoopConstruct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
Assignment{ Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
@ -10630,7 +10630,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_BeforeLast) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Loop{ auto* expect = R"(Loop{
If{ If{
( (
@ -10699,7 +10699,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_LoopContinue_FromSwitch) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -10769,7 +10769,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromThen) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -10812,7 +10812,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_IfBreak_FromElse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(If{ auto* expect = R"(If{
( (
ScalarConstructor[not set]{false} ScalarConstructor[not set]{false}
@ -10864,7 +10864,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Fallthrough) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -10915,7 +10915,7 @@ TEST_F(SpvParserTest, EmitBody_Branch_Forward) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11019,7 +11019,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Back_SingleBlock_Back) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11062,7 +11062,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11113,7 +11113,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11171,7 +11171,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11227,7 +11227,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11287,7 +11287,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11348,7 +11348,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11431,7 +11431,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnTrue) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11526,7 +11526,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Continue_OnFalse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11611,7 +11611,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11680,7 +11680,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_SwitchBreak_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11747,7 +11747,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11821,7 +11821,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -11890,7 +11890,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -11948,7 +11948,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12021,7 +12021,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12117,7 +12117,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Continue_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12256,7 +12256,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12337,7 +12337,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopBreak_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12405,7 +12405,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Continue_FromHeader) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12462,7 +12462,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12534,7 +12534,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12622,7 +12622,7 @@ TEST_F(
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12701,7 +12701,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_LoopContinue_FromSwitch) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -12789,7 +12789,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12886,7 +12886,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_IfBreak_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -12982,7 +12982,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -13091,7 +13091,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Fallthrough_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -13188,7 +13188,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnTrue) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -13269,7 +13269,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Continue_Forward_OnFalse) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -13333,7 +13333,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_IfBreak_IfBreak_Same) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
@ -13418,7 +13418,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Fallthrough_Fallthrough_Same) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -13509,7 +13509,7 @@ TEST_F(SpvParserTest, EmitBody_BranchConditional_Forward_Forward_Same) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = R"(Assignment{ auto* expect = R"(Assignment{
Identifier[not set]{var_1} Identifier[not set]{var_1}
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
@ -13578,7 +13578,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = "unhandled case"; auto* expect = "unhandled case";
ASSERT_EQ(expect, got); ASSERT_EQ(expect, got);
} }
@ -13613,7 +13613,7 @@ TEST_F(SpvParserTest,
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto got = ToString(fe.ast_body()); auto got = ToString(p->get_module(), fe.ast_body());
auto* expect = "unhandled case"; auto* expect = "unhandled case";
ASSERT_EQ(expect, got); ASSERT_EQ(expect, got);
} }

View File

@ -86,7 +86,8 @@ TEST_F(SpvParserTest_Composite_Construct, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -127,7 +128,7 @@ VariableDeclStatement{
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_Composite_Construct, Matrix) { TEST_F(SpvParserTest_Composite_Construct, Matrix) {
@ -142,7 +143,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -168,7 +169,7 @@ TEST_F(SpvParserTest_Composite_Construct, Matrix) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_Composite_Construct, Array) { TEST_F(SpvParserTest_Composite_Construct, Array) {
@ -183,7 +184,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -199,7 +200,7 @@ TEST_F(SpvParserTest_Composite_Construct, Array) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_Composite_Construct, Struct) { TEST_F(SpvParserTest_Composite_Construct, Struct) {
@ -214,7 +215,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -232,7 +233,7 @@ TEST_F(SpvParserTest_Composite_Construct, Struct) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
using SpvParserTest_CompositeExtract = SpvParserTest; using SpvParserTest_CompositeExtract = SpvParserTest;
@ -249,7 +250,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -265,7 +266,7 @@ TEST_F(SpvParserTest_CompositeExtract, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, Vector_IndexTooBigError) { TEST_F(SpvParserTest_CompositeExtract, Vector_IndexTooBigError) {
@ -300,7 +301,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -312,7 +313,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, Matrix_IndexTooBigError) { TEST_F(SpvParserTest_CompositeExtract, Matrix_IndexTooBigError) {
@ -351,7 +352,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -366,7 +367,7 @@ TEST_F(SpvParserTest_CompositeExtract, Matrix_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, Array) { TEST_F(SpvParserTest_CompositeExtract, Array) {
@ -385,7 +386,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -397,7 +398,7 @@ TEST_F(SpvParserTest_CompositeExtract, Array) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, RuntimeArray_IsError) { TEST_F(SpvParserTest_CompositeExtract, RuntimeArray_IsError) {
@ -436,7 +437,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -448,7 +449,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) { TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
@ -478,7 +479,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -490,8 +491,8 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_4 x_4
none none
@ -503,7 +504,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_DifferOnlyInMemberName) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CompositeExtract, Struct_IndexTooBigError) { TEST_F(SpvParserTest_CompositeExtract, Struct_IndexTooBigError) {
@ -544,7 +545,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -565,7 +566,7 @@ TEST_F(SpvParserTest_CompositeExtract, Struct_Array_Matrix_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
using SpvParserTest_CopyObject = SpvParserTest; using SpvParserTest_CopyObject = SpvParserTest;
@ -583,7 +584,8 @@ TEST_F(SpvParserTest_CopyObject, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -602,7 +604,7 @@ VariableDeclStatement{
Identifier[not set]{x_1} Identifier[not set]{x_1}
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_CopyObject, Pointer) { TEST_F(SpvParserTest_CopyObject, Pointer) {
@ -621,7 +623,8 @@ TEST_F(SpvParserTest_CopyObject, Pointer) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -640,7 +643,7 @@ VariableDeclStatement{
Identifier[not set]{x_1} Identifier[not set]{x_1}
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
using SpvParserTest_VectorShuffle = SpvParserTest; using SpvParserTest_VectorShuffle = SpvParserTest;
@ -661,7 +664,8 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__vec_4__u32 __vec_4__u32
@ -687,7 +691,7 @@ TEST_F(SpvParserTest_VectorShuffle, FunctionScopeOperands_UseBoth) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) { TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
@ -703,7 +707,8 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__vec_4__u32 __vec_4__u32
@ -745,7 +750,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_UseBoth) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) { TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
@ -762,7 +767,8 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_10 x_10
none none
__vec_2__u32 __vec_2__u32
@ -777,7 +783,7 @@ TEST_F(SpvParserTest_VectorShuffle, ConstantOperands_AllOnesMapToNull) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest_VectorShuffle, IndexTooBig_IsError) { TEST_F(SpvParserTest_VectorShuffle, IndexTooBig_IsError) {

View File

@ -82,7 +82,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -93,7 +93,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, Bitcast_Vector) { TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
@ -108,7 +108,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -123,7 +123,7 @@ TEST_F(SpvUnaryConversionTest, Bitcast_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) { TEST_F(SpvUnaryConversionTest, ConvertSToF_BadArg) {
@ -238,7 +238,8 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__f32 __f32
@ -249,7 +250,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
@ -265,7 +266,8 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__f32 __f32
@ -278,7 +280,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Scalar_FromUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) { TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
@ -294,7 +296,8 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__f32 __vec_2__f32
@ -305,7 +308,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
@ -321,7 +324,8 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__f32 __vec_2__f32
@ -334,7 +338,7 @@ TEST_F(SpvUnaryConversionTest, ConvertSToF_Vector_FromUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) { TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_BadArgType) {
@ -383,7 +387,8 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__f32 __f32
@ -396,7 +401,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
@ -412,7 +417,8 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__f32 __f32
@ -423,7 +429,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Scalar_FromUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) { TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
@ -439,7 +445,8 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__f32 __vec_2__f32
@ -452,7 +459,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
@ -468,7 +475,8 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__f32 __vec_2__f32
@ -479,7 +487,7 @@ TEST_F(SpvUnaryConversionTest, ConvertUToF_Vector_FromUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) { TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_BadArgType) {
@ -529,7 +537,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__i32 __i32
@ -540,7 +549,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
@ -556,7 +565,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__u32 __u32
@ -569,7 +579,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Scalar_ToUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) { TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
@ -585,7 +595,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__i32 __vec_2__i32
@ -596,7 +607,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
@ -612,7 +623,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__u32 __vec_2__u32
@ -625,7 +637,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToS_Vector_ToUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) { TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_BadArgType) {
@ -675,7 +687,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__i32 __i32
@ -688,7 +701,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
@ -704,7 +717,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__u32 __u32
@ -715,7 +729,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Scalar_ToUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) { TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
@ -731,7 +745,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__i32 __vec_2__i32
@ -744,7 +759,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToSigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) { TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
@ -760,7 +775,8 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableConst{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableConst{
x_1 x_1
none none
__vec_2__u32 __vec_2__u32
@ -771,7 +787,7 @@ TEST_F(SpvUnaryConversionTest, ConvertFToU_Vector_ToUnsigned) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
// TODO(dneto): OpSConvert // only if multiple widths // TODO(dneto): OpSConvert // only if multiple widths

View File

@ -183,7 +183,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -198,7 +198,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) { TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
@ -212,7 +212,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -227,7 +227,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_Floating, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) { TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
@ -241,7 +241,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -257,7 +257,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) { TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
@ -271,7 +271,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -287,7 +287,7 @@ TEST_P(SpvParserTest_GlslStd450_Float_FloatingFloating, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) { TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
@ -301,7 +301,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -316,7 +316,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) { TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
@ -330,7 +330,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -345,7 +345,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_Floating, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
@ -359,7 +359,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -375,7 +375,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
@ -389,7 +389,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -405,7 +405,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloating, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
@ -419,7 +419,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -436,7 +436,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
@ -451,7 +451,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -468,7 +468,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingFloatingFloating, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
@ -482,7 +482,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -498,7 +498,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
@ -513,7 +513,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -529,7 +529,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingUinting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
@ -543,7 +543,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -559,7 +559,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) { TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
@ -574,7 +574,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -590,7 +590,7 @@ TEST_P(SpvParserTest_GlslStd450_Floating_FloatingInting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) { TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
@ -605,7 +605,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -621,7 +621,7 @@ TEST_P(SpvParserTest_GlslStd450_Float3_Float3Float3, Samples) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
INSTANTIATE_TEST_SUITE_P(Samples, INSTANTIATE_TEST_SUITE_P(Samples,
@ -709,7 +709,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -724,7 +724,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) { TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
@ -739,7 +739,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -754,7 +754,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_Inting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) { TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
@ -769,7 +769,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -785,7 +785,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) { TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
@ -800,7 +800,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -816,7 +816,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingInting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) { TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
@ -831,7 +831,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -848,7 +848,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) { TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
@ -863,7 +863,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -880,7 +880,7 @@ TEST_P(SpvParserTest_GlslStd450_Inting_IntingIntingInting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
INSTANTIATE_TEST_SUITE_P(Samples, INSTANTIATE_TEST_SUITE_P(Samples,
@ -907,7 +907,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -923,7 +923,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) { TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
@ -938,7 +938,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -954,7 +954,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUinting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) { TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
@ -968,7 +968,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -985,7 +985,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) { TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
@ -1000,7 +1000,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1017,7 +1017,7 @@ TEST_P(SpvParserTest_GlslStd450_Uinting_UintingUintingUinting, Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
INSTANTIATE_TEST_SUITE_P(Samples, INSTANTIATE_TEST_SUITE_P(Samples,
@ -1043,7 +1043,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SAbs) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1095,7 +1095,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMax) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1153,7 +1153,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SMin) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1211,7 +1211,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_SClamp) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1271,7 +1271,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMax) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1329,7 +1329,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UMin) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
@ -1387,7 +1387,7 @@ TEST_F(SpvParserTest, RectifyOperandsAndResult_UClamp) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
auto body = ToString(fe.ast_body()); auto body = ToString(p->get_module(), fe.ast_body());
EXPECT_THAT(body, HasSubstr(R"( EXPECT_THAT(body, HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1

View File

@ -206,7 +206,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -218,7 +218,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) { TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
@ -233,7 +233,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -249,7 +249,7 @@ TEST_F(SpvUnaryLogicalTest, LogicalNot_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
struct BinaryData { struct BinaryData {
@ -296,7 +296,8 @@ TEST_P(SpvBinaryLogicalTest, EmitExpression) {
<< GetParam().ast_type << "\n {\n Binary[not set]{" << GetParam().ast_type << "\n {\n Binary[not set]{"
<< "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op << "\n " << GetParam().ast_lhs << "\n " << GetParam().ast_op
<< "\n " << GetParam().ast_rhs; << "\n " << GetParam().ast_rhs;
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(ss.str())) << assembly; EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(ss.str()))
<< assembly;
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -701,7 +702,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -717,7 +718,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordEqual_Vector) { TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
@ -732,7 +733,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -756,7 +757,7 @@ TEST_F(SpvFUnordTest, FUnordEqual_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) { TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
@ -771,7 +772,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -787,7 +788,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) { TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
@ -802,7 +803,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -826,7 +827,7 @@ TEST_F(SpvFUnordTest, FUnordNotEqual_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) { TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
@ -841,7 +842,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -857,7 +858,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordLessThan_Vector) { TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
@ -872,7 +873,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -896,7 +897,7 @@ TEST_F(SpvFUnordTest, FUnordLessThan_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) { TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
@ -911,7 +912,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -927,7 +928,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) { TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
@ -942,7 +943,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -966,7 +967,7 @@ TEST_F(SpvFUnordTest, FUnordLessThanEqual_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) { TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
@ -981,7 +982,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -997,7 +998,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) { TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
@ -1012,7 +1013,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1036,7 +1037,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThan_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) { TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
@ -1051,7 +1052,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1067,7 +1068,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Scalar) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) { TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
@ -1082,7 +1083,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1106,7 +1107,7 @@ TEST_F(SpvFUnordTest, FUnordGreaterThanEqual_Vector) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) { TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
@ -1121,7 +1122,8 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1137,7 +1139,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_BoolParams) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) { TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
@ -1152,7 +1154,8 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1168,7 +1171,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_IntScalarParams) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) { TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
@ -1183,7 +1186,8 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1199,7 +1203,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_FloatScalarParams) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) { TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
@ -1214,7 +1218,8 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1238,7 +1243,7 @@ TEST_F(SpvFUnordTest, Select_BoolCond_VectorParams) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) { TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
@ -1253,7 +1258,8 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1281,7 +1287,7 @@ TEST_F(SpvFUnordTest, Select_VecBoolCond_VectorParams) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
using SpvLogicalTest = SpvParserTestBase<::testing::Test>; using SpvLogicalTest = SpvParserTestBase<::testing::Test>;
@ -1298,7 +1304,8 @@ TEST_F(SpvLogicalTest, Any) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1316,7 +1323,7 @@ TEST_F(SpvLogicalTest, Any) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvLogicalTest, All) { TEST_F(SpvLogicalTest, All) {
@ -1331,7 +1338,8 @@ TEST_F(SpvLogicalTest, All) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1349,7 +1357,7 @@ TEST_F(SpvLogicalTest, All) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvLogicalTest, IsNan_Scalar) { TEST_F(SpvLogicalTest, IsNan_Scalar) {
@ -1364,7 +1372,8 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1378,7 +1387,7 @@ TEST_F(SpvLogicalTest, IsNan_Scalar) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvLogicalTest, IsNan_Vector) { TEST_F(SpvLogicalTest, IsNan_Vector) {
@ -1393,7 +1402,8 @@ TEST_F(SpvLogicalTest, IsNan_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1411,7 +1421,7 @@ TEST_F(SpvLogicalTest, IsNan_Vector) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvLogicalTest, IsInf_Scalar) { TEST_F(SpvLogicalTest, IsInf_Scalar) {
@ -1426,7 +1436,8 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1440,7 +1451,7 @@ TEST_F(SpvLogicalTest, IsInf_Scalar) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvLogicalTest, IsInf_Vector) { TEST_F(SpvLogicalTest, IsInf_Vector) {
@ -1455,7 +1466,8 @@ TEST_F(SpvLogicalTest, IsInf_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1473,7 +1485,7 @@ TEST_F(SpvLogicalTest, IsInf_Vector) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
// TODO(dneto): Kernel-guarded instructions. // TODO(dneto): Kernel-guarded instructions.

View File

@ -50,7 +50,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreBoolConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{true} ScalarConstructor[not set]{true}
} }
@ -82,7 +82,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreUintConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
} }
@ -110,7 +110,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreIntConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
} }
@ -138,7 +138,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreFloatConst) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{42.000000} ScalarConstructor[not set]{42.000000}
} }
@ -167,7 +167,7 @@ TEST_F(SpvParserTest, EmitStatement_LoadBool) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_2 x_2
none none
@ -196,7 +196,8 @@ TEST_F(SpvParserTest, EmitStatement_LoadScalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_2 x_2
none none
@ -237,7 +238,8 @@ TEST_F(SpvParserTest, EmitStatement_UseLoadedScalarTwice) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_2 x_2
none none
@ -274,7 +276,7 @@ TEST_F(SpvParserTest, EmitStatement_StoreToModuleScopeVar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
})")); })"));
@ -341,13 +343,13 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorSwizzle) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
Identifier[not set]{z} Identifier[not set]{z}
} }
ScalarConstructor[not set]{42} ScalarConstructor[not set]{42}
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorConstOutOfBounds) { TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorConstOutOfBounds) {
@ -404,7 +406,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_VectorNonConstIndex) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
Identifier[not set]{x_11} Identifier[not set]{x_11}
@ -441,7 +443,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Matrix) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
ScalarConstructor[not set]{2} ScalarConstructor[not set]{2}
@ -484,7 +486,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Array) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
ScalarConstructor[not set]{2} ScalarConstructor[not set]{2}
@ -526,7 +528,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
Identifier[not set]{age} Identifier[not set]{age}
@ -574,7 +576,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_DifferOnlyMemberName) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
Identifier[not set]{age} Identifier[not set]{age}
@ -587,7 +589,7 @@ Assignment{
Identifier[not set]{ancientness} Identifier[not set]{ancientness}
} }
ScalarConstructor[not set]{420.000000} ScalarConstructor[not set]{420.000000}
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_AccessChain_StructNonConstIndex) { TEST_F(SpvParserTest, EmitStatement_AccessChain_StructNonConstIndex) {
@ -684,7 +686,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Struct_RuntimeArray) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
@ -724,7 +726,7 @@ TEST_F(SpvParserTest, EmitStatement_AccessChain_Compound_Matrix_Vector) {
<< assembly << p->error(); << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()); EXPECT_TRUE(fe.EmitBody());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
@ -832,7 +834,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_NonCascaded) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
Identifier[not set]{field0} Identifier[not set]{field0}
@ -848,7 +850,7 @@ Assignment{
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
} }
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
})")) << ToString(fe.ast_body()) })")) << ToString(p->get_module(), fe.ast_body())
<< p->error(); << p->error();
} }
@ -871,7 +873,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(Assignment{
ArrayAccessor[not set]{ ArrayAccessor[not set]{
MemberAccessor[not set]{ MemberAccessor[not set]{
Identifier[not set]{myvar} Identifier[not set]{myvar}
@ -880,7 +882,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughAccessChain_Cascaded) {
ScalarConstructor[not set]{1} ScalarConstructor[not set]{1}
} }
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
})")) << ToString(fe.ast_body()) })")) << ToString(p->get_module(), fe.ast_body())
<< p->error(); << p->error();
} }
@ -904,7 +906,8 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_2 x_2
none none
@ -923,7 +926,7 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithoutHoisting) {
Assignment{ Assignment{
Identifier[not set]{x_2} Identifier[not set]{x_2}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
})")) << ToString(fe.ast_body()) })")) << ToString(p->get_module(), fe.ast_body())
<< p->error(); << p->error();
} }
@ -959,7 +962,8 @@ TEST_F(SpvParserTest, RemapStorageBuffer_ThroughCopyObject_WithHoisting) {
ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error(); ASSERT_TRUE(p->BuildAndParseInternalModule()) << assembly << p->error();
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{ Variable{
x_2 x_2
function function
@ -993,7 +997,7 @@ Assignment{
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
} }
Return{} Return{}
)")) << ToString(fe.ast_body()) )")) << ToString(p->get_module(), fe.ast_body())
<< p->error(); << p->error();
} }

View File

@ -68,7 +68,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Scalar) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_11 x_11
none none
@ -107,7 +108,7 @@ VariableDeclStatement{
ScalarConstructor[not set]{0.000000} ScalarConstructor[not set]{0.000000}
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
@ -128,7 +129,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Vector) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_11 x_11
none none
@ -169,7 +171,7 @@ VariableDeclStatement{
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
@ -188,7 +190,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_11 x_11
none none
@ -209,7 +212,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Matrix) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
@ -229,7 +232,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_11 x_11
none none
@ -242,7 +246,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Array) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) { TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
@ -261,7 +265,8 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly; ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_11 x_11
none none
@ -276,7 +281,7 @@ TEST_F(SpvParserTestMiscInstruction, OpUndef_InFunction_Struct) {
} }
} }
} }
})")) << ToString(fe.ast_body()); })")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTestMiscInstruction, OpNop) { TEST_F(SpvParserTestMiscInstruction, OpNop) {
@ -292,8 +297,8 @@ TEST_F(SpvParserTestMiscInstruction, OpNop) {
<< p->error() << assembly; << p->error() << assembly;
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Return{} EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
// Test swizzle generation. // Test swizzle generation.
@ -324,7 +329,8 @@ TEST_P(SpvParserSwizzleTest, Sample) {
ASSERT_NE(result, nullptr); ASSERT_NE(result, nullptr);
std::ostringstream ss; std::ostringstream ss;
result->to_str(ss, 0); result->to_str(ss, 0);
EXPECT_THAT(ss.str(), Eq(GetParam().expected_expr)); auto str = Demangler().Demangle(p->get_module(), ss.str());
EXPECT_THAT(str, Eq(GetParam().expected_expr));
} else { } else {
EXPECT_EQ(result, nullptr); EXPECT_EQ(result, nullptr);
EXPECT_FALSE(fe.success()); EXPECT_FALSE(fe.success());

View File

@ -91,7 +91,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_AnonymousVars) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_1 x_1
function function
@ -129,7 +130,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_NamedVars) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
function function
@ -167,7 +169,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MixedTypes) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
function function
@ -208,7 +211,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarInitializers) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
function function
@ -281,7 +285,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarNullInitializers) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
function function
@ -340,7 +345,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -354,7 +360,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) { TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) {
@ -378,7 +384,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -424,7 +431,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -438,7 +446,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) { TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
@ -458,7 +466,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -472,7 +481,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) { TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
@ -491,7 +500,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -505,7 +515,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Null) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) { TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
@ -525,7 +535,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -539,7 +550,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer_Alias_Null) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) { TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
@ -559,7 +570,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -578,7 +590,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) { TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
@ -598,7 +610,8 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitFunctionVariables()); EXPECT_TRUE(fe.EmitFunctionVariables());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
function function
@ -617,7 +630,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer_Null) {
} }
} }
} }
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, TEST_F(SpvParserTest,
@ -642,7 +655,8 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{ Variable{
x_25 x_25
function function
@ -662,7 +676,7 @@ Assignment{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_CombinatorialValue_Immediate_UsedTwice) { TEST_F(SpvParserTest, EmitStatement_CombinatorialValue_Immediate_UsedTwice) {
@ -687,7 +701,8 @@ TEST_F(SpvParserTest, EmitStatement_CombinatorialValue_Immediate_UsedTwice) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{ Variable{
x_25 x_25
function function
@ -721,7 +736,7 @@ Assignment{
Identifier[not set]{x_2} Identifier[not set]{x_2}
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, TEST_F(SpvParserTest,
@ -757,7 +772,8 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{ Variable{
x_25 x_25
function function
@ -795,7 +811,7 @@ Assignment{
ScalarConstructor[not set]{2} ScalarConstructor[not set]{2}
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F( TEST_F(
@ -854,7 +870,7 @@ TEST_F(
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Assignment{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(Assignment{
Identifier[not set]{x_1} Identifier[not set]{x_1}
ScalarConstructor[not set]{0} ScalarConstructor[not set]{0}
} }
@ -926,7 +942,7 @@ Assignment{
ScalarConstructor[not set]{5} ScalarConstructor[not set]{5}
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F( TEST_F(
@ -970,7 +986,8 @@ TEST_F(
// We don't hoist x_1 into its own mutable variable. It is emitted as // We don't hoist x_1 into its own mutable variable. It is emitted as
// a const definition. // a const definition.
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1002,7 +1019,7 @@ Assignment{
Identifier[not set]{x_3} Identifier[not set]{x_3}
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, TEST_F(SpvParserTest,
@ -1053,7 +1070,7 @@ TEST_F(SpvParserTest,
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(If{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(If{
( (
ScalarConstructor[not set]{true} ScalarConstructor[not set]{true}
) )
@ -1092,7 +1109,7 @@ TEST_F(SpvParserTest,
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F( TEST_F(
@ -1138,7 +1155,7 @@ TEST_F(
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(If{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(If{
( (
ScalarConstructor[not set]{true} ScalarConstructor[not set]{true}
) )
@ -1179,7 +1196,7 @@ TEST_F(
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, TEST_F(SpvParserTest,
@ -1219,7 +1236,8 @@ TEST_F(SpvParserTest,
// We don't hoist x_1 into its own mutable variable. It is emitted as // We don't hoist x_1 into its own mutable variable. It is emitted as
// a const definition. // a const definition.
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1247,7 +1265,7 @@ If{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) { TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) {
@ -1291,7 +1309,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Loop{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(Loop{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
x_2_phi x_2_phi
@ -1386,7 +1404,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_SingleBlockLoopIndex) {
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) { TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) {
@ -1433,7 +1451,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(Loop{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), Eq(R"(Loop{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
x_2_phi x_2_phi
@ -1541,7 +1559,7 @@ TEST_F(SpvParserTest, EmitStatement_Phi_MultiBlockLoopIndex) {
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_Phi_ValueFromLoopBodyAndContinuing) { TEST_F(SpvParserTest, EmitStatement_Phi_ValueFromLoopBodyAndContinuing) {
@ -1589,7 +1607,8 @@ TEST_F(SpvParserTest, EmitStatement_Phi_ValueFromLoopBodyAndContinuing) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_101 x_101
none none
@ -1707,7 +1726,7 @@ Loop{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()) )")) << ToString(p->get_module(), fe.ast_body())
<< assembly; << assembly;
} }
@ -1757,7 +1776,8 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromElseAndThen) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_101 x_101
none none
@ -1831,7 +1851,7 @@ Loop{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_Phi_FromHeaderAndThen) { TEST_F(SpvParserTest, EmitStatement_Phi_FromHeaderAndThen) {
@ -1877,7 +1897,8 @@ TEST_F(SpvParserTest, EmitStatement_Phi_FromHeaderAndThen) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
VariableConst{ VariableConst{
x_101 x_101
none none
@ -1946,7 +1967,7 @@ Loop{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
TEST_F(SpvParserTest, EmitStatement_UseInPhiCountsAsUse) { TEST_F(SpvParserTest, EmitStatement_UseInPhiCountsAsUse) {
@ -1983,7 +2004,8 @@ TEST_F(SpvParserTest, EmitStatement_UseInPhiCountsAsUse) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_THAT(ToString(fe.ast_body()), Eq(R"(VariableDeclStatement{ EXPECT_THAT(ToString(p->get_module(), fe.ast_body()),
Eq(R"(VariableDeclStatement{
Variable{ Variable{
x_101_phi x_101_phi
function function
@ -2043,7 +2065,7 @@ VariableDeclStatement{
} }
} }
Return{} Return{}
)")) << ToString(fe.ast_body()); )")) << ToString(p->get_module(), fe.ast_body());
} }
} // namespace } // namespace

View File

@ -199,10 +199,10 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
)")); )"));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_ast = p->get_module().to_str(); const auto module_ast =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module_ast, HasSubstr(R"( EXPECT_THAT(module_ast, HasSubstr(R"(
Function )" + p->get_module().GetSymbol("leaf").to_str() + Function leaf -> __u32
R"( -> __u32
() ()
{ {
Return{ Return{
@ -211,8 +211,7 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
} }
} }
} }
Function )" + p->get_module().GetSymbol("branch").to_str() + Function branch -> __u32
R"( -> __u32
() ()
{ {
VariableDeclStatement{ VariableDeclStatement{
@ -235,8 +234,7 @@ TEST_F(SpvParserTest, EmitFunctions_CalleePrecedesCaller) {
} }
} }
} }
Function )" + p->get_module().GetSymbol("root").to_str() + Function root -> __void
R"( -> __void
() ()
{ {
VariableDeclStatement{ VariableDeclStatement{

View File

@ -16,6 +16,7 @@
#include <vector> #include <vector>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "src/demangler.h"
#include "src/reader/spirv/function.h" #include "src/reader/spirv/function.h"
#include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/parser_impl_test_helper.h"
@ -1128,7 +1129,8 @@ TEST_P(SpvParserTest_DeclUnderspecifiedHandle, Variable) {
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error();
const auto module = p->module().to_str(); const auto module =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) << module; EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) << module;
} }
@ -1300,7 +1302,8 @@ TEST_P(SpvParserTest_SampledImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error();
const auto module = p->module().to_str(); const auto module =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) EXPECT_THAT(module, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << module; << "DECLARATIONS ARE BAD " << module;
EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin)) EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin))
@ -2373,7 +2376,8 @@ TEST_P(SpvParserTest_ImageAccessTest, Variable) {
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly; ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error() << assembly;
EXPECT_TRUE(p->error().empty()) << p->error(); EXPECT_TRUE(p->error().empty()) << p->error();
const auto module = p->module().to_str(); const auto module =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module, HasSubstr(GetParam().var_decl)) EXPECT_THAT(module, HasSubstr(GetParam().var_decl))
<< "DECLARATIONS ARE BAD " << module; << "DECLARATIONS ARE BAD " << module;
EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin)) EXPECT_THAT(module, HasSubstr(GetParam().texture_builtin))
@ -3670,7 +3674,8 @@ TEST_P(SpvParserTest_ImageCoordsTest, MakeCoordinateOperandsForImageAccess) {
std::vector<std::string> result_strings; std::vector<std::string> result_strings;
for (auto* expr : result) { for (auto* expr : result) {
ASSERT_NE(expr, nullptr); ASSERT_NE(expr, nullptr);
result_strings.push_back(expr->str()); result_strings.push_back(
Demangler().Demangle(p->get_module(), expr->str()));
} }
EXPECT_THAT(result_strings, EXPECT_THAT(result_strings,
::testing::ContainerEq(GetParam().expected_expressions)); ::testing::ContainerEq(GetParam().expected_expressions));

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "src/demangler.h"
#include "src/reader/spirv/function.h" #include "src/reader/spirv/function.h"
#include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl.h"
#include "src/reader/spirv/parser_impl_test_helper.h" #include "src/reader/spirv/parser_impl_test_helper.h"
@ -326,7 +327,8 @@ TEST_F(SpvParserTest, ModuleScopeVar_BuiltinPosition_StorePosition) {
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{ Assignment{
Identifier[not set]{gl_Position} Identifier[not set]{gl_Position}
@ -357,7 +359,8 @@ TEST_F(SpvParserTest,
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
Assignment{ Assignment{
MemberAccessor[not set]{ MemberAccessor[not set]{
@ -388,7 +391,8 @@ TEST_F(SpvParserTest,
auto p = parser(test::Assemble(assembly)); auto p = parser(test::Assemble(assembly));
EXPECT_TRUE(p->BuildAndParseInternalModule()); EXPECT_TRUE(p->BuildAndParseInternalModule());
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
const auto module_str = p->module().to_str(); const auto module_str =
Demangler().Demangle(p->get_module(), p->get_module().to_str());
EXPECT_THAT(module_str, HasSubstr(R"( EXPECT_THAT(module_str, HasSubstr(R"(
{ {
Assignment{ Assignment{
@ -1654,7 +1658,7 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_UsedInFunction) {
FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100)); FunctionEmitter fe(p.get(), *spirv_function(p.get(), 100));
EXPECT_TRUE(fe.EmitBody()) << p->error(); EXPECT_TRUE(fe.EmitBody()) << p->error();
EXPECT_TRUE(p->error().empty()); EXPECT_TRUE(p->error().empty());
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"( EXPECT_THAT(ToString(p->get_module(), fe.ast_body()), HasSubstr(R"(
VariableConst{ VariableConst{
x_1 x_1
none none
@ -1667,7 +1671,7 @@ TEST_F(SpvParserTest, ModuleScopeVar_ScalarSpecConstant_UsedInFunction) {
} }
} }
})")) })"))
<< ToString(fe.ast_body()); << ToString(p->get_module(), fe.ast_body());
} }
} // namespace } // namespace

View File

@ -22,6 +22,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "source/opt/ir_context.h" #include "source/opt/ir_context.h"
#include "src/demangler.h"
#include "src/reader/spirv/parser_impl.h" #include "src/reader/spirv/parser_impl.h"
namespace tint { namespace tint {
@ -59,12 +60,13 @@ using SpvParserTest = SpvParserTestBase<::testing::Test>;
/// Returns the string dump of a function body. /// Returns the string dump of a function body.
/// @param body the statement in the body /// @param body the statement in the body
/// @returnss the string dump of a function body. /// @returnss the string dump of a function body.
inline std::string ToString(const ast::BlockStatement* body) { inline std::string ToString(const ast::Module& mod,
const ast::BlockStatement* body) {
std::ostringstream outs; std::ostringstream outs;
for (const auto* stmt : *body) { for (const auto* stmt : *body) {
stmt->to_str(outs, 0); stmt->to_str(outs, 0);
} }
return outs.str(); return Demangler().Demangle(mod, outs.str());
} }
} // namespace spirv } // namespace spirv

View File

@ -2026,7 +2026,9 @@ Maybe<ast::CallStatement*> ParserImpl::func_call_stmt() {
return Failure::kErrored; return Failure::kErrored;
return create<ast::CallStatement>(create<ast::CallExpression>( return create<ast::CallStatement>(create<ast::CallExpression>(
source, create<ast::IdentifierExpression>(name), std::move(params))); source,
create<ast::IdentifierExpression>(module_.RegisterSymbol(name), name),
std::move(params)));
} }
// break_stmt // break_stmt
@ -2097,7 +2099,8 @@ Maybe<ast::Expression*> ParserImpl::primary_expression() {
} }
if (match(Token::Type::kIdentifier)) if (match(Token::Type::kIdentifier))
return create<ast::IdentifierExpression>(t.source(), t.to_str()); return create<ast::IdentifierExpression>(
t.source(), module_.RegisterSymbol(t.to_str()), t.to_str());
auto type = type_decl(); auto type = type_decl();
if (type.errored) if (type.errored)
@ -2172,7 +2175,8 @@ Maybe<ast::Expression*> ParserImpl::postfix_expr(ast::Expression* prefix) {
return postfix_expr(create<ast::MemberAccessorExpression>( return postfix_expr(create<ast::MemberAccessorExpression>(
ident.source, prefix, ident.source, prefix,
create<ast::IdentifierExpression>(ident.source, ident.value))); create<ast::IdentifierExpression>(
ident.source, module_.RegisterSymbol(ident.value), ident.value)));
} }
return prefix; return prefix;

View File

@ -135,7 +135,9 @@ ast::ArrayAccessorExpression* BoundArrayAccessors::Transform(
ctx->mod->create<ast::UintLiteral>(u32, size - 1))); ctx->mod->create<ast::UintLiteral>(u32, size - 1)));
auto* call_expr = ctx->mod->create<ast::CallExpression>( auto* call_expr = ctx->mod->create<ast::CallExpression>(
ctx->mod->create<ast::IdentifierExpression>("min"), std::move(params)); ctx->mod->create<ast::IdentifierExpression>(
ctx->mod->RegisterSymbol("min"), "min"),
std::move(params));
call_expr->set_result_type(u32); call_expr->set_result_type(u32);
idx_expr = call_expr; idx_expr = call_expr;

View File

@ -67,8 +67,8 @@ Transform::Output EmitVertexPointSize::Run(ast::Module* in) {
// Build the AST expression & statement for assigning pointsize one. // Build the AST expression & statement for assigning pointsize one.
auto* one = mod->create<ast::ScalarConstructorExpression>( auto* one = mod->create<ast::ScalarConstructorExpression>(
mod->create<ast::FloatLiteral>(f32, 1.0f)); mod->create<ast::FloatLiteral>(f32, 1.0f));
auto* pointsize_ident = auto* pointsize_ident = mod->create<ast::IdentifierExpression>(
mod->create<ast::IdentifierExpression>(Source{}, kPointSizeVar); Source{}, mod->RegisterSymbol(kPointSizeVar), kPointSizeVar);
auto* pointsize_assign = auto* pointsize_assign =
mod->create<ast::AssignmentStatement>(pointsize_ident, one); mod->create<ast::AssignmentStatement>(pointsize_ident, one);

View File

@ -21,6 +21,7 @@
#include "src/ast/builder.h" #include "src/ast/builder.h"
#include "src/ast/stage_decoration.h" #include "src/ast/stage_decoration.h"
#include "src/ast/variable_decl_statement.h" #include "src/ast/variable_decl_statement.h"
#include "src/demangler.h"
#include "src/diagnostic/formatter.h" #include "src/diagnostic/formatter.h"
#include "src/transform/manager.h" #include "src/transform/manager.h"
@ -85,7 +86,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
ASSERT_FALSE(result.diagnostics.contains_errors()) ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics); << diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{ auto* expected = R"(Module{
Variable{ Variable{
Decorations{ Decorations{
BuiltinDecoration{pointsize} BuiltinDecoration{pointsize}
@ -94,13 +95,11 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
out out
__f32 __f32
} }
Function )" + result.module.RegisterSymbol("non_entry_a").to_str() + Function non_entry_a -> __void
R"( -> __void
() ()
{ {
} }
Function )" + result.module.RegisterSymbol("entry").to_str() + Function entry -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -116,14 +115,14 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) {
} }
} }
} }
Function )" + result.module.RegisterSymbol("non_entry_b").to_str() + Function non_entry_b -> __void
R"( -> __void
() ()
{ {
} }
} }
)"; )";
EXPECT_EQ(expected, result.module.to_str()); EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
@ -156,7 +155,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
ASSERT_FALSE(result.diagnostics.contains_errors()) ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics); << diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{ auto* expected = R"(Module{
Variable{ Variable{
Decorations{ Decorations{
BuiltinDecoration{pointsize} BuiltinDecoration{pointsize}
@ -165,13 +164,11 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
out out
__f32 __f32
} }
Function )" + result.module.RegisterSymbol("non_entry_a").to_str() + Function non_entry_a -> __void
R"( -> __void
() ()
{ {
} }
Function )" + result.module.RegisterSymbol("entry").to_str() + Function entry -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -180,14 +177,14 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) {
ScalarConstructor[__f32]{1.000000} ScalarConstructor[__f32]{1.000000}
} }
} }
Function )" + result.module.RegisterSymbol("non_entry_b").to_str() + Function non_entry_b -> __void
R"( -> __void
() ()
{ {
} }
} }
)"; )";
EXPECT_EQ(expected, result.module.to_str()); EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(EmitVertexPointSizeTest, NonVertexStage) { TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
@ -219,22 +216,21 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) {
ASSERT_FALSE(result.diagnostics.contains_errors()) ASSERT_FALSE(result.diagnostics.contains_errors())
<< diag::Formatter().format(result.diagnostics); << diag::Formatter().format(result.diagnostics);
auto expected = R"(Module{ auto* expected = R"(Module{
Function )" + result.module.RegisterSymbol("fragment_entry").to_str() + Function fragment_entry -> __void
R"( -> __void
StageDecoration{fragment} StageDecoration{fragment}
() ()
{ {
} }
Function )" + result.module.RegisterSymbol("compute_entry").to_str() + Function compute_entry -> __void
R"( -> __void
StageDecoration{compute} StageDecoration{compute}
() ()
{ {
} }
} }
)"; )";
EXPECT_EQ(expected, result.module.to_str()); EXPECT_EQ(expected,
Demangler().Demangle(result.module, result.module.to_str()));
} }
} // namespace } // namespace

View File

@ -251,13 +251,16 @@ ast::VariableDeclStatement* FirstIndexOffset::CreateFirstIndexOffset(
const std::string& field_name, const std::string& field_name,
ast::Variable* buffer_var, ast::Variable* buffer_var,
ast::Module* mod) { ast::Module* mod) {
auto* buffer = mod->create<ast::IdentifierExpression>(buffer_var->name()); auto* buffer = mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(buffer_var->name()), buffer_var->name());
auto* constructor = mod->create<ast::BinaryExpression>( auto* constructor = mod->create<ast::BinaryExpression>(
ast::BinaryOp::kAdd, ast::BinaryOp::kAdd,
mod->create<ast::IdentifierExpression>(kIndexOffsetPrefix + mod->create<ast::IdentifierExpression>(
original_name), mod->RegisterSymbol(kIndexOffsetPrefix + original_name),
kIndexOffsetPrefix + original_name),
mod->create<ast::MemberAccessorExpression>( mod->create<ast::MemberAccessorExpression>(
buffer, mod->create<ast::IdentifierExpression>(field_name))); buffer, mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(field_name), field_name)));
auto* var = auto* var =
mod->create<ast::Variable>(Source{}, // source mod->create<ast::Variable>(Source{}, // source
original_name, // name original_name, // name

View File

@ -74,7 +74,8 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
void Build() override { void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx"))); Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
} }
}; };
@ -115,7 +116,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
void Build() override { void Build() override {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx"))); Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
} }
}; };
@ -191,7 +193,8 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
void Build() override { void Build() override {
AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx); AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx);
AddFunction("test")->body()->append(create<ast::ReturnStatement>( AddFunction("test")->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("inst_idx"))); Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("inst_idx"), "inst_idx")));
} }
}; };
@ -344,11 +347,13 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) {
AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx);
ast::Function* func1 = AddFunction("func1"); ast::Function* func1 = AddFunction("func1");
func1->body()->append(create<ast::ReturnStatement>( func1->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("vert_idx"))); Source{}, create<ast::IdentifierExpression>(
mod->RegisterSymbol("vert_idx"), "vert_idx")));
ast::Function* func2 = AddFunction("func2"); ast::Function* func2 = AddFunction("func2");
func2->body()->append(create<ast::ReturnStatement>( func2->body()->append(create<ast::ReturnStatement>(
Source{}, create<ast::CallExpression>( Source{}, create<ast::CallExpression>(
create<ast::IdentifierExpression>("func1"), create<ast::IdentifierExpression>(
mod->RegisterSymbol("func1"), "func1"),
ast::ExpressionList{}))); ast::ExpressionList{})));
} }
}; };

View File

@ -321,11 +321,12 @@ void VertexPulling::State::AddVertexPullingPreamble(
} }
auto* v = it->second; auto* v = it->second;
auto name = buffer_layout.step_mode == InputStepMode::kVertex
? vertex_index_name
: instance_index_name;
// Identifier to index by // Identifier to index by
auto* index_identifier = mod->create<ast::IdentifierExpression>( auto* index_identifier = mod->create<ast::IdentifierExpression>(
buffer_layout.step_mode == InputStepMode::kVertex mod->RegisterSymbol(name), name);
? vertex_index_name
: instance_index_name);
// An expression for the start of the read in the buffer in bytes // An expression for the start of the read in the buffer in bytes
auto* pos_value = mod->create<ast::BinaryExpression>( auto* pos_value = mod->create<ast::BinaryExpression>(
@ -341,7 +342,8 @@ void VertexPulling::State::AddVertexPullingPreamble(
block->append(set_pos_expr); block->append(set_pos_expr);
block->append(mod->create<ast::AssignmentStatement>( block->append(mod->create<ast::AssignmentStatement>(
mod->create<ast::IdentifierExpression>(v->name()), mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(v->name()),
v->name()),
AccessByFormat(i, attribute_desc.format))); AccessByFormat(i, attribute_desc.format)));
} }
} }
@ -355,7 +357,8 @@ ast::Expression* VertexPulling::State::GenUint(uint32_t value) {
} }
ast::Expression* VertexPulling::State::CreatePullingPositionIdent() { ast::Expression* VertexPulling::State::CreatePullingPositionIdent() {
return mod->create<ast::IdentifierExpression>(kPullingPosVarName); return mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kPullingPosVarName), kPullingPosVarName);
} }
ast::Expression* VertexPulling::State::AccessByFormat(uint32_t buffer, ast::Expression* VertexPulling::State::AccessByFormat(uint32_t buffer,
@ -392,10 +395,13 @@ ast::Expression* VertexPulling::State::AccessU32(uint32_t buffer,
// by dividing. Then, that element is going to be read, and if needed, // by dividing. Then, that element is going to be read, and if needed,
// unpacked into an appropriate variable. All reads should end up here as a // unpacked into an appropriate variable. All reads should end up here as a
// base case. // base case.
auto vbuf_name = GetVertexBufferName(buffer);
return mod->create<ast::ArrayAccessorExpression>( return mod->create<ast::ArrayAccessorExpression>(
mod->create<ast::MemberAccessorExpression>( mod->create<ast::MemberAccessorExpression>(
mod->create<ast::IdentifierExpression>(GetVertexBufferName(buffer)), mod->create<ast::IdentifierExpression>(mod->RegisterSymbol(vbuf_name),
mod->create<ast::IdentifierExpression>(kStructBufferName)), vbuf_name),
mod->create<ast::IdentifierExpression>(
mod->RegisterSymbol(kStructBufferName), kStructBufferName)),
mod->create<ast::BinaryExpression>(ast::BinaryOp::kDivide, pos, mod->create<ast::BinaryExpression>(ast::BinaryOp::kDivide, pos,
GenUint(4))); GenUint(4)));
} }

View File

@ -24,7 +24,7 @@
#include "src/ast/type/f32_type.h" #include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h" #include "src/ast/type/i32_type.h"
#include "src/ast/type/void_type.h" #include "src/ast/type/void_type.h"
#include "src/ast/variable.h" #include "src/demangler.h"
#include "src/diagnostic/formatter.h" #include "src/diagnostic/formatter.h"
#include "src/transform/manager.h" #include "src/transform/manager.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
@ -195,8 +195,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -240,7 +239,7 @@ TEST_F(VertexPullingTest, OneAttribute) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(VertexPullingTest, OneInstancedAttribute) { TEST_F(VertexPullingTest, OneInstancedAttribute) {
@ -283,8 +282,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -328,7 +326,7 @@ TEST_F(VertexPullingTest, OneInstancedAttribute) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) { TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
@ -371,8 +369,7 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -416,7 +413,7 @@ TEST_F(VertexPullingTest, OneAttributeDifferentOutputSet) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
// We expect the transform to use an existing builtin variables if it finds them // We expect the transform to use an existing builtin variables if it finds them
@ -510,8 +507,7 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -583,7 +579,7 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(VertexPullingTest, TwoAttributesSameBuffer) { TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
@ -636,8 +632,7 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -767,7 +762,7 @@ TEST_F(VertexPullingTest, TwoAttributesSameBuffer) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
TEST_F(VertexPullingTest, FloatVectorAttributes) { TEST_F(VertexPullingTest, FloatVectorAttributes) {
@ -847,8 +842,7 @@ TEST_F(VertexPullingTest, FloatVectorAttributes) {
storage_buffer storage_buffer
__struct_TintVertexData __struct_TintVertexData
} }
Function )" + result.module.GetSymbol("main").to_str() + Function main -> __void
R"( -> __void
StageDecoration{vertex} StageDecoration{vertex}
() ()
{ {
@ -1071,7 +1065,7 @@ TEST_F(VertexPullingTest, FloatVectorAttributes) {
} }
} }
)", )",
result.module.to_str()); Demangler().Demangle(result.module, result.module.to_str()));
} }
} // namespace } // namespace

File diff suppressed because it is too large Load Diff

View File

@ -53,8 +53,8 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
create<ast::SintLiteral>(&f32, 3.14f)), // constructor create<ast::SintLiteral>(&f32, 3.14f)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* cond = auto* cond = create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(); auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body; ast::CaseStatementList body;
@ -87,7 +87,8 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, 1)); csl.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseStatementList body; ast::CaseStatementList body;
@ -125,7 +126,8 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl_1; ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>(); auto* block_default_1 = create<ast::BlockStatement>();
@ -174,7 +176,8 @@ TEST_F(ValidateControlBlockTest,
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(&u32, 1)); csl.push_back(create<ast::UintLiteral>(&u32, 1));
@ -216,7 +219,8 @@ TEST_F(ValidateControlBlockTest,
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl; ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, -1)); csl.push_back(create<ast::SintLiteral>(&i32, -1));
@ -257,7 +261,8 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(&u32, 0)); csl_1.push_back(create<ast::UintLiteral>(&u32, 0));
@ -304,7 +309,8 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::CaseStatementList switch_body; ast::CaseStatementList switch_body;
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList csl_1; ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(&i32, 10)); csl_1.push_back(create<ast::SintLiteral>(&i32, 10));
@ -350,7 +356,8 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(); auto* block_default = create<ast::BlockStatement>();
block_default->append( block_default->append(
@ -386,7 +393,8 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(); auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body; ast::CaseStatementList body;
@ -425,7 +433,8 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
create<ast::SintLiteral>(&u32, 2)), // constructor create<ast::SintLiteral>(&u32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* cond = create<ast::IdentifierExpression>("a"); auto* cond =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
ast::CaseSelectorList default_csl; ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>(); auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body; ast::CaseStatementList body;

View File

@ -237,7 +237,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
ast::ExpressionList call_params; ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>( auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}}, Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), call_params); create<ast::IdentifierExpression>(mod()->RegisterSymbol("func"), "func"),
call_params);
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(); auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::CallStatement>(call_expr)); body0->append(create<ast::CallStatement>(call_expr));
@ -258,7 +259,8 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
ast::ExpressionList call_params; ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>( auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}}, Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), call_params); create<ast::IdentifierExpression>(mod()->RegisterSymbol("func"), "func"),
call_params);
auto* var = auto* var =
create<ast::Variable>(Source{}, // source create<ast::Variable>(Source{}, // source
"a", // name "a", // name
@ -267,6 +269,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
false, // is_const false, // is_const
call_expr, // constructor call_expr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::VariableList params0; ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>(); auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(var)); body0->append(create<ast::VariableDeclStatement>(var));

View File

@ -66,7 +66,8 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
auto* lhs = create<ast::ScalarConstructorExpression>( auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)); create<ast::SintLiteral>(&i32, 1));
auto* rhs = create<ast::IdentifierExpression>("my_var"); auto* rhs = create<ast::IdentifierExpression>(mod()->RegisterSymbol("my_var"),
"my_var");
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs); ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
// TODO(sarahM0): Invalidate assignment to scalar. // TODO(sarahM0): Invalidate assignment to scalar.
@ -79,8 +80,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
// b = 2; // b = 2;
ast::type::I32 i32; ast::type::I32 i32;
auto* lhs = auto* lhs = create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "b"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("b"), "b");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
auto* assign = create<ast::AssignmentStatement>( auto* assign = create<ast::AssignmentStatement>(
@ -97,8 +98,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
// } // }
ast::type::I32 i32; ast::type::I32 i32;
auto* lhs = auto* lhs = create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "b"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("b"), "b");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
@ -125,7 +126,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
@ -155,7 +157,8 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f)); create<ast::FloatLiteral>(&f32, 2.3f));
@ -188,7 +191,8 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
@ -221,7 +225,8 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f)); create<ast::FloatLiteral>(&f32, 2.3f));
@ -323,7 +328,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, "not_global_var"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("not_global_var"),
"not_global_var");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f)); create<ast::FloatLiteral>(&f32, 3.14f));
@ -360,7 +366,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
create<ast::FloatLiteral>(&f32, 2.1)), // constructor create<ast::FloatLiteral>(&f32, 2.1)), // constructor
ast::VariableDecorationList{})); // decorations ast::VariableDecorationList{})); // decorations
auto* lhs = create<ast::IdentifierExpression>("global_var"); auto* lhs = create<ast::IdentifierExpression>(
mod()->RegisterSymbol("global_var"), "global_var");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f)); create<ast::FloatLiteral>(&f32, 3.14f));
@ -404,8 +411,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(var)); body->append(create<ast::VariableDeclStatement>(var));
auto* lhs = auto* lhs = create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f)); create<ast::FloatLiteral>(&f32, 3.14f));
@ -438,8 +445,8 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
create<ast::FloatLiteral>(&f32, 2.0)), // constructor create<ast::FloatLiteral>(&f32, 2.0)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = auto* lhs = create<ast::IdentifierExpression>(
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a"); Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f)); create<ast::FloatLiteral>(&f32, 3.14f));
@ -539,7 +546,8 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
create<ast::SintLiteral>(&i32, 2)), // constructor create<ast::SintLiteral>(&i32, 2)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
@ -802,7 +810,8 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
td()->RegisterVariableForTesting(var); td()->RegisterVariableForTesting(var);
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs =
create<ast::IdentifierExpression>(mod()->RegisterSymbol("a"), "a");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));

View File

@ -33,7 +33,8 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32 i32; ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(&i32, 5); auto* lit = create<ast::SintLiteral>(&i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(lit); auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);
@ -42,8 +43,10 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
} }
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) { TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
auto* idx = create<ast::IdentifierExpression>("idx"); create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<ast::IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);

View File

@ -28,8 +28,10 @@ namespace {
using HlslGeneratorImplTest_Assign = TestHelper; using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) { TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent(); gen.increment_indent();

View File

@ -79,8 +79,10 @@ TEST_P(HlslBinaryTest, Emit_f32) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
@ -113,8 +115,10 @@ TEST_P(HlslBinaryTest, Emit_u32) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
@ -147,8 +151,10 @@ TEST_P(HlslBinaryTest, Emit_i32) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
@ -243,7 +249,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
@ -270,7 +277,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::ScalarConstructorExpression>( auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
auto* rhs = create<ast::IdentifierExpression>("mat"); auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -294,7 +302,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
@ -337,7 +346,8 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals); auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals);
auto* rhs = create<ast::IdentifierExpression>("mat"); auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -361,8 +371,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("mat"); create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -374,8 +386,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
} }
TEST_F(HlslGeneratorImplTest_Binary, Logical_And) { TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, left, right); ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, left, right);
@ -390,10 +404,10 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
// (a && b) || (c || d) // (a && b) || (c || d)
auto* a = create<ast::IdentifierExpression>("a"); auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>("d"); auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
ast::BinaryExpression expr( ast::BinaryExpression expr(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
@ -418,8 +432,10 @@ if (!_tint_tmp_0) {
} }
TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, left, right); ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, left, right);
@ -454,9 +470,10 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
Source{}, create<ast::ScalarConstructorExpression>( Source{}, create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* else_if_stmt = create<ast::ElseStatement>( auto* else_if_stmt = create<ast::ElseStatement>(
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("b"), ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>("c")), create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
body); body);
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
@ -466,9 +483,10 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
ast::IfStatement expr( ast::IfStatement expr(
Source{}, Source{},
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("a"), ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
body, body,
{ {
else_if_stmt, else_if_stmt,
@ -498,9 +516,9 @@ if ((_tint_tmp)) {
TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
// return (a && b) || c; // return (a && b) || c;
auto* a = create<ast::IdentifierExpression>("a"); auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
ast::ReturnStatement expr( ast::ReturnStatement expr(
Source{}, Source{},
@ -523,10 +541,10 @@ return (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
// a = (b || c) && d; // a = (b || c) && d;
auto* a = create<ast::IdentifierExpression>("a"); auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>("d"); auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
ast::AssignmentStatement expr( ast::AssignmentStatement expr(
a, a,
@ -551,9 +569,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
// var a : bool = (b && c) || d; // var a : bool = (b && c) || d;
ast::type::Bool bool_type; ast::type::Bool bool_type;
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
auto* d = create<ast::IdentifierExpression>("d"); auto* d = create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d");
auto* var = create<ast::Variable>( auto* var = create<ast::Variable>(
Source{}, // source Source{}, // source
@ -586,9 +604,9 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
// as<i32>(a && (b || c)) // as<i32>(a && (b || c))
ast::type::I32 i32; ast::type::I32 i32;
auto* a = create<ast::IdentifierExpression>("a"); auto* a = create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a");
auto* b = create<ast::IdentifierExpression>("b"); auto* b = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
auto* c = create<ast::IdentifierExpression>("c"); auto* c = create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c");
ast::BitcastExpression expr(&i32, create<ast::BinaryExpression>( ast::BitcastExpression expr(&i32, create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, a, ast::BinaryOp::kLogicalAnd, a,
@ -620,22 +638,27 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>( params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, create<ast::IdentifierExpression>("a"), ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>("b"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")));
params.push_back(create<ast::BinaryExpression>( params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, create<ast::IdentifierExpression>("c"), ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>("d"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d")));
params.push_back(create<ast::BinaryExpression>( params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("a"), ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>("c")), create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"),
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
create<ast::IdentifierExpression>("b"), create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("d")))); ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"), "d"))));
ast::CallStatement expr(create<ast::CallExpression>( ast::CallStatement expr(create<ast::CallExpression>(
create<ast::IdentifierExpression>("foo"), params)); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
params));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;

View File

@ -31,7 +31,7 @@ using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32 f32; ast::type::F32 f32;
auto* id = create<ast::IdentifierExpression>("id"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&f32, id); ast::BitcastExpression bitcast(&f32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32 i32; ast::type::I32 i32;
auto* id = create<ast::IdentifierExpression>("id"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&i32, id); ast::BitcastExpression bitcast(&i32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32 u32; ast::type::U32 u32;
auto* id = create<ast::IdentifierExpression>("id"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&u32, id); ast::BitcastExpression bitcast(&u32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();

View File

@ -32,7 +32,8 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::CallExpression call(id, {}); ast::CallExpression call(id, {});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -47,10 +48,13 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(id, params); ast::CallExpression call(id, params);
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -65,10 +69,13 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(id, params)); ast::CallStatement call(create<ast::CallExpression>(id, params));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(

View File

@ -32,7 +32,8 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::type::F32 f32; ast::type::F32 f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&f32, params); ast::TypeConstructorExpression cast(&f32, params);
@ -45,7 +46,8 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
ast::type::Vector vec3(&f32, 3); ast::type::Vector vec3(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&vec3, params); ast::TypeConstructorExpression cast(&vec3, params);

View File

@ -84,11 +84,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -157,11 +157,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -230,11 +230,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -302,11 +302,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -371,11 +371,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -435,11 +435,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -506,10 +506,11 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,

View File

@ -171,8 +171,8 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -241,10 +241,11 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params,
@ -304,8 +305,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -375,9 +378,12 @@ TEST_F(HlslGeneratorImplTest_Function,
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("uniforms"), create<ast::IdentifierExpression>(mod.RegisterSymbol("uniforms"),
create<ast::IdentifierExpression>("coord")), "uniforms"),
create<ast::IdentifierExpression>("x")), // constructor create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord")),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -452,8 +458,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("b")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -524,8 +532,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("b")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -592,8 +602,9 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* assign = create<ast::AssignmentStatement>( auto* assign = create<ast::AssignmentStatement>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("b")), "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
@ -683,13 +694,14 @@ TEST_F(
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("val"), create<ast::IdentifierExpression>(mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>("param"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("foo"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -702,8 +714,10 @@ TEST_F(
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
@ -774,7 +788,8 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("param"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -787,8 +802,10 @@ TEST_F(HlslGeneratorImplTest_Function,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
@ -867,12 +884,14 @@ TEST_F(
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("param"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -885,8 +904,10 @@ TEST_F(
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
@ -956,9 +977,11 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{},
create<ast::IdentifierExpression>("coord"), create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -969,13 +992,15 @@ TEST_F(HlslGeneratorImplTest_Function,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
auto* var = create<ast::Variable>( auto* var =
Source{}, // source create<ast::Variable>(Source{}, // source
"v", // name "v", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
@ -1044,9 +1069,11 @@ TEST_F(HlslGeneratorImplTest_Function,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{},
create<ast::IdentifierExpression>("coord"), create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1057,13 +1084,15 @@ TEST_F(HlslGeneratorImplTest_Function,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
auto* var = create<ast::Variable>( auto* var =
Source{}, // source create<ast::Variable>(Source{}, // source
"v", // name "v", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
@ -1119,7 +1148,7 @@ TEST_F(HlslGeneratorImplTest_Function,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)))); create<ast::FloatLiteral>(&f32, 1.0f))));
@ -1326,8 +1355,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -1352,8 +1383,10 @@ TEST_F(HlslGeneratorImplTest_Function,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();

View File

@ -24,14 +24,14 @@ namespace {
using HlslGeneratorImplTest_Identifier = TestHelper; using HlslGeneratorImplTest_Identifier = TestHelper;
TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) { TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) {
ast::IdentifierExpression i("foo"); ast::IdentifierExpression i(mod.RegisterSymbol("foo"), "foo");
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
EXPECT_EQ(result(), "foo"); EXPECT_EQ(result(), "foo");
} }
TEST_F(HlslGeneratorImplTest_Identifier, TEST_F(HlslGeneratorImplTest_Identifier,
EmitIdentifierExpression_Single_WithCollision) { EmitIdentifierExpression_Single_WithCollision) {
ast::IdentifierExpression i("virtual"); ast::IdentifierExpression i(mod.RegisterSymbol("virtual"), "virtual");
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
EXPECT_EQ(result(), "virtual_tint_0"); EXPECT_EQ(result(), "virtual_tint_0");
} }

View File

@ -27,7 +27,8 @@ namespace {
using HlslGeneratorImplTest_If = TestHelper; using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -42,11 +43,13 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -70,7 +73,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -89,7 +93,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
@ -97,7 +102,8 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>(Source{})); else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));

View File

@ -56,7 +56,8 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(param.name); auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name);
ast::CallExpression expr(ident, params); ast::CallExpression expr(ident, params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -101,7 +102,8 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -124,7 +126,8 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f))); create<ast::FloatLiteral>(&f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -169,7 +172,8 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
create<ast::FloatLiteral>(&f32, 6.f)), create<ast::FloatLiteral>(&f32, 6.f)),
})); }));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -194,7 +198,8 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -220,7 +225,8 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f))); create<ast::FloatLiteral>(&f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -253,7 +259,8 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3))); create<ast::SintLiteral>(&i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -278,9 +285,12 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("var")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("var"), "var"));
ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"), ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("determinant"),
"determinant"),
params); params);
mod.AddGlobalVariable(var); mod.AddGlobalVariable(var);

View File

@ -93,10 +93,14 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("a")); params.push_back(
params.push_back(create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"), ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("outer_product"),
"outer_product"),
params); params);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -122,10 +126,14 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
ast::type::Vector vec(&f32, 3); ast::type::Vector vec(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"), params); ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("dot"), "dot"),
params);
ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec, ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});

View File

@ -86,8 +86,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(inner); body->append(inner);
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>(); continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs)); continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
@ -165,8 +167,10 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{}))); // decorations
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs)); continuing->append(create<ast::AssignmentStatement>(lhs, rhs));

View File

@ -66,8 +66,10 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* str = create<ast::IdentifierExpression>("str"); auto* str =
auto* mem = create<ast::IdentifierExpression>("mem"); create<ast::IdentifierExpression>(mod.RegisterSymbol("str"), "str");
auto* mem =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mem"), "mem");
ast::MemberAccessorExpression expr(str, mem); ast::MemberAccessorExpression expr(str, mem);
@ -115,8 +117,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var); gen.register_global(coord_var);
@ -164,8 +167,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var); gen.register_global(coord_var);
@ -226,9 +230,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
auto* rhs = create<ast::IdentifierExpression>("b"); auto* rhs = create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b");
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
@ -289,8 +293,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
auto* rhs = auto* rhs =
create<ast::TypeConstructorExpression>(&mat, ast::ExpressionList{}); create<ast::TypeConstructorExpression>(&mat, ast::ExpressionList{});
@ -349,8 +353,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var); gen.register_global(coord_var);
@ -405,8 +410,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var); gen.register_global(coord_var);
@ -453,8 +459,9 @@ TEST_F(
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
gen.register_global(coord_var); gen.register_global(coord_var);
@ -508,8 +515,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("a")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
@ -562,8 +570,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")), create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
@ -614,8 +622,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")), create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
ast::BinaryOp::kSubtract, ast::BinaryOp::kSubtract,
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
@ -681,8 +689,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f)); create<ast::FloatLiteral>(&f32, 2.0f));
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
@ -736,8 +744,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* lhs = create<ast::ArrayAccessorExpression>( auto* lhs = create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")), create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
@ -793,8 +801,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)); create<ast::SintLiteral>(&i32, 2));
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
@ -849,8 +857,9 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("data"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -910,8 +919,8 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
values.push_back(create<ast::ScalarConstructorExpression>(lit3)); values.push_back(create<ast::ScalarConstructorExpression>(lit3));
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"), "data"),
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values); auto* rhs = create<ast::TypeConstructorExpression>(&fvec3, values);
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
@ -988,11 +997,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1066,12 +1076,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>("xy")); create<ast::IdentifierExpression>(mod.RegisterSymbol("xy"), "xy"));
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1144,12 +1156,14 @@ TEST_F(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>("g")); create<ast::IdentifierExpression>(mod.RegisterSymbol("g"), "g"));
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
@ -1221,11 +1235,13 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
@ -1298,11 +1314,12 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"), "c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
auto* lit1 = create<ast::FloatLiteral>(&f32, 1.f); auto* lit1 = create<ast::FloatLiteral>(&f32, 1.f);
auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f); auto* lit2 = create<ast::FloatLiteral>(&f32, 2.f);
@ -1388,12 +1405,14 @@ TEST_F(HlslGeneratorImplTest_MemberAccessor,
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("c")), "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("c"),
"c")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b")),
create<ast::IdentifierExpression>("y")); create<ast::IdentifierExpression>(mod.RegisterSymbol("y"), "y"));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&i32, 1.f)); create<ast::FloatLiteral>(&i32, 1.f));

View File

@ -36,7 +36,8 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
} }
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) { TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::ReturnStatement r(Source{}, expr); ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();

View File

@ -48,7 +48,8 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
body.push_back(case_stmt); body.push_back(case_stmt);
body.push_back(def); body.push_back(def);
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body); ast::SwitchStatement s(cond, body);
gen.increment_indent(); gen.increment_indent();

View File

@ -56,7 +56,8 @@ TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) {
TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) { TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) {
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
ast::IdentifierExpression ident("func_main_in"); ast::IdentifierExpression ident(mod.RegisterSymbol("func_main_in"),
"func_main_in");
ASSERT_TRUE(gen.EmitIdentifier(pre, out, &ident)); ASSERT_TRUE(gen.EmitIdentifier(pre, out, &ident));
EXPECT_EQ(result(), "func_main_in_0"); EXPECT_EQ(result(), "func_main_in_0");
} }

View File

@ -37,7 +37,8 @@ using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(HlslUnaryOpTest, Emit) { TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(params.op, expr); ast::UnaryOpExpression op(params.op, expr);
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error();

View File

@ -127,7 +127,8 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_Private) { Emit_VariableDeclStatement_Initializer_Private) {
auto* ident = create<ast::IdentifierExpression>("initializer"); auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol("initializer"), "initializer");
ast::type::F32 f32; ast::type::F32 f32;
auto* var = auto* var =

View File

@ -35,7 +35,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
ast::type::I32 i32; ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(&i32, 5); auto* lit = create<ast::SintLiteral>(&i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(lit); auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);
@ -44,8 +45,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) {
} }
TEST_F(MslGeneratorImplTest, EmitArrayAccessor) { TEST_F(MslGeneratorImplTest, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
auto* idx = create<ast::IdentifierExpression>("idx"); create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<ast::IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);

View File

@ -30,8 +30,10 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Assign) { TEST_F(MslGeneratorImplTest, Emit_Assign) {
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(lhs, rhs); ast::AssignmentStatement assign(lhs, rhs);
gen.increment_indent(); gen.increment_indent();

View File

@ -38,8 +38,10 @@ using MslBinaryTest = TestParamHelper<BinaryData>;
TEST_P(MslBinaryTest, Emit) { TEST_P(MslBinaryTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto* left = create<ast::IdentifierExpression>("left"); auto* left =
auto* right = create<ast::IdentifierExpression>("right"); create<ast::IdentifierExpression>(mod.RegisterSymbol("left"), "left");
auto* right =
create<ast::IdentifierExpression>(mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(params.op, left, right); ast::BinaryExpression expr(params.op, left, right);

View File

@ -31,7 +31,7 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) { TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) {
ast::type::F32 f32; ast::type::F32 f32;
auto* id = create<ast::IdentifierExpression>("id"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(&f32, id); ast::BitcastExpression bitcast(&f32, id);
ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error();

View File

@ -34,7 +34,8 @@ using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::CallExpression call(id, {}); ast::CallExpression call(id, {});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -49,10 +50,13 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) {
TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(id, params); ast::CallExpression call(id, params);
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -67,10 +71,13 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) {
TEST_F(MslGeneratorImplTest, EmitStatement_Call) { TEST_F(MslGeneratorImplTest, EmitStatement_Call) {
ast::type::Void void_type; ast::type::Void void_type;
auto* id = create<ast::IdentifierExpression>("my_func"); auto* id = create<ast::IdentifierExpression>(mod.RegisterSymbol("my_func"),
"my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(create<ast::CallExpression>(id, params)); ast::CallStatement call(create<ast::CallExpression>(id, params));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(

View File

@ -34,7 +34,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) {
ast::type::F32 f32; ast::type::F32 f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&f32, params); ast::TypeConstructorExpression cast(&f32, params);
@ -47,7 +48,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) {
ast::type::Vector vec3(&f32, 3); ast::type::Vector vec3(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("id")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(&vec3, params); ast::TypeConstructorExpression cast(&vec3, params);

View File

@ -83,11 +83,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -153,11 +153,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body,
@ -223,11 +223,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
@ -292,11 +292,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -359,11 +359,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -421,11 +421,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar")));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body,
@ -490,10 +490,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body,

View File

@ -179,8 +179,8 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) {
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -252,10 +252,11 @@ TEST_F(MslGeneratorImplTest,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
@ -315,8 +316,10 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) {
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"),
"x")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -392,8 +395,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("b")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -474,8 +479,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("b")), // constructor "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"),
"b")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -571,13 +578,14 @@ TEST_F(
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("val"), create<ast::IdentifierExpression>(mod.RegisterSymbol("val"), "val"),
create<ast::IdentifierExpression>("param"))); create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("foo"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("foo"), "foo")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -590,8 +598,10 @@ TEST_F(
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
@ -665,7 +675,8 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("param"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -678,8 +689,10 @@ TEST_F(MslGeneratorImplTest,
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -762,12 +775,14 @@ TEST_F(
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
create<ast::IdentifierExpression>("x")))); "coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("param"))); Source{},
create<ast::IdentifierExpression>(mod.RegisterSymbol("param"), "param")));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -780,8 +795,10 @@ TEST_F(
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>(mod.RegisterSymbol("depth"), "depth"),
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(mod.RegisterSymbol("sub_func"),
"sub_func"),
expr))); expr)));
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
auto* func_1 = create<ast::Function>( auto* func_1 = create<ast::Function>(
@ -849,9 +866,11 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{},
create<ast::IdentifierExpression>("coord"), create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("x"), "x"))));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -862,13 +881,15 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
auto* var = create<ast::Variable>( auto* var =
Source{}, // source create<ast::Variable>(Source{}, // source
"v", // name "v", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
@ -951,9 +972,11 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{},
create<ast::IdentifierExpression>("coord"), create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"))));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -964,13 +987,15 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
auto* var = create<ast::Variable>( auto* var =
Source{}, // source create<ast::Variable>(Source{}, // source
"v", // name "v", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
@ -1059,9 +1084,11 @@ TEST_F(MslGeneratorImplTest,
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::MemberAccessorExpression>( Source{},
create<ast::IdentifierExpression>("coord"), create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("b")))); create<ast::IdentifierExpression>(mod.RegisterSymbol("coord"),
"coord"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"))));
auto* sub_func = create<ast::Function>( auto* sub_func = create<ast::Function>(
Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body,
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
@ -1072,13 +1099,15 @@ TEST_F(MslGeneratorImplTest,
expr.push_back(create<ast::ScalarConstructorExpression>( expr.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
auto* var = create<ast::Variable>( auto* var =
Source{}, // source create<ast::Variable>(Source{}, // source
"v", // name "v", // name
ast::StorageClass::kFunction, // storage_class ast::StorageClass::kFunction, // storage_class
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::CallExpression>(create<ast::IdentifierExpression>("sub_func"), create<ast::CallExpression>(
create<ast::IdentifierExpression>(
mod.RegisterSymbol("sub_func"), "sub_func"),
expr), // constructor expr), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
@ -1141,7 +1170,7 @@ TEST_F(MslGeneratorImplTest,
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>(mod.RegisterSymbol("bar"), "bar"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)))); create<ast::FloatLiteral>(&f32, 1.0f))));
@ -1306,8 +1335,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -1333,8 +1364,10 @@ TEST_F(MslGeneratorImplTest,
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod.RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod.RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();

View File

@ -26,14 +26,14 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) { TEST_F(MslGeneratorImplTest, EmitIdentifierExpression) {
ast::IdentifierExpression i("foo"); ast::IdentifierExpression i(mod.RegisterSymbol("foo"), "foo");
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
EXPECT_EQ(gen.result(), "foo"); EXPECT_EQ(gen.result(), "foo");
} }
TEST_F(MslGeneratorImplTest, EmitIdentifierExpression_Single_WithCollision) { TEST_F(MslGeneratorImplTest, EmitIdentifierExpression_Single_WithCollision) {
ast::IdentifierExpression i("virtual"); ast::IdentifierExpression i(mod.RegisterSymbol("virtual"), "virtual");
ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(&i)) << gen.error();
EXPECT_EQ(gen.result(), "virtual_tint_0"); EXPECT_EQ(gen.result(), "virtual_tint_0");

View File

@ -29,7 +29,8 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_If) { TEST_F(MslGeneratorImplTest, Emit_If) {
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -45,11 +46,13 @@ TEST_F(MslGeneratorImplTest, Emit_If) {
} }
TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -71,7 +74,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));
@ -90,7 +94,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) {
} }
TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) { TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>("else_cond"); auto* else_cond = create<ast::IdentifierExpression>(
mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append(create<ast::ReturnStatement>(Source{})); else_body->append(create<ast::ReturnStatement>(Source{}));
@ -98,7 +103,8 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) {
auto* else_body_2 = create<ast::BlockStatement>(); auto* else_body_2 = create<ast::BlockStatement>();
else_body_2->append(create<ast::ReturnStatement>(Source{})); else_body_2->append(create<ast::ReturnStatement>(Source{}));
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(Source{})); body->append(create<ast::ReturnStatement>(Source{}));

View File

@ -57,7 +57,8 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(param.name); auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name);
ast::CallExpression call(ident, params); ast::CallExpression call(ident, params);
@ -100,7 +101,9 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
ast::CallExpression expr(create<ast::IdentifierExpression>("abs"), params); ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("abs"), "abs"),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -120,7 +123,8 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f))); create<ast::FloatLiteral>(&f32, 2.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -168,7 +172,8 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) {
create<ast::FloatLiteral>(&f32, 6.f)), create<ast::FloatLiteral>(&f32, 6.f)),
})); }));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -193,7 +198,8 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -219,7 +225,8 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.f))); create<ast::FloatLiteral>(&f32, 3.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -250,7 +257,8 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) {
params.push_back(create<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3))); create<ast::SintLiteral>(&i32, 3)));
ast::CallExpression expr(create<ast::IdentifierExpression>(param.name), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod.RegisterSymbol(param.name), param.name),
params); params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -277,9 +285,12 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("var")); params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("var"), "var"));
ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"), ast::CallExpression expr(
create<ast::IdentifierExpression>(mod.RegisterSymbol("determinant"),
"determinant"),
params); params);
mod.AddGlobalVariable(var); mod.AddGlobalVariable(var);

View File

@ -88,10 +88,14 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("a")); params.push_back(
params.push_back(create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod.RegisterSymbol("a"), "a"));
params.push_back(
create<ast::IdentifierExpression>(mod.RegisterSymbol("b"), "b"));
ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"), ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("outer_product"),
"outer_product"),
params); params);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -117,10 +121,14 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) {
ast::type::Vector vec(&f32, 3); ast::type::Vector vec(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>(
params.push_back(create<ast::IdentifierExpression>("param2")); mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(create<ast::IdentifierExpression>("dot"), params); ast::CallExpression call(
create<ast::IdentifierExpression>(mod.RegisterSymbol("dot"), "dot"),
params);
ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec, ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});

View File

@ -90,8 +90,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) {
body = create<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(inner); body->append(inner);
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>(); continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs)); continuing->append(create<ast::AssignmentStatement>(lhs, rhs));
@ -170,8 +172,10 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{}))); // decorations
auto* lhs = create<ast::IdentifierExpression>("lhs"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("rhs"); create<ast::IdentifierExpression>(mod.RegisterSymbol("lhs"), "lhs");
auto* rhs =
create<ast::IdentifierExpression>(mod.RegisterSymbol("rhs"), "rhs");
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append(create<ast::AssignmentStatement>(lhs, rhs)); continuing->append(create<ast::AssignmentStatement>(lhs, rhs));

View File

@ -29,8 +29,10 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) { TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) {
auto* str = create<ast::IdentifierExpression>("str"); auto* str =
auto* mem = create<ast::IdentifierExpression>("mem"); create<ast::IdentifierExpression>(mod.RegisterSymbol("str"), "str");
auto* mem =
create<ast::IdentifierExpression>(mod.RegisterSymbol("mem"), "mem");
ast::MemberAccessorExpression expr(str, mem); ast::MemberAccessorExpression expr(str, mem);

View File

@ -39,7 +39,8 @@ TEST_F(MslGeneratorImplTest, Emit_Return) {
} }
TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) { TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::ReturnStatement r(Source{}, expr); ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();

View File

@ -50,7 +50,8 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) {
body.push_back(case_stmt); body.push_back(case_stmt);
body.push_back(def); body.push_back(def);
auto* cond = create<ast::IdentifierExpression>("cond"); auto* cond =
create<ast::IdentifierExpression>(mod.RegisterSymbol("cond"), "cond");
ast::SwitchStatement s(cond, body); ast::SwitchStatement s(cond, body);
gen.increment_indent(); gen.increment_indent();

View File

@ -79,7 +79,8 @@ TEST_F(MslGeneratorImplTest, InputStructName_ConflictWithExisting) {
TEST_F(MslGeneratorImplTest, NameConflictWith_InputStructName) { TEST_F(MslGeneratorImplTest, NameConflictWith_InputStructName) {
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
ast::IdentifierExpression ident("func_main_in"); ast::IdentifierExpression ident(mod.RegisterSymbol("func_main_in"),
"func_main_in");
ASSERT_TRUE(gen.EmitIdentifier(&ident)); ASSERT_TRUE(gen.EmitIdentifier(&ident));
EXPECT_EQ(gen.result(), "func_main_in_0"); EXPECT_EQ(gen.result(), "func_main_in_0");
} }

View File

@ -39,7 +39,8 @@ using MslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(MslUnaryOpTest, Emit) { TEST_P(MslUnaryOpTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto* expr = create<ast::IdentifierExpression>("expr"); auto* expr =
create<ast::IdentifierExpression>(mod.RegisterSymbol("expr"), "expr");
ast::UnaryOpExpression op(params.op, expr); ast::UnaryOpExpression op(params.op, expr);
ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error();

View File

@ -193,7 +193,8 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
} }
TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) {
auto* ident = create<ast::IdentifierExpression>("initializer"); auto* ident = create<ast::IdentifierExpression>(
mod.RegisterSymbol("initializer"), "initializer");
ast::type::F32 f32; ast::type::F32 f32;
auto* var = auto* var =

View File

@ -56,7 +56,8 @@ TEST_F(BuilderTest, ArrayAccessor) {
ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false, ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
auto* idx_expr = create<ast::ScalarConstructorExpression>( auto* idx_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)); create<ast::SintLiteral>(&i32, 1));
@ -100,8 +101,10 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
ast::Variable idx(Source{}, "idx", ast::StorageClass::kFunction, &i32, false, ast::Variable idx(Source{}, "idx", ast::StorageClass::kFunction, &i32, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
auto* idx_expr = create<ast::IdentifierExpression>("idx"); create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
auto* idx_expr =
create<ast::IdentifierExpression>(mod->RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx_expr); ast::ArrayAccessorExpression expr(ary, idx_expr);
@ -145,7 +148,8 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false, ast::Variable var(Source{}, "ary", ast::StorageClass::kFunction, &vec3, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
ary, ary,
@ -195,7 +199,7 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("ary"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3))), create<ast::SintLiteral>(&i32, 3))),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
@ -243,10 +247,10 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("ary"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ary"), "ary"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("xy")); create<ast::IdentifierExpression>(mod->RegisterSymbol("xy"), "xy"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -298,8 +302,9 @@ TEST_F(BuilderTest, MemberAccessor) {
ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &s_type, ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &s_type,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -355,9 +360,11 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("inner")), "ident"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -416,9 +423,11 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("inner")), "ident"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -476,9 +485,11 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
auto* lhs = create<ast::MemberAccessorExpression>( auto* lhs = create<ast::MemberAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("inner")), "ident"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.f)); create<ast::FloatLiteral>(&f32, 2.f));
@ -543,13 +554,16 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
ast::Variable store(Source{}, "store", ast::StorageClass::kFunction, &f32, ast::Variable store(Source{}, "store", ast::StorageClass::kFunction, &f32,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
auto* lhs = create<ast::IdentifierExpression>("store"); auto* lhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("store"), "store");
auto* rhs = create<ast::MemberAccessorExpression>( auto* rhs = create<ast::MemberAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("inner")), "ident"),
create<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>(mod->RegisterSymbol("inner"),
"inner")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"));
ast::AssignmentStatement expr(lhs, rhs); ast::AssignmentStatement expr(lhs, rhs);
@ -593,8 +607,9 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &vec3, ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &vec3,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("y")); create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("y"), "y"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -629,8 +644,9 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &vec3, ast::Variable var(Source{}, "ident", ast::StorageClass::kFunction, &vec3,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"), ast::MemberAccessorExpression expr(
create<ast::IdentifierExpression>("yx")); create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yx"), "yx"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -666,9 +682,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("yxz")), "ident"),
create<ast::IdentifierExpression>("xz")); create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("xz"), "xz"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -705,9 +722,10 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("yxz")), "ident"),
create<ast::IdentifierExpression>("x")); create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("x"), "x"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -744,8 +762,9 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"),
create<ast::IdentifierExpression>("yxz")), "ident"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yxz"), "yxz")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
@ -818,15 +837,18 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("index"), create<ast::IdentifierExpression>(
mod->RegisterSymbol("index"), "index"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 0))), create<ast::SintLiteral>(&i32, 0))),
create<ast::IdentifierExpression>("foo")), create<ast::IdentifierExpression>(
mod->RegisterSymbol("foo"), "foo")),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
create<ast::IdentifierExpression>("bar")), create<ast::IdentifierExpression>(mod->RegisterSymbol("bar"),
create<ast::IdentifierExpression>("baz")), "bar")),
create<ast::IdentifierExpression>("yx")); create<ast::IdentifierExpression>(mod->RegisterSymbol("baz"), "baz")),
create<ast::IdentifierExpression>(mod->RegisterSymbol("yx"), "yx"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -906,7 +928,8 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
create<ast::TypeConstructorExpression>(&arr, ary_params), create<ast::TypeConstructorExpression>(&arr, ary_params),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(create<ast::IdentifierExpression>("pos"), ast::ArrayAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("pos"), "pos"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
@ -963,7 +986,8 @@ TEST_F(BuilderTest, Accessor_Const_Vec) {
create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)), create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
ast::ArrayAccessorExpression expr(create<ast::IdentifierExpression>("pos"), ast::ArrayAccessorExpression expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("pos"), "pos"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));

View File

@ -47,7 +47,8 @@ TEST_F(BuilderTest, Assign_Var) {
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &f32, false, ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &f32, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::IdentifierExpression>("var"); auto* ident =
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
auto* val = create<ast::ScalarConstructorExpression>( auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)); create<ast::FloatLiteral>(&f32, 1.0f));
@ -82,7 +83,8 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec, false, ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::IdentifierExpression>("var"); auto* ident =
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
ast::ExpressionList vals; ast::ExpressionList vals;
auto* val = create<ast::TypeConstructorExpression>(&vec, vals); auto* val = create<ast::TypeConstructorExpression>(&vec, vals);
@ -133,7 +135,8 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false, ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"), ast::AssignmentStatement assign(
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
init); init);
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
@ -182,7 +185,8 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false, ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"), ast::AssignmentStatement assign(
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
init); init);
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
@ -231,8 +235,8 @@ TEST_F(BuilderTest, Assign_StructMember) {
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::MemberAccessorExpression>( auto* ident = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>(mod->RegisterSymbol("ident"), "ident"),
create<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b"));
auto* val = create<ast::ScalarConstructorExpression>( auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 4.0f)); create<ast::FloatLiteral>(&f32, 4.0f));
@ -273,7 +277,8 @@ TEST_F(BuilderTest, Assign_Vector) {
ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false, ast::Variable v(Source{}, "var", ast::StorageClass::kOutput, &vec3, false,
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::IdentifierExpression>("var"); auto* ident =
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
@ -322,8 +327,8 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::MemberAccessorExpression>( auto* ident = create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
create<ast::IdentifierExpression>("y")); create<ast::IdentifierExpression>(mod->RegisterSymbol("y"), "y"));
auto* val = create<ast::ScalarConstructorExpression>( auto* val = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)); create<ast::FloatLiteral>(&f32, 1.0f));
@ -368,7 +373,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
nullptr, ast::VariableDecorationList{}); nullptr, ast::VariableDecorationList{});
auto* ident = create<ast::ArrayAccessorExpression>( auto* ident = create<ast::ArrayAccessorExpression>(
create<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto* val = create<ast::ScalarConstructorExpression>( auto* val = create<ast::ScalarConstructorExpression>(

View File

@ -124,8 +124,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &i32, ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &i32,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
auto* lhs = create<ast::IdentifierExpression>("param"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("param"); create<ast::IdentifierExpression>(mod->RegisterSymbol("param"), "param");
auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("param"), "param");
ast::BinaryExpression expr(param.op, lhs, rhs); ast::BinaryExpression expr(param.op, lhs, rhs);
@ -642,7 +644,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::ScalarConstructorExpression>( auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
@ -683,7 +686,8 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::ScalarConstructorExpression>( auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
auto* rhs = create<ast::IdentifierExpression>("mat"); auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -721,7 +725,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
@ -779,7 +784,8 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals); auto* lhs = create<ast::TypeConstructorExpression>(&vec3, vals);
auto* rhs = create<ast::IdentifierExpression>("mat"); auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -818,8 +824,10 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
false, // is_const false, // is_const
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("mat"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("mat"); create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
@ -911,8 +919,8 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
create<ast::BoolLiteral>(&bool_type, false)), // constructor create<ast::BoolLiteral>(&bool_type, false)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs = create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a");
auto* rhs = create<ast::IdentifierExpression>("b"); auto* rhs = create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b");
td.RegisterVariableForTesting(a_var); td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var); td.RegisterVariableForTesting(b_var);
@ -1107,8 +1115,8 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
create<ast::BoolLiteral>(&bool_type, false)), // constructor create<ast::BoolLiteral>(&bool_type, false)), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>("a"); auto* lhs = create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a");
auto* rhs = create<ast::IdentifierExpression>("b"); auto* rhs = create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b");
td.RegisterVariableForTesting(a_var); td.RegisterVariableForTesting(a_var);
td.RegisterVariableForTesting(b_var); td.RegisterVariableForTesting(b_var);

View File

@ -50,7 +50,7 @@ TEST_F(BuilderTest, Block) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{}))); // decorations
outer.append(create<ast::AssignmentStatement>( outer.append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.0f)))); create<ast::FloatLiteral>(&f32, 1.0f))));
@ -64,13 +64,13 @@ TEST_F(BuilderTest, Block) {
nullptr, // constructor nullptr, // constructor
ast::VariableDecorationList{}))); // decorations ast::VariableDecorationList{}))); // decorations
inner->append(create<ast::AssignmentStatement>( inner->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.0f)))); create<ast::FloatLiteral>(&f32, 2.0f))));
outer.append(inner); outer.append(inner);
outer.append(create<ast::AssignmentStatement>( outer.append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.0f)))); create<ast::FloatLiteral>(&f32, 3.0f))));

View File

@ -1,3 +1,4 @@
// Copyright 2020 The Tint Authors. // Copyright 2020 The Tint Authors.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
@ -62,9 +63,11 @@ TEST_F(BuilderTest, Expression_Call) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>( Source{},
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"), create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("b")))); ast::BinaryOp::kAdd,
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b"))));
ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func",
func_params, &f32, body, ast::FunctionDecorationList{}); func_params, &f32, body, ast::FunctionDecorationList{});
@ -78,7 +81,8 @@ TEST_F(BuilderTest, Expression_Call) {
call_params.push_back(create<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallExpression expr(create<ast::IdentifierExpression>("a_func"), ast::CallExpression expr(create<ast::IdentifierExpression>(
mod->RegisterSymbol("a_func"), "a_func"),
call_params); call_params);
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error(); ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
@ -139,9 +143,11 @@ TEST_F(BuilderTest, Statement_Call) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::BinaryExpression>( Source{},
ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"), create<ast::BinaryExpression>(
create<ast::IdentifierExpression>("b")))); ast::BinaryOp::kAdd,
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("b"), "b"))));
ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func",
func_params, &void_type, body, func_params, &void_type, body,
@ -157,8 +163,10 @@ TEST_F(BuilderTest, Statement_Call) {
call_params.push_back(create<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallStatement expr(create<ast::CallExpression>( ast::CallStatement expr(
create<ast::IdentifierExpression>("a_func"), call_params)); create<ast::CallExpression>(create<ast::IdentifierExpression>(
mod->RegisterSymbol("a_func"), "a_func"),
call_params));
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();

View File

@ -165,15 +165,20 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("my_out"), create<ast::IdentifierExpression>(mod->RegisterSymbol("my_out"),
create<ast::IdentifierExpression>("my_in"))); "my_out"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("my_in"),
"my_in")));
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("my_wg"), create<ast::IdentifierExpression>(mod->RegisterSymbol("my_wg"), "my_wg"),
create<ast::IdentifierExpression>("my_wg"))); create<ast::IdentifierExpression>(mod->RegisterSymbol("my_wg"),
"my_wg")));
// Add duplicate usages so we show they don't get output multiple times. // Add duplicate usages so we show they don't get output multiple times.
body->append(create<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>("my_out"), create<ast::IdentifierExpression>(mod->RegisterSymbol("my_out"),
create<ast::IdentifierExpression>("my_in"))); "my_out"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("my_in"),
"my_in")));
ast::Function func( ast::Function func(
Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, body, Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, body,

View File

@ -98,7 +98,8 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("a"))); Source{},
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a")));
ASSERT_TRUE(td.DetermineResultType(body)) << td.error(); ASSERT_TRUE(td.DetermineResultType(body)) << td.error();
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {},
@ -167,7 +168,8 @@ TEST_F(BuilderTest, Function_WithParams) {
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(
Source{}, create<ast::IdentifierExpression>("a"))); Source{},
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a")));
ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", params, ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", params,
&f32, body, ast::FunctionDecorationList{}); &f32, body, ast::FunctionDecorationList{});
@ -299,8 +301,10 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod->RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
@ -326,8 +330,10 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
&f32, // type &f32, // type
false, // is_const false, // is_const
create<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
create<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>(mod->RegisterSymbol("data"),
create<ast::IdentifierExpression>("d")), // constructor "data"),
create<ast::IdentifierExpression>(mod->RegisterSymbol("d"),
"d")), // constructor
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();

View File

@ -168,8 +168,9 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructorLoadedFromVar) {
init, ast::VariableDecorationList{}); init, ast::VariableDecorationList{});
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
ast::Variable v2(Source{}, "v2", ast::StorageClass::kFunction, &f32, false, ast::Variable v2(
create<ast::IdentifierExpression>("v"), Source{}, "v2", ast::StorageClass::kFunction, &f32, false,
create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
td.RegisterVariableForTesting(&v2); td.RegisterVariableForTesting(&v2);
@ -214,8 +215,9 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
init, ast::VariableDecorationList{}); init, ast::VariableDecorationList{});
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
ast::Variable v2(Source{}, "v2", ast::StorageClass::kFunction, &f32, true, ast::Variable v2(
create<ast::IdentifierExpression>("v"), Source{}, "v2", ast::StorageClass::kFunction, &f32, true,
create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
ast::VariableDecorationList{}); ast::VariableDecorationList{});
td.RegisterVariableForTesting(&v2); td.RegisterVariableForTesting(&v2);

View File

@ -68,7 +68,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
%5 = OpConstantComposite %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
)"); )");
ast::IdentifierExpression expr("var"); ast::IdentifierExpression expr(mod->RegisterSymbol("var"), "var");
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 5u); EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 5u);
@ -91,7 +91,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
%1 = OpVariable %2 Output %4 %1 = OpVariable %2 Output %4
)"); )");
ast::IdentifierExpression expr("var"); ast::IdentifierExpression expr(mod->RegisterSymbol("var"), "var");
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 1u); EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 1u);
} }
@ -126,7 +126,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
%5 = OpConstantComposite %1 %3 %3 %4 %5 = OpConstantComposite %1 %3 %3 %4
)"); )");
ast::IdentifierExpression expr("var"); ast::IdentifierExpression expr(mod->RegisterSymbol("var"), "var");
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 5u); EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 5u);
} }
@ -152,7 +152,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
R"(%1 = OpVariable %2 Function %4 R"(%1 = OpVariable %2 Function %4
)"); )");
ast::IdentifierExpression expr("var"); ast::IdentifierExpression expr(mod->RegisterSymbol("var"), "var");
ASSERT_TRUE(td.DetermineResultType(&expr)); ASSERT_TRUE(td.DetermineResultType(&expr));
EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 1u); EXPECT_EQ(b.GenerateIdentifierExpression(&expr), 1u);
} }
@ -165,8 +165,10 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
auto* lhs = create<ast::IdentifierExpression>("var"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("var"); create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
ast::BinaryExpression expr(ast::BinaryOp::kAdd, lhs, rhs); ast::BinaryExpression expr(ast::BinaryOp::kAdd, lhs, rhs);
@ -198,8 +200,10 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
auto* lhs = create<ast::IdentifierExpression>("var"); auto* lhs =
auto* rhs = create<ast::IdentifierExpression>("var"); create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
auto* rhs =
create<ast::IdentifierExpression>(mod->RegisterSymbol("var"), "var");
ast::BinaryExpression expr(ast::BinaryOp::kAdd, lhs, rhs); ast::BinaryExpression expr(ast::BinaryOp::kAdd, lhs, rhs);

View File

@ -85,8 +85,8 @@ TEST_F(BuilderTest, If_WithStatements) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
@ -139,14 +139,14 @@ TEST_F(BuilderTest, If_WithElse) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append( else_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
@ -205,14 +205,14 @@ TEST_F(BuilderTest, If_WithElseIf) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append( else_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
@ -283,23 +283,23 @@ TEST_F(BuilderTest, If_WithMultiple) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* elseif_1_body = create<ast::BlockStatement>(); auto* elseif_1_body = create<ast::BlockStatement>();
elseif_1_body->append( elseif_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
auto* elseif_2_body = create<ast::BlockStatement>(); auto* elseif_2_body = create<ast::BlockStatement>();
elseif_2_body->append( elseif_2_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 4)))); create<ast::SintLiteral>(&i32, 4))));
auto* else_body = create<ast::BlockStatement>(); auto* else_body = create<ast::BlockStatement>();
else_body->append( else_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 5)))); create<ast::SintLiteral>(&i32, 5))));
@ -643,9 +643,10 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::IfStatement expr(Source{}, create<ast::IdentifierExpression>("a"), ast::IfStatement expr(
create<ast::BlockStatement>(), Source{},
ast::ElseStatementList{}); create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"),
create<ast::BlockStatement>(), ast::ElseStatementList{});
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -75,8 +75,8 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
@ -128,14 +128,14 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>(); auto* body = create<ast::BlockStatement>();
body->append( body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* continuing = create<ast::BlockStatement>(); auto* continuing = create<ast::BlockStatement>();
continuing->append( continuing->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::LoopStatement expr(body, continuing); ast::LoopStatement expr(body, continuing);

View File

@ -84,8 +84,9 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &f32, ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &f32,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
ast::ReturnStatement ret(Source{}, ast::ReturnStatement ret(
create<ast::IdentifierExpression>("param")); Source{},
create<ast::IdentifierExpression>(mod->RegisterSymbol("param"), "param"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();

View File

@ -94,14 +94,14 @@ TEST_F(BuilderTest, Switch_WithCase) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(); auto* case_1_body = create<ast::BlockStatement>();
case_1_body->append( case_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
auto* case_2_body = create<ast::BlockStatement>(); auto* case_2_body = create<ast::BlockStatement>();
case_2_body->append( case_2_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
@ -115,7 +115,8 @@ TEST_F(BuilderTest, Switch_WithCase) {
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body)); cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body)); cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -187,15 +188,16 @@ TEST_F(BuilderTest, Switch_WithDefault) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* default_body = create<ast::BlockStatement>(); auto* default_body = create<ast::BlockStatement>();
default_body->append( default_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(default_body)); cases.push_back(create<ast::CaseStatement>(default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -265,20 +267,20 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(); auto* case_1_body = create<ast::BlockStatement>();
case_1_body->append( case_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
auto* case_2_body = create<ast::BlockStatement>(); auto* case_2_body = create<ast::BlockStatement>();
case_2_body->append( case_2_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* default_body = create<ast::BlockStatement>(); auto* default_body = create<ast::BlockStatement>();
default_body->append( default_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
@ -294,7 +296,8 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body)); cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(default_body)); cases.push_back(create<ast::CaseStatement>(default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -373,21 +376,21 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(); auto* case_1_body = create<ast::BlockStatement>();
case_1_body->append( case_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
case_1_body->append(create<ast::FallthroughStatement>()); case_1_body->append(create<ast::FallthroughStatement>());
auto* case_2_body = create<ast::BlockStatement>(); auto* case_2_body = create<ast::BlockStatement>();
case_2_body->append( case_2_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto* default_body = create<ast::BlockStatement>(); auto* default_body = create<ast::BlockStatement>();
default_body->append( default_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
@ -402,7 +405,8 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body)); cases.push_back(create<ast::CaseStatement>(selector_2, case_2_body));
cases.push_back(create<ast::CaseStatement>(default_body)); cases.push_back(create<ast::CaseStatement>(default_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -477,8 +481,8 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
ast::VariableDecorationList{}); // decorations ast::VariableDecorationList{}); // decorations
auto* case_1_body = create<ast::BlockStatement>(); auto* case_1_body = create<ast::BlockStatement>();
case_1_body->append( case_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
case_1_body->append(create<ast::FallthroughStatement>()); case_1_body->append(create<ast::FallthroughStatement>());
@ -489,7 +493,8 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body)); cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
@ -546,8 +551,8 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
create<ast::BoolLiteral>(&bool_type, true)), create<ast::BoolLiteral>(&bool_type, true)),
if_body, ast::ElseStatementList{})); if_body, ast::ElseStatementList{}));
case_1_body->append( case_1_body->append(create<ast::AssignmentStatement>(
create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"), create<ast::IdentifierExpression>(mod->RegisterSymbol("v"), "v"),
create<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
@ -557,7 +562,8 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body)); cases.push_back(create<ast::CaseStatement>(selector_1, case_1_body));
ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"), cases); ast::SwitchStatement expr(
create<ast::IdentifierExpression>(mod->RegisterSymbol("a"), "a"), cases);
td.RegisterVariableForTesting(v); td.RegisterVariableForTesting(v);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);

View File

@ -101,8 +101,9 @@ TEST_F(BuilderTest, UnaryOp_LoadRequired) {
ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &vec, ast::Variable var(Source{}, "param", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{}); false, nullptr, ast::VariableDecorationList{});
ast::UnaryOpExpression expr(ast::UnaryOp::kNegation, ast::UnaryOpExpression expr(
create<ast::IdentifierExpression>("param")); ast::UnaryOp::kNegation,
create<ast::IdentifierExpression>(mod->RegisterSymbol("param"), "param"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -34,7 +34,8 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_ArrayAccessor) {
ast::type::I32 i32; ast::type::I32 i32;
auto* lit = create<ast::SintLiteral>(&i32, 5); auto* lit = create<ast::SintLiteral>(&i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(lit); auto* idx = create<ast::ScalarConstructorExpression>(lit);
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);
@ -43,8 +44,10 @@ TEST_F(WgslGeneratorImplTest, EmitExpression_ArrayAccessor) {
} }
TEST_F(WgslGeneratorImplTest, EmitArrayAccessor) { TEST_F(WgslGeneratorImplTest, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>("ary"); auto* ary =
auto* idx = create<ast::IdentifierExpression>("idx"); create<ast::IdentifierExpression>(mod.RegisterSymbol("ary"), "ary");
auto* idx =
create<ast::IdentifierExpression>(mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(ary, idx); ast::ArrayAccessorExpression expr(ary, idx);

Some files were not shown because too many files have changed in this diff Show More