From 537039009663418971b7104b0659a4e4525ba078 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Tue, 26 May 2020 15:05:54 +0000 Subject: [PATCH] Remove NOP. The NOP command was added for complete SPIR-V bijectivity which is no longer a goal of WGSL. The NOP command has been removed from the spec, so remove from Tint. Change-Id: Ic640d9d3b987a19668dc169ff549444921c5bbb8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22160 Reviewed-by: Ryan Harrison --- BUILD.gn | 4 -- src/CMakeLists.txt | 4 -- src/ast/case_statement_test.cc | 22 +++---- src/ast/else_statement_test.cc | 20 +++---- src/ast/function_test.cc | 16 ++--- src/ast/if_statement_test.cc | 37 ++++++------ src/ast/loop_statement_test.cc | 21 ++++--- src/ast/nop_statement.cc | 40 ------------- src/ast/nop_statement.h | 53 ----------------- src/ast/nop_statement_test.cc | 59 ------------------- src/ast/statement.cc | 15 ----- src/ast/statement.h | 7 --- src/ast/unless_statement_test.cc | 24 ++++---- src/reader/spirv/function.cc | 45 +++++++------- src/reader/wgsl/lexer.cc | 2 - src/reader/wgsl/lexer_test.cc | 1 - src/reader/wgsl/parser_impl.cc | 14 ----- src/reader/wgsl/parser_impl_body_stmt_test.cc | 6 +- .../wgsl/parser_impl_continuing_stmt_test.cc | 8 +-- src/reader/wgsl/parser_impl_loop_stmt_test.cc | 8 +-- src/reader/wgsl/parser_impl_statement_test.cc | 16 ----- .../wgsl/parser_impl_statements_test.cc | 9 ++- src/reader/wgsl/token.cc | 2 - src/reader/wgsl/token.h | 4 -- src/type_determiner.cc | 3 - src/writer/spirv/binary_writer_test.cc | 12 ++-- src/writer/wgsl/generator_impl.cc | 9 --- src/writer/wgsl/generator_impl.h | 4 -- src/writer/wgsl/generator_impl_loop_test.cc | 5 +- src/writer/wgsl/generator_impl_nop_test.cc | 39 ------------ src/writer/wgsl/generator_impl_unless_test.cc | 5 +- 31 files changed, 115 insertions(+), 399 deletions(-) delete mode 100644 src/ast/nop_statement.cc delete mode 100644 src/ast/nop_statement.h delete mode 100644 src/ast/nop_statement_test.cc delete mode 100644 src/writer/wgsl/generator_impl_nop_test.cc diff --git a/BUILD.gn b/BUILD.gn index 7764afc6fe..93bc286927 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -266,8 +266,6 @@ source_set("libtint_core_src") { "src/ast/module.h", "src/ast/node.cc", "src/ast/node.h", - "src/ast/nop_statement.cc", - "src/ast/nop_statement.h", "src/ast/null_literal.cc", "src/ast/null_literal.h", "src/ast/pipeline_stage.cc", @@ -605,7 +603,6 @@ source_set("tint_unittests_core_src") { "src/ast/loop_statement_test.cc", "src/ast/member_accessor_expression_test.cc", "src/ast/module_test.cc", - "src/ast/nop_statement_test.cc", "src/ast/null_literal_test.cc", "src/ast/return_statement_test.cc", "src/ast/scalar_constructor_expression_test.cc", @@ -829,7 +826,6 @@ source_set("tint_unittests_wgsl_writer_src") { "src/writer/wgsl/generator_impl_kill_test.cc", "src/writer/wgsl/generator_impl_loop_test.cc", "src/writer/wgsl/generator_impl_member_accessor_test.cc", - "src/writer/wgsl/generator_impl_nop_test.cc", "src/writer/wgsl/generator_impl_relational_test.cc", "src/writer/wgsl/generator_impl_return_test.cc", "src/writer/wgsl/generator_impl_switch_test.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c07fdd9458..a1637eb33c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,8 +103,6 @@ set(TINT_LIB_SRCS ast/module.h ast/node.cc ast/node.h - ast/nop_statement.cc - ast/nop_statement.h ast/null_literal.cc ast/null_literal.h ast/pipeline_stage.cc @@ -284,7 +282,6 @@ set(TINT_TEST_SRCS ast/loop_statement_test.cc ast/member_accessor_expression_test.cc ast/module_test.cc - ast/nop_statement_test.cc ast/null_literal_test.cc ast/binary_expression_test.cc ast/return_statement_test.cc @@ -478,7 +475,6 @@ if(${TINT_BUILD_WGSL_WRITER}) writer/wgsl/generator_impl_kill_test.cc writer/wgsl/generator_impl_loop_test.cc writer/wgsl/generator_impl_member_accessor_test.cc - writer/wgsl/generator_impl_nop_test.cc writer/wgsl/generator_impl_relational_test.cc writer/wgsl/generator_impl_return_test.cc writer/wgsl/generator_impl_switch_test.cc diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 8aad2ba9ea..4e841ace72 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/bool_literal.h" #include "src/ast/if_statement.h" -#include "src/ast/nop_statement.h" +#include "src/ast/kill_statement.h" #include "src/ast/type/bool_type.h" namespace tint { @@ -30,22 +30,22 @@ TEST_F(CaseStatementTest, Creation) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); auto* bool_ptr = b.get(); - auto* nop_ptr = stmts[0].get(); + auto* kill_ptr = stmts[0].get(); CaseStatement c(std::move(b), std::move(stmts)); EXPECT_EQ(c.condition(), bool_ptr); ASSERT_EQ(c.body().size(), 1u); - EXPECT_EQ(c.body()[0].get(), nop_ptr); + EXPECT_EQ(c.body()[0].get(), kill_ptr); } TEST_F(CaseStatementTest, Creation_WithSource) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); CaseStatement c(Source{20, 2}, std::move(b), std::move(stmts)); auto src = c.source(); @@ -55,7 +55,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) { TEST_F(CaseStatementTest, IsDefault_WithoutCondition) { StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); CaseStatement c; c.set_body(std::move(stmts)); @@ -84,7 +84,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); stmts.push_back(nullptr); CaseStatement c(std::move(b), std::move(stmts)); @@ -105,26 +105,26 @@ TEST_F(CaseStatementTest, ToStr_WithCondition) { ast::type::BoolType bool_type; auto b = std::make_unique(&bool_type, true); StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); CaseStatement c(std::move(b), std::move(stmts)); std::ostringstream out; c.to_str(out, 2); EXPECT_EQ(out.str(), R"( Case true{ - Nop{} + Kill{} } )"); } TEST_F(CaseStatementTest, ToStr_WithoutCondition) { StatementList stmts; - stmts.push_back(std::make_unique()); + stmts.push_back(std::make_unique()); CaseStatement c(nullptr, std::move(stmts)); std::ostringstream out; c.to_str(out, 2); EXPECT_EQ(out.str(), R"( Default{ - Nop{} + Kill{} } )"); } diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 07ee8ec1f3..05d04cb30e 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/bool_literal.h" #include "src/ast/if_statement.h" -#include "src/ast/nop_statement.h" +#include "src/ast/kill_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/type/bool_type.h" @@ -32,15 +32,15 @@ TEST_F(ElseStatementTest, Creation) { auto cond = std::make_unique( std::make_unique(&bool_type, true)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); auto* cond_ptr = cond.get(); - auto* nop_ptr = body[0].get(); + auto* kill_ptr = body[0].get(); ElseStatement e(std::move(cond), std::move(body)); EXPECT_EQ(e.condition(), cond_ptr); ASSERT_EQ(e.body().size(), 1u); - EXPECT_EQ(e.body()[0].get(), nop_ptr); + EXPECT_EQ(e.body()[0].get(), kill_ptr); } TEST_F(ElseStatementTest, Creation_WithSource) { @@ -75,7 +75,7 @@ TEST_F(ElseStatementTest, IsValid) { TEST_F(ElseStatementTest, IsValid_WithBody) { StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatement e(std::move(body)); EXPECT_TRUE(e.IsValid()); @@ -83,7 +83,7 @@ TEST_F(ElseStatementTest, IsValid_WithBody) { TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(nullptr); ElseStatement e(std::move(body)); @@ -109,7 +109,7 @@ TEST_F(ElseStatementTest, ToStr) { auto cond = std::make_unique( std::make_unique(&bool_type, true)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatement e(std::move(cond), std::move(body)); std::ostringstream out; @@ -119,7 +119,7 @@ TEST_F(ElseStatementTest, ToStr) { ScalarConstructor{true} ) { - Nop{} + Kill{} } } )"); @@ -127,14 +127,14 @@ TEST_F(ElseStatementTest, ToStr) { TEST_F(ElseStatementTest, ToStr_NoCondition) { StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatement e(std::move(body)); std::ostringstream out; e.to_str(out, 2); EXPECT_EQ(out.str(), R"( Else{ { - Nop{} + Kill{} } } )"); diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index faae8d1415..300244c09f 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -15,7 +15,7 @@ #include "src/ast/function.h" #include "gtest/gtest.h" -#include "src/ast/nop_statement.h" +#include "src/ast/kill_statement.h" #include "src/ast/type/f32_type.h" #include "src/ast/type/i32_type.h" #include "src/ast/type/void_type.h" @@ -66,7 +66,7 @@ TEST_F(FunctionTest, IsValid) { std::make_unique("var", StorageClass::kNone, &i32)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); Function f("func", std::move(params), &void_type); f.set_body(std::move(body)); @@ -129,7 +129,7 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) { std::make_unique("var", StorageClass::kNone, &i32)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(nullptr); Function f("func", std::move(params), &void_type); @@ -146,7 +146,7 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { std::make_unique("var", StorageClass::kNone, &i32)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(nullptr); Function f("func", std::move(params), &void_type); @@ -159,7 +159,7 @@ TEST_F(FunctionTest, ToStr) { type::I32Type i32; StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); Function f("func", {}, &void_type); f.set_body(std::move(body)); @@ -169,7 +169,7 @@ TEST_F(FunctionTest, ToStr) { EXPECT_EQ(out.str(), R"( Function func -> __void () { - Nop{} + Kill{} } )"); } @@ -183,7 +183,7 @@ TEST_F(FunctionTest, ToStr_WithParams) { std::make_unique("var", StorageClass::kNone, &i32)); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); Function f("func", std::move(params), &void_type); f.set_body(std::move(body)); @@ -199,7 +199,7 @@ TEST_F(FunctionTest, ToStr_WithParams) { } ) { - Nop{} + Kill{} } )"); } diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index 845561306a..e2fe8409e0 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" #include "src/ast/kill_statement.h" -#include "src/ast/nop_statement.h" namespace tint { namespace ast { @@ -28,7 +27,7 @@ using IfStatementTest = testing::Test; TEST_F(IfStatementTest, Creation) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); auto* cond_ptr = cond.get(); auto* stmt_ptr = body[0].get(); @@ -42,7 +41,7 @@ TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation_WithSource) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); IfStatement stmt(Source{20, 2}, std::move(cond), std::move(body)); auto src = stmt.source(); @@ -58,7 +57,7 @@ TEST_F(IfStatementTest, IsIf) { TEST_F(IfStatementTest, IsValid) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); EXPECT_TRUE(stmt.IsValid()); @@ -67,7 +66,7 @@ TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid_WithElseStatements) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); @@ -81,7 +80,7 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) { TEST_F(IfStatementTest, IsValid_MissingCondition) { StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); IfStatement stmt(nullptr, std::move(body)); EXPECT_FALSE(stmt.IsValid()); @@ -90,7 +89,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) { auto cond = std::make_unique(""); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); EXPECT_FALSE(stmt.IsValid()); @@ -99,7 +98,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(nullptr); IfStatement stmt(std::move(cond), std::move(body)); @@ -109,7 +108,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -119,7 +118,7 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); @@ -135,7 +134,7 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); @@ -149,7 +148,7 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); @@ -163,7 +162,7 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_ElseNotLast) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); ElseStatementList else_stmts; else_stmts.push_back(std::make_unique()); @@ -178,7 +177,7 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, ToStr) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); IfStatement stmt(std::move(cond), std::move(body)); @@ -189,7 +188,7 @@ TEST_F(IfStatementTest, ToStr) { Identifier{cond} ) { - Nop{} + Kill{} } } )"); @@ -198,13 +197,13 @@ TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr_WithElseStatements) { auto cond = std::make_unique("cond"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); StatementList else_if_body; else_if_body.push_back(std::make_unique()); StatementList else_body; - else_body.push_back(std::make_unique()); + else_body.push_back(std::make_unique()); else_body.push_back(std::make_unique()); ElseStatementList else_stmts; @@ -224,7 +223,7 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) { Identifier{cond} ) { - Nop{} + Kill{} } } Else{ @@ -237,7 +236,7 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) { } Else{ { - Nop{} + Kill{} Kill{} } } diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index a12b2f75c6..d7f2187d82 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -20,7 +20,6 @@ #include "gtest/gtest.h" #include "src/ast/if_statement.h" #include "src/ast/kill_statement.h" -#include "src/ast/nop_statement.h" namespace tint { namespace ast { @@ -34,7 +33,7 @@ TEST_F(LoopStatementTest, Creation) { auto* b_ptr = body[0].get(); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); auto* c_ptr = continuing[0].get(); LoopStatement l(std::move(body), std::move(continuing)); @@ -49,7 +48,7 @@ TEST_F(LoopStatementTest, Creation_WithSource) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(Source{20, 2}, std::move(body), std::move(continuing)); auto src = l.source(); @@ -75,7 +74,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_TRUE(l.has_continuing()); @@ -86,7 +85,7 @@ TEST_F(LoopStatementTest, IsValid) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_TRUE(l.IsValid()); @@ -111,7 +110,7 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { body.push_back(nullptr); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_FALSE(l.IsValid()); @@ -123,7 +122,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_FALSE(l.IsValid()); @@ -134,7 +133,7 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); continuing.push_back(nullptr); LoopStatement l(std::move(body), std::move(continuing)); @@ -146,7 +145,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); @@ -171,7 +170,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) { body.push_back(std::make_unique()); StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); LoopStatement l(std::move(body), std::move(continuing)); std::ostringstream out; @@ -179,7 +178,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) { EXPECT_EQ(out.str(), R"( Loop{ Kill{} continuing { - Nop{} + Kill{} } } )"); diff --git a/src/ast/nop_statement.cc b/src/ast/nop_statement.cc deleted file mode 100644 index 86699cb7f2..0000000000 --- a/src/ast/nop_statement.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/ast/nop_statement.h" - -namespace tint { -namespace ast { - -NopStatement::NopStatement() : Statement() {} - -NopStatement::NopStatement(const Source& source) : Statement(source) {} - -NopStatement::~NopStatement() = default; - -bool NopStatement::IsNop() const { - return true; -} - -bool NopStatement::IsValid() const { - return true; -} - -void NopStatement::to_str(std::ostream& out, size_t indent) const { - make_indent(out, indent); - out << "Nop{}" << std::endl; -} - -} // namespace ast -} // namespace tint diff --git a/src/ast/nop_statement.h b/src/ast/nop_statement.h deleted file mode 100644 index eae7c6020a..0000000000 --- a/src/ast/nop_statement.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_AST_NOP_STATEMENT_H_ -#define SRC_AST_NOP_STATEMENT_H_ - -#include "src/ast/statement.h" - -namespace tint { -namespace ast { - -/// A nop statement -class NopStatement : public Statement { - public: - /// Constructor - NopStatement(); - /// Constructor - /// @param source the nop statement source - explicit NopStatement(const Source& source); - /// Move constructor - NopStatement(NopStatement&&) = default; - ~NopStatement() override; - - /// @returns true if this is a nop statement - bool IsNop() const override; - - /// @returns true if the node is valid - bool IsValid() const override; - - /// Writes a representation of the node to the output stream - /// @param out the stream to write to - /// @param indent number of spaces to indent the node when writing - void to_str(std::ostream& out, size_t indent) const override; - - private: - NopStatement(const NopStatement&) = delete; -}; - -} // namespace ast -} // namespace tint - -#endif // SRC_AST_NOP_STATEMENT_H_ diff --git a/src/ast/nop_statement_test.cc b/src/ast/nop_statement_test.cc deleted file mode 100644 index b7dda992fc..0000000000 --- a/src/ast/nop_statement_test.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/ast/nop_statement.h" - -#include - -#include "gtest/gtest.h" - -namespace tint { -namespace ast { -namespace { - -using NopStatementTest = testing::Test; - -TEST_F(NopStatementTest, Creation) { - NopStatement n; - EXPECT_EQ(n.line(), 0u); - EXPECT_EQ(n.column(), 0u); -} - -TEST_F(NopStatementTest, Creation_WithSource) { - NopStatement n(Source{20, 2}); - EXPECT_EQ(n.line(), 20u); - EXPECT_EQ(n.column(), 2u); -} - -TEST_F(NopStatementTest, IsNop) { - NopStatement n; - EXPECT_TRUE(n.IsNop()); -} - -TEST_F(NopStatementTest, IsValid) { - NopStatement n; - EXPECT_TRUE(n.IsValid()); -} - -TEST_F(NopStatementTest, ToStr) { - NopStatement n; - std::ostringstream out; - n.to_str(out, 2); - EXPECT_EQ(out.str(), R"( Nop{} -)"); -} - -} // namespace -} // namespace ast -} // namespace tint diff --git a/src/ast/statement.cc b/src/ast/statement.cc index a5d7f3616c..6aa138055d 100644 --- a/src/ast/statement.cc +++ b/src/ast/statement.cc @@ -25,7 +25,6 @@ #include "src/ast/if_statement.h" #include "src/ast/kill_statement.h" #include "src/ast/loop_statement.h" -#include "src/ast/nop_statement.h" #include "src/ast/return_statement.h" #include "src/ast/switch_statement.h" #include "src/ast/unless_statement.h" @@ -78,10 +77,6 @@ bool Statement::IsLoop() const { return false; } -bool Statement::IsNop() const { - return false; -} - bool Statement::IsReturn() const { return false; } @@ -143,11 +138,6 @@ const LoopStatement* Statement::AsLoop() const { return static_cast(this); } -const NopStatement* Statement::AsNop() const { - assert(IsNop()); - return static_cast(this); -} - const ReturnStatement* Statement::AsReturn() const { assert(IsReturn()); return static_cast(this); @@ -213,11 +203,6 @@ LoopStatement* Statement::AsLoop() { return static_cast(this); } -NopStatement* Statement::AsNop() { - assert(IsNop()); - return static_cast(this); -} - ReturnStatement* Statement::AsReturn() { assert(IsReturn()); return static_cast(this); diff --git a/src/ast/statement.h b/src/ast/statement.h index c3188acca6..a813818747 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -32,7 +32,6 @@ class FallthroughStatement; class IfStatement; class KillStatement; class LoopStatement; -class NopStatement; class ReturnStatement; class SwitchStatement; class UnlessStatement; @@ -61,8 +60,6 @@ class Statement : public Node { virtual bool IsKill() const; /// @returns true if this is a loop statement virtual bool IsLoop() const; - /// @returns true if this is a nop statement - virtual bool IsNop() const; /// @returns true if this is a return statement virtual bool IsReturn() const; /// @returns true if this is a switch statement @@ -90,8 +87,6 @@ class Statement : public Node { const KillStatement* AsKill() const; /// @returns the statement as a const loop statement const LoopStatement* AsLoop() const; - /// @returns the statement as a const nop statement - const NopStatement* AsNop() const; /// @returns the statement as a const return statement const ReturnStatement* AsReturn() const; /// @returns the statement as a const switch statement @@ -119,8 +114,6 @@ class Statement : public Node { KillStatement* AsKill(); /// @returns the statement as a loop statement LoopStatement* AsLoop(); - /// @returns the statement as a nop statement - NopStatement* AsNop(); /// @returns the statement as a return statement ReturnStatement* AsReturn(); /// @returns the statement as a switch statement diff --git a/src/ast/unless_statement_test.cc b/src/ast/unless_statement_test.cc index 45b7b7dece..b3c1ae9cc8 100644 --- a/src/ast/unless_statement_test.cc +++ b/src/ast/unless_statement_test.cc @@ -17,7 +17,7 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" #include "src/ast/if_statement.h" -#include "src/ast/nop_statement.h" +#include "src/ast/kill_statement.h" namespace tint { namespace ast { @@ -28,21 +28,21 @@ using UnlessStatementTest = testing::Test; TEST_F(UnlessStatementTest, Creation) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); auto* ident_ptr = ident.get(); - auto* nop_ptr = body[0].get(); + auto* kill_ptr = body[0].get(); UnlessStatement u(std::move(ident), std::move(body)); EXPECT_EQ(u.condition(), ident_ptr); ASSERT_EQ(u.body().size(), 1u); - EXPECT_EQ(u.body()[0].get(), nop_ptr); + EXPECT_EQ(u.body()[0].get(), kill_ptr); } TEST_F(UnlessStatementTest, Creation_WithSource) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); UnlessStatement u(Source{20, 2}, std::move(ident), std::move(body)); auto src = u.source(); @@ -58,7 +58,7 @@ TEST_F(UnlessStatementTest, IsUnless) { TEST_F(UnlessStatementTest, IsValid) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); EXPECT_TRUE(u.IsValid()); @@ -66,7 +66,7 @@ TEST_F(UnlessStatementTest, IsValid) { TEST_F(UnlessStatementTest, IsValid_NullCondition) { StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); UnlessStatement u; u.set_body(std::move(body)); @@ -76,7 +76,7 @@ TEST_F(UnlessStatementTest, IsValid_NullCondition) { TEST_F(UnlessStatementTest, IsValid_InvalidCondition) { auto ident = std::make_unique(""); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); EXPECT_FALSE(u.IsValid()); @@ -85,7 +85,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidCondition) { TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(nullptr); UnlessStatement u(std::move(ident), std::move(body)); @@ -95,7 +95,7 @@ TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) { TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); @@ -105,7 +105,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) { TEST_F(UnlessStatementTest, ToStr) { auto ident = std::make_unique("ident"); StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); UnlessStatement u(std::move(ident), std::move(body)); std::ostringstream out; @@ -115,7 +115,7 @@ TEST_F(UnlessStatementTest, ToStr) { Identifier{ident} ) { - Nop{} + Kill{} } } )"); diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 8b2617c558..7970f8479e 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -1613,7 +1613,7 @@ TypedExpression FunctionEmitter::MakeAccessChain( const auto* ptr_type = type_mgr_->GetType(ptr_ty_id); if (!ptr_type || !ptr_type->AsPointer()) { Fail() << "Access chain %" << inst.result_id() - << " base pointer is not of pointer type"; + << " base pointer is not of pointer type"; return {}; } const auto* pointee_type = ptr_type->AsPointer()->pointee_type(); @@ -1631,11 +1631,9 @@ TypedExpression FunctionEmitter::MakeAccessChain( if (index_const_val < 0 || pointee_type->AsVector()->element_count() <= index_const_val) { Fail() << "Access chain %" << inst.result_id() << " index %" - << inst.GetSingleWordInOperand(index) << " value " - << index_const_val - << " is out of bounds for vector of " - << pointee_type->AsVector()->element_count() - << " elements"; + << inst.GetSingleWordInOperand(index) << " value " + << index_const_val << " is out of bounds for vector of " + << pointee_type->AsVector()->element_count() << " elements"; return {}; } if (uint64_t(index_const_val) >= @@ -1659,36 +1657,38 @@ TypedExpression FunctionEmitter::MakeAccessChain( case spvtools::opt::analysis::Type::kMatrix: // Use array syntax. next_expr = std::make_unique( - std::move(current_expr.expr), std::move(MakeOperand(inst, index).expr)); + std::move(current_expr.expr), + std::move(MakeOperand(inst, index).expr)); pointee_type = pointee_type->AsMatrix()->element_type(); break; case spvtools::opt::analysis::Type::kArray: next_expr = std::make_unique( - std::move(current_expr.expr), std::move(MakeOperand(inst, index).expr)); + std::move(current_expr.expr), + std::move(MakeOperand(inst, index).expr)); pointee_type = pointee_type->AsArray()->element_type(); break; case spvtools::opt::analysis::Type::kRuntimeArray: next_expr = std::make_unique( - std::move(current_expr.expr), std::move(MakeOperand(inst, index).expr)); + std::move(current_expr.expr), + std::move(MakeOperand(inst, index).expr)); pointee_type = pointee_type->AsRuntimeArray()->element_type(); break; case spvtools::opt::analysis::Type::kStruct: { if (!index_const) { Fail() << "Access chain %" << inst.result_id() << " index %" - << inst.GetSingleWordInOperand(index) - << " is a non-constant index into a structure %" - << type_mgr_->GetId(pointee_type); + << inst.GetSingleWordInOperand(index) + << " is a non-constant index into a structure %" + << type_mgr_->GetId(pointee_type); return {}; } if ((index_const_val < 0) || pointee_type->AsStruct()->element_types().size() <= uint64_t(index_const_val)) { - Fail() << "Access chain %" << inst.result_id() - << " index value " << index_const_val - << " is out of bounds for structure %" - << type_mgr_->GetId(pointee_type) << " having " - << pointee_type->AsStruct()->element_types().size() - << " elements"; + Fail() << "Access chain %" << inst.result_id() << " index value " + << index_const_val << " is out of bounds for structure %" + << type_mgr_->GetId(pointee_type) << " having " + << pointee_type->AsStruct()->element_types().size() + << " elements"; return {}; } auto member_access = @@ -1700,16 +1700,15 @@ TypedExpression FunctionEmitter::MakeAccessChain( pointee_type = pointee_type->AsStruct()->element_types()[index_const_val]; break; - } + } default: Fail() << "Access chain with unknown pointee type %" - << type_mgr_->GetId(pointee_type) << " " - << pointee_type->str(); + << type_mgr_->GetId(pointee_type) << " " << pointee_type->str(); return {}; } current_expr.reset(TypedExpression( - parser_impl_.ConvertType(type_mgr_->GetId(pointee_type)), - std::move(next_expr))); + parser_impl_.ConvertType(type_mgr_->GetId(pointee_type)), + std::move(next_expr))); } return current_expr; } diff --git a/src/reader/wgsl/lexer.cc b/src/reader/wgsl/lexer.cc index bb18f368d3..4c8545e4f7 100644 --- a/src/reader/wgsl/lexer.cc +++ b/src/reader/wgsl/lexer.cc @@ -586,8 +586,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) { return {Token::Type::kMat4x3, source, "mat4x3"}; if (str == "mat4x4") return {Token::Type::kMat4x4, source, "mat4x4"}; - if (str == "nop") - return {Token::Type::kNop, source, "nop"}; if (str == "num_workgroups") return {Token::Type::kNumWorkgroups, source, "num_workgroups"}; if (str == "offset") diff --git a/src/reader/wgsl/lexer_test.cc b/src/reader/wgsl/lexer_test.cc index c59e4fbb9b..9944ee03e1 100644 --- a/src/reader/wgsl/lexer_test.cc +++ b/src/reader/wgsl/lexer_test.cc @@ -468,7 +468,6 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"mat4x2", Token::Type::kMat4x2}, TokenData{"mat4x3", Token::Type::kMat4x3}, TokenData{"mat4x4", Token::Type::kMat4x4}, - TokenData{"nop", Token::Type::kNop}, TokenData{"num_workgroups", Token::Type::kNumWorkgroups}, TokenData{"offset", Token::Type::kOffset}, TokenData{"out", Token::Type::kOut}, diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index cf282296f9..e64a74b672 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -38,7 +38,6 @@ #include "src/ast/kill_statement.h" #include "src/ast/location_decoration.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/nop_statement.h" #include "src/ast/return_statement.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/set_decoration.h" @@ -1450,7 +1449,6 @@ ast::StatementList ParserImpl::statements() { // | break_stmt SEMICOLON // | continue_stmt SEMICOLON // | KILL SEMICOLON -// | NOP SEMICOLON // | assignment_expression SEMICOLON std::unique_ptr ParserImpl::statement() { auto t = peek(); @@ -1552,18 +1550,6 @@ std::unique_ptr ParserImpl::statement() { return std::make_unique(source); } - if (t.IsNop()) { - auto source = t.source(); - next(); // Consume the peek - - t = next(); - if (!t.IsSemicolon()) { - set_error(t, "missing ;"); - return nullptr; - } - return std::make_unique(source); - } - auto assign = assignment_stmt(); if (has_error()) return nullptr; diff --git a/src/reader/wgsl/parser_impl_body_stmt_test.cc b/src/reader/wgsl/parser_impl_body_stmt_test.cc index 6f16508d5d..90e0d73720 100644 --- a/src/reader/wgsl/parser_impl_body_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_body_stmt_test.cc @@ -24,15 +24,13 @@ namespace { TEST_F(ParserImplTest, BodyStmt) { auto* p = parser(R"({ kill; - nop; return 1 + b / 2; })"); auto e = p->body_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e.size(), 3u); + ASSERT_EQ(e.size(), 2u); EXPECT_TRUE(e[0]->IsKill()); - EXPECT_TRUE(e[1]->IsNop()); - EXPECT_TRUE(e[2]->IsReturn()); + EXPECT_TRUE(e[1]->IsReturn()); } TEST_F(ParserImplTest, BodyStmt_Empty) { diff --git a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc index c996c843fc..91543120e9 100644 --- a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc @@ -22,19 +22,19 @@ namespace wgsl { namespace { TEST_F(ParserImplTest, ContinuingStmt) { - auto* p = parser("continuing { nop; }"); + auto* p = parser("continuing { kill; }"); auto e = p->continuing_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_EQ(e.size(), 1u); - ASSERT_TRUE(e[0]->IsNop()); + ASSERT_TRUE(e[0]->IsKill()); } TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) { - auto* p = parser("continuing { nop }"); + auto* p = parser("continuing { kill }"); auto e = p->continuing_stmt(); ASSERT_TRUE(p->has_error()); ASSERT_EQ(e.size(), 0u); - EXPECT_EQ(p->error(), "1:18: missing ;"); + EXPECT_EQ(p->error(), "1:19: missing ;"); } } // namespace diff --git a/src/reader/wgsl/parser_impl_loop_stmt_test.cc b/src/reader/wgsl/parser_impl_loop_stmt_test.cc index ea7a2454b9..71bd39b47f 100644 --- a/src/reader/wgsl/parser_impl_loop_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_loop_stmt_test.cc @@ -22,25 +22,25 @@ namespace wgsl { namespace { TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) { - auto* p = parser("loop { nop; }"); + auto* p = parser("loop { kill; }"); auto e = p->loop_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e, nullptr); ASSERT_EQ(e->body().size(), 1u); - EXPECT_TRUE(e->body()[0]->IsNop()); + EXPECT_TRUE(e->body()[0]->IsKill()); EXPECT_EQ(e->continuing().size(), 0u); } TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { - auto* p = parser("loop { nop; continuing { kill; }}"); + auto* p = parser("loop { kill; continuing { kill; }}"); auto e = p->loop_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e, nullptr); ASSERT_EQ(e->body().size(), 1u); - EXPECT_TRUE(e->body()[0]->IsNop()); + EXPECT_TRUE(e->body()[0]->IsKill()); EXPECT_EQ(e->continuing().size(), 1u); EXPECT_TRUE(e->continuing()[0]->IsKill()); diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc index f123437dc2..40a8bfcebe 100644 --- a/src/reader/wgsl/parser_impl_statement_test.cc +++ b/src/reader/wgsl/parser_impl_statement_test.cc @@ -253,22 +253,6 @@ TEST_F(ParserImplTest, Statement_Kill_MissingSemicolon) { EXPECT_EQ(p->error(), "1:5: missing ;"); } -TEST_F(ParserImplTest, Statement_Nop) { - auto* p = parser("nop;"); - auto e = p->statement(); - ASSERT_FALSE(p->has_error()) << p->error(); - EXPECT_NE(e, nullptr); - ASSERT_TRUE(e->IsNop()); -} - -TEST_F(ParserImplTest, Statement_Nop_MissingSemicolon) { - auto* p = parser("nop"); - auto e = p->statement(); - ASSERT_TRUE(p->has_error()); - EXPECT_EQ(e, nullptr); - EXPECT_EQ(p->error(), "1:4: missing ;"); -} - } // namespace } // namespace wgsl } // namespace reader diff --git a/src/reader/wgsl/parser_impl_statements_test.cc b/src/reader/wgsl/parser_impl_statements_test.cc index 3e6a959059..343d501ab0 100644 --- a/src/reader/wgsl/parser_impl_statements_test.cc +++ b/src/reader/wgsl/parser_impl_statements_test.cc @@ -23,13 +23,12 @@ namespace wgsl { namespace { TEST_F(ParserImplTest, Statements) { - auto* p = parser("nop; kill; return;"); + auto* p = parser("kill; return;"); auto e = p->statements(); ASSERT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e.size(), 3u); - EXPECT_TRUE(e[0]->IsNop()); - EXPECT_TRUE(e[1]->IsKill()); - EXPECT_TRUE(e[2]->IsReturn()); + ASSERT_EQ(e.size(), 2u); + EXPECT_TRUE(e[0]->IsKill()); + EXPECT_TRUE(e[1]->IsReturn()); } TEST_F(ParserImplTest, Statements_Empty) { diff --git a/src/reader/wgsl/token.cc b/src/reader/wgsl/token.cc index 1481018e9d..0d78a9cbe9 100644 --- a/src/reader/wgsl/token.cc +++ b/src/reader/wgsl/token.cc @@ -223,8 +223,6 @@ std::string Token::TypeToName(Type type) { return "mat4x3"; case Token::Type::kMat4x4: return "mat4x4"; - case Token::Type::kNop: - return "nop"; case Token::Type::kNumWorkgroups: return "num_workgroups"; case Token::Type::kOffset: diff --git a/src/reader/wgsl/token.h b/src/reader/wgsl/token.h index b2cf05dc47..1953f6fd8b 100644 --- a/src/reader/wgsl/token.h +++ b/src/reader/wgsl/token.h @@ -234,8 +234,6 @@ class Token { kMat4x3, /// A 'mat4x4' kMat4x4, - /// A 'nop' - kNop, /// A 'num_workgroups' kNumWorkgroups, /// A 'offset' @@ -547,8 +545,6 @@ class Token { bool IsMat4x3() const { return type_ == Type::kMat4x3; } /// @returns true if token is a 'mat4x4' bool IsMat4x4() const { return type_ == Type::kMat4x4; } - /// @returns true if token is a 'nop' - bool IsNop() const { return type_ == Type::kNop; } /// @returns true if token is a 'num_workgroups' bool IsNumWorkgroups() const { return type_ == Type::kNumWorkgroups; } /// @returns true if token is a 'offset' diff --git a/src/type_determiner.cc b/src/type_determiner.cc index 31e66bdec2..0def87071a 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -183,9 +183,6 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) { return DetermineStatements(l->body()) && DetermineStatements(l->continuing()); } - if (stmt->IsNop()) { - return true; - } if (stmt->IsReturn()) { auto* r = stmt->AsReturn(); return DetermineResultType(r->value()); diff --git a/src/writer/spirv/binary_writer_test.cc b/src/writer/spirv/binary_writer_test.cc index 4de1aae31b..63e6f04911 100644 --- a/src/writer/spirv/binary_writer_test.cc +++ b/src/writer/spirv/binary_writer_test.cc @@ -45,7 +45,7 @@ TEST_F(BinaryWriterTest, Preamble) { TEST_F(BinaryWriterTest, Float) { ast::Module mod; Builder b(&mod); - b.push_preamble(spv::Op::OpNop, {Operand::Float(2.4f)}); + b.push_preamble(spv::Op::OpKill, {Operand::Float(2.4f)}); BinaryWriter bw; bw.WriteBuilder(b); @@ -59,7 +59,7 @@ TEST_F(BinaryWriterTest, Float) { TEST_F(BinaryWriterTest, Int) { ast::Module mod; Builder b(&mod); - b.push_preamble(spv::Op::OpNop, {Operand::Int(2)}); + b.push_preamble(spv::Op::OpKill, {Operand::Int(2)}); BinaryWriter bw; bw.WriteBuilder(b); @@ -71,7 +71,7 @@ TEST_F(BinaryWriterTest, Int) { TEST_F(BinaryWriterTest, String) { ast::Module mod; Builder b(&mod); - b.push_preamble(spv::Op::OpNop, {Operand::String("my_string")}); + b.push_preamble(spv::Op::OpKill, {Operand::String("my_string")}); BinaryWriter bw; bw.WriteBuilder(b); @@ -96,7 +96,7 @@ TEST_F(BinaryWriterTest, String) { TEST_F(BinaryWriterTest, String_Multiple4Length) { ast::Module mod; Builder b(&mod); - b.push_preamble(spv::Op::OpNop, {Operand::String("mystring")}); + b.push_preamble(spv::Op::OpKill, {Operand::String("mystring")}); BinaryWriter bw; bw.WriteBuilder(b); @@ -119,8 +119,8 @@ TEST_F(BinaryWriterTest, String_Multiple4Length) { } TEST_F(BinaryWriterTest, TestInstructionWriter) { - Instruction i1{spv::Op::OpNop, {Operand::Int(2)}}; - Instruction i2{spv::Op::OpNop, {Operand::Int(4)}}; + Instruction i1{spv::Op::OpKill, {Operand::Int(2)}}; + Instruction i2{spv::Op::OpKill, {Operand::Int(4)}}; BinaryWriter bw; bw.WriteInstruction(i1); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index d45a1a1353..e3ddcebcd5 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -736,9 +736,6 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) { if (stmt->IsLoop()) { return EmitLoop(stmt->AsLoop()); } - if (stmt->IsNop()) { - return EmitNop(stmt->AsNop()); - } if (stmt->IsReturn()) { return EmitReturn(stmt->AsReturn()); } @@ -920,12 +917,6 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) { return true; } -bool GeneratorImpl::EmitNop(ast::NopStatement*) { - make_indent(); - out_ << "nop;" << std::endl; - return true; -} - bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { make_indent(); diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index d4ee578e5d..d9282bd14d 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -162,10 +162,6 @@ class GeneratorImpl { /// @param expr the member accessor expression /// @returns true if the member accessor was emitted bool EmitMemberAccessor(ast::MemberAccessorExpression* expr); - /// Handles generating a nop statement - /// @param stmt the nop statement - /// @returns true if the statement was successfully emitted - bool EmitNop(ast::NopStatement* stmt); /// Handles return statements /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted diff --git a/src/writer/wgsl/generator_impl_loop_test.cc b/src/writer/wgsl/generator_impl_loop_test.cc index 4ddc0dae95..bb21ff9b31 100644 --- a/src/writer/wgsl/generator_impl_loop_test.cc +++ b/src/writer/wgsl/generator_impl_loop_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/kill_statement.h" #include "src/ast/loop_statement.h" -#include "src/ast/nop_statement.h" #include "src/writer/wgsl/generator_impl.h" namespace tint { @@ -48,7 +47,7 @@ TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) { body.push_back(std::make_unique()); ast::StatementList continuing; - continuing.push_back(std::make_unique()); + continuing.push_back(std::make_unique()); ast::LoopStatement l(std::move(body), std::move(continuing)); @@ -60,7 +59,7 @@ TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) { kill; continuing { - nop; + kill; } } )"); diff --git a/src/writer/wgsl/generator_impl_nop_test.cc b/src/writer/wgsl/generator_impl_nop_test.cc deleted file mode 100644 index 0c50ea70ed..0000000000 --- a/src/writer/wgsl/generator_impl_nop_test.cc +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "gtest/gtest.h" -#include "src/ast/nop_statement.h" -#include "src/writer/wgsl/generator_impl.h" - -namespace tint { -namespace writer { -namespace wgsl { -namespace { - -using GeneratorImplTest = testing::Test; - -TEST_F(GeneratorImplTest, Emit_Nop) { - ast::NopStatement n; - - GeneratorImpl g; - g.increment_indent(); - - ASSERT_TRUE(g.EmitStatement(&n)) << g.error(); - EXPECT_EQ(g.result(), " nop;\n"); -} - -} // namespace -} // namespace wgsl -} // namespace writer -} // namespace tint diff --git a/src/writer/wgsl/generator_impl_unless_test.cc b/src/writer/wgsl/generator_impl_unless_test.cc index 721f877c0f..413f3b5c64 100644 --- a/src/writer/wgsl/generator_impl_unless_test.cc +++ b/src/writer/wgsl/generator_impl_unless_test.cc @@ -17,7 +17,6 @@ #include "gtest/gtest.h" #include "src/ast/identifier_expression.h" #include "src/ast/kill_statement.h" -#include "src/ast/nop_statement.h" #include "src/ast/unless_statement.h" #include "src/writer/wgsl/generator_impl.h" @@ -32,7 +31,7 @@ TEST_F(GeneratorImplTest, Emit_Unless) { auto cond = std::make_unique("cond"); ast::StatementList body; - body.push_back(std::make_unique()); + body.push_back(std::make_unique()); body.push_back(std::make_unique()); ast::UnlessStatement u(std::move(cond), std::move(body)); @@ -42,7 +41,7 @@ TEST_F(GeneratorImplTest, Emit_Unless) { ASSERT_TRUE(g.EmitStatement(&u)) << g.error(); EXPECT_EQ(g.result(), R"( unless (cond) { - nop; + kill; kill; } )");