Emit variable statements

This Cl updates the WGSL writer to output variable statements.

Bug: tint:4
Change-Id: Ic557ea0c1b366644a8496dd43e4cfd85b9e8a84f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/17281
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-03-20 19:06:45 +00:00 committed by dan sinclair
parent 187f9165a5
commit 4202d7d016
4 changed files with 54 additions and 2 deletions

View File

@ -429,6 +429,7 @@ if(${TINT_BUILD_WGSL_WRITER})
writer/wgsl/generator_impl_unary_method_test.cc
writer/wgsl/generator_impl_unary_op_test.cc
writer/wgsl/generator_impl_unless_test.cc
writer/wgsl/generator_impl_variable_statement_test.cc
writer/wgsl/generator_impl_variable_test.cc
)
endif()

View File

@ -39,7 +39,6 @@
#include "src/ast/regardless_statement.h"
#include "src/ast/relational_expression.h"
#include "src/ast/return_statement.h"
#include "src/ast/unless_statement.h"
#include "src/ast/set_decoration.h"
#include "src/ast/statement.h"
#include "src/ast/struct.h"
@ -55,6 +54,8 @@
#include "src/ast/unary_derivative_expression.h"
#include "src/ast/unary_method_expression.h"
#include "src/ast/unary_op_expression.h"
#include "src/ast/unless_statement.h"
#include "src/ast/variable_statement.h"
namespace tint {
namespace writer {
@ -678,6 +679,9 @@ bool GeneratorImpl::EmitStatement(ast::Statement* stmt) {
if (stmt->IsReturn()) {
return EmitReturn(stmt->AsReturn());
}
if (stmt->IsVariable()) {
return EmitVariable(stmt->AsVariable()->variable());
}
if (stmt->IsUnless()) {
return EmitUnless(stmt->AsUnless());
}

View File

@ -53,4 +53,3 @@ TEST_F(GeneratorImplTest, Emit_Unless) {
} // namespace wgsl
} // namespace writer
} // namespace tint

View File

@ -0,0 +1,48 @@
// 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/type/f32_type.h"
#include "src/ast/variable.h"
#include "src/ast/variable_statement.h"
#include "src/writer/wgsl/generator_impl.h"
namespace tint {
namespace writer {
namespace wgsl {
namespace {
using GeneratorImplTest = testing::Test;
TEST_F(GeneratorImplTest, Emit_VariableStatement) {
ast::type::F32Type f32;
auto var =
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
ast::VariableStatement stmt(std::move(var));
GeneratorImpl g;
g.increment_indent();
ASSERT_TRUE(g.EmitStatement(&stmt)) << g.error();
EXPECT_EQ(g.result(), " var a : f32;\n");
}
} // namespace
} // namespace wgsl
} // namespace writer
} // namespace tint