LLVM: include/llvm/Support/Format.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef LLVM_SUPPORT_FORMAT_H
23#define LLVM_SUPPORT_FORMAT_H
24
29#include
30#include
31#include
32#include
33#include
34
35namespace llvm {
36
37
38
40protected:
44 virtual void home();
45
46
47 virtual int snprint(char *Buffer, unsigned BufferSize) const = 0;
48
49public:
51
52
53
54
55 unsigned print(char *Buffer, unsigned BufferSize) const {
56 assert(BufferSize && "Invalid buffer size!");
57
58
59 int N = snprint(Buffer, BufferSize);
60
61
62 if (N < 0)
63 return BufferSize * 2;
64
65
66
67 if (unsigned(N) >= BufferSize)
68 return N + 1;
69
70
71 return N;
72 }
73};
74
75
76
77
78
79
80
82template <typename Arg, typename... Args>
84 static_assert(std::is_scalar_v,
85 "format can't be used with non fundamental / non pointer type");
87};
89
90template <typename... Ts>
92 std::tuple<Ts...> Vals;
93
94 template <std::size_t... Is>
95 int snprint_tuple(char *Buffer, unsigned BufferSize,
96 std::index_sequence<Is...>) const {
97#ifdef _MSC_VER
98 return _snprintf(Buffer, BufferSize, Fmt, std::get(Vals)...);
99#else
100 return snprintf(Buffer, BufferSize, Fmt, std::get(Vals)...);
101#endif
102 }
103
104public:
108 }
109
110 int snprint(char *Buffer, unsigned BufferSize) const override {
111 return snprint_tuple(Buffer, BufferSize, std::index_sequence_for<Ts...>());
112 }
113};
114
115
116
117
118
119
120
121
122
123
124template <typename... Ts>
127}
128
129
131public:
134 : Str(S), Width(W), Justify(J) {}
135
136private:
138 unsigned Width;
141};
142
143
144
145
148}
149
150
151
152
155}
156
157
158
159
162}
163
164
167 int64_t DecValue;
168 unsigned Width;
169 bool Hex;
170 bool Upper;
171 bool HexPrefix;
173
174public:
176 bool Prefix)
177 : HexValue(HV), DecValue(DV), Width(W), Hex(H), Upper(U),
178 HexPrefix(Prefix) {}
179};
180
181
182
183
184
185
186
188 bool Upper = false) {
189 assert(Width <= 18 && "hex width must be <= 18");
191}
192
193
194
195
196
197
198
199
201 bool Upper = false) {
202 assert(Width <= 16 && "hex width must be <= 16");
204}
205
206
207
208
209
210
211
214}
215
218
219
220
221 std::optional<uint64_t> FirstByteOffset;
222 uint32_t IndentLevel;
223 uint32_t NumPerLine;
224 uint8_t ByteGroupSize;
225 bool Upper;
226 bool ASCII;
228
229public:
232 : Bytes(B), FirstByteOffset(O), IndentLevel(IL), NumPerLine(NPL),
233 ByteGroupSize(BGS), Upper(U), ASCII(A) {
234
235 if (ByteGroupSize > NumPerLine)
236 ByteGroupSize = NumPerLine;
237 }
238};
239
240inline FormattedBytes
242 std::optional<uint64_t> FirstByteOffset = std::nullopt,
245 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
246 ByteGroupSize, Upper, false);
247}
248
249inline FormattedBytes
251 std::optional<uint64_t> FirstByteOffset = std::nullopt,
254 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,
255 ByteGroupSize, Upper, true);
256}
257
258}
259
260#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
FormattedBytes(ArrayRef< uint8_t > B, uint32_t IL, std::optional< uint64_t > O, uint32_t NPL, uint8_t BGS, bool U, bool A)
This is a helper class used for format_hex() and format_decimal().
FormattedNumber(uint64_t HV, int64_t DV, unsigned W, bool H, bool U, bool Prefix)
This is a helper class for left_justify, right_justify, and center_justify.
FormattedString(StringRef S, unsigned W, Justification J)
StringRef - Represent a constant reference to a string, i.e.
This is a helper class used for handling formatted output.
format_object_base(const char *fmt)
unsigned print(char *Buffer, unsigned BufferSize) const
Format the object into the specified buffer.
virtual int snprint(char *Buffer, unsigned BufferSize) const =0
Call snprintf() for this object, on the given buffer and size.
format_object_base(const format_object_base &)=default
~format_object_base()=default
format_object(const char *fmt, const Ts &... vals)
int snprint(char *Buffer, unsigned BufferSize) const override
Call snprintf() for this object, on the given buffer and size.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
FormattedNumber format_decimal(int64_t N, unsigned Width)
format_decimal - Output N as a right justified, fixed-width decimal.
FormattedString right_justify(StringRef Str, unsigned Width)
right_justify - add spaces before string so total output is Width characters.
FormattedString center_justify(StringRef Str, unsigned Width)
center_justify - add spaces before and after string so total output is Width characters.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
FormattedBytes format_bytes_with_ascii(ArrayRef< uint8_t > Bytes, std::optional< uint64_t > FirstByteOffset=std::nullopt, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)
FormattedString left_justify(StringRef Str, unsigned Width)
left_justify - append spaces after string so total output is Width characters.
FormattedBytes format_bytes(ArrayRef< uint8_t > Bytes, std::optional< uint64_t > FirstByteOffset=std::nullopt, uint32_t NumPerLine=16, uint8_t ByteGroupSize=4, uint32_t IndentLevel=0, bool Upper=false)
validate_format_parameters()
These are templated helper classes used by the format function that capture the object to be formatte...