[PM] Wire up the Verifier for the new pass manager and connect it to the
[oota-llvm.git] / include / llvm / IR / DiagnosticInfo.h
1 //===- llvm/Support/DiagnosticInfo.h - Diagnostic Declaration ---*- 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 different classes involved in low level diagnostics.
11 //
12 // Diagnostics reporting is still done as part of the LLVMContext.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_DIAGNOSTICINFO_H
16 #define LLVM_SUPPORT_DIAGNOSTICINFO_H
17
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/Support/Casting.h"
20
21 namespace llvm {
22
23 // Forward declarations.
24 class DiagnosticPrinter;
25 class Function;
26 class Instruction;
27 class Twine;
28 class Value;
29
30 /// \brief Defines the different supported severity of a diagnostic.
31 enum DiagnosticSeverity {
32   DS_Error,
33   DS_Warning,
34   DS_Note
35 };
36
37 /// \brief Defines the different supported kind of a diagnostic.
38 /// This enum should be extended with a new ID for each added concrete subclass.
39 enum DiagnosticKind {
40   DK_InlineAsm,
41   DK_StackSize,
42   DK_DebugMetadataVersion,
43   DK_FirstPluginKind
44 };
45
46 /// \brief Get the next available kind ID for a plugin diagnostic.
47 /// Each time this function is called, it returns a different number.
48 /// Therefore, a plugin that wants to "identify" its own classes
49 /// with a dynamic identifier, just have to use this method to get a new ID
50 /// and assign it to each of its classes.
51 /// The returned ID will be greater than or equal to DK_FirstPluginKind.
52 /// Thus, the plugin identifiers will not conflict with the
53 /// DiagnosticKind values.
54 int getNextAvailablePluginDiagnosticKind();
55
56 /// \brief This is the base abstract class for diagnostic reporting in
57 /// the backend.
58 /// The print method must be overloaded by the subclasses to print a
59 /// user-friendly message in the client of the backend (let us call it a
60 /// frontend).
61 class DiagnosticInfo {
62 private:
63   /// Kind defines the kind of report this is about.
64   const /* DiagnosticKind */ int Kind;
65   /// Severity gives the severity of the diagnostic.
66   const DiagnosticSeverity Severity;
67
68 public:
69   DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
70       : Kind(Kind), Severity(Severity) {}
71
72   virtual ~DiagnosticInfo() {}
73
74   /* DiagnosticKind */ int getKind() const { return Kind; }
75   DiagnosticSeverity getSeverity() const { return Severity; }
76
77   /// Print using the given \p DP a user-friendly message.
78   /// This is the default message that will be printed to the user.
79   /// It is used when the frontend does not directly take advantage
80   /// of the information contained in fields of the subclasses.
81   /// The printed message must not end with '.' nor start with a severity
82   /// keyword.
83   virtual void print(DiagnosticPrinter &DP) const = 0;
84 };
85
86 /// Diagnostic information for inline asm reporting.
87 /// This is basically a message and an optional location.
88 class DiagnosticInfoInlineAsm : public DiagnosticInfo {
89 private:
90   /// Optional line information. 0 if not set.
91   unsigned LocCookie;
92   /// Message to be reported.
93   const Twine &MsgStr;
94   /// Optional origin of the problem.
95   const Instruction *Instr;
96
97 public:
98   /// \p MsgStr is the message to be reported to the frontend.
99   /// This class does not copy \p MsgStr, therefore the reference must be valid
100   /// for the whole life time of the Diagnostic.
101   DiagnosticInfoInlineAsm(const Twine &MsgStr,
102                           DiagnosticSeverity Severity = DS_Error)
103       : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(0), MsgStr(MsgStr),
104         Instr(NULL) {}
105
106   /// \p LocCookie if non-zero gives the line number for this report.
107   /// \p MsgStr gives the message.
108   /// This class does not copy \p MsgStr, therefore the reference must be valid
109   /// for the whole life time of the Diagnostic.
110   DiagnosticInfoInlineAsm(unsigned LocCookie, const Twine &MsgStr,
111                           DiagnosticSeverity Severity = DS_Error)
112       : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
113         MsgStr(MsgStr), Instr(NULL) {}
114
115   /// \p Instr gives the original instruction that triggered the diagnostic.
116   /// \p MsgStr gives the message.
117   /// This class does not copy \p MsgStr, therefore the reference must be valid
118   /// for the whole life time of the Diagnostic.
119   /// Same for \p I.
120   DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
121                           DiagnosticSeverity Severity = DS_Error);
122
123   unsigned getLocCookie() const { return LocCookie; }
124   const Twine &getMsgStr() const { return MsgStr; }
125   const Instruction *getInstruction() const { return Instr; }
126
127   /// \see DiagnosticInfo::print.
128   virtual void print(DiagnosticPrinter &DP) const;
129
130   /// Hand rolled RTTI.
131   static bool classof(const DiagnosticInfo *DI) {
132     return DI->getKind() == DK_InlineAsm;
133   }
134 };
135
136 /// Diagnostic information for stack size reporting.
137 /// This is basically a function and a size.
138 class DiagnosticInfoStackSize : public DiagnosticInfo {
139 private:
140   /// The function that is concerned by this stack size diagnostic.
141   const Function &Fn;
142   /// The computed stack size.
143   unsigned StackSize;
144
145 public:
146   /// \p The function that is concerned by this stack size diagnostic.
147   /// \p The computed stack size.
148   DiagnosticInfoStackSize(const Function &Fn, unsigned StackSize,
149                           DiagnosticSeverity Severity = DS_Warning)
150       : DiagnosticInfo(DK_StackSize, Severity), Fn(Fn), StackSize(StackSize) {}
151
152   const Function &getFunction() const { return Fn; }
153   unsigned getStackSize() const { return StackSize; }
154
155   /// \see DiagnosticInfo::print.
156   virtual void print(DiagnosticPrinter &DP) const;
157
158   /// Hand rolled RTTI.
159   static bool classof(const DiagnosticInfo *DI) {
160     return DI->getKind() == DK_StackSize;
161   }
162 };
163
164 /// Diagnostic information for debug metadata version reporting.
165 /// This is basically a module and a version.
166 class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo {
167 private:
168   /// The module that is concerned by this debug metadata version diagnostic.
169   const Module &M;
170   /// The actual metadata version.
171   unsigned MetadataVersion;
172
173 public:
174   /// \p The module that is concerned by this debug metadata version diagnostic.
175   /// \p The actual metadata version.
176   DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
177                           DiagnosticSeverity Severity = DS_Warning)
178       : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
179         MetadataVersion(MetadataVersion) {}
180
181   const Module &getModule() const { return M; }
182   unsigned getMetadataVersion() const { return MetadataVersion; }
183
184   /// \see DiagnosticInfo::print.
185   virtual void print(DiagnosticPrinter &DP) const;
186
187   /// Hand rolled RTTI.
188   static bool classof(const DiagnosticInfo *DI) {
189     return DI->getKind() == DK_DebugMetadataVersion;
190   }
191 };
192
193 } // End namespace llvm
194
195 #endif