Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 1 | // 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 sinclair | e4392c9 | 2020-03-17 21:00:22 +0000 | [diff] [blame] | 15 | #include "src/writer/spirv/generator.h" |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 16 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 17 | namespace tint { |
| 18 | namespace writer { |
dan sinclair | e4392c9 | 2020-03-17 21:00:22 +0000 | [diff] [blame] | 19 | namespace spirv { |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 20 | |
Ben Clayton | c40f627 | 2021-01-26 16:57:10 +0000 | [diff] [blame] | 21 | Generator::Generator(const Program* program) |
| 22 | : builder_(std::make_unique<Builder>(program)), |
Ben Clayton | d59cedb | 2021-01-25 18:14:08 +0000 | [diff] [blame] | 23 | writer_(std::make_unique<BinaryWriter>()) {} |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 24 | |
Ben Clayton | d59cedb | 2021-01-25 18:14:08 +0000 | [diff] [blame] | 25 | Generator::~Generator() = default; |
dan sinclair | 0f49753 | 2020-09-03 01:02:06 +0000 | [diff] [blame] | 26 | |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 27 | bool Generator::Generate() { |
dan sinclair | 836027e | 2020-09-03 00:58:46 +0000 | [diff] [blame] | 28 | if (!builder_->Build()) { |
| 29 | set_error(builder_->error()); |
dan sinclair | e4392c9 | 2020-03-17 21:00:22 +0000 | [diff] [blame] | 30 | return false; |
dan sinclair | 781a4ac | 2020-03-23 20:07:34 +0000 | [diff] [blame] | 31 | } |
dan sinclair | e4392c9 | 2020-03-17 21:00:22 +0000 | [diff] [blame] | 32 | |
dan sinclair | 836027e | 2020-09-03 00:58:46 +0000 | [diff] [blame] | 33 | writer_->WriteHeader(builder_->id_bound()); |
| 34 | writer_->WriteBuilder(builder_.get()); |
dan sinclair | dc200f7 | 2020-03-23 20:59:12 +0000 | [diff] [blame] | 35 | return true; |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 36 | } |
| 37 | |
dan sinclair | e4392c9 | 2020-03-17 21:00:22 +0000 | [diff] [blame] | 38 | } // namespace spirv |
Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 39 | } // namespace writer |
| 40 | } // namespace tint |