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
17 namespace tint {
18 namespace {
19
20 InternalCompilerErrorReporter* ice_reporter = nullptr;
21
22 } // namespace
23
SetInternalCompilerErrorReporter(InternalCompilerErrorReporter * reporter)24 void SetInternalCompilerErrorReporter(InternalCompilerErrorReporter* reporter) {
25 ice_reporter = reporter;
26 }
27
InternalCompilerError(const char * file,size_t line,diag::System system,diag::List & diagnostics)28 InternalCompilerError::InternalCompilerError(const char* file,
29 size_t line,
30 diag::System system,
31 diag::List& diagnostics)
32 : file_(file), line_(line), system_(system), diagnostics_(diagnostics) {}
33
~InternalCompilerError()34 InternalCompilerError::~InternalCompilerError() {
35 Source source{Source::Range{Source::Location{line_}}, file_};
36 diagnostics_.add_ice(system_, msg_.str(), source);
37
38 if (ice_reporter) {
39 ice_reporter(diagnostics_);
40 }
41 }
42
43 } // namespace tint
44