30 "Unexpected end of file reading %u bits at bit "
31 "%" PRIu64
" of %" PRIu64,
36 size_t ByteNo = BitNo / 8;
37 std::memcpy(Buf, BitcodeBytes.data() + ByteNo,
38 std::min(
sizeof(Buf), BitcodeBytes.size() - ByteNo));
43 return R & (
~word_t(0) >> (BitsInWord - NumBits));
49 BlockScope.push_back(
Block(CurCodeSize));
50 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
55 BlockInfo->getBlockInfo(BlockID)) {
64 CurCodeSize = MaybeVBR.
get();
68 std::errc::illegal_byte_sequence,
69 "can't read more than %zu at a time, trying to read %u", +
MaxChunkSize,
78 *NumWordsP = NumWords;
82 std::errc::illegal_byte_sequence,
83 "can't enter sub-block: current code size is 0");
86 std::errc::illegal_byte_sequence,
87 "can't enter sub block: already at end of stream");
94 assert(!
Op.isLiteral() &&
"Not to be used with literals!");
97 switch (
Op.getEncoding()) {
102 assert((
unsigned)
Op.getEncodingData() <= Cursor.MaxChunkSize);
103 return Cursor.Read((
unsigned)
Op.getEncodingData());
105 assert((
unsigned)
Op.getEncodingData() <= Cursor.MaxChunkSize);
106 return Cursor.ReadVBR64((
unsigned)
Op.getEncodingData());
111 return Res.takeError();
123 unsigned Code = MaybeCode.
get();
127 unsigned NumElts = MaybeVBR.
get();
128 for (
unsigned i = 0; i != NumElts; ++i)
132 return Res.takeError();
149 std::errc::illegal_byte_sequence,
150 "Abbreviation starts with an Array or a Blob");
154 Code = MaybeCode.
get();
167 return MaybeField.takeError();
175 unsigned NumElts = MaybeNum.
get();
178 assert(i+2 == e &&
"array op not second to last?");
185 return error(
"Array element type can't be an Array or a Blob");
195 for (; NumElts; --NumElts)
200 return Res.takeError();
215 unsigned NumElts = MaybeNum.
get();
250 return error(
"Size is not plausible");
253 for (
unsigned i = 0; i != NumElts; ++i)
257 return MaybeVal.takeError();
275 return error(
"Abbreviation starts with an Array or a Blob");
277 Code = MaybeCode.get();
279 return MaybeCode.takeError();
284 if (
Op.isLiteral()) {
294 return MaybeVal.takeError();
307 return error(
"Size is not plausible");
312 return error(
"Array op not second to last");
316 "Array element type has to be an encoding of a type");
321 return error(
"Array element type can't be an Array or a Blob");
323 for (; NumElts; --NumElts)
328 return MaybeVal.takeError();
331 for (; NumElts; --NumElts)
336 return MaybeVal.takeError();
339 for (; NumElts; --NumElts)
343 return MaybeVal.takeError();
358 const size_t NewEnd =
359 CurBitPos +
static_cast<uint64_t
>(
alignTo(NumElts, 4)) * 8;
363 return error(
"Blob ends too soon");
377 auto *UPtr =
reinterpret_cast<const unsigned char *
>(Ptr);
378 Vals.
append(UPtr, UPtr + NumElts);
386 auto Abbv = std::make_shared<BitCodeAbbrev>();
390 unsigned NumOpInfo = MaybeNumOpInfo.
get();
391 for (
unsigned i = 0; i != NumOpInfo; ++i) {
395 bool IsLiteral = MaybeIsLiteral.
get();
408 return error(
"Invalid encoding");
416 uint64_t
Data = MaybeData.
get();
429 return error(
"Fixed or VBR abbrev record with size > MaxChunkData");
436 if (Abbv->getNumOperandInfos() == 0)
437 return error(
"Abbrev record with no operands");
438 CurAbbrevs.push_back(std::move(Abbv));
461 switch (Entry.Kind) {
466 return std::move(NewBlockInfo);
481 CurBlockInfo->
Abbrevs.push_back(std::move(CurAbbrevs.back()));
482 CurAbbrevs.pop_back();
491 switch (MaybeBlockInfo.
get()) {
502 if (!ReadBlockInfoNames)
510 if (!ReadBlockInfoNames)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Expected< uint64_t > readAbbreviatedField(BitstreamCursor &Cursor, const BitCodeAbbrevOp &Op)
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
uint64_t getLiteralValue() const
static bool isValidEncoding(uint64_t E)
bool hasEncodingData() const
Encoding getEncoding() const
static char DecodeChar6(unsigned V)
uint64_t getEncodingData() const
BitCodeAbbrev - This class represents an abbreviation record.
unsigned getNumOperandInfos() const
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
This class maintains the abbreviations read from a block info block.
BlockInfo & getOrCreateBlockInfo(unsigned BlockID)
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
LLVM_ABI Error ReadAbbrevRecord()
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Expected< uint64_t > ReadVBR64(const unsigned NumBits)
static const size_t MaxChunkSize
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
Expected< const BitCodeAbbrev * > getAbbrev(unsigned AbbrevID)
Return the abbreviation for the specified AbbrevId.
LLVM_ABI Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
LLVM_ABI Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
LLVM_ABI Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
@ AF_DontAutoprocessAbbrevs
If this flag is used, abbrev entries are returned just like normal records.
void skipToEnd()
Skip to the end of the file.
LLVM_ABI Expected< std::optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
Error JumpToBit(uint64_t NewBitNo)
Reset the stream to the specified bit number.
Expected< uint32_t > ReadVBR(const unsigned NumBits)
bool canSkipToPos(size_t pos) const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
LLVM_ABI Expected< word_t > readSlow(unsigned NumBits)
Read NumBits bits that don't fit in a word load from the current byte, or are near the end of the str...
const uint8_t * getPointerToBit(uint64_t BitNo, uint64_t NumBytes)
Get a pointer into the bitstream at the specified bit offset.
size_t word_t
The type of the values returned by Read.
void SkipToFourByteBoundary()
bool isSizePlausible(size_t Size) const
Check whether a reservation of Size elements is plausible.
uint64_t sizeInBits() const
Return the size of the stream in bits.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BLOCKINFO_CODE_BLOCKNAME
@ BLOCKINFO_CODE_SETRECORDNAME
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
@ DEFINE_ABBREV
DEFINE_ABBREV - Defines an abbrev for the current block.
value_type readAtBitAlignment(const void *memory, uint64_t startBit)
Read a value of a particular endianness from memory, for a location that starts at the given bit offs...
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
DWARFExpression::Operation Op
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
This contains information emitted to BLOCKINFO_BLOCK blocks.
std::vector< std::pair< unsigned, std::string > > RecordNames
std::vector< std::shared_ptr< BitCodeAbbrev > > Abbrevs
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...