DiagnosticPrinter.h 3.5 KB

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