blob: d000b1154855b7f339be889492c27dde83e05f10 [file] [log] [blame]
Dan Sinclair6e581892020-03-02 15:47:43 -05001// Copyright 2020 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
dan sinclaire4392c92020-03-17 21:00:22 +000015#include "src/writer/spirv/generator.h"
Dan Sinclair6e581892020-03-02 15:47:43 -050016
Dan Sinclair6e581892020-03-02 15:47:43 -050017namespace tint {
18namespace writer {
dan sinclaire4392c92020-03-17 21:00:22 +000019namespace spirv {
Dan Sinclair6e581892020-03-02 15:47:43 -050020
Ben Claytonc40f6272021-01-26 16:57:10 +000021Generator::Generator(const Program* program)
22 : builder_(std::make_unique<Builder>(program)),
Ben Claytond59cedb2021-01-25 18:14:08 +000023 writer_(std::make_unique<BinaryWriter>()) {}
Dan Sinclair6e581892020-03-02 15:47:43 -050024
Ben Claytond59cedb2021-01-25 18:14:08 +000025Generator::~Generator() = default;
dan sinclair0f497532020-09-03 01:02:06 +000026
Dan Sinclair6e581892020-03-02 15:47:43 -050027bool Generator::Generate() {
dan sinclair836027e2020-09-03 00:58:46 +000028 if (!builder_->Build()) {
29 set_error(builder_->error());
dan sinclaire4392c92020-03-17 21:00:22 +000030 return false;
dan sinclair781a4ac2020-03-23 20:07:34 +000031 }
dan sinclaire4392c92020-03-17 21:00:22 +000032
dan sinclair836027e2020-09-03 00:58:46 +000033 writer_->WriteHeader(builder_->id_bound());
34 writer_->WriteBuilder(builder_.get());
dan sinclairdc200f72020-03-23 20:59:12 +000035 return true;
Dan Sinclair6e581892020-03-02 15:47:43 -050036}
37
dan sinclaire4392c92020-03-17 21:00:22 +000038} // namespace spirv
Dan Sinclair6e581892020-03-02 15:47:43 -050039} // namespace writer
40} // namespace tint