DiagnosticPrinter.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/IR/DiagnosticPrinter.h - Diagnostic Printer ---------*- 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. //
  14. // This file declares the main interface for printer backend diagnostic.
  15. //
  16. // Clients of the backend diagnostics should overload this interface based
  17. // on their needs.
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_IR_DIAGNOSTICPRINTER_H
  20. #define LLVM_IR_DIAGNOSTICPRINTER_H
  21. #include <string>
  22. namespace llvm {
  23. // Forward declarations.
  24. class Module;
  25. class raw_ostream;
  26. class SMDiagnostic;
  27. class StringRef;
  28. class Twine;
  29. class Value;
  30. /// Interface for custom diagnostic printing.
  31. class DiagnosticPrinter {
  32. public:
  33. virtual ~DiagnosticPrinter() = default;
  34. // Simple types.
  35. virtual DiagnosticPrinter &operator<<(char C) = 0;
  36. virtual DiagnosticPrinter &operator<<(unsigned char C) = 0;
  37. virtual DiagnosticPrinter &operator<<(signed char C) = 0;
  38. virtual DiagnosticPrinter &operator<<(StringRef Str) = 0;
  39. virtual DiagnosticPrinter &operator<<(const char *Str) = 0;
  40. virtual DiagnosticPrinter &operator<<(const std::string &Str) = 0;
  41. virtual DiagnosticPrinter &operator<<(unsigned long N) = 0;
  42. virtual DiagnosticPrinter &operator<<(long N) = 0;
  43. virtual DiagnosticPrinter &operator<<(unsigned long long N) = 0;
  44. virtual DiagnosticPrinter &operator<<(long long N) = 0;
  45. virtual DiagnosticPrinter &operator<<(const void *P) = 0;
  46. virtual DiagnosticPrinter &operator<<(unsigned int N) = 0;
  47. virtual DiagnosticPrinter &operator<<(int N) = 0;
  48. virtual DiagnosticPrinter &operator<<(double N) = 0;
  49. virtual DiagnosticPrinter &operator<<(const Twine &Str) = 0;
  50. // IR related types.
  51. virtual DiagnosticPrinter &operator<<(const Value &V) = 0;
  52. virtual DiagnosticPrinter &operator<<(const Module &M) = 0;
  53. // Other types.
  54. virtual DiagnosticPrinter &operator<<(const SMDiagnostic &Diag) = 0;
  55. };
  56. /// Basic diagnostic printer that uses an underlying raw_ostream.
  57. class DiagnosticPrinterRawOStream : public DiagnosticPrinter {
  58. protected:
  59. raw_ostream &Stream;
  60. public:
  61. DiagnosticPrinterRawOStream(raw_ostream &Stream) : Stream(Stream) {}
  62. // Simple types.
  63. DiagnosticPrinter &operator<<(char C) override;
  64. DiagnosticPrinter &operator<<(unsigned char C) override;
  65. DiagnosticPrinter &operator<<(signed char C) override;
  66. DiagnosticPrinter &operator<<(StringRef Str) override;
  67. DiagnosticPrinter &operator<<(const char *Str) override;
  68. DiagnosticPrinter &operator<<(const std::string &Str) override;
  69. DiagnosticPrinter &operator<<(unsigned long N) override;
  70. DiagnosticPrinter &operator<<(long N) override;
  71. DiagnosticPrinter &operator<<(unsigned long long N) override;
  72. DiagnosticPrinter &operator<<(long long N) override;
  73. DiagnosticPrinter &operator<<(const void *P) override;
  74. DiagnosticPrinter &operator<<(unsigned int N) override;
  75. DiagnosticPrinter &operator<<(int N) override;
  76. DiagnosticPrinter &operator<<(double N) override;
  77. DiagnosticPrinter &operator<<(const Twine &Str) override;
  78. // IR related types.
  79. DiagnosticPrinter &operator<<(const Value &V) override;
  80. DiagnosticPrinter &operator<<(const Module &M) override;
  81. // Other types.
  82. DiagnosticPrinter &operator<<(const SMDiagnostic &Diag) override;
  83. };
  84. } // end namespace llvm
  85. #endif // LLVM_IR_DIAGNOSTICPRINTER_H
  86. #ifdef __GNUC__
  87. #pragma GCC diagnostic pop
  88. #endif