LLVM: lib/DebugInfo/CodeView/CodeViewRecordIO.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
17
18using namespace llvm;
20
22 RecordLimit Limit;
23 Limit.MaxLength = MaxLength;
24 Limit.BeginOffset = getCurrentOffset();
27}
28
30 assert(!Limits.empty() && "Not in a record!");
32
33
34
35
36
37
38
39
40
42
43
47
48 int PaddingBytes = 4 - Align;
49 while (PaddingBytes > 0) {
50 char Pad = static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
53 --PaddingBytes;
54 }
55 resetStreamedLen();
56 }
58}
59
62 return 0;
63
64 assert(!Limits.empty() && "Not in a record!");
65
66
67
68
69
71 std::optional<uint32_t> Min = Limits.front().bytesRemaining(Offset);
72 for (auto X : ArrayRef(Limits).drop_front()) {
73 std::optional<uint32_t> ThisMin = X.bytesRemaining(Offset);
74 if (ThisMin)
75 Min = Min ? std::min(*Min, *ThisMin) : *ThisMin;
76 }
77 assert(Min && "Every field must have a maximum length!");
78
79 return *Min;
80}
81
86}
87
89 assert(() && "Cannot skip padding while writing!");
90
93
95 if (Leaf < LF_PAD0)
97
98
99 unsigned BytesToAdvance = Leaf & 0x0F;
100 return Reader->skip(BytesToAdvance);
101}
102
104 const Twine &Comment) {
106 emitComment(Comment);
108 incrStreamedLen(Bytes.size());
111 return EC;
112 } else {
114 return EC;
115 }
117}
118
120 const Twine &Comment) {
123 return EC;
125 Bytes.assign(BytesRef.begin(), BytesRef.end());
126
128}
129
132 std::string TypeNameStr = Streamer->getTypeName(TypeInd);
133 if (!TypeNameStr.empty())
134 emitComment(Comment + ": " + TypeNameStr);
135 else
136 emitComment(Comment);
138 incrStreamedLen(sizeof(TypeInd.getIndex()));
141 return EC;
142 } else {
145 return EC;
147 }
149}
150
152 const Twine &Comment) {
155 emitEncodedUnsignedInteger(static_cast<uint64_t>(Value), Comment);
156 else
157 emitEncodedSignedInteger(Value, Comment);
159 if (Value >= 0) {
160 if (auto EC = writeEncodedUnsignedInteger(static_cast<uint64_t>(Value)))
161 return EC;
162 } else {
163 if (auto EC = writeEncodedSignedInteger(Value))
164 return EC;
165 }
166 } else {
169 return EC;
171 }
172
174}
175
177 const Twine &Comment) {
179 emitEncodedUnsignedInteger(Value, Comment);
181 if (auto EC = writeEncodedUnsignedInteger(Value))
182 return EC;
183 } else {
186 return EC;
188 }
190}
191
194
195
196 if (Value.isSigned())
197 emitEncodedSignedInteger(Value.getSExtValue(), Comment);
198 else
199 emitEncodedUnsignedInteger(Value.getZExtValue(), Comment);
201 if (Value.isSigned())
202 return writeEncodedSignedInteger(
204 return writeEncodedUnsignedInteger(Value.getLimitedValue());
205 } else
208}
209
213 emitComment(Comment);
214 Streamer->emitBytes(NullTerminatedString);
215 incrStreamedLen(NullTerminatedString.size());
217
220 return EC;
221 } else {
223 return EC;
224 }
226}
227
229 constexpr uint32_t GuidSize = 16;
230
233 StringRef((reinterpret_cast<const char *>(&Guid)), GuidSize);
234 emitComment(Comment);
236 incrStreamedLen(GuidSize);
238 }
239
242
245 return EC;
246 } else {
248 if (auto EC = Reader->readBytes(GuidBytes, GuidSize))
249 return EC;
250 memcpy(Guid.Guid, GuidBytes.data(), GuidSize);
251 }
253}
254
256 const Twine &Comment) {
257
259 emitComment(Comment);
260 for (auto V : Value) {
262 return EC;
263 }
266 return EC;
267 } else {
270 return EC;
271 while (!S.empty()) {
272 Value.push_back(S);
274 return EC;
275 };
276 }
278}
279
280void CodeViewRecordIO::emitEncodedSignedInteger(const int64_t &Value,
281 const Twine &Comment) {
282
283
284
285 if (Value < LF_NUMERIC && Value >= 0) {
286 emitComment(Comment);
288 incrStreamedLen(2);
289 } else if (Value >= std::numeric_limits<int8_t>::min() &&
290 Value <= std::numeric_limits<int8_t>::max()) {
292 emitComment(Comment);
294 incrStreamedLen(3);
295 } else if (Value >= std::numeric_limits<int16_t>::min() &&
296 Value <= std::numeric_limits<int16_t>::max()) {
298 emitComment(Comment);
300 incrStreamedLen(4);
301 } else if (Value >= std::numeric_limits<int32_t>::min() &&
302 Value <= std::numeric_limits<int32_t>::max()) {
304 emitComment(Comment);
306 incrStreamedLen(6);
307 } else {
309 emitComment(Comment);
310 Streamer->emitIntValue(Value, 4);
311 incrStreamedLen(6);
312 }
313}
314
315void CodeViewRecordIO::emitEncodedUnsignedInteger(const uint64_t &Value,
316 const Twine &Comment) {
317 if (Value < LF_NUMERIC) {
318 emitComment(Comment);
320 incrStreamedLen(2);
321 } else if (Value <= std::numeric_limits<uint16_t>::max()) {
323 emitComment(Comment);
325 incrStreamedLen(4);
326 } else if (Value <= std::numeric_limits<uint32_t>::max()) {
328 emitComment(Comment);
330 incrStreamedLen(6);
331 } else {
332
334 emitComment(Comment);
336 incrStreamedLen(6);
337 }
338}
339
340Error CodeViewRecordIO::writeEncodedSignedInteger(const int64_t &Value) {
341 if (Value < LF_NUMERIC && Value >= 0) {
343 return EC;
344 } else if (Value >= std::numeric_limits<int8_t>::min() &&
345 Value <= std::numeric_limits<int8_t>::max()) {
347 return EC;
349 return EC;
350 } else if (Value >= std::numeric_limits<int16_t>::min() &&
351 Value <= std::numeric_limits<int16_t>::max()) {
353 return EC;
355 return EC;
356 } else if (Value >= std::numeric_limits<int32_t>::min() &&
357 Value <= std::numeric_limits<int32_t>::max()) {
359 return EC;
361 return EC;
362 } else {
364 return EC;
366 return EC;
367 }
369}
370
371Error CodeViewRecordIO::writeEncodedUnsignedInteger(const uint64_t &Value) {
372 if (Value < LF_NUMERIC) {
374 return EC;
375 } else if (Value <= std::numeric_limits<uint16_t>::max()) {
377 return EC;
379 return EC;
380 } else if (Value <= std::numeric_limits<uint32_t>::max()) {
382 return EC;
384 return EC;
385 } else {
387 return EC;
389 return EC;
390 }
391
393}
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
An arbitrary precision integer that knows its signedness.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Error readCString(StringRef &Dest)
Read a null terminated string from Dest.
Error readBytes(ArrayRef< uint8_t > &Buffer, uint32_t Size)
Read Size bytes from the underlying stream at the current offset and and set Buffer to the resulting ...
uint8_t peek() const
Examine the next byte of the underlying stream without advancing the stream's offset.
Error readInteger(T &Dest)
Read an integer of the specified endianness into Dest and update the stream's offset.
uint64_t bytesRemaining() const
Error padToAlignment(uint32_t Align)
Error skip(uint64_t Amount)
Advance the stream's offset by Amount bytes.
Error writeCString(StringRef Str)
Write the string Str to the underlying stream followed by a null terminator.
Error writeInteger(T Value)
Write the integer Value to the underlying stream in the specified endianness.
Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
Error padToAlignment(uint32_t Align)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Error padToAlignment(uint32_t Align)
Error mapInteger(TypeIndex &TypeInd, const Twine &Comment="")
Error mapGuid(GUID &Guid, const Twine &Comment="")
Error mapStringZVectorZ(std::vector< StringRef > &Value, const Twine &Comment="")
Error mapStringZ(StringRef &Value, const Twine &Comment="")
uint64_t getStreamedLen()
Error mapEncodedInteger(int64_t &Value, const Twine &Comment="")
Error beginRecord(std::optional< uint32_t > MaxLength)
Error mapByteVectorTail(ArrayRef< uint8_t > &Bytes, const Twine &Comment="")
uint32_t maxFieldLength() const
virtual void emitBytes(StringRef Data)=0
virtual void emitIntValue(uint64_t Value, unsigned Size)=0
virtual void emitBinaryData(StringRef Data)=0
virtual std::string getTypeName(TypeIndex TI)=0
void setIndex(uint32_t I)
uint32_t getIndex() const
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This represents the 'GUID' type from windows.h.