Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 15 | #include "Diagnostics.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 16 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 17 | #include "debug.h" |
| 18 | #include "InfoSink.h" |
| 19 | #include "preprocessor/SourceLocation.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 20 | |
| 21 | TDiagnostics::TDiagnostics(TInfoSink& infoSink) : |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 22 | mShaderVersion(100), |
| 23 | mInfoSink(infoSink), |
| 24 | mNumErrors(0), |
Nicolas Capens | 937e6a5 | 2018-05-29 17:11:37 -0400 | [diff] [blame] | 25 | mNumWarnings(0), |
| 26 | mNumInfos(0) |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 27 | { |
| 28 | } |
| 29 | |
| 30 | TDiagnostics::~TDiagnostics() |
| 31 | { |
| 32 | } |
| 33 | |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame] | 34 | void TDiagnostics::setShaderVersion(int version) |
| 35 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 36 | mShaderVersion = version; |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame] | 37 | } |
| 38 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 39 | void TDiagnostics::writeInfo(Severity severity, |
| 40 | const pp::SourceLocation& loc, |
| 41 | const std::string& reason, |
| 42 | const std::string& token, |
| 43 | const std::string& extra) |
| 44 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 45 | TPrefixType prefix = EPrefixNone; |
| 46 | switch(severity) |
| 47 | { |
| 48 | case PP_ERROR: |
| 49 | ++mNumErrors; |
| 50 | prefix = EPrefixError; |
| 51 | break; |
| 52 | case PP_WARNING: |
| 53 | ++mNumWarnings; |
| 54 | prefix = EPrefixWarning; |
| 55 | break; |
Nicolas Capens | 937e6a5 | 2018-05-29 17:11:37 -0400 | [diff] [blame] | 56 | case PP_INFO: |
| 57 | ++mNumInfos; |
| 58 | prefix = EPrefixInfo; |
| 59 | break; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 60 | default: |
| 61 | UNREACHABLE(severity); |
| 62 | break; |
| 63 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 64 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 65 | TInfoSinkBase& sink = mInfoSink.info; |
| 66 | /* VC++ format: file(linenum) : error #: 'token' : extrainfo */ |
| 67 | sink.prefix(prefix); |
| 68 | TSourceLoc sourceLoc; |
| 69 | sourceLoc.first_file = sourceLoc.last_file = loc.file; |
| 70 | sourceLoc.first_line = sourceLoc.last_line = loc.line; |
| 71 | sink.location(sourceLoc); |
| 72 | sink << "'" << token << "' : " << reason << " " << extra << "\n"; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void TDiagnostics::writeDebug(const std::string& str) |
| 76 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 77 | mInfoSink.debug << str; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void TDiagnostics::print(ID id, |
| 81 | const pp::SourceLocation& loc, |
| 82 | const std::string& text) |
| 83 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 84 | writeInfo(severity(id), loc, message(id), text, ""); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 85 | } |