Emit regardless.
This Cl updates the WGSL writer to emit the regardless statement. Bug: tint:4 Change-Id: Iab35f3f0d956bd6cdd1411a06b4ca022147b0f87 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17261 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
2a6e275057
commit
b42c76c47d
|
@ -421,6 +421,7 @@ if(${TINT_BUILD_WGSL_WRITER})
|
|||
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_regardless_test.cc
|
||||
writer/wgsl/generator_impl_relational_test.cc
|
||||
writer/wgsl/generator_impl_return_test.cc
|
||||
writer/wgsl/generator_impl_type_test.cc
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "src/ast/int_literal.h"
|
||||
#include "src/ast/location_decoration.h"
|
||||
#include "src/ast/member_accessor_expression.h"
|
||||
#include "src/ast/regardless_statement.h"
|
||||
#include "src/ast/relational_expression.h"
|
||||
#include "src/ast/return_statement.h"
|
||||
#include "src/ast/set_decoration.h"
|
||||
|
@ -670,6 +671,9 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
|||
if (stmt->IsNop()) {
|
||||
return EmitNop(stmt->AsNop());
|
||||
}
|
||||
if (stmt->IsRegardless()) {
|
||||
return EmitRegardless(stmt->AsRegardless());
|
||||
}
|
||||
if (stmt->IsReturn()) {
|
||||
return EmitReturn(stmt->AsReturn());
|
||||
}
|
||||
|
@ -793,6 +797,27 @@ bool GeneratorImpl::EmitNop(ast::NopStatement*) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitRegardless(ast::RegardlessStatement* stmt) {
|
||||
make_indent();
|
||||
|
||||
out_ << "regardless (";
|
||||
if (!EmitExpression(stmt->condition())) {
|
||||
return false;
|
||||
}
|
||||
out_ << ") {" << std::endl;
|
||||
|
||||
increment_indent();
|
||||
for (const auto& b : stmt->body()) {
|
||||
if (!EmitStatement(b.get())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
decrement_indent();
|
||||
make_indent();
|
||||
out_ << "}" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitReturn(ast::ReturnStatement* stmt) {
|
||||
make_indent();
|
||||
|
||||
|
|
|
@ -146,6 +146,10 @@ class GeneratorImpl {
|
|||
/// @param stmt the nop statement
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitNop(ast::NopStatement* stmt);
|
||||
/// Handles regardless statements
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was successfully emitted
|
||||
bool EmitRegardless(ast::RegardlessStatement* stmt);
|
||||
/// Handles generating a relational expression
|
||||
/// @param expr the relational expression
|
||||
/// @returns true if the expression was emitted, false otherwise
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// 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 <memory>
|
||||
#include <vector>
|
||||
|
||||
#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/regardless_statement.h"
|
||||
#include "src/writer/wgsl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
using GeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(GeneratorImplTest, Emit_Regardless) {
|
||||
auto cond = std::make_unique<ast::IdentifierExpression>("cond");
|
||||
|
||||
std::vector<std::unique_ptr<ast::Statement>> body;
|
||||
body.push_back(std::make_unique<ast::NopStatement>());
|
||||
body.push_back(std::make_unique<ast::KillStatement>());
|
||||
|
||||
ast::RegardlessStatement r(std::move(cond), std::move(body));
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&r)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"( regardless (cond) {
|
||||
nop;
|
||||
kill;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
Loading…
Reference in New Issue