1 //===- FormatUtil.h ------------------------------------------- *- C++ --*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
11 #define LLVM_TOOLS_LLVMPDBUTIL_FORMAT_UTIL_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/DebugInfo/CodeView/CodeView.h"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/FormatAdapters.h"
18 #include "llvm/Support/FormatVariadic.h"
21 #include <type_traits>
26 std::string
truncateStringBack(StringRef S
, uint32_t MaxLen
);
27 std::string
truncateStringMiddle(StringRef S
, uint32_t MaxLen
);
28 std::string
truncateStringFront(StringRef S
, uint32_t MaxLen
);
29 std::string
truncateQuotedNameFront(StringRef Label
, StringRef Name
,
31 std::string
truncateQuotedNameBack(StringRef Label
, StringRef Name
,
34 #define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text) \
35 if (Enum::TheOpt == (Value & Mask)) \
38 #define PUSH_FLAG(Enum, TheOpt, Value, Text) \
39 PUSH_MASKED_FLAG(Enum, Enum::TheOpt, TheOpt, Value, Text)
41 #define RETURN_CASE(Enum, X, Ret) \
45 template <typename T
> std::string
formatUnknownEnum(T Value
) {
46 return formatv("unknown ({0})",
47 static_cast<typename
std::underlying_type
<T
>::type
>(Value
))
51 std::string
formatSegmentOffset(uint16_t Segment
, uint32_t Offset
);
53 enum class CharacteristicStyle
{
54 HeaderDefinition
, // format as windows header definition
55 Descriptive
, // format as human readable words
57 std::string
formatSectionCharacteristics(
58 uint32_t IndentLevel
, uint32_t C
, uint32_t FlagsPerLine
,
60 CharacteristicStyle Style
= CharacteristicStyle::HeaderDefinition
);
62 std::string
typesetItemList(ArrayRef
<std::string
> Opts
, uint32_t IndentLevel
,
63 uint32_t GroupSize
, StringRef Sep
);
65 std::string
typesetStringList(uint32_t IndentLevel
,
66 ArrayRef
<StringRef
> Strings
);
68 std::string
formatChunkKind(codeview::DebugSubsectionKind Kind
,
69 bool Friendly
= true);
70 std::string
formatSymbolKind(codeview::SymbolKind K
);
71 StringRef
formatTypeLeafKind(codeview::TypeLeafKind K
);
73 /// Returns the number of digits in the given integer.
74 inline int NumDigits(uint64_t N
) {
91 if (N
< 1000000000ULL)
93 if (N
< 10000000000ULL)
95 if (N
< 100000000000ULL)
97 if (N
< 1000000000000ULL)
99 if (N
< 10000000000000ULL)
101 if (N
< 100000000000000ULL)
103 if (N
< 1000000000000000ULL)
105 if (N
< 10000000000000000ULL)
107 if (N
< 100000000000000000ULL)
109 if (N
< 1000000000000000000ULL)
111 if (N
< 10000000000000000000ULL)
117 template <typename T
>
118 struct EndianAdapter final
119 : public FormatAdapter
<support::detail::packed_endian_specific_integral
<
120 T
, support::little
, support::unaligned
>> {
122 support::detail::packed_endian_specific_integral
<T
, support::little
,
125 explicit EndianAdapter(EndianType
&&Item
)
126 : FormatAdapter
<EndianType
>(std::move(Item
)) {}
128 void format(llvm::raw_ostream
&Stream
, StringRef Style
) {
129 format_provider
<T
>::format(static_cast<T
>(this->Item
), Stream
, Style
);
132 } // namespace detail
134 template <typename T
>
135 detail::EndianAdapter
<T
>
136 fmtle(support::detail::packed_endian_specific_integral
<T
, support::little
,
139 return detail::EndianAdapter
<T
>(std::move(Value
));