• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- llvm/Support/DiagnosticPrinter.h - Diagnostic Printer ----*- 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 //
10 // This file declares the main interface for printer backend diagnostic.
11 //
12 // Clients of the backend diagnostics should overload this interface based
13 // on their needs.
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_SUPPORT_DIAGNOSTICPRINTER_H
17 #define LLVM_SUPPORT_DIAGNOSTICPRINTER_H
18 
19 #include <string>
20 
21 namespace llvm {
22 // Forward declarations.
23 class Module;
24 class raw_ostream;
25 class StringRef;
26 class Twine;
27 class Value;
28 
29 /// \brief Interface for custom diagnostic printing.
30 class DiagnosticPrinter {
31 public:
~DiagnosticPrinter()32   virtual ~DiagnosticPrinter() {}
33 
34   // Simple types.
35   virtual DiagnosticPrinter &operator<<(char C) = 0;
36   virtual DiagnosticPrinter &operator<<(unsigned char C) = 0;
37   virtual DiagnosticPrinter &operator<<(signed char C) = 0;
38   virtual DiagnosticPrinter &operator<<(StringRef Str) = 0;
39   virtual DiagnosticPrinter &operator<<(const char *Str) = 0;
40   virtual DiagnosticPrinter &operator<<(const std::string &Str) = 0;
41   virtual DiagnosticPrinter &operator<<(unsigned long N) = 0;
42   virtual DiagnosticPrinter &operator<<(long N) = 0;
43   virtual DiagnosticPrinter &operator<<(unsigned long long N) = 0;
44   virtual DiagnosticPrinter &operator<<(long long N) = 0;
45   virtual DiagnosticPrinter &operator<<(const void *P) = 0;
46   virtual DiagnosticPrinter &operator<<(unsigned int N) = 0;
47   virtual DiagnosticPrinter &operator<<(int N) = 0;
48   virtual DiagnosticPrinter &operator<<(double N) = 0;
49   virtual DiagnosticPrinter &operator<<(const Twine &Str) = 0;
50 
51   // IR related types.
52   virtual DiagnosticPrinter &operator<<(const Value &V) = 0;
53   virtual DiagnosticPrinter &operator<<(const Module &M) = 0;
54 };
55 
56 /// \brief Basic diagnostic printer that uses an underlying raw_ostream.
57 class DiagnosticPrinterRawOStream : public DiagnosticPrinter {
58 protected:
59   raw_ostream &Stream;
60 
61 public:
DiagnosticPrinterRawOStream(raw_ostream & Stream)62   DiagnosticPrinterRawOStream(raw_ostream &Stream) : Stream(Stream) {};
63 
64   // Simple types.
65   DiagnosticPrinter &operator<<(char C) override;
66   DiagnosticPrinter &operator<<(unsigned char C) override;
67   DiagnosticPrinter &operator<<(signed char C) override;
68   DiagnosticPrinter &operator<<(StringRef Str) override;
69   DiagnosticPrinter &operator<<(const char *Str) override;
70   DiagnosticPrinter &operator<<(const std::string &Str) override;
71   DiagnosticPrinter &operator<<(unsigned long N) override;
72   DiagnosticPrinter &operator<<(long N) override;
73   DiagnosticPrinter &operator<<(unsigned long long N) override;
74   DiagnosticPrinter &operator<<(long long N) override;
75   DiagnosticPrinter &operator<<(const void *P) override;
76   DiagnosticPrinter &operator<<(unsigned int N) override;
77   DiagnosticPrinter &operator<<(int N) override;
78   DiagnosticPrinter &operator<<(double N) override;
79   DiagnosticPrinter &operator<<(const Twine &Str) override;
80 
81   // IR related types.
82   DiagnosticPrinter &operator<<(const Value &V) override;
83   DiagnosticPrinter &operator<<(const Module &M) override;
84 };
85 } // End namespace llvm
86 
87 #endif
88