Formatters.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. namespace detail {
  26. class GuidAdapter final : public FormatAdapter<ArrayRef<uint8_t>> {
  27. ArrayRef<uint8_t> Guid;
  28. public:
  29. explicit GuidAdapter(ArrayRef<uint8_t> Guid);
  30. explicit GuidAdapter(StringRef Guid);
  31. void format(raw_ostream &Stream, StringRef Style) override;
  32. };
  33. } // end namespace detail
  34. inline detail::GuidAdapter fmt_guid(StringRef Item) {
  35. return detail::GuidAdapter(Item);
  36. }
  37. inline detail::GuidAdapter fmt_guid(ArrayRef<uint8_t> Item) {
  38. return detail::GuidAdapter(Item);
  39. }
  40. } // end namespace codeview
  41. template <> struct format_provider<codeview::TypeIndex> {
  42. public:
  43. static void format(const codeview::TypeIndex &V, raw_ostream &Stream,
  44. StringRef Style) {
  45. if (V.isNoneType())
  46. Stream << "<no type>";
  47. else {
  48. Stream << formatv("{0:X+4}", V.getIndex());
  49. if (V.isSimple())
  50. Stream << " (" << codeview::TypeIndex::simpleTypeName(V) << ")";
  51. }
  52. }
  53. };
  54. template <> struct format_provider<codeview::GUID> {
  55. static void format(const codeview::GUID &V, llvm::raw_ostream &Stream,
  56. StringRef Style) {
  57. Stream << V;
  58. }
  59. };
  60. } // end namespace llvm
  61. #endif // LLVM_DEBUGINFO_CODEVIEW_FORMATTERS_H
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif