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 <rharrison@chromium.org>
This commit is contained in:
dan sinclair 2020-05-26 15:05:54 +00:00
parent 53f2026fc5
commit 5370390096
31 changed files with 115 additions and 399 deletions

View File

@ -266,8 +266,6 @@ source_set("libtint_core_src") {
"src/ast/module.h", "src/ast/module.h",
"src/ast/node.cc", "src/ast/node.cc",
"src/ast/node.h", "src/ast/node.h",
"src/ast/nop_statement.cc",
"src/ast/nop_statement.h",
"src/ast/null_literal.cc", "src/ast/null_literal.cc",
"src/ast/null_literal.h", "src/ast/null_literal.h",
"src/ast/pipeline_stage.cc", "src/ast/pipeline_stage.cc",
@ -605,7 +603,6 @@ source_set("tint_unittests_core_src") {
"src/ast/loop_statement_test.cc", "src/ast/loop_statement_test.cc",
"src/ast/member_accessor_expression_test.cc", "src/ast/member_accessor_expression_test.cc",
"src/ast/module_test.cc", "src/ast/module_test.cc",
"src/ast/nop_statement_test.cc",
"src/ast/null_literal_test.cc", "src/ast/null_literal_test.cc",
"src/ast/return_statement_test.cc", "src/ast/return_statement_test.cc",
"src/ast/scalar_constructor_expression_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_kill_test.cc",
"src/writer/wgsl/generator_impl_loop_test.cc", "src/writer/wgsl/generator_impl_loop_test.cc",
"src/writer/wgsl/generator_impl_member_accessor_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_relational_test.cc",
"src/writer/wgsl/generator_impl_return_test.cc", "src/writer/wgsl/generator_impl_return_test.cc",
"src/writer/wgsl/generator_impl_switch_test.cc", "src/writer/wgsl/generator_impl_switch_test.cc",

View File

@ -103,8 +103,6 @@ set(TINT_LIB_SRCS
ast/module.h ast/module.h
ast/node.cc ast/node.cc
ast/node.h ast/node.h
ast/nop_statement.cc
ast/nop_statement.h
ast/null_literal.cc ast/null_literal.cc
ast/null_literal.h ast/null_literal.h
ast/pipeline_stage.cc ast/pipeline_stage.cc
@ -284,7 +282,6 @@ set(TINT_TEST_SRCS
ast/loop_statement_test.cc ast/loop_statement_test.cc
ast/member_accessor_expression_test.cc ast/member_accessor_expression_test.cc
ast/module_test.cc ast/module_test.cc
ast/nop_statement_test.cc
ast/null_literal_test.cc ast/null_literal_test.cc
ast/binary_expression_test.cc ast/binary_expression_test.cc
ast/return_statement_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_kill_test.cc
writer/wgsl/generator_impl_loop_test.cc writer/wgsl/generator_impl_loop_test.cc
writer/wgsl/generator_impl_member_accessor_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_relational_test.cc
writer/wgsl/generator_impl_return_test.cc writer/wgsl/generator_impl_return_test.cc
writer/wgsl/generator_impl_switch_test.cc writer/wgsl/generator_impl_switch_test.cc

View File

@ -17,7 +17,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/if_statement.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" #include "src/ast/type/bool_type.h"
namespace tint { namespace tint {
@ -30,22 +30,22 @@ TEST_F(CaseStatementTest, Creation) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true); auto b = std::make_unique<BoolLiteral>(&bool_type, true);
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
auto* bool_ptr = b.get(); 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)); CaseStatement c(std::move(b), std::move(stmts));
EXPECT_EQ(c.condition(), bool_ptr); EXPECT_EQ(c.condition(), bool_ptr);
ASSERT_EQ(c.body().size(), 1u); 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) { TEST_F(CaseStatementTest, Creation_WithSource) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true); auto b = std::make_unique<BoolLiteral>(&bool_type, true);
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
CaseStatement c(Source{20, 2}, std::move(b), std::move(stmts)); CaseStatement c(Source{20, 2}, std::move(b), std::move(stmts));
auto src = c.source(); auto src = c.source();
@ -55,7 +55,7 @@ TEST_F(CaseStatementTest, Creation_WithSource) {
TEST_F(CaseStatementTest, IsDefault_WithoutCondition) { TEST_F(CaseStatementTest, IsDefault_WithoutCondition) {
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
CaseStatement c; CaseStatement c;
c.set_body(std::move(stmts)); c.set_body(std::move(stmts));
@ -84,7 +84,7 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true); auto b = std::make_unique<BoolLiteral>(&bool_type, true);
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
stmts.push_back(nullptr); stmts.push_back(nullptr);
CaseStatement c(std::move(b), std::move(stmts)); CaseStatement c(std::move(b), std::move(stmts));
@ -105,26 +105,26 @@ TEST_F(CaseStatementTest, ToStr_WithCondition) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto b = std::make_unique<BoolLiteral>(&bool_type, true); auto b = std::make_unique<BoolLiteral>(&bool_type, true);
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
CaseStatement c(std::move(b), std::move(stmts)); CaseStatement c(std::move(b), std::move(stmts));
std::ostringstream out; std::ostringstream out;
c.to_str(out, 2); c.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Case true{ EXPECT_EQ(out.str(), R"( Case true{
Nop{} Kill{}
} }
)"); )");
} }
TEST_F(CaseStatementTest, ToStr_WithoutCondition) { TEST_F(CaseStatementTest, ToStr_WithoutCondition) {
StatementList stmts; StatementList stmts;
stmts.push_back(std::make_unique<NopStatement>()); stmts.push_back(std::make_unique<KillStatement>());
CaseStatement c(nullptr, std::move(stmts)); CaseStatement c(nullptr, std::move(stmts));
std::ostringstream out; std::ostringstream out;
c.to_str(out, 2); c.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Default{ EXPECT_EQ(out.str(), R"( Default{
Nop{} Kill{}
} }
)"); )");
} }

