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