blob: 2ac9ce7274cebfc4d106841a1af772caa022cb63 [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
17#include <stdio.h>
18
19#include <sstream>
20#include <string>
21#include <vector>
22
23#include "src/diagnostic/diagnostic.h"
24
25namespace tint {
26namespace {
27
28InternalCompilerErrorReporter* ice_reporter = nullptr;
29
Ben Clayton6b4924f2021-02-17 20:13:34 +000030} // namespace
31
Ben Clayton6b4924f2021-02-17 20:13:34 +000032void SetInternalCompilerErrorReporter(InternalCompilerErrorReporter* reporter) {
33 ice_reporter = reporter;
34}
35
Ben Clayton3a9a55e2021-02-18 16:33:38 +000036InternalCompilerError::InternalCompilerError(const char* file,
37 size_t line,
38 diag::List& diagnostics)
39 : file_(file), line_(line), diagnostics_(diagnostics) {}
40
41InternalCompilerError::~InternalCompilerError() {
Ben Clayton1d982362021-02-18 21:40:19 +000042 Source source{Source::Range{Source::Location{line_}}, file_};
Ben Clayton3a9a55e2021-02-18 16:33:38 +000043 diagnostics_.add_ice(msg_.str(), source);
Ben Clayton6b4924f2021-02-17 20:13:34 +000044
45 if (ice_reporter) {
Ben Clayton3a9a55e2021-02-18 16:33:38 +000046 ice_reporter(diagnostics_);
Ben Clayton6b4924f2021-02-17 20:13:34 +000047 }
48}
49
50} // namespace tint