View File

@ -17,7 +17,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/bool_literal.h" #include "src/ast/bool_literal.h"
#include "src/ast/if_statement.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/scalar_constructor_expression.h"
#include "src/ast/type/bool_type.h" #include "src/ast/type/bool_type.h"
@ -32,15 +32,15 @@ TEST_F(ElseStatementTest, Creation) {
auto cond = std::make_unique<ScalarConstructorExpression>( auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true)); std::make_unique<BoolLiteral>(&bool_type, true));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
auto* cond_ptr = cond.get(); 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)); ElseStatement e(std::move(cond), std::move(body));
EXPECT_EQ(e.condition(), cond_ptr); EXPECT_EQ(e.condition(), cond_ptr);
ASSERT_EQ(e.body().size(), 1u); 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) { TEST_F(ElseStatementTest, Creation_WithSource) {
@ -75,7 +75,7 @@ TEST_F(ElseStatementTest, IsValid) {
TEST_F(ElseStatementTest, IsValid_WithBody) { TEST_F(ElseStatementTest, IsValid_WithBody) {
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatement e(std::move(body)); ElseStatement e(std::move(body));
EXPECT_TRUE(e.IsValid()); EXPECT_TRUE(e.IsValid());
@ -83,7 +83,7 @@ TEST_F(ElseStatementTest, IsValid_WithBody) {
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr); body.push_back(nullptr);
ElseStatement e(std::move(body)); ElseStatement e(std::move(body));
@ -109,7 +109,7 @@ TEST_F(ElseStatementTest, ToStr) {
auto cond = std::make_unique<ScalarConstructorExpression>( auto cond = std::make_unique<ScalarConstructorExpression>(
std::make_unique<BoolLiteral>(&bool_type, true)); std::make_unique<BoolLiteral>(&bool_type, true));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatement e(std::move(cond), std::move(body)); ElseStatement e(std::move(cond), std::move(body));
std::ostringstream out; std::ostringstream out;
@ -119,7 +119,7 @@ TEST_F(ElseStatementTest, ToStr) {
ScalarConstructor{true} ScalarConstructor{true}
) )
{ {
Nop{} Kill{}
} }
} }
)"); )");
@ -127,14 +127,14 @@ TEST_F(ElseStatementTest, ToStr) {
TEST_F(ElseStatementTest, ToStr_NoCondition) { TEST_F(ElseStatementTest, ToStr_NoCondition) {
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatement e(std::move(body)); ElseStatement e(std::move(body));
std::ostringstream out; std::ostringstream out;
e.to_str(out, 2); e.to_str(out, 2);
EXPECT_EQ(out.str(), R"( Else{ EXPECT_EQ(out.str(), R"( Else{
{ {
Nop{} Kill{}
} }
} }
)"); )");

View File

@ -15,7 +15,7 @@
#include "src/ast/function.h" #include "src/ast/function.h"
#include "gtest/gtest.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/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"
@ -66,7 +66,7 @@ TEST_F(FunctionTest, IsValid) {
std::make_unique<Variable>("var", StorageClass::kNone, &i32)); std::make_unique<Variable>("var", StorageClass::kNone, &i32));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
Function f("func", std::move(params), &void_type); Function f("func", std::move(params), &void_type);
f.set_body(std::move(body)); f.set_body(std::move(body));
@ -129,7 +129,7 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
std::make_unique<Variable>("var", StorageClass::kNone, &i32)); std::make_unique<Variable>("var", StorageClass::kNone, &i32));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr); body.push_back(nullptr);
Function f("func", std::move(params), &void_type); Function f("func", std::move(params), &void_type);
@ -146,7 +146,7 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) {
std::make_unique<Variable>("var", StorageClass::kNone, &i32)); std::make_unique<Variable>("var", StorageClass::kNone, &i32));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr); body.push_back(nullptr);
Function f("func", std::move(params), &void_type); Function f("func", std::move(params), &void_type);
@ -159,7 +159,7 @@ TEST_F(FunctionTest, ToStr) {
type::I32Type i32; type::I32Type i32;
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
Function f("func", {}, &void_type); Function f("func", {}, &void_type);
f.set_body(std::move(body)); f.set_body(std::move(body));
@ -169,7 +169,7 @@ TEST_F(FunctionTest, ToStr) {
EXPECT_EQ(out.str(), R"( Function func -> __void EXPECT_EQ(out.str(), R"( Function func -> __void
() ()
{ {
Nop{} Kill{}
} }
)"); )");
} }
@ -183,7 +183,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
std::make_unique<Variable>("var", StorageClass::kNone, &i32)); std::make_unique<Variable>("var", StorageClass::kNone, &i32));
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
Function f("func", std::move(params), &void_type); Function f("func", std::move(params), &void_type);
f.set_body(std::move(body)); f.set_body(std::move(body));
@ -199,7 +199,7 @@ TEST_F(FunctionTest, ToStr_WithParams) {
} }
) )
{ {
Nop{} Kill{}
} }
)"); )");
} }

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/nop_statement.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -28,7 +27,7 @@ using IfStatementTest = testing::Test;
TEST_F(IfStatementTest, Creation) { TEST_F(IfStatementTest, Creation) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
auto* cond_ptr = cond.get(); auto* cond_ptr = cond.get();
auto* stmt_ptr = body[0].get(); auto* stmt_ptr = body[0].get();
@ -42,7 +41,7 @@ TEST_F(IfStatementTest, Creation) {
TEST_F(IfStatementTest, Creation_WithSource) { TEST_F(IfStatementTest, Creation_WithSource) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
IfStatement stmt(Source{20, 2}, std::move(cond), std::move(body)); IfStatement stmt(Source{20, 2}, std::move(cond), std::move(body));
auto src = stmt.source(); auto src = stmt.source();
@ -58,7 +57,7 @@ TEST_F(IfStatementTest, IsIf) {
TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
IfStatement stmt(std::move(cond), std::move(body)); IfStatement stmt(std::move(cond), std::move(body));
EXPECT_TRUE(stmt.IsValid()); EXPECT_TRUE(stmt.IsValid());
@ -67,7 +66,7 @@ TEST_F(IfStatementTest, IsValid) {
TEST_F(IfStatementTest, IsValid_WithElseStatements) { TEST_F(IfStatementTest, IsValid_WithElseStatements) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>()); else_stmts.push_back(std::make_unique<ElseStatement>());
@ -81,7 +80,7 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
TEST_F(IfStatementTest, IsValid_MissingCondition) { TEST_F(IfStatementTest, IsValid_MissingCondition) {
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
IfStatement stmt(nullptr, std::move(body)); IfStatement stmt(nullptr, std::move(body));
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -90,7 +89,7 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) {
TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) {
auto cond = std::make_unique<IdentifierExpression>(""); auto cond = std::make_unique<IdentifierExpression>("");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
IfStatement stmt(std::move(cond), std::move(body)); IfStatement stmt(std::move(cond), std::move(body));
EXPECT_FALSE(stmt.IsValid()); EXPECT_FALSE(stmt.IsValid());
@ -99,7 +98,7 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) {
TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr); body.push_back(nullptr);
IfStatement stmt(std::move(cond), std::move(body)); IfStatement stmt(std::move(cond), std::move(body));
@ -109,7 +108,7 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) {
TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(std::make_unique<IfStatement>()); body.push_back(std::make_unique<IfStatement>());
IfStatement stmt(std::move(cond), std::move(body)); IfStatement stmt(std::move(cond), std::move(body));
@ -119,7 +118,7 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>()); else_stmts.push_back(std::make_unique<ElseStatement>());
@ -135,7 +134,7 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>()); else_stmts.push_back(std::make_unique<ElseStatement>());
@ -149,7 +148,7 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>()); else_stmts.push_back(std::make_unique<ElseStatement>());
@ -163,7 +162,7 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ElseStatement>()); else_stmts.push_back(std::make_unique<ElseStatement>());
@ -178,7 +177,7 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
IfStatement stmt(std::move(cond), std::move(body)); IfStatement stmt(std::move(cond), std::move(body));
@ -189,7 +188,7 @@ TEST_F(IfStatementTest, ToStr) {
Identifier{cond} Identifier{cond}
) )
{ {
Nop{} Kill{}
} }
} }
)"); )");
@ -198,13 +197,13 @@ TEST_F(IfStatementTest, ToStr) {
TEST_F(IfStatementTest, ToStr_WithElseStatements) { TEST_F(IfStatementTest, ToStr_WithElseStatements) {
auto cond = std::make_unique<IdentifierExpression>("cond"); auto cond = std::make_unique<IdentifierExpression>("cond");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList else_if_body; StatementList else_if_body;
else_if_body.push_back(std::make_unique<KillStatement>()); else_if_body.push_back(std::make_unique<KillStatement>());
StatementList else_body; StatementList else_body;
else_body.push_back(std::make_unique<NopStatement>()); else_body.push_back(std::make_unique<KillStatement>());
else_body.push_back(std::make_unique<KillStatement>()); else_body.push_back(std::make_unique<KillStatement>());
ElseStatementList else_stmts; ElseStatementList else_stmts;
@ -224,7 +223,7 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
Identifier{cond} Identifier{cond}
) )
{ {
Nop{} Kill{}
} }
} }
Else{ Else{
@ -237,7 +236,7 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
} }
Else{ Else{
{ {
Nop{} Kill{}
Kill{} Kill{}
} }
} }

