Formatters.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Formatters.h ---------------------------------------------*- 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. #ifndef LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H
  14. #define LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/DebugInfo/CodeView/GUID.h"
  18. #include "llvm/DebugInfo/CodeView/TypeIndex.h"
  19. #include "llvm/Support/FormatAdapters.h"
  20. #include "llvm/Support/FormatVariadic.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. #include <cstdint>
  23. namespace llvm {
  24. namespace codeview {
  25. struct GUID;
  26. namespace detail {
  27. class GuidAdapter final : public FormatAdapter<ArrayRef<uint8_t>> {
  28. ArrayRef<uint8_t> Guid;
  29. public:
  30. explicit GuidAdapter(ArrayRef<uint8_t> Guid);
  31. explicit GuidAdapter(StringRef Guid);
  32. void format(raw_ostream &Stream, StringRef Style) override;
  33. };
  34. } // end namespace detail
  35. inline detail::GuidAdapter fmt_guid(StringRef Item) {
  36. return detail::GuidAdapter(Item);
  37. }
  38. inline detail::GuidAdapter fmt_guid(ArrayRef<uint8_t> Item) {
  39. return detail::GuidAdapter(Item);
  40. }
  41. } // end namespace codeview
  42. template <> struct format_provider<codeview::TypeIndex> {
  43. public:
  44. static void format(const codeview::TypeIndex &V, raw_ostream &Stream,
  45. StringRef Style) {
  46. if (V.isNoneType())
  47. Stream << "<no type>";
  48. else {
  49. Stream << formatv("{0:X+4}", V.getIndex());
  50. if (V.isSimple())
  51. Stream << " (" << codeview::TypeIndex::simpleTypeName(V) << ")";
  52. }
  53. }
  54. };
  55. template <> struct format_provider<codeview::GUID> {
  56. static void format(const codeview::GUID &V, llvm::raw_ostream &Stream,
  57. StringRef Style) {
  58. Stream << V;
  59. }
  60. };
  61. } // end namespace llvm
  62. #endif // LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H
  63. #ifdef __GNUC__
  64. #pragma GCC diagnostic pop
  65. #endif