23 Limit.MaxLength = MaxLength;
24 Limit.BeginOffset = getCurrentOffset();
25 Limits.push_back(Limit);
30 assert(!Limits.empty() &&
"Not in a record!");
48 int PaddingBytes = 4 -
Align;
49 while (PaddingBytes > 0) {
50 char Pad =
static_cast<uint8_t>(LF_PAD0 + PaddingBytes);
52 Streamer->emitBytes(BytesSR);
64 assert(!Limits.empty() &&
"Not in a record!");
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);
75 Min = Min ? std::min(*Min, *ThisMin) : *ThisMin;
77 assert(Min &&
"Every field must have a maximum length!");
84 return Reader->padToAlignment(
Align);
85 return Writer->padToAlignment(
Align);
91 if (Reader->bytesRemaining() == 0)
99 unsigned BytesToAdvance = Leaf & 0x0F;
100 return Reader->skip(BytesToAdvance);
104 const Twine &Comment) {
106 emitComment(Comment);
108 incrStreamedLen(Bytes.
size());
110 if (
auto EC = Writer->writeBytes(Bytes))
113 if (
auto EC = Reader->readBytes(Bytes, Reader->bytesRemaining()))
120 const Twine &Comment) {
125 Bytes.assign(BytesRef.
begin(), BytesRef.
end());
132 std::string TypeNameStr = Streamer->getTypeName(TypeInd);
133 if (!TypeNameStr.empty())
134 emitComment(Comment +
": " + TypeNameStr);
136 emitComment(Comment);
138 incrStreamedLen(
sizeof(TypeInd.
getIndex()));
140 if (
auto EC = Writer->writeInteger(TypeInd.
getIndex()))
144 if (
auto EC = Reader->readInteger(
I))
152 const Twine &Comment) {
155 emitEncodedUnsignedInteger(
static_cast<uint64_t>(
Value), Comment);
157 emitEncodedSignedInteger(
Value, Comment);
160 if (
auto EC = writeEncodedUnsignedInteger(
static_cast<uint64_t>(
Value)))
163 if (
auto EC = writeEncodedSignedInteger(
Value))
177 const Twine &Comment) {
179 emitEncodedUnsignedInteger(
Value, Comment);
181 if (
auto EC = writeEncodedUnsignedInteger(
Value))
196 if (
Value.isSigned())
197 emitEncodedSignedInteger(
Value.getSExtValue(), Comment);
199 emitEncodedUnsignedInteger(
Value.getZExtValue(), Comment);
201 if (
Value.isSigned())
202 return writeEncodedSignedInteger(
204 return writeEncodedUnsignedInteger(
Value.getLimitedValue());
214 emitComment(Comment);
215 Streamer->emitBytes(NullTerminatedString);
216 incrStreamedLen(NullTerminatedString.size());
220 if (
auto EC = Writer->writeCString(S))
223 if (
auto EC = Reader->readCString(
Value))
234 StringRef((
reinterpret_cast<const char *
>(&
Guid)), GuidSize);
235 emitComment(Comment);
236 Streamer->emitBytes(GuidSR);
237 incrStreamedLen(GuidSize);
245 if (
auto EC = Writer->writeBytes(
Guid.Guid))
249 if (
auto EC = Reader->readBytes(GuidBytes, GuidSize))
251 memcpy(
Guid.Guid, GuidBytes.
data(), GuidSize);
257 const Twine &Comment) {
260 emitComment(Comment);
261 for (
auto V :
Value) {
281void CodeViewRecordIO::emitEncodedSignedInteger(
const int64_t &
Value,
282 const Twine &Comment) {
287 emitComment(Comment);
290 }
else if (
Value >= std::numeric_limits<int8_t>::min() &&
291 Value <= std::numeric_limits<int8_t>::max()) {
293 emitComment(Comment);
296 }
else if (
Value >= std::numeric_limits<int16_t>::min() &&
297 Value <= std::numeric_limits<int16_t>::max()) {
299 emitComment(Comment);
302 }
else if (
Value >= std::numeric_limits<int32_t>::min() &&
303 Value <= std::numeric_limits<int32_t>::max()) {
304 Streamer->emitIntValue(LF_LONG, 2);
305 emitComment(Comment);
306 Streamer->emitIntValue(
Value, 4);
309 Streamer->emitIntValue(LF_QUADWORD, 2);
310 emitComment(Comment);
311 Streamer->emitIntValue(
Value, 4);
316void CodeViewRecordIO::emitEncodedUnsignedInteger(
const uint64_t &
Value,
317 const Twine &Comment) {
318 if (
Value < LF_NUMERIC) {
319 emitComment(Comment);
320 Streamer->emitIntValue(
Value, 2);
322 }
else if (
Value <= std::numeric_limits<uint16_t>::max()) {
323 Streamer->emitIntValue(LF_USHORT, 2);
324 emitComment(Comment);
325 Streamer->emitIntValue(
Value, 2);
327 }
else if (
Value <= std::numeric_limits<uint32_t>::max()) {
328 Streamer->emitIntValue(LF_ULONG, 2);
329 emitComment(Comment);
330 Streamer->emitIntValue(
Value, 4);
334 Streamer->emitIntValue(LF_UQUADWORD, 2);
335 emitComment(Comment);
336 Streamer->emitIntValue(
Value, 8);
341Error CodeViewRecordIO::writeEncodedSignedInteger(
const int64_t &
Value) {
343 if (
auto EC = Writer->writeInteger<int16_t>(
Value))
345 }
else if (
Value >= std::numeric_limits<int8_t>::min() &&
346 Value <= std::numeric_limits<int8_t>::max()) {
347 if (
auto EC = Writer->writeInteger<uint16_t>(LF_CHAR))
349 if (
auto EC = Writer->writeInteger<int8_t>(
Value))
351 }
else if (
Value >= std::numeric_limits<int16_t>::min() &&
352 Value <= std::numeric_limits<int16_t>::max()) {
353 if (
auto EC = Writer->writeInteger<uint16_t>(LF_SHORT))
355 if (
auto EC = Writer->writeInteger<int16_t>(
Value))
357 }
else if (
Value >= std::numeric_limits<int32_t>::min() &&
358 Value <= std::numeric_limits<int32_t>::max()) {
359 if (
auto EC = Writer->writeInteger<uint16_t>(LF_LONG))
361 if (
auto EC = Writer->writeInteger<int32_t>(
Value))
364 if (
auto EC = Writer->writeInteger<uint16_t>(LF_QUADWORD))
366 if (
auto EC = Writer->writeInteger(
Value))
372Error CodeViewRecordIO::writeEncodedUnsignedInteger(
const uint64_t &
Value) {
373 if (
Value < LF_NUMERIC) {
374 if (
auto EC = Writer->writeInteger<uint16_t>(
Value))
376 }
else if (
Value <= std::numeric_limits<uint16_t>::max()) {
377 if (
auto EC = Writer->writeInteger<uint16_t>(LF_USHORT))
379 if (
auto EC = Writer->writeInteger<uint16_t>(
Value))
381 }
else if (
Value <= std::numeric_limits<uint32_t>::max()) {
382 if (
auto EC = Writer->writeInteger<uint16_t>(LF_ULONG))
384 if (
auto EC = Writer->writeInteger<uint32_t>(
Value))
387 if (
auto EC = Writer->writeInteger<uint16_t>(LF_UQUADWORD))
389 if (
auto EC = Writer->writeInteger(
Value))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
LLVM_ABI Error padToAlignment(uint32_t Align)
LLVM_ABI Error endRecord()
LLVM_ABI Error mapInteger(TypeIndex &TypeInd, const Twine &Comment="")
LLVM_ABI Error mapGuid(GUID &Guid, const Twine &Comment="")
LLVM_ABI Error mapStringZVectorZ(std::vector< StringRef > &Value, const Twine &Comment="")
LLVM_ABI Error skipPadding()
LLVM_ABI Error mapStringZ(StringRef &Value, const Twine &Comment="")
uint64_t getStreamedLen()
LLVM_ABI Error mapEncodedInteger(int64_t &Value, const Twine &Comment="")
LLVM_ABI Error beginRecord(std::optional< uint32_t > MaxLength)
LLVM_ABI Error mapByteVectorTail(ArrayRef< uint8_t > &Bytes, const Twine &Comment="")
LLVM_ABI uint32_t maxFieldLength() const
virtual void emitIntValue(uint64_t Value, unsigned Size)=0
void setIndex(uint32_t I)
uint32_t getIndex() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This represents the 'GUID' type from windows.h.