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

30#include

31#include

32#include

33#include

34#include

35

36namespace llvm {

37

38

39

41protected:

45 virtual void home();

46

47

48 virtual int snprint(char *Buffer, unsigned BufferSize) const = 0;

49

50public:

52

53

54

55

56 unsigned print(char *Buffer, unsigned BufferSize) const {

57 assert(BufferSize && "Invalid buffer size!");

58

59

60 int N = snprint(Buffer, BufferSize);

61

62

63 if (N < 0)

64 return BufferSize * 2;

65

66

67

68 if (unsigned(N) >= BufferSize)

69 return N + 1;

70

71

72 return N;

73 }

74};

75

76

77

78

79

80

86 using type = const char *;

87};

88template

90}

91

92template <typename... Ts>

94 std::tuple<detail::decay_if_c_char_array_t...> Vals;

95

96 template <std::size_t... Is>

97 int snprint_tuple(char *Buffer, unsigned BufferSize,

98 std::index_sequence<Is...>) const {

99#ifdef _MSC_VER

100 return _snprintf(Buffer, BufferSize, Fmt, std::get(Vals)...);

101#else

102 return snprintf(Buffer, BufferSize, Fmt, std::get(Vals)...);

103#endif

104 }

105

106public:

109 static_assert(

110 (std::is_scalar_v<detail::decay_if_c_char_array_t> && ...),

111 "format can't be used with non fundamental / non pointer type");

112 }

113

114 int snprint(char *Buffer, unsigned BufferSize) const override {

115 return snprint_tuple(Buffer, BufferSize, std::index_sequence_for<Ts...>());

116 }

117};

118

119

120

121

122

123

124

125

126

127

128template <typename... Ts>

132

133

135public:

138 : Str(S), Width(W), Justify(J) {}

139

140private:

142 unsigned Width;

143 Justification Justify;

145};

146

147

148

149

153

154

155

156

160

161

162

163

167

168

171 int64_t DecValue;

172 unsigned Width;

173 bool Hex;

174 bool Upper;

175 bool HexPrefix;

177

178public:

180 bool Prefix)

181 : HexValue(HV), DecValue(DV), Width(W), Hex(H), Upper(U),

182 HexPrefix(Prefix) {}

183};

184

185

186

187

188

189

190

192 bool Upper = false) {

193 assert(Width <= 18 && "hex width must be <= 18");

195}

196

197

198

199

200

201

202

203

205 bool Upper = false) {

206 assert(Width <= 16 && "hex width must be <= 16");

208}

209

210

211

212

213

214

215

219

222

223

224

225 std::optional<uint64_t> FirstByteOffset;

226 uint32_t IndentLevel;

227 uint32_t NumPerLine;

228 uint8_t ByteGroupSize;

229 bool Upper;

230 bool ASCII;

232

233public:

236 : Bytes(B), FirstByteOffset(O), IndentLevel(IL), NumPerLine(NPL),

237 ByteGroupSize(BGS), Upper(U), ASCII(A) {

238

239 if (ByteGroupSize > NumPerLine)

240 ByteGroupSize = NumPerLine;

241 }

242};

243

244inline FormattedBytes

246 std::optional<uint64_t> FirstByteOffset = std::nullopt,

249 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,

250 ByteGroupSize, Upper, false);

251}

252

253inline FormattedBytes

255 std::optional<uint64_t> FirstByteOffset = std::nullopt,

258 return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine,

259 ByteGroupSize, Upper, true);

260}

261

262}

263

264#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

friend class raw_ostream

Definition Format.h:231

FormattedBytes(ArrayRef< uint8_t > B, uint32_t IL, std::optional< uint64_t > O, uint32_t NPL, uint8_t BGS, bool U, bool A)

Definition Format.h:234

This is a helper class used for format_hex() and format_decimal().

Definition Format.h:169

friend class raw_ostream

Definition Format.h:176

FormattedNumber(uint64_t HV, int64_t DV, unsigned W, bool H, bool U, bool Prefix)

Definition Format.h:179

This is a helper class for left_justify, right_justify, and center_justify.

Definition Format.h:134

FormattedString(StringRef S, unsigned W, Justification J)

Definition Format.h:137

friend class raw_ostream

Definition Format.h:144

Justification

Definition Format.h:136

@ JustifyLeft

Definition Format.h:136

@ JustifyCenter

Definition Format.h:136

@ JustifyRight

Definition Format.h:136

@ JustifyNone

Definition Format.h:136

StringRef - Represent a constant reference to a string, i.e.

format_object_base(const char *fmt)

Definition Format.h:51

unsigned print(char *Buffer, unsigned BufferSize) const

Format the object into the specified buffer.

Definition Format.h:56

const char * Fmt

Definition Format.h:42

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)

Definition Format.h:107

int snprint(char *Buffer, unsigned BufferSize) const override

Call snprintf() for this object, on the given buffer and size.

Definition Format.h:114

typename decay_if_c_char_array< T >::type decay_if_c_char_array_t

Definition Format.h:89

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.

Definition Format.h:216

FormattedString right_justify(StringRef Str, unsigned Width)

right_justify - add spaces before string so total output is Width characters.

Definition Format.h:157

FormattedString center_justify(StringRef Str, unsigned Width)

center_justify - add spaces before and after string so total output is Width characters.

Definition Format.h:164

FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)

format_hex - Output N as a fixed width hexadecimal.

Definition Format.h:191

FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)

format_hex_no_prefix - Output N as a fixed width hexadecimal.

Definition Format.h:204

format_object< Ts... > format(const char *Fmt, const Ts &... Vals)

These are helper functions used to produce formatted output.

Definition Format.h:129

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)

Definition Format.h:254

FormattedString left_justify(StringRef Str, unsigned Width)

left_justify - append spaces after string so total output is Width characters.

Definition Format.h:150

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)

Definition Format.h:245

const char * type

Definition Format.h:86

T type

Definition Format.h:83