View File

@ -20,7 +20,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/nop_statement.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -34,7 +33,7 @@ TEST_F(LoopStatementTest, Creation) {
auto* b_ptr = body[0].get(); auto* b_ptr = body[0].get();
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
auto* c_ptr = continuing[0].get(); auto* c_ptr = continuing[0].get();
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
@ -49,7 +48,7 @@ TEST_F(LoopStatementTest, Creation_WithSource) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(Source{20, 2}, std::move(body), std::move(continuing)); LoopStatement l(Source{20, 2}, std::move(body), std::move(continuing));
auto src = l.source(); auto src = l.source();
@ -75,7 +74,7 @@ TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
EXPECT_TRUE(l.has_continuing()); EXPECT_TRUE(l.has_continuing());
@ -86,7 +85,7 @@ TEST_F(LoopStatementTest, IsValid) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
EXPECT_TRUE(l.IsValid()); EXPECT_TRUE(l.IsValid());
@ -111,7 +110,7 @@ TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
body.push_back(nullptr); body.push_back(nullptr);
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
@ -123,7 +122,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
body.push_back(std::make_unique<IfStatement>()); body.push_back(std::make_unique<IfStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
EXPECT_FALSE(l.IsValid()); EXPECT_FALSE(l.IsValid());
@ -134,7 +133,7 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
continuing.push_back(nullptr); continuing.push_back(nullptr);
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
@ -146,7 +145,7 @@ TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
continuing.push_back(std::make_unique<IfStatement>()); continuing.push_back(std::make_unique<IfStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
@ -171,7 +170,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) {
body.push_back(std::make_unique<KillStatement>()); body.push_back(std::make_unique<KillStatement>());
StatementList continuing; StatementList continuing;
continuing.push_back(std::make_unique<NopStatement>()); continuing.push_back(std::make_unique<KillStatement>());
LoopStatement l(std::move(body), std::move(continuing)); LoopStatement l(std::move(body), std::move(continuing));
std::ostringstream out; std::ostringstream out;
@ -179,7 +178,7 @@ TEST_F(LoopStatementTest, ToStr_WithContinuing) {
EXPECT_EQ(out.str(), R"( Loop{ EXPECT_EQ(out.str(), R"( Loop{
Kill{} Kill{}
continuing { continuing {
Nop{} Kill{}
} }
} }
)"); )");

View File

@ -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

View File

@ -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_

View File

@ -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 <sstream>
#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

View File

@ -25,7 +25,6 @@
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/nop_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/switch_statement.h" #include "src/ast/switch_statement.h"
#include "src/ast/unless_statement.h" #include "src/ast/unless_statement.h"
@ -78,10 +77,6 @@ bool Statement::IsLoop() const {
return false; return false;
} }
bool Statement::IsNop() const {
return false;
}
bool Statement::IsReturn() const { bool Statement::IsReturn() const {
return false; return false;
} }
@ -143,11 +138,6 @@ const LoopStatement* Statement::AsLoop() const {
return static_cast<const LoopStatement*>(this); return static_cast<const LoopStatement*>(this);
} }
const NopStatement* Statement::AsNop() const {
assert(IsNop());
return static_cast<const NopStatement*>(this);
}
const ReturnStatement* Statement::AsReturn() const { const ReturnStatement* Statement::AsReturn() const {
assert(IsReturn()); assert(IsReturn());
return static_cast<const ReturnStatement*>(this); return static_cast<const ReturnStatement*>(this);
@ -213,11 +203,6 @@ LoopStatement* Statement::AsLoop() {
return static_cast<LoopStatement*>(this); return static_cast<LoopStatement*>(this);
} }
NopStatement* Statement::AsNop() {
assert(IsNop());
return static_cast<NopStatement*>(this);
}
ReturnStatement* Statement::AsReturn() { ReturnStatement* Statement::AsReturn() {
assert(IsReturn()); assert(IsReturn());
return static_cast<ReturnStatement*>(this); return static_cast<ReturnStatement*>(this);

View File

@ -32,7 +32,6 @@ class FallthroughStatement;
class IfStatement; class IfStatement;
class KillStatement; class KillStatement;
class LoopStatement; class LoopStatement;
class NopStatement;
class ReturnStatement; class ReturnStatement;
class SwitchStatement; class SwitchStatement;
class UnlessStatement; class UnlessStatement;
@ -61,8 +60,6 @@ class Statement : public Node {
virtual bool IsKill() const; virtual bool IsKill() const;
/// @returns true if this is a loop statement /// @returns true if this is a loop statement
virtual bool IsLoop() const; virtual bool IsLoop() const;
/// @returns true if this is a nop statement
virtual bool IsNop() const;
/// @returns true if this is a return statement /// @returns true if this is a return statement
virtual bool IsReturn() const; virtual bool IsReturn() const;
/// @returns true if this is a switch statement /// @returns true if this is a switch statement
@ -90,8 +87,6 @@ class Statement : public Node {
const KillStatement* AsKill() const; const KillStatement* AsKill() const;
/// @returns the statement as a const loop statement /// @returns the statement as a const loop statement
const LoopStatement* AsLoop() const; const LoopStatement* AsLoop() const;
/// @returns the statement as a const nop statement
const NopStatement* AsNop() const;
/// @returns the statement as a const return statement /// @returns the statement as a const return statement
const ReturnStatement* AsReturn() const; const ReturnStatement* AsReturn() const;
/// @returns the statement as a const switch statement /// @returns the statement as a const switch statement
@ -119,8 +114,6 @@ class Statement : public Node {
KillStatement* AsKill(); KillStatement* AsKill();
/// @returns the statement as a loop statement /// @returns the statement as a loop statement
LoopStatement* AsLoop(); LoopStatement* AsLoop();
/// @returns the statement as a nop statement
NopStatement* AsNop();
/// @returns the statement as a return statement /// @returns the statement as a return statement
ReturnStatement* AsReturn(); ReturnStatement* AsReturn();
/// @returns the statement as a switch statement /// @returns the statement as a switch statement

View File

@ -17,7 +17,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/if_statement.h" #include "src/ast/if_statement.h"
#include "src/ast/nop_statement.h" #include "src/ast/kill_statement.h"
namespace tint { namespace tint {
namespace ast { namespace ast {
@ -28,21 +28,21 @@ using UnlessStatementTest = testing::Test;
TEST_F(UnlessStatementTest, Creation) { TEST_F(UnlessStatementTest, Creation) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
auto* ident_ptr = ident.get(); 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)); UnlessStatement u(std::move(ident), std::move(body));
EXPECT_EQ(u.condition(), ident_ptr); EXPECT_EQ(u.condition(), ident_ptr);
ASSERT_EQ(u.body().size(), 1u); 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) { TEST_F(UnlessStatementTest, Creation_WithSource) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
UnlessStatement u(Source{20, 2}, std::move(ident), std::move(body)); UnlessStatement u(Source{20, 2}, std::move(ident), std::move(body));
auto src = u.source(); auto src = u.source();
@ -58,7 +58,7 @@ TEST_F(UnlessStatementTest, IsUnless) {
TEST_F(UnlessStatementTest, IsValid) { TEST_F(UnlessStatementTest, IsValid) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
UnlessStatement u(std::move(ident), std::move(body)); UnlessStatement u(std::move(ident), std::move(body));
EXPECT_TRUE(u.IsValid()); EXPECT_TRUE(u.IsValid());
@ -66,7 +66,7 @@ TEST_F(UnlessStatementTest, IsValid) {
TEST_F(UnlessStatementTest, IsValid_NullCondition) { TEST_F(UnlessStatementTest, IsValid_NullCondition) {
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
UnlessStatement u; UnlessStatement u;
u.set_body(std::move(body)); u.set_body(std::move(body));
@ -76,7 +76,7 @@ TEST_F(UnlessStatementTest, IsValid_NullCondition) {
TEST_F(UnlessStatementTest, IsValid_InvalidCondition) { TEST_F(UnlessStatementTest, IsValid_InvalidCondition) {
auto ident = std::make_unique<IdentifierExpression>(""); auto ident = std::make_unique<IdentifierExpression>("");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
UnlessStatement u(std::move(ident), std::move(body)); UnlessStatement u(std::move(ident), std::move(body));
EXPECT_FALSE(u.IsValid()); EXPECT_FALSE(u.IsValid());
@ -85,7 +85,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidCondition) {
TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) { TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(nullptr); body.push_back(nullptr);
UnlessStatement u(std::move(ident), std::move(body)); UnlessStatement u(std::move(ident), std::move(body));
@ -95,7 +95,7 @@ TEST_F(UnlessStatementTest, IsValid_NullBodyStatement) {
TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) { TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
body.push_back(std::make_unique<IfStatement>()); body.push_back(std::make_unique<IfStatement>());
UnlessStatement u(std::move(ident), std::move(body)); UnlessStatement u(std::move(ident), std::move(body));
@ -105,7 +105,7 @@ TEST_F(UnlessStatementTest, IsValid_InvalidBodyStatement) {
TEST_F(UnlessStatementTest, ToStr) { TEST_F(UnlessStatementTest, ToStr) {
auto ident = std::make_unique<IdentifierExpression>("ident"); auto ident = std::make_unique<IdentifierExpression>("ident");
StatementList body; StatementList body;
body.push_back(std::make_unique<NopStatement>()); body.push_back(std::make_unique<KillStatement>());
UnlessStatement u(std::move(ident), std::move(body)); UnlessStatement u(std::move(ident), std::move(body));
std::ostringstream out; std::ostringstream out;
@ -115,7 +115,7 @@ TEST_F(UnlessStatementTest, ToStr) {
Identifier{ident} Identifier{ident}
) )
{ {
Nop{} Kill{}
} }
} }
)"); )");

View File

@ -1632,10 +1632,8 @@ TypedExpression FunctionEmitter::MakeAccessChain(
pointee_type->AsVector()->element_count() <= index_const_val) { pointee_type->AsVector()->element_count() <= index_const_val) {
Fail() << "Access chain %" << inst.result_id() << " index %" Fail() << "Access chain %" << inst.result_id() << " index %"
<< inst.GetSingleWordInOperand(index) << " value " << inst.GetSingleWordInOperand(index) << " value "
<< index_const_val << index_const_val << " is out of bounds for vector of "
<< " is out of bounds for vector of " << pointee_type->AsVector()->element_count() << " elements";
<< pointee_type->AsVector()->element_count()
<< " elements";
return {}; return {};
} }
if (uint64_t(index_const_val) >= if (uint64_t(index_const_val) >=
@ -1659,17 +1657,20 @@ TypedExpression FunctionEmitter::MakeAccessChain(
case spvtools::opt::analysis::Type::kMatrix: case spvtools::opt::analysis::Type::kMatrix:
// Use array syntax. // Use array syntax.
next_expr = std::make_unique<ast::ArrayAccessorExpression>( next_expr = std::make_unique<ast::ArrayAccessorExpression>(
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(); pointee_type = pointee_type->AsMatrix()->element_type();
break; break;
case spvtools::opt::analysis::Type::kArray: case spvtools::opt::analysis::Type::kArray:
next_expr = std::make_unique<ast::ArrayAccessorExpression>( next_expr = std::make_unique<ast::ArrayAccessorExpression>(
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(); pointee_type = pointee_type->AsArray()->element_type();
break; break;
case spvtools::opt::analysis::Type::kRuntimeArray: case spvtools::opt::analysis::Type::kRuntimeArray:
next_expr = std::make_unique<ast::ArrayAccessorExpression>( next_expr = std::make_unique<ast::ArrayAccessorExpression>(
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(); pointee_type = pointee_type->AsRuntimeArray()->element_type();
break; break;
case spvtools::opt::analysis::Type::kStruct: { case spvtools::opt::analysis::Type::kStruct: {
@ -1683,9 +1684,8 @@ TypedExpression FunctionEmitter::MakeAccessChain(
if ((index_const_val < 0) || if ((index_const_val < 0) ||
pointee_type->AsStruct()->element_types().size() <= pointee_type->AsStruct()->element_types().size() <=
uint64_t(index_const_val)) { uint64_t(index_const_val)) {
Fail() << "Access chain %" << inst.result_id() Fail() << "Access chain %" << inst.result_id() << " index value "
<< " index value " << index_const_val << index_const_val << " is out of bounds for structure %"
<< " is out of bounds for structure %"
<< type_mgr_->GetId(pointee_type) << " having " << type_mgr_->GetId(pointee_type) << " having "
<< pointee_type->AsStruct()->element_types().size() << pointee_type->AsStruct()->element_types().size()
<< " elements"; << " elements";
@ -1703,8 +1703,7 @@ TypedExpression FunctionEmitter::MakeAccessChain(
} }
default: default:
Fail() << "Access chain with unknown pointee type %" Fail() << "Access chain with unknown pointee type %"
<< type_mgr_->GetId(pointee_type) << " " << type_mgr_->GetId(pointee_type) << " " << pointee_type->str();
<< pointee_type->str();
return {}; return {};
} }
current_expr.reset(TypedExpression( current_expr.reset(TypedExpression(

View File

@ -586,8 +586,6 @@ Token Lexer::check_keyword(const Source& source, const std::string& str) {
return {Token::Type::kMat4x3, source, "mat4x3"}; return {Token::Type::kMat4x3, source, "mat4x3"};
if (str == "mat4x4") if (str == "mat4x4")
return {Token::Type::kMat4x4, source, "mat4x4"}; return {Token::Type::kMat4x4, source, "mat4x4"};
if (str == "nop")
return {Token::Type::kNop, source, "nop"};
if (str == "num_workgroups") if (str == "num_workgroups")
return {Token::Type::kNumWorkgroups, source, "num_workgroups"}; return {Token::Type::kNumWorkgroups, source, "num_workgroups"};
if (str == "offset") if (str == "offset")

View File

@ -468,7 +468,6 @@ INSTANTIATE_TEST_SUITE_P(
TokenData{"mat4x2", Token::Type::kMat4x2}, TokenData{"mat4x2", Token::Type::kMat4x2},
TokenData{"mat4x3", Token::Type::kMat4x3}, TokenData{"mat4x3", Token::Type::kMat4x3},
TokenData{"mat4x4", Token::Type::kMat4x4}, TokenData{"mat4x4", Token::Type::kMat4x4},
TokenData{"nop", Token::Type::kNop},
TokenData{"num_workgroups", Token::Type::kNumWorkgroups}, TokenData{"num_workgroups", Token::Type::kNumWorkgroups},
TokenData{"offset", Token::Type::kOffset}, TokenData{"offset", Token::Type::kOffset},
TokenData{"out", Token::Type::kOut}, TokenData{"out", Token::Type::kOut},

View File

@ -38,7 +38,6 @@
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/location_decoration.h" #include "src/ast/location_decoration.h"
#include "src/ast/member_accessor_expression.h" #include "src/ast/member_accessor_expression.h"
#include "src/ast/nop_statement.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/scalar_constructor_expression.h" #include "src/ast/scalar_constructor_expression.h"
#include "src/ast/set_decoration.h" #include "src/ast/set_decoration.h"
@ -1450,7 +1449,6 @@ ast::StatementList ParserImpl::statements() {
// | break_stmt SEMICOLON // | break_stmt SEMICOLON
// | continue_stmt SEMICOLON // | continue_stmt SEMICOLON
// | KILL SEMICOLON // | KILL SEMICOLON
// | NOP SEMICOLON
// | assignment_expression SEMICOLON // | assignment_expression SEMICOLON
std::unique_ptr<ast::Statement> ParserImpl::statement() { std::unique_ptr<ast::Statement> ParserImpl::statement() {
auto t = peek(); auto t = peek();
@ -1552,18 +1550,6 @@ std::unique_ptr<ast::Statement> ParserImpl::statement() {
return std::make_unique<ast::KillStatement>(source); return std::make_unique<ast::KillStatement>(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<ast::NopStatement>(source);
}
auto assign = assignment_stmt(); auto assign = assignment_stmt();
if (has_error()) if (has_error())
return nullptr; return nullptr;

View File

@ -24,15 +24,13 @@ namespace {
TEST_F(ParserImplTest, BodyStmt) { TEST_F(ParserImplTest, BodyStmt) {
auto* p = parser(R"({ auto* p = parser(R"({
kill; kill;
nop;
return 1 + b / 2; return 1 + b / 2;
})"); })");
auto e = p->body_stmt(); auto e = p->body_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); 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[0]->IsKill());
EXPECT_TRUE(e[1]->IsNop()); EXPECT_TRUE(e[1]->IsReturn());
EXPECT_TRUE(e[2]->IsReturn());
} }
TEST_F(ParserImplTest, BodyStmt_Empty) { TEST_F(ParserImplTest, BodyStmt_Empty) {

View File

@ -22,19 +22,19 @@ namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, ContinuingStmt) { TEST_F(ParserImplTest, ContinuingStmt) {
auto* p = parser("continuing { nop; }"); auto* p = parser("continuing { kill; }");
auto e = p->continuing_stmt(); auto e = p->continuing_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e.size(), 1u); ASSERT_EQ(e.size(), 1u);
ASSERT_TRUE(e[0]->IsNop()); ASSERT_TRUE(e[0]->IsKill());
} }
TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) { TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) {
auto* p = parser("continuing { nop }"); auto* p = parser("continuing { kill }");
auto e = p->continuing_stmt(); auto e = p->continuing_stmt();
ASSERT_TRUE(p->has_error()); ASSERT_TRUE(p->has_error());
ASSERT_EQ(e.size(), 0u); ASSERT_EQ(e.size(), 0u);
EXPECT_EQ(p->error(), "1:18: missing ;"); EXPECT_EQ(p->error(), "1:19: missing ;");
} }
} // namespace } // namespace

View File

@ -22,25 +22,25 @@ namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) { TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) {
auto* p = parser("loop { nop; }"); auto* p = parser("loop { kill; }");
auto e = p->loop_stmt(); auto e = p->loop_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_EQ(e->body().size(), 1u); ASSERT_EQ(e->body().size(), 1u);
EXPECT_TRUE(e->body()[0]->IsNop()); EXPECT_TRUE(e->body()[0]->IsKill());
EXPECT_EQ(e->continuing().size(), 0u); EXPECT_EQ(e->continuing().size(), 0u);
} }
TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) {
auto* p = parser("loop { nop; continuing { kill; }}"); auto* p = parser("loop { kill; continuing { kill; }}");
auto e = p->loop_stmt(); auto e = p->loop_stmt();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e, nullptr); ASSERT_NE(e, nullptr);
ASSERT_EQ(e->body().size(), 1u); 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_EQ(e->continuing().size(), 1u);
EXPECT_TRUE(e->continuing()[0]->IsKill()); EXPECT_TRUE(e->continuing()[0]->IsKill());

View File

@ -253,22 +253,6 @@ TEST_F(ParserImplTest, Statement_Kill_MissingSemicolon) {
EXPECT_EQ(p->error(), "1:5: missing ;"); 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
} // namespace wgsl } // namespace wgsl
} // namespace reader } // namespace reader

View File

@ -23,13 +23,12 @@ namespace wgsl {
namespace { namespace {
TEST_F(ParserImplTest, Statements) { TEST_F(ParserImplTest, Statements) {
auto* p = parser("nop; kill; return;"); auto* p = parser("kill; return;");
auto e = p->statements(); auto e = p->statements();
ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e.size(), 3u); ASSERT_EQ(e.size(), 2u);
EXPECT_TRUE(e[0]->IsNop()); EXPECT_TRUE(e[0]->IsKill());
EXPECT_TRUE(e[1]->IsKill()); EXPECT_TRUE(e[1]->IsReturn());
EXPECT_TRUE(e[2]->IsReturn());
} }
TEST_F(ParserImplTest, Statements_Empty) { TEST_F(ParserImplTest, Statements_Empty) {

View File

@ -223,8 +223,6 @@ std::string Token::TypeToName(Type type) {
return "mat4x3"; return "mat4x3";
case Token::Type::kMat4x4: case Token::Type::kMat4x4:
return "mat4x4"; return "mat4x4";
case Token::Type::kNop:
return "nop";
case Token::Type::kNumWorkgroups: case Token::Type::kNumWorkgroups:
return "num_workgroups"; return "num_workgroups";
case Token::Type::kOffset: case Token::Type::kOffset:

View File

@ -234,8 +234,6 @@ class Token {
kMat4x3, kMat4x3,
/// A 'mat4x4' /// A 'mat4x4'
kMat4x4, kMat4x4,
/// A 'nop'
kNop,
/// A 'num_workgroups' /// A 'num_workgroups'
kNumWorkgroups, kNumWorkgroups,
/// A 'offset' /// A 'offset'
@ -547,8 +545,6 @@ class Token {
bool IsMat4x3() const { return type_ == Type::kMat4x3; } bool IsMat4x3() const { return type_ == Type::kMat4x3; }
/// @returns true if token is a 'mat4x4' /// @returns true if token is a 'mat4x4'
bool IsMat4x4() const { return type_ == Type::kMat4x4; } 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' /// @returns true if token is a 'num_workgroups'
bool IsNumWorkgroups() const { return type_ == Type::kNumWorkgroups; } bool IsNumWorkgroups() const { return type_ == Type::kNumWorkgroups; }
/// @returns true if token is a 'offset' /// @returns true if token is a 'offset'

View File

@ -183,9 +183,6 @@ bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
return DetermineStatements(l->body()) && return DetermineStatements(l->body()) &&
DetermineStatements(l->continuing()); DetermineStatements(l->continuing());
} }
if (stmt->IsNop()) {
return true;
}
if (stmt->IsReturn()) { if (stmt->IsReturn()) {
auto* r = stmt->AsReturn(); auto* r = stmt->AsReturn();
return DetermineResultType(r->value()); return DetermineResultType(r->value());

View File

@ -45,7 +45,7 @@ TEST_F(BinaryWriterTest, Preamble) {
TEST_F(BinaryWriterTest, Float) { TEST_F(BinaryWriterTest, Float) {
ast::Module mod; ast::Module mod;
Builder b(&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; BinaryWriter bw;
bw.WriteBuilder(b); bw.WriteBuilder(b);
@ -59,7 +59,7 @@ TEST_F(BinaryWriterTest, Float) {
TEST_F(BinaryWriterTest, Int) { TEST_F(BinaryWriterTest, Int) {
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
b.push_preamble(spv::Op::OpNop, {Operand::Int(2)}); b.push_preamble(spv::Op::OpKill, {Operand::Int(2)});
BinaryWriter bw; BinaryWriter bw;
bw.WriteBuilder(b); bw.WriteBuilder(b);
@ -71,7 +71,7 @@ TEST_F(BinaryWriterTest, Int) {
TEST_F(BinaryWriterTest, String) { TEST_F(BinaryWriterTest, String) {
ast::Module mod; ast::Module mod;
Builder b(&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; BinaryWriter bw;
bw.WriteBuilder(b); bw.WriteBuilder(b);
@ -96,7 +96,7 @@ TEST_F(BinaryWriterTest, String) {
TEST_F(BinaryWriterTest, String_Multiple4Length) { TEST_F(BinaryWriterTest, String_Multiple4Length) {
ast::Module mod; ast::Module mod;
Builder b(&mod); Builder b(&mod);
b.push_preamble(spv::Op::OpNop, {Operand::String("mystring")}); b.push_preamble(spv::Op::OpKill, {Operand::String("mystring")});
BinaryWriter bw; BinaryWriter bw;
bw.WriteBuilder(b); bw.WriteBuilder(b);
@ -119,8 +119,8 @@ TEST_F(BinaryWriterTest, String_Multiple4Length) {
} }
TEST_F(BinaryWriterTest, TestInstructionWriter) { TEST_F(BinaryWriterTest, TestInstructionWriter) {
Instruction i1{spv::Op::OpNop, {Operand::Int(2)}}; Instruction i1{spv::Op::OpKill, {Operand::Int(2)}};
Instruction i2{spv::Op::OpNop, {Operand::Int(4)}}; Instruction i2{spv::Op::OpKill, {Operand::Int(4)}};
BinaryWriter bw; BinaryWriter bw;
bw.WriteInstruction(i1); bw.WriteInstruction(i1);

View File

@ -736,9 +736,6 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
if (stmt->IsLoop()) { if (stmt->IsLoop()) {
return EmitLoop(stmt->AsLoop()); return EmitLoop(stmt->AsLoop());
} }
if (stmt->IsNop()) {
return EmitNop(stmt->AsNop());
}
if (stmt->IsReturn()) { if (stmt->IsReturn()) {
return EmitReturn(stmt->AsReturn()); return EmitReturn(stmt->AsReturn());
} }
@ -920,12 +917,6 @@ bool GeneratorImpl::EmitLoop(ast::LoopStatement* stmt) {
return true; return true;
} }
bool GeneratorImpl::EmitNop(ast::NopStatement*) {
make_indent();
out_ << "nop;" << std::endl;
return true;
}
bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) { bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) {
make_indent(); make_indent();

View File

@ -162,10 +162,6 @@ class GeneratorImpl {
/// @param expr the member accessor expression /// @param expr the member accessor expression
/// @returns true if the member accessor was emitted /// @returns true if the member accessor was emitted
bool EmitMemberAccessor(ast::MemberAccessorExpression* expr); 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 /// Handles return statements
/// @param stmt the statement to emit /// @param stmt the statement to emit
/// @returns true if the statement was successfully emitted /// @returns true if the statement was successfully emitted

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/loop_statement.h" #include "src/ast/loop_statement.h"
#include "src/ast/nop_statement.h"
#include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/generator_impl.h"
namespace tint { namespace tint {
@ -48,7 +47,7 @@ TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) {
body.push_back(std::make_unique<ast::KillStatement>()); body.push_back(std::make_unique<ast::KillStatement>());
ast::StatementList continuing; ast::StatementList continuing;
continuing.push_back(std::make_unique<ast::NopStatement>()); continuing.push_back(std::make_unique<ast::KillStatement>());
ast::LoopStatement l(std::move(body), std::move(continuing)); ast::LoopStatement l(std::move(body), std::move(continuing));
@ -60,7 +59,7 @@ TEST_F(GeneratorImplTest, Emit_LoopWithContinuing) {
kill; kill;
continuing { continuing {
nop; kill;
} }
} }
)"); )");

View File

@ -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

View File

@ -17,7 +17,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/identifier_expression.h" #include "src/ast/identifier_expression.h"
#include "src/ast/kill_statement.h" #include "src/ast/kill_statement.h"
#include "src/ast/nop_statement.h"
#include "src/ast/unless_statement.h" #include "src/ast/unless_statement.h"
#include "src/writer/wgsl/generator_impl.h" #include "src/writer/wgsl/generator_impl.h"
@ -32,7 +31,7 @@ TEST_F(GeneratorImplTest, Emit_Unless) {
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = std::make_unique<ast::IdentifierExpression>("cond");
ast::StatementList body; ast::StatementList body;
body.push_back(std::make_unique<ast::NopStatement>()); body.push_back(std::make_unique<ast::KillStatement>());
body.push_back(std::make_unique<ast::KillStatement>()); body.push_back(std::make_unique<ast::KillStatement>());
ast::UnlessStatement u(std::move(cond), std::move(body)); 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(); ASSERT_TRUE(g.EmitStatement(&u)) << g.error();
EXPECT_EQ(g.result(), R"( unless (cond) { EXPECT_EQ(g.result(), R"( unless (cond) {
nop; kill;
kill; kill;
} }
)"); )");