1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -*- C++ ---*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Base DiagnosticHandler class declaration. Derive from this class to provide
10 // custom diagnostic reporting.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
14 #define LLVM_IR_DIAGNOSTICHANDLER_H
16 #include "llvm/ADT/StringRef.h"
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.
25 struct DiagnosticHandler {
26 void *DiagnosticContext = nullptr;
27 DiagnosticHandler(void *DiagContext = nullptr)
28 : DiagnosticContext(DiagContext) {}
29 virtual ~DiagnosticHandler() = default;
31 using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
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().
37 DiagnosticHandlerTy DiagHandlerCallback = nullptr;
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);
51 /// Return true if analysis remarks are enabled, override
52 /// to provide different implementation.
53 virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
55 /// Return true if missed optimization remarks are enabled, override
56 /// to provide different implementation.
57 virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
59 /// Return true if passed optimization remarks are enabled, override
60 /// to provide different implementation.
61 virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
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));
70 /// Return true if any type of remarks are enabled for any pass.
71 virtual bool isAnyRemarkEnabled() const;
75 #endif // LLVM_IR_DIAGNOSTICHANDLER_H