Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 8940182 | 2014-05-06 15:04:28 -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 | 8940182 | 2014-05-06 15:04:28 -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 | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 14 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 15 | #include "InfoSink.h" |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 16 | |
| 17 | void TInfoSinkBase::prefix(TPrefixType message) { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 18 | switch(message) { |
| 19 | case EPrefixNone: |
| 20 | break; |
Nicolas Capens | 937e6a5 | 2018-05-29 17:11:37 -0400 | [diff] [blame] | 21 | case EPrefixInfo: |
| 22 | sink.append("INFO: "); |
| 23 | break; |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 24 | case EPrefixWarning: |
| 25 | sink.append("WARNING: "); |
| 26 | break; |
| 27 | case EPrefixError: |
| 28 | sink.append("ERROR: "); |
| 29 | break; |
| 30 | case EPrefixInternalError: |
| 31 | sink.append("INTERNAL ERROR: "); |
| 32 | break; |
| 33 | case EPrefixUnimplemented: |
| 34 | sink.append("UNIMPLEMENTED: "); |
| 35 | break; |
| 36 | case EPrefixNote: |
| 37 | sink.append("NOTE: "); |
| 38 | break; |
| 39 | default: |
| 40 | sink.append("UNKOWN ERROR: "); |
| 41 | break; |
| 42 | } |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 43 | } |
| 44 | |
Alexis Hetu | 253fdd1 | 2015-07-07 15:12:46 -0400 | [diff] [blame] | 45 | void TInfoSinkBase::location(const TSourceLoc& loc) { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 46 | int string = loc.first_file, line = loc.first_line; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 47 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 48 | TPersistStringStream stream; |
| 49 | if (line) |
| 50 | stream << string << ":" << line; |
| 51 | else |
| 52 | stream << string << ":? "; |
| 53 | stream << ": "; |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 54 | |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 55 | sink.append(stream.str()); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void TInfoSinkBase::message(TPrefixType message, const char* s) { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 59 | prefix(message); |
| 60 | sink.append(s); |
| 61 | sink.append("\n"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 65 | prefix(message); |
| 66 | location(loc); |
| 67 | sink.append(s); |
| 68 | sink.append("\n"); |
John Bauman | 8940182 | 2014-05-06 15:04:28 -0400 | [diff] [blame] | 69 | } |