Add Kill, Nop and Fallthrough to WGSL writer
This CL adds the Kill, Nop and Fallthrough statements to the WGSL writer. Bug: tint:4 Change-Id: Ic0c635cfa7ca4c3195c593b119f9436ffeb1f9dc Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17201 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
17686fc57c
commit
c083af83ea
|
@ -414,10 +414,13 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
writer/wgsl/generator_impl_cast_test.cc
|
||||
writer/wgsl/generator_impl_continue_test.cc
|
||||
writer/wgsl/generator_impl_entry_point_test.cc
|
||||
writer/wgsl/generator_impl_fallthrough_test.cc
|
||||
writer/wgsl/generator_impl_identifier_test.cc
|
||||
writer/wgsl/generator_impl_import_test.cc
|
||||
writer/wgsl/generator_impl_initializer_test.cc
|
||||
writer/wgsl/generator_impl_kill_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_type_test.cc
|
||||
writer/wgsl/generator_impl_unary_derivative_test.cc
|
||||
|
|
|
@ -660,6 +660,15 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
|||
if (stmt->IsContinue()) {
|
||||
return EmitContinue(stmt->AsContinue());
|
||||
}
|
||||
if (stmt->IsFallthrough()) {
|
||||
return EmitFallthrough(stmt->AsFallthrough());
|
||||
}
|
||||
if (stmt->IsKill()) {
|
||||
return EmitKill(stmt->AsKill());
|
||||
}
|
||||
if (stmt->IsNop()) {
|
||||
return EmitNop(stmt->AsNop());
|
||||
}
|
||||
|
||||
error_ = "unknown statement type";
|
||||
return false;
|
||||
|
@ -762,6 +771,24 @@ bool GeneratorImpl::EmitContinue(ast::ContinueStatement* stmt) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitFallthrough(ast::FallthroughStatement*) {
|
||||
make_indent();
|
||||
out_ << "fallthrough;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitKill(ast::KillStatement*) {
|
||||
make_indent();
|
||||
out_ << "kill;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitNop(ast::NopStatement*) {
|
||||
make_indent();
|
||||
out_ << "nop;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace wgsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
||||
|
|
|
@ -114,6 +114,10 @@ class GeneratorImpl {
|
|||
/// @param expr the expression
|
||||
/// @returns true if the expression was emitted
|
||||
bool EmitExpression(ast::Expression* expr);
|
||||
/// Handles generating a fallthrough statement
|
||||
/// @param stmt the fallthrough statement
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitFallthrough(ast::FallthroughStatement* stmt);
|
||||
/// Handles generating an identifier expression
|
||||
/// @param expr the identifier expression
|
||||
/// @returns true if the identifeir was emitted
|
||||
|
@ -126,6 +130,10 @@ class GeneratorImpl {
|
|||
/// @param expr the initializer expression
|
||||
/// @returns true if the expression was emitted
|
||||
bool EmitInitializer(ast::InitializerExpression* expr);
|
||||
/// Handles generating a kill statement
|
||||
/// @param stmt the kill statement
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitKill(ast::KillStatement* stmt);
|
||||
/// Handles a literal
|
||||
/// @param lit the literal to emit
|
||||
/// @returns true if the literal was successfully emitted
|
||||
|
@ -134,6 +142,10 @@ 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 generating a relational expression
|
||||
/// @param expr the relational expression
|
||||
/// @returns true if the expression was emitted, false otherwise
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
// 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/fallthrough_statement.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Fallthrough) {
|
||||
ast::FallthroughStatement f;
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&f)) << g.error();
|
||||
EXPECT_EQ(g.result(), " fallthrough;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,39 @@
|
|||
// 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/kill_statement.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_kill) {
|
||||
ast::KillStatement k;
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&k)) << g.error();
|
||||
EXPECT_EQ(g.result(), " kill;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,39 @@
|
|||
// 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
|
Loading…
Reference in New Issue