[msl-writer] Add break and continue emission.
This CL adds writting of break and continue statements to the MSL backend. Bug: tint:8 Change-Id: If2443c036fa82f54708d209d924192ee7a159e76 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24121 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
fa1659a3ef
commit
57b3b1d117
2
BUILD.gn
2
BUILD.gn
|
@ -889,8 +889,10 @@ source_set("tint_unittests_msl_writer_src") {
|
|||
"src/writer/msl/generator_impl_as_test.cc",
|
||||
"src/writer/msl/generator_impl_assign_test.cc",
|
||||
"src/writer/msl/generator_impl_binary_test.cc",
|
||||
"src/writer/msl/generator_impl_break_test.cc",
|
||||
"src/writer/msl/generator_impl_cast_test.cc",
|
||||
"src/writer/msl/generator_impl_constructor_test.cc",
|
||||
"src/writer/msl/generator_impl_continue_test.cc",
|
||||
"src/writer/msl/generator_impl_function_test.cc",
|
||||
"src/writer/msl/generator_impl_identifier_test.cc",
|
||||
"src/writer/msl/generator_impl_if_test.cc",
|
||||
|
|
|
@ -497,8 +497,10 @@ if(${TINT_BUILD_MSL_WRITER})
|
|||
writer/msl/generator_impl_as_test.cc
|
||||
writer/msl/generator_impl_assign_test.cc
|
||||
writer/msl/generator_impl_binary_test.cc
|
||||
writer/msl/generator_impl_break_test.cc
|
||||
writer/msl/generator_impl_cast_test.cc
|
||||
writer/msl/generator_impl_constructor_test.cc
|
||||
writer/msl/generator_impl_continue_test.cc
|
||||
writer/msl/generator_impl_function_test.cc
|
||||
writer/msl/generator_impl_identifier_test.cc
|
||||
writer/msl/generator_impl_if_test.cc
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
#include "src/ast/assignment_statement.h"
|
||||
#include "src/ast/binary_expression.h"
|
||||
#include "src/ast/bool_literal.h"
|
||||
#include "src/ast/break_statement.h"
|
||||
#include "src/ast/cast_expression.h"
|
||||
#include "src/ast/continue_statement.h"
|
||||
#include "src/ast/else_statement.h"
|
||||
#include "src/ast/float_literal.h"
|
||||
#include "src/ast/function.h"
|
||||
|
@ -213,6 +215,12 @@ bool GeneratorImpl::EmitBinary(ast::BinaryExpression* expr) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitBreak(ast::BreakStatement*) {
|
||||
make_indent();
|
||||
out_ << "break;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitCast(ast::CastExpression* expr) {
|
||||
if (!EmitType(expr->type(), "")) {
|
||||
return false;
|
||||
|
@ -233,6 +241,12 @@ bool GeneratorImpl::EmitConstructor(ast::ConstructorExpression* expr) {
|
|||
return EmitTypeConstructor(expr->AsTypeConstructor());
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitContinue(ast::ContinueStatement*) {
|
||||
make_indent();
|
||||
out_ << "continue;" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GeneratorImpl::EmitTypeConstructor(ast::TypeConstructorExpression* expr) {
|
||||
if (!EmitType(expr->type(), "")) {
|
||||
return false;
|
||||
|
@ -493,6 +507,12 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
|
|||
if (stmt->IsAssign()) {
|
||||
return EmitAssign(stmt->AsAssign());
|
||||
}
|
||||
if (stmt->IsBreak()) {
|
||||
return EmitBreak(stmt->AsBreak());
|
||||
}
|
||||
if (stmt->IsContinue()) {
|
||||
return EmitContinue(stmt->AsContinue());
|
||||
}
|
||||
if (stmt->IsIf()) {
|
||||
return EmitIf(stmt->AsIf());
|
||||
}
|
||||
|
|
|
@ -60,6 +60,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param expr the binary expression
|
||||
/// @returns true if the expression was emitted, false otherwise
|
||||
bool EmitBinary(ast::BinaryExpression* expr);
|
||||
/// Handles a break statement
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted successfully
|
||||
bool EmitBreak(ast::BreakStatement* stmt);
|
||||
/// Handles generating a cast expression
|
||||
/// @param expr the cast expression
|
||||
/// @returns true if the cast was emitted
|
||||
|
@ -68,6 +72,10 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param expr the constructor expression
|
||||
/// @returns true if the expression was emitted
|
||||
bool EmitConstructor(ast::ConstructorExpression* expr);
|
||||
/// Handles a continue statement
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted successfully
|
||||
bool EmitContinue(ast::ContinueStatement* stmt);
|
||||
/// Handles generating an else statement
|
||||
/// @param stmt the statement to emit
|
||||
/// @returns true if the statement was emitted
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
// 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/break_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Break) {
|
||||
ast::BreakStatement b;
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&b)) << g.error();
|
||||
EXPECT_EQ(g.result(), " break;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
|
@ -0,0 +1,42 @@
|
|||
// 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/continue_statement.h"
|
||||
#include "src/writer/msl/generator_impl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace writer {
|
||||
namespace msl {
|
||||
namespace {
|
||||
|
||||
using MslGeneratorImplTest = testing::Test;
|
||||
|
||||
TEST_F(MslGeneratorImplTest, Emit_Continue) {
|
||||
ast::ContinueStatement c;
|
||||
|
||||
GeneratorImpl g;
|
||||
g.increment_indent();
|
||||
|
||||
ASSERT_TRUE(g.EmitStatement(&c)) << g.error();
|
||||
EXPECT_EQ(g.result(), " continue;\n");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace msl
|
||||
} // namespace writer
|
||||
} // namespace tint
|
Loading…
Reference in New Issue