DiagnosticPrinter.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //===- llvm/IR/DiagnosticPrinter.cpp - 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 defines a diagnostic printer relying on raw_ostream.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/IR/DiagnosticPrinter.h"
  13. #include "llvm/ADT/Twine.h"
  14. #include "llvm/IR/Module.h"
  15. #include "llvm/IR/Value.h"
  16. #include "llvm/Support/SourceMgr.h"
  17. #include "llvm/Support/raw_ostream.h"
  18. using namespace llvm;
  19. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(char C) {
  20. Stream << C;
  21. return *this;
  22. }
  23. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned char C) {
  24. Stream << C;
  25. return *this;
  26. }
  27. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(signed char C) {
  28. Stream << C;
  29. return *this;
  30. }
  31. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(StringRef Str) {
  32. Stream << Str;
  33. return *this;
  34. }
  35. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const char *Str) {
  36. Stream << Str;
  37. return *this;
  38. }
  39. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(
  40. const std::string &Str) {
  41. Stream << Str;
  42. return *this;
  43. }
  44. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned long N) {
  45. Stream << N;
  46. return *this;
  47. }
  48. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long N) {
  49. Stream << N;
  50. return *this;
  51. }
  52. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(
  53. unsigned long long N) {
  54. Stream << N;
  55. return *this;
  56. }
  57. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(long long N) {
  58. Stream << N;
  59. return *this;
  60. }
  61. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const void *P) {
  62. Stream << P;
  63. return *this;
  64. }
  65. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(unsigned int N) {
  66. Stream << N;
  67. return *this;
  68. }
  69. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(int N) {
  70. Stream << N;
  71. return *this;
  72. }
  73. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(double N) {
  74. Stream << N;
  75. return *this;
  76. }
  77. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Twine &Str) {
  78. Str.print(Stream);
  79. return *this;
  80. }
  81. // IR related types.
  82. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) {
  83. Stream << V.getName();
  84. return *this;
  85. }
  86. DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Module &M) {
  87. Stream << M.getModuleIdentifier();
  88. return *this;
  89. }
  90. // Other types.
  91. DiagnosticPrinter &DiagnosticPrinterRawOStream::
  92. operator<<(const SMDiagnostic &Diag) {
  93. // We don't have to print the SMDiagnostic kind, as the diagnostic severity
  94. // is printed by the diagnostic handler.
  95. Diag.print("", Stream, /*ShowColors=*/true, /*ShowKindLabel=*/false);
  96. return *this;
  97. }