Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:59

0001 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 // Base DiagnosticHandler class declaration. Derive from this class to provide
0009 // custom diagnostic reporting.
0010 //===----------------------------------------------------------------------===//
0011 
0012 #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
0013 #define LLVM_IR_DIAGNOSTICHANDLER_H
0014 
0015 #include "llvm/ADT/StringRef.h"
0016 
0017 namespace llvm {
0018 class DiagnosticInfo;
0019 
0020 /// This is the base class for diagnostic handling in LLVM.
0021 /// The handleDiagnostics method must be overriden by the subclasses to handle
0022 /// diagnostic. The *RemarkEnabled methods can be overriden to control
0023 /// which remarks are enabled.
0024 struct DiagnosticHandler {
0025   void *DiagnosticContext = nullptr;
0026   bool HasErrors = false;
0027   DiagnosticHandler(void *DiagContext = nullptr)
0028       : DiagnosticContext(DiagContext) {}
0029   virtual ~DiagnosticHandler() = default;
0030 
0031   using DiagnosticHandlerTy = void (*)(const DiagnosticInfo *DI, void *Context);
0032 
0033   /// DiagHandlerCallback is settable from the C API and base implementation
0034   /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
0035   /// class of DiagnosticHandler should not use callback but
0036   /// implement handleDiagnostics().
0037   DiagnosticHandlerTy DiagHandlerCallback = nullptr;
0038 
0039   /// Override handleDiagnostics to provide custom implementation.
0040   /// Return true if it handles diagnostics reporting properly otherwise
0041   /// return false to make LLVMContext::diagnose() to print the message
0042   /// with a prefix based on the severity.
0043   virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
0044     if (DiagHandlerCallback) {
0045       DiagHandlerCallback(&DI, DiagnosticContext);
0046       return true;
0047     }
0048     return false;
0049   }
0050 
0051   /// Return true if analysis remarks are enabled, override
0052   /// to provide different implementation.
0053   virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
0054 
0055   /// Return true if missed optimization remarks are enabled, override
0056   /// to provide different implementation.
0057   virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
0058 
0059   /// Return true if passed optimization remarks are enabled, override
0060   /// to provide different implementation.
0061   virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
0062 
0063   /// Return true if any type of remarks are enabled for this pass.
0064   bool isAnyRemarkEnabled(StringRef PassName) const {
0065     return (isMissedOptRemarkEnabled(PassName) ||
0066             isPassedOptRemarkEnabled(PassName) ||
0067             isAnalysisRemarkEnabled(PassName));
0068   }
0069 
0070   /// Return true if any type of remarks are enabled for any pass.
0071   virtual bool isAnyRemarkEnabled() const;
0072 };
0073 } // namespace llvm
0074 
0075 #endif // LLVM_IR_DIAGNOSTICHANDLER_H