Formatters.h 1.9 KB

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