blob: 03a6fde3f9bb65aecff945750e29219d98a0c28c [file] [log] [blame]
Ben Clayton6b4924f2021-02-17 20:13:34 +00001// 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 Clayton6b4924f2021-02-17 20:13:34 +000017namespace tint {
18namespace {
19
20InternalCompilerErrorReporter* ice_reporter = nullptr;
21
Ben Clayton6b4924f2021-02-17 20:13:34 +000022} // namespace
23
Ben Clayton6b4924f2021-02-17 20:13:34 +000024void SetInternalCompilerErrorReporter(InternalCompilerErrorReporter* reporter) {
25 ice_reporter = reporter;
26}
27
Ben Clayton3a9a55e2021-02-18 16:33:38 +000028InternalCompilerError::InternalCompilerError(const char* file,
29 size_t line,
Ben Claytonffd28e22021-06-24 11:27:36 +000030 diag::System system,
Ben Clayton3a9a55e2021-02-18 16:33:38 +000031 diag::List& diagnostics)
Ben Claytonffd28e22021-06-24 11:27:36 +000032 : file_(file), line_(line), system_(system), diagnostics_(diagnostics) {}
Ben Clayton3a9a55e2021-02-18 16:33:38 +000033
34InternalCompilerError::~InternalCompilerError() {
Ben Clayton1d982362021-02-18 21:40:19 +000035 Source source{Source::Range{Source::Location{line_}}, file_};
Ben Claytonffd28e22021-06-24 11:27:36 +000036 diagnostics_.add_ice(system_, msg_.str(), source);
Ben Clayton6b4924f2021-02-17 20:13:34 +000037
38 if (ice_reporter) {
Ben Clayton3a9a55e2021-02-18 16:33:38 +000039 ice_reporter(diagnostics_);
Ben Clayton6b4924f2021-02-17 20:13:34 +000040 }
41}
42
43} // namespace tint