Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 1 | //===- llvm/Support/DiagnosticInfo.cpp - Diagnostic Definitions -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Robin Morisset | 217b38e | 2014-08-29 21:53:01 +0000 | [diff] [blame] | 10 | // This file defines a diagnostic printer relying on raw_ostream. |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 14 | #include "llvm/IR/DiagnosticPrinter.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/Twine.h" |
Manman Ren | 2666b15 | 2014-01-16 01:51:12 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Module.h" |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Value.h" |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 18 | #include "llvm/Support/SourceMgr.h" |
Chandler Carruth | e3e43d9 | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace llvm; |
| 22 | |
| 23 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(char C) { |
| 24 | Stream << C; |
| 25 | return *this; |
| 26 | } |
| 27 | |
| 28 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned char C) { |
| 29 | Stream << C; |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(signed char C) { |
| 34 | Stream << C; |
| 35 | return *this; |
| 36 | } |
| 37 | |
| 38 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(StringRef Str) { |
| 39 | Stream << Str; |
| 40 | return *this; |
| 41 | } |
| 42 | |
| 43 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const char *Str) { |
| 44 | Stream << Str; |
| 45 | return *this; |
| 46 | } |
| 47 | |
| 48 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<( |
| 49 | const std::string &Str) { |
| 50 | Stream << Str; |
| 51 | return *this; |
| 52 | } |
| 53 | |
| 54 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned long N) { |
| 55 | Stream << N; |
| 56 | return *this; |
| 57 | } |
| 58 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long N) { |
| 59 | Stream << N; |
| 60 | return *this; |
| 61 | } |
| 62 | |
| 63 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<( |
| 64 | unsigned long long N) { |
| 65 | Stream << N; |
| 66 | return *this; |
| 67 | } |
| 68 | |
| 69 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long long N) { |
| 70 | Stream << N; |
| 71 | return *this; |
| 72 | } |
| 73 | |
| 74 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const void *P) { |
| 75 | Stream << P; |
| 76 | return *this; |
| 77 | } |
| 78 | |
| 79 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned int N) { |
| 80 | Stream << N; |
| 81 | return *this; |
| 82 | } |
| 83 | |
| 84 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(int N) { |
| 85 | Stream << N; |
| 86 | return *this; |
| 87 | } |
| 88 | |
| 89 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(double N) { |
| 90 | Stream << N; |
| 91 | return *this; |
| 92 | } |
| 93 | |
| 94 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Twine &Str) { |
Quentin Colombet | 5103745 | 2013-12-17 22:35:07 +0000 | [diff] [blame] | 95 | Str.print(Stream); |
Quentin Colombet | de262fe | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 96 | return *this; |
| 97 | } |
| 98 | |
| 99 | // IR related types. |
| 100 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) { |
| 101 | Stream << V.getName(); |
| 102 | return *this; |
| 103 | } |
Manman Ren | 2666b15 | 2014-01-16 01:51:12 +0000 | [diff] [blame] | 104 | |
| 105 | DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Module &M) { |
| 106 | Stream << M.getModuleIdentifier(); |
| 107 | return *this; |
| 108 | } |
Alex Lorenz | a15d888 | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 109 | |
| 110 | // Other types. |
| 111 | DiagnosticPrinter &DiagnosticPrinterRawOStream:: |
| 112 | operator<<(const SMDiagnostic &Diag) { |
| 113 | // We don't have to print the SMDiagnostic kind, as the diagnostic severity |
| 114 | // is printed by the diagnostic handler. |
| 115 | Diag.print("", Stream, /*ShowColors=*/true, /*ShowKindLabel=*/false); |
| 116 | return *this; |
| 117 | } |