ProgramBuilder: Migrate away from using Ignore()
The `Ignore()` intrinsic is about to be deprecated, so don't use it for testing. Bug: tint:1213 Change-Id: Ib5d5966da6d566a9f02940970ebd79d520b5e0e8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67065 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Ben Clayton <bclayton@google.com> Reviewed-by: David Neto <dneto@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
a41694e9a3
commit
cc7c4f309b
|
@ -1643,11 +1643,11 @@ class ProgramBuilder {
|
|||
const ast::PhonyExpression* Phony() { return create<ast::PhonyExpression>(); }
|
||||
|
||||
/// @param expr the expression to ignore
|
||||
/// @returns a `ast::CallStatement` that calls the `ignore` intrinsic which is
|
||||
/// passed the single `expr` argument
|
||||
/// @returns a `ast::AssignmentStatement` that assigns 'expr' to the phony
|
||||
/// (underscore) variable.
|
||||
template <typename EXPR>
|
||||
const ast::CallStatement* Ignore(EXPR&& expr) {
|
||||
return create<ast::CallStatement>(Call("ignore", Expr(expr)));
|
||||
const ast::AssignmentStatement* Ignore(EXPR&& expr) {
|
||||
return create<ast::AssignmentStatement>(Phony(), Expr(expr));
|
||||
}
|
||||
|
||||
/// @param lhs the left hand argument to the addition operation
|
||||
|
|
|
@ -190,28 +190,33 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleInit) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
|
||||
// fn f(i : i32) {}
|
||||
//
|
||||
// var<workgroup> a : atomic<i32>;
|
||||
// for({ignore(1); ignore(2);}; ; ) {
|
||||
// for({f(1); f(2);}; ; ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
|
||||
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
|
||||
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
|
||||
auto* multi_stmt = Block(Ignore(1), Ignore(2));
|
||||
auto* f =
|
||||
auto* multi_stmt = Block(f(1), f(2));
|
||||
auto* loop =
|
||||
For(multi_stmt, nullptr, nullptr, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(loop);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
{
|
||||
(void) 1;
|
||||
(void) 2;
|
||||
f(1);
|
||||
f(2);
|
||||
}
|
||||
for(; ; ) {
|
||||
a_statement();
|
||||
|
@ -267,29 +272,34 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleCont) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
|
||||
// fn f(i : i32) {}
|
||||
//
|
||||
// var<workgroup> a : atomic<i32>;
|
||||
// for(; ; { ignore(1); ignore(2); }) {
|
||||
// for(; ; { f(1); f(2); }) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
|
||||
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
|
||||
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
|
||||
auto* multi_stmt = Block(Ignore(1), Ignore(2));
|
||||
auto* f =
|
||||
auto* multi_stmt = Block(f(1), f(2));
|
||||
auto* loop =
|
||||
For(nullptr, nullptr, multi_stmt, Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(f);
|
||||
WrapInFunction(loop);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( while (true) {
|
||||
a_statement();
|
||||
{
|
||||
(void) 1;
|
||||
(void) 2;
|
||||
f(1);
|
||||
f(2);
|
||||
}
|
||||
}
|
||||
)");
|
||||
|
@ -320,36 +330,41 @@ TEST_F(MslGeneratorImplTest, Emit_ForLoopWithSimpleInitCondCont) {
|
|||
}
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
|
||||
// fn f(i : i32) {}
|
||||
//
|
||||
// var<workgroup> a : atomic<i32>;
|
||||
// for({ ignore(1); ignore(2); }; true; { ignore(3); ignore(4); }) {
|
||||
// for({ f(1); f(2); }; true; { f(3); f(4); }) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
Func("f", {Param("i", ty.i32())}, ty.void_(), {});
|
||||
auto f = [&](auto&& expr) { return CallStmt(Call("f", expr)); };
|
||||
|
||||
Func("a_statement", {}, ty.void_(), {});
|
||||
|
||||
Global("a", ty.atomic<i32>(), ast::StorageClass::kWorkgroup);
|
||||
auto* multi_stmt_a = Block(Ignore(1), Ignore(2));
|
||||
auto* multi_stmt_b = Block(Ignore(3), Ignore(4));
|
||||
auto* f = For(multi_stmt_a, Expr(true), multi_stmt_b,
|
||||
Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(f);
|
||||
auto* multi_stmt_a = Block(f(1), f(2));
|
||||
auto* multi_stmt_b = Block(f(3), f(4));
|
||||
auto* loop = For(multi_stmt_a, Expr(true), multi_stmt_b,
|
||||
Block(CallStmt(Call("a_statement"))));
|
||||
WrapInFunction(loop);
|
||||
|
||||
GeneratorImpl& gen = Build();
|
||||
|
||||
gen.increment_indent();
|
||||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
ASSERT_TRUE(gen.EmitStatement(loop)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( {
|
||||
{
|
||||
(void) 1;
|
||||
(void) 2;
|
||||
f(1);
|
||||
f(2);
|
||||
}
|
||||
while (true) {
|
||||
if (!(true)) { break; }
|
||||
a_statement();
|
||||
{
|
||||
(void) 3;
|
||||
(void) 4;
|
||||
f(3);
|
||||
f(4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInit) {
|
|||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( for({
|
||||
ignore(1);
|
||||
ignore(2);
|
||||
_ = 1;
|
||||
_ = 2;
|
||||
}; ; ) {
|
||||
return;
|
||||
}
|
||||
|
@ -143,8 +143,8 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtCont) {
|
|||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( for(; ; {
|
||||
ignore(1);
|
||||
ignore(2);
|
||||
_ = 1;
|
||||
_ = 2;
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
|
@ -188,11 +188,11 @@ TEST_F(WgslGeneratorImplTest, Emit_ForLoopWithMultiStmtInitCondCont) {
|
|||
|
||||
ASSERT_TRUE(gen.EmitStatement(f)) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"( for({
|
||||
ignore(1);
|
||||
ignore(2);
|
||||
_ = 1;
|
||||
_ = 2;
|
||||
}; true; {
|
||||
ignore(3);
|
||||
ignore(4);
|
||||
_ = 3;
|
||||
_ = 4;
|
||||
}) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue