blob: 490ecfe0de651732ac4e21740f7caa236872c31e [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// 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.
John Bauman66b8ab22014-05-06 15:57:45 -040014
Nicolas Capenscc863da2015-01-21 15:50:55 -050015#include "Diagnostics.h"
John Bauman66b8ab22014-05-06 15:57:45 -040016
Nicolas Capenscc863da2015-01-21 15:50:55 -050017#include "debug.h"
18#include "InfoSink.h"
19#include "preprocessor/SourceLocation.h"
John Bauman66b8ab22014-05-06 15:57:45 -040020
21TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
Nicolas Capens0bac2852016-05-07 06:09:58 -040022 mShaderVersion(100),
23 mInfoSink(infoSink),
24 mNumErrors(0),
25 mNumWarnings(0)
John Bauman66b8ab22014-05-06 15:57:45 -040026{
27}
28
29TDiagnostics::~TDiagnostics()
30{
31}
32
Nicolas Capensb28964b2015-02-10 15:23:06 -050033void TDiagnostics::setShaderVersion(int version)
34{
Nicolas Capens0bac2852016-05-07 06:09:58 -040035 mShaderVersion = version;
Nicolas Capensb28964b2015-02-10 15:23:06 -050036}
37
John Bauman66b8ab22014-05-06 15:57:45 -040038void TDiagnostics::writeInfo(Severity severity,
39 const pp::SourceLocation& loc,
40 const std::string& reason,
41 const std::string& token,
42 const std::string& extra)
43{
Nicolas Capens0bac2852016-05-07 06:09:58 -040044 TPrefixType prefix = EPrefixNone;
45 switch(severity)
46 {
47 case PP_ERROR:
48 ++mNumErrors;
49 prefix = EPrefixError;
50 break;
51 case PP_WARNING:
52 ++mNumWarnings;
53 prefix = EPrefixWarning;
54 break;
55 default:
56 UNREACHABLE(severity);
57 break;
58 }
John Bauman66b8ab22014-05-06 15:57:45 -040059
Nicolas Capens0bac2852016-05-07 06:09:58 -040060 TInfoSinkBase& sink = mInfoSink.info;
61 /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
62 sink.prefix(prefix);
63 TSourceLoc sourceLoc;
64 sourceLoc.first_file = sourceLoc.last_file = loc.file;
65 sourceLoc.first_line = sourceLoc.last_line = loc.line;
66 sink.location(sourceLoc);
67 sink << "'" << token << "' : " << reason << " " << extra << "\n";
John Bauman66b8ab22014-05-06 15:57:45 -040068}
69
70void TDiagnostics::writeDebug(const std::string& str)
71{
Nicolas Capens0bac2852016-05-07 06:09:58 -040072 mInfoSink.debug << str;
John Bauman66b8ab22014-05-06 15:57:45 -040073}
74
75void TDiagnostics::print(ID id,
76 const pp::SourceLocation& loc,
77 const std::string& text)
78{
Nicolas Capens0bac2852016-05-07 06:09:58 -040079 writeInfo(severity(id), loc, message(id), text, "");
John Bauman66b8ab22014-05-06 15:57:45 -040080}