LLVM  15.0.0git
FormatUtil.h
Go to the documentation of this file.
1 //===- FormatUtil.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_PDB_NATIVE_FORMATUTIL_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_FORMATUTIL_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Endian.h"
18 
19 #include <string>
20 #include <type_traits>
21 
22 namespace llvm {
23 namespace pdb {
24 
25 #define PUSH_MASKED_FLAG(Enum, Mask, TheOpt, Value, Text) \
26  if (Enum::TheOpt == (Value & Mask)) \
27  Opts.push_back(Text);
28 
29 #define PUSH_FLAG(Enum, TheOpt, Value, Text) \
30  PUSH_MASKED_FLAG(Enum, Enum::TheOpt, TheOpt, Value, Text)
31 
32 #define RETURN_CASE(Enum, X, Ret) \
33  case Enum::X: \
34  return Ret;
35 
36 template <typename T> std::string formatUnknownEnum(T Value) {
37  return formatv("unknown ({0})", static_cast<std::underlying_type_t<T>>(Value))
38  .str();
39 }
40 
41 std::string formatSegmentOffset(uint16_t Segment, uint32_t Offset);
42 
43 enum class CharacteristicStyle {
44  HeaderDefinition, // format as windows header definition
45  Descriptive, // format as human readable words
46 };
48  uint32_t IndentLevel, uint32_t C, uint32_t FlagsPerLine,
49  StringRef Separator,
51 
52 std::string typesetItemList(ArrayRef<std::string> Opts, uint32_t IndentLevel,
53  uint32_t GroupSize, StringRef Sep);
54 
55 std::string typesetStringList(uint32_t IndentLevel,
56  ArrayRef<StringRef> Strings);
57 
59  bool Friendly = true);
62 
63 /// Returns the number of digits in the given integer.
64 inline int NumDigits(uint64_t N) {
65  if (N < 10ULL)
66  return 1;
67  if (N < 100ULL)
68  return 2;
69  if (N < 1000ULL)
70  return 3;
71  if (N < 10000ULL)
72  return 4;
73  if (N < 100000ULL)
74  return 5;
75  if (N < 1000000ULL)
76  return 6;
77  if (N < 10000000ULL)
78  return 7;
79  if (N < 100000000ULL)
80  return 8;
81  if (N < 1000000000ULL)
82  return 9;
83  if (N < 10000000000ULL)
84  return 10;
85  if (N < 100000000000ULL)
86  return 11;
87  if (N < 1000000000000ULL)
88  return 12;
89  if (N < 10000000000000ULL)
90  return 13;
91  if (N < 100000000000000ULL)
92  return 14;
93  if (N < 1000000000000000ULL)
94  return 15;
95  if (N < 10000000000000000ULL)
96  return 16;
97  if (N < 100000000000000000ULL)
98  return 17;
99  if (N < 1000000000000000000ULL)
100  return 18;
101  if (N < 10000000000000000000ULL)
102  return 19;
103  return 20;
104 }
105 
106 namespace detail {
107 template <typename T>
108 struct EndianAdapter final
109  : public FormatAdapter<support::detail::packed_endian_specific_integral<
110  T, support::little, support::unaligned>> {
111  using EndianType =
114 
117 
118  void format(llvm::raw_ostream &Stream, StringRef Style) override {
119  format_provider<T>::format(static_cast<T>(this->Item), Stream, Style);
120  }
121 };
122 } // namespace detail
123 
124 template <typename T>
125 detail::EndianAdapter<T>
128  Value) {
130 }
131 } // namespace pdb
132 } // namespace llvm
133 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::FormatAdapter< support::detail::packed_endian_specific_integral< T, support::little, support::unaligned > >::Item
support::detail::packed_endian_specific_integral< T, support::little, support::unaligned > Item
Definition: FormatAdapters.h:23
llvm::support::detail::packed_endian_specific_integral< T, support::little, support::unaligned >
StringRef.h
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:47
llvm::pdb::detail::EndianAdapter::format
void format(llvm::raw_ostream &Stream, StringRef Style) override
Definition: FormatUtil.h:118
llvm::support::unaligned
@ unaligned
Definition: Endian.h:30
llvm::pdb::NumDigits
int NumDigits(uint64_t N)
Returns the number of digits in the given integer.
Definition: FormatUtil.h:64
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::support::little
@ little
Definition: Endian.h:27
llvm::pdb::detail::EndianAdapter
Definition: FormatUtil.h:108
llvm::pdb::detail::EndianAdapter::EndianAdapter
EndianAdapter(EndianType &&Item)
Definition: FormatUtil.h:115
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::pdb::fmtle
detail::EndianAdapter< T > fmtle(support::detail::packed_endian_specific_integral< T, support::little, support::unaligned > Value)
Definition: FormatUtil.h:126
CodeView.h
FormatVariadic.h
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::pdb::typesetItemList
std::string typesetItemList(ArrayRef< std::string > Opts, uint32_t IndentLevel, uint32_t GroupSize, StringRef Sep)
Definition: FormatUtil.cpp:22
llvm::pdb::formatChunkKind
std::string formatChunkKind(codeview::DebugSubsectionKind Kind, bool Friendly=true)
Definition: FormatUtil.cpp:50
uint64_t
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::pdb::formatSegmentOffset
std::string formatSegmentOffset(uint16_t Segment, uint32_t Offset)
Definition: FormatUtil.cpp:121
ArrayRef.h
llvm::HexStyle::Style
Style
Definition: MCInstPrinter.h:32
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1675
llvm::pdb::formatTypeLeafKind
std::string formatTypeLeafKind(codeview::TypeLeafKind K)
Definition: FormatUtil.cpp:108
llvm::pdb::CharacteristicStyle::Descriptive
@ Descriptive
llvm::ArrayRef< std::string >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
uint32_t
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::pdb::formatSectionCharacteristics
std::string formatSectionCharacteristics(uint32_t IndentLevel, uint32_t C, uint32_t FlagsPerLine, StringRef Separator, CharacteristicStyle Style=CharacteristicStyle::HeaderDefinition)
Definition: FormatUtil.cpp:137
llvm::FormatAdapter
Definition: FormatAdapters.h:19
llvm::pdb::CharacteristicStyle::HeaderDefinition
@ HeaderDefinition
std
Definition: BitVector.h:851
uint16_t
llvm::pdb::CharacteristicStyle
CharacteristicStyle
Definition: FormatUtil.h:43
llvm::pdb::typesetStringList
std::string typesetStringList(uint32_t IndentLevel, ArrayRef< StringRef > Strings)
Definition: FormatUtil.cpp:40
llvm::pdb::formatUnknownEnum
std::string formatUnknownEnum(T Value)
Definition: FormatUtil.h:36
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition: CodeView.h:315
llvm::codeview::TypeLeafKind
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:33
FormatAdapters.h
N
#define N
Endian.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::pdb::formatSymbolKind
std::string formatSymbolKind(codeview::SymbolKind K)
Definition: FormatUtil.cpp:97