LLVM 22.0.0git
DiagnosticHandler.h
Go to the documentation of this file.
1//===- DiagnosticHandler.h - DiagnosticHandler class for LLVM ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// Base DiagnosticHandler class declaration. Derive from this class to provide
9// custom diagnostic reporting.
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_IR_DIAGNOSTICHANDLER_H
13#define LLVM_IR_DIAGNOSTICHANDLER_H
14
15#include "llvm/ADT/StringRef.h"
17
18namespace llvm {
19class 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 bool HasErrors = false;
28 DiagnosticHandler(void *DiagContext = nullptr)
29 : DiagnosticContext(DiagContext) {}
30 virtual ~DiagnosticHandler() = default;
31
32 using DiagnosticHandlerTy = void (*)(const DiagnosticInfo *DI, void *Context);
33
34 /// DiagHandlerCallback is settable from the C API and base implementation
35 /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
36 /// class of DiagnosticHandler should not use callback but
37 /// implement handleDiagnostics().
39
40 /// Override handleDiagnostics to provide custom implementation.
41 /// Return true if it handles diagnostics reporting properly otherwise
42 /// return false to make LLVMContext::diagnose() to print the message
43 /// with a prefix based on the severity.
44 virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
47 return true;
48 }
49 return false;
50 }
51
52 /// Return true if analysis remarks are enabled, override
53 /// to provide different implementation.
54 virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
55
56 /// Return true if missed optimization remarks are enabled, override
57 /// to provide different implementation.
58 virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
59
60 /// Return true if passed optimization remarks are enabled, override
61 /// to provide different implementation.
62 virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
63
64 /// Return true if any type of remarks are enabled for this pass.
70
71 /// Return true if any type of remarks are enabled for any pass.
72 virtual bool isAnyRemarkEnabled() const;
73};
74} // namespace llvm
75
76#endif // LLVM_IR_DIAGNOSTICHANDLER_H
#define LLVM_ABI
Definition Compiler.h:213
static const char PassName[]
This is the base abstract class for diagnostic reporting in the backend.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
virtual bool isPassedOptRemarkEnabled(StringRef PassName) const
Return true if passed optimization remarks are enabled, override to provide different implementation.
virtual bool handleDiagnostics(const DiagnosticInfo &DI)
Override handleDiagnostics to provide custom implementation.
virtual ~DiagnosticHandler()=default
void(*)(const DiagnosticInfo *DI, void *Context) DiagnosticHandlerTy
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const
Return true if missed optimization remarks are enabled, override to provide different implementation.
bool isAnyRemarkEnabled(StringRef PassName) const
Return true if any type of remarks are enabled for this pass.
DiagnosticHandler(void *DiagContext=nullptr)
DiagnosticHandlerTy DiagHandlerCallback
DiagHandlerCallback is settable from the C API and base implementation of DiagnosticHandler will call...