DiagnosticHandler.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. // Base DiagnosticHandler class declaration. Derive from this class to provide
  14. // custom diagnostic reporting.
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
  17. #define LLVM_IR_DIAGNOSTICHANDLER_H
  18. #include "llvm/ADT/StringRef.h"
  19. namespace llvm {
  20. class DiagnosticInfo;
  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;
  30. using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
  31. /// DiagHandlerCallback is settable from the C API and base implementation
  32. /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
  33. /// class of DiagnosticHandler should not use callback but
  34. /// implement handleDiagnostics().
  35. DiagnosticHandlerTy DiagHandlerCallback = nullptr;
  36. /// Override handleDiagnostics to provide custom implementation.
  37. /// Return true if it handles diagnostics reporting properly otherwise
  38. /// return false to make LLVMContext::diagnose() to print the message
  39. /// with a prefix based on the severity.
  40. virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
  41. if (DiagHandlerCallback) {
  42. DiagHandlerCallback(DI, DiagnosticContext);
  43. return true;
  44. }
  45. return false;
  46. }
  47. /// Return true if analysis remarks are enabled, override
  48. /// to provide different implementation.
  49. virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
  50. /// Return true if missed optimization remarks are enabled, override
  51. /// to provide different implementation.
  52. virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
  53. /// Return true if passed optimization remarks are enabled, override
  54. /// to provide different implementation.
  55. virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
  56. /// Return true if any type of remarks are enabled for this pass.
  57. bool isAnyRemarkEnabled(StringRef PassName) const {
  58. return (isMissedOptRemarkEnabled(PassName) ||
  59. isPassedOptRemarkEnabled(PassName) ||
  60. isAnalysisRemarkEnabled(PassName));
  61. }
  62. /// Return true if any type of remarks are enabled for any pass.
  63. virtual bool isAnyRemarkEnabled() const;
  64. };
  65. } // namespace llvm
  66. #endif // LLVM_IR_DIAGNOSTICHANDLER_H
  67. #ifdef __GNUC__
  68. #pragma GCC diagnostic pop
  69. #endif