Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 1 | // Copyright 2021 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 | |
| 15 | #include "src/debug.h" |
| 16 | |
Ben Clayton | e1159c7 | 2022-02-01 17:16:01 +0000 | [diff] [blame] | 17 | #include <memory> |
| 18 | |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 19 | namespace tint { |
| 20 | namespace { |
| 21 | |
| 22 | InternalCompilerErrorReporter* ice_reporter = nullptr; |
| 23 | |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 24 | } // namespace |
| 25 | |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 26 | void SetInternalCompilerErrorReporter(InternalCompilerErrorReporter* reporter) { |
| 27 | ice_reporter = reporter; |
| 28 | } |
| 29 | |
Ben Clayton | 3a9a55e | 2021-02-18 16:33:38 +0000 | [diff] [blame] | 30 | InternalCompilerError::InternalCompilerError(const char* file, |
| 31 | size_t line, |
Ben Clayton | ffd28e2 | 2021-06-24 11:27:36 +0000 | [diff] [blame] | 32 | diag::System system, |
Ben Clayton | 3a9a55e | 2021-02-18 16:33:38 +0000 | [diff] [blame] | 33 | diag::List& diagnostics) |
Ben Clayton | ffd28e2 | 2021-06-24 11:27:36 +0000 | [diff] [blame] | 34 | : file_(file), line_(line), system_(system), diagnostics_(diagnostics) {} |
Ben Clayton | 3a9a55e | 2021-02-18 16:33:38 +0000 | [diff] [blame] | 35 | |
| 36 | InternalCompilerError::~InternalCompilerError() { |
Ben Clayton | e1159c7 | 2022-02-01 17:16:01 +0000 | [diff] [blame] | 37 | auto file = std::make_shared<Source::File>(file_, ""); |
| 38 | Source source{Source::Range{{line_}}, file.get()}; |
| 39 | diagnostics_.add_ice(system_, msg_.str(), source, std::move(file)); |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 40 | |
| 41 | if (ice_reporter) { |
Ben Clayton | 3a9a55e | 2021-02-18 16:33:38 +0000 | [diff] [blame] | 42 | ice_reporter(diagnostics_); |
Ben Clayton | 6b4924f | 2021-02-17 20:13:34 +0000 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | } // namespace tint |