LLVM 19.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"
16
17namespace llvm {
18class DiagnosticInfo;
19
20/// This is the base class for diagnostic handling in LLVM.
21/// The handleDiagnostics method must be overriden by the subclasses to handle
22/// diagnostic. The *RemarkEnabled methods can be overriden to control
23/// which remarks are enabled.
25 void *DiagnosticContext = nullptr;
26 bool HasErrors = false;
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) {
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.
58
59 /// Return true if passed optimization remarks are enabled, override
60 /// to provide different implementation.
62
63 /// Return true if any type of remarks are enabled for this pass.
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
LLVMContext & Context
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:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This is the base class for diagnostic handling in LLVM.
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...
virtual bool isAnyRemarkEnabled() const
Return true if any type of remarks are enabled for any pass.