LLVM  8.0.1
DiagnosticHandler.h
Go to the documentation of this file.
1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -*- 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 // Base DiagnosticHandler class declaration. Derive from this class to provide
10 // custom diagnostic reporting.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
14 #define LLVM_IR_DIAGNOSTICHANDLER_H
15 
16 #include "llvm/ADT/StringRef.h"
17 
18 namespace llvm {
19 class DiagnosticInfo;
20 
21 /// This is the base class for diagnostic handling in LLVM.
22 /// The handleDiagnostics method must be overriden by the subclasses to handle
23 /// diagnostic. The *RemarkEnabled methods can be overriden to control
24 /// which remarks are enabled.
26  void *DiagnosticContext = nullptr;
27  DiagnosticHandler(void *DiagContext = nullptr)
28  : DiagnosticContext(DiagContext) {}
29  virtual ~DiagnosticHandler() = default;
30 
31  using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
32 
33  /// DiagHandlerCallback is settable from the C API and base implementation
34  /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
35  /// class of DiagnosticHandler should not use callback but
36  /// implement handleDiagnostics().
38 
39  /// Override handleDiagnostics to provide custom implementation.
40  /// Return true if it handles diagnostics reporting properly otherwise
41  /// return false to make LLVMContext::diagnose() to print the message
42  /// with a prefix based on the severity.
43  virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
44  if (DiagHandlerCallback) {
45  DiagHandlerCallback(DI, DiagnosticContext);
46  return true;
47  }
48  return false;
49  }
50 
51  /// Return true if analysis remarks are enabled, override
52  /// to provide different implementation.
53  virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
54 
55  /// Return true if missed optimization remarks are enabled, override
56  /// to provide different implementation.
57  virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
58 
59  /// Return true if passed optimization remarks are enabled, override
60  /// to provide different implementation.
61  virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
62 
63  /// Return true if any type of remarks are enabled for this pass.
64  bool isAnyRemarkEnabled(StringRef PassName) const {
65  return (isMissedOptRemarkEnabled(PassName) ||
66  isPassedOptRemarkEnabled(PassName) ||
67  isAnalysisRemarkEnabled(PassName));
68  }
69 
70  /// Return true if any type of remarks are enabled for any pass.
71  virtual bool isAnyRemarkEnabled() const;
72 };
73 } // namespace llvm
74 
75 #endif // LLVM_IR_DIAGNOSTICHANDLER_H
This is the base class for diagnostic handling in LLVM.
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:24
virtual ~DiagnosticHandler()=default
void(*)(const DiagnosticInfo &DI, void *Context) DiagnosticHandlerTy
This is the base abstract class for diagnostic reporting in the backend.
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const
Return true if missed optimization remarks are enabled, override to provide different implementation...
DiagnosticHandler(void *DiagContext=nullptr)
virtual bool isPassedOptRemarkEnabled(StringRef PassName) const
Return true if passed optimization remarks are enabled, override to provide different implementation...
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
virtual bool isAnyRemarkEnabled() const
Return true if any type of remarks are enabled for any pass.
DiagnosticHandlerTy DiagHandlerCallback
DiagHandlerCallback is settable from the C API and base implementation of DiagnosticHandler will call...
bool isAnyRemarkEnabled(StringRef PassName) const
Return true if any type of remarks are enabled for this pass.
virtual bool handleDiagnostics(const DiagnosticInfo &DI)
Override handleDiagnostics to provide custom implementation.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49