llvm.org GIT mirror llvm / cce2cdd
Don't repeat names in comments. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221495 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
1 changed file(s) with 57 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
2323
2424 namespace llvm {
2525
26 class Deserializer;
27
28 /// BitstreamReader - This class is used to read from an LLVM bitcode stream,
29 /// maintaining information that is global to decoding the entire file. While
30 /// a file is being read, multiple cursors can be independently advanced or
31 /// skipped around within the file. These are represented by the
32 /// BitstreamCursor class.
26 class Deserializer;
27
28 /// This class is used to read from an LLVM bitcode stream, maintaining
29 /// information that is global to decoding the entire file. While a file is
30 /// being read, multiple cursors can be independently advanced or skipped around
31 /// within the file. These are represented by the BitstreamCursor class.
3332 class BitstreamReader {
3433 public:
35 /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks.
36 /// These describe abbreviations that all blocks of the specified ID inherit.
34 /// This contains information emitted to BLOCKINFO_BLOCK blocks. These
35 /// describe abbreviations that all blocks of the specified ID inherit.
3736 struct BlockInfo {
3837 unsigned BlockID;
3938 std::vector> Abbrevs;
4645
4746 std::vector BlockInfoRecords;
4847
49 /// IgnoreBlockInfoNames - This is set to true if we don't care about the
50 /// block/record name information in the BlockInfo block. Only llvm-bcanalyzer
51 /// uses this.
48 /// This is set to true if we don't care about the block/record name
49 /// information in the BlockInfo block. Only llvm-bcanalyzer uses this.
5250 bool IgnoreBlockInfoNames;
5351
5452 BitstreamReader(const BitstreamReader&) LLVM_DELETED_FUNCTION;
8583
8684 StreamableMemoryObject &getBitcodeBytes() { return *BitcodeBytes; }
8785
88 /// CollectBlockInfoNames - This is called by clients that want block/record
89 /// name information.
86 /// This is called by clients that want block/record name information.
9087 void CollectBlockInfoNames() { IgnoreBlockInfoNames = false; }
9188 bool isIgnoringBlockInfoNames() { return IgnoreBlockInfoNames; }
9289
9491 // Block Manipulation
9592 //===--------------------------------------------------------------------===//
9693
97 /// hasBlockInfoRecords - Return true if we've already read and processed the
98 /// block info block for this Bitstream. We only process it for the first
99 /// cursor that walks over it.
94 /// Return true if we've already read and processed the block info block for
95 /// this Bitstream. We only process it for the first cursor that walks over
96 /// it.
10097 bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); }
10198
102 /// getBlockInfo - If there is block info for the specified ID, return it,
103 /// otherwise return null.
99 /// If there is block info for the specified ID, return it, otherwise return
100 /// null.
104101 const BlockInfo *getBlockInfo(unsigned BlockID) const {
105102 // Common case, the most recent entry matches BlockID.
106103 if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
133130 }
134131 };
135132
136
137 /// BitstreamEntry - When advancing through a bitstream cursor, each advance can
138 /// discover a few different kinds of entries:
139 /// Error - Malformed bitcode was found.
140 /// EndBlock - We've reached the end of the current block, (or the end of the
141 /// file, which is treated like a series of EndBlock records.
142 /// SubBlock - This is the start of a new subblock of a specific ID.
143 /// Record - This is a record with a specific AbbrevID.
144 ///
133 /// When advancing through a bitstream cursor, each advance can discover a few
134 /// different kinds of entries:
145135 struct BitstreamEntry {
146136 enum {
147 Error,
148 EndBlock,
149 SubBlock,
150 Record
137 Error, // Malformed bitcode was found.
138 EndBlock, // We've reached the end of the current block, (or the end of the
139 // file, which is treated like a series of EndBlock records.
140 SubBlock, // This is the start of a new subblock of a specific ID.
141 Record // This is a record with a specific AbbrevID.
151142 } Kind;
152143
153144 unsigned ID;
166157 }
167158 };
168159
169 /// BitstreamCursor - This represents a position within a bitcode file. There
170 /// may be multiple independent cursors reading within one bitstream, each
171 /// maintaining their own local state.
160 /// This represents a position within a bitcode file. There may be multiple
161 /// independent cursors reading within one bitstream, each maintaining their own
162 /// local state.
172163 ///
173164 /// Unlike iterators, BitstreamCursors are heavy-weight objects that should not
174165 /// be passed by value.
177168 BitstreamReader *BitStream;
178169 size_t NextChar;
179170
180
181 /// CurWord/word_t - This is the current data we have pulled from the stream
182 /// but have not returned to the client. This is specifically and
183 /// intentionally defined to follow the word size of the host machine for
184 /// efficiency. We use word_t in places that are aware of this to make it
185 /// perfectly explicit what is going on.
171 /// This is the current data we have pulled from the stream but have not
172 /// returned to the client. This is specifically and intentionally defined to
173 /// follow the word size of the host machine for efficiency. We use word_t in
174 /// places that are aware of this to make it perfectly explicit what is going
175 /// on.
186176 typedef uint32_t word_t;
187177 word_t CurWord;
188178
189 /// BitsInCurWord - This is the number of bits in CurWord that are valid. This
190 /// is always from [0...31/63] inclusive (depending on word size).
179 /// This is the number of bits in CurWord that are valid. This is always from
180 /// [0...31/63] inclusive (depending on word size).
191181 unsigned BitsInCurWord;
192182
193 // CurCodeSize - This is the declared size of code values used for the current
194 // block, in bits.
183 // This is the declared size of code values used for the current block, in
184 // bits.
195185 unsigned CurCodeSize;
196186
197 /// CurAbbrevs - Abbrevs installed at in this block.
187 /// Abbrevs installed at in this block.
198188 std::vector> CurAbbrevs;
199189
200190 struct Block {
203193 explicit Block(unsigned PCS) : PrevCodeSize(PCS) {}
204194 };
205195
206 /// BlockScope - This tracks the codesize of parent blocks.
196 /// This tracks the codesize of parent blocks.
207197 SmallVector BlockScope;
208198
209199
249239 return BitsInCurWord == 0 && isEndPos(NextChar);
250240 }
251241
252 /// getAbbrevIDWidth - Return the number of bits used to encode an abbrev #.
242 /// Return the number of bits used to encode an abbrev #.
253243 unsigned getAbbrevIDWidth() const { return CurCodeSize; }
254244
255 /// GetCurrentBitNo - Return the bit # of the bit we are reading.
245 /// Return the bit # of the bit we are reading.
256246 uint64_t GetCurrentBitNo() const {
257247 return NextChar*CHAR_BIT - BitsInCurWord;
258248 }
266256
267257 /// Flags that modify the behavior of advance().
268258 enum {
269 /// AF_DontPopBlockAtEnd - If this flag is used, the advance() method does
270 /// not automatically pop the block scope when the end of a block is
271 /// reached.
259 /// If this flag is used, the advance() method does not automatically pop
260 /// the block scope when the end of a block is reached.
272261 AF_DontPopBlockAtEnd = 1,
273262
274 /// AF_DontAutoprocessAbbrevs - If this flag is used, abbrev entries are
275 /// returned just like normal records.
263 /// If this flag is used, abbrev entries are returned just like normal
264 /// records.
276265 AF_DontAutoprocessAbbrevs = 2
277266 };
278267
279 /// advance - Advance the current bitstream, returning the next entry in the
280 /// stream.
281 BitstreamEntry advance(unsigned Flags = 0) {
268 /// Advance the current bitstream, returning the next entry in the stream.
269 BitstreamEntry advance(unsigned Flags = 0) {
282270 while (1) {
283271 unsigned Code = ReadCode();
284272 if (Code == bitc::END_BLOCK) {
303291 }
304292 }
305293
306 /// advanceSkippingSubblocks - This is a convenience function for clients that
307 /// don't expect any subblocks. This just skips over them automatically.
294 /// This is a convenience function for clients that don't expect any
295 /// subblocks. This just skips over them automatically.
308296 BitstreamEntry advanceSkippingSubblocks(unsigned Flags = 0) {
309297 while (1) {
310298 // If we found a normal entry, return it.
318306 }
319307 }
320308
321 /// JumpToBit - Reset the stream to the specified bit number.
309 /// Reset the stream to the specified bit number.
322310 void JumpToBit(uint64_t BitNo) {
323311 uintptr_t ByteNo = uintptr_t(BitNo/8) & ~(sizeof(word_t)-1);
324312 unsigned WordBitNo = unsigned(BitNo & (sizeof(word_t)*8-1));
416404 }
417405 }
418406
419 // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size. The
420 // chunk size of the VBR must still be <= 32 bits though.
407 // Read a VBR that may have a value up to 64-bits in size. The chunk size of
408 // the VBR must still be <= 32 bits though.
421409 uint64_t ReadVBR64(unsigned NumBits) {
422410 uint32_t Piece = Read(NumBits);
423411 if ((Piece & (1U << (NumBits-1))) == 0)
460448 // Block header:
461449 // [ENTER_SUBBLOCK, blockid, newcodelen, , blocklen]
462450
463 /// ReadSubBlockID - Having read the ENTER_SUBBLOCK code, read the BlockID for
464 /// the block.
451 /// Having read the ENTER_SUBBLOCK code, read the BlockID for the block.
465452 unsigned ReadSubBlockID() {
466453 return ReadVBR(bitc::BlockIDWidth);
467454 }
468455
469 /// SkipBlock - Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip
470 /// over the body of this block. If the block record is malformed, return
471 /// true.
456 /// Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body
457 /// of this block. If the block record is malformed, return true.
472458 bool SkipBlock() {
473459 // Read and ignore the codelen value. Since we are skipping this block, we
474460 // don't care what code widths are used inside of it.
486472 return false;
487473 }
488474
489 /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
490 /// the block, and return true if the block has an error.
475 /// Having read the ENTER_SUBBLOCK abbrevid, enter the block, and return true
476 /// if the block has an error.
491477 bool EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = nullptr);
492478
493479 bool ReadBlockEnd() {
523509
524510 public:
525511
526 /// getAbbrev - Return the abbreviation for the specified AbbrevId.
512 /// Return the abbreviation for the specified AbbrevId.
527513 const BitCodeAbbrev *getAbbrev(unsigned AbbrevID) {
528514 unsigned AbbrevNo = AbbrevID-bitc::FIRST_APPLICATION_ABBREV;
529515 assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
530516 return CurAbbrevs[AbbrevNo].get();
531517 }
532518
533 /// skipRecord - Read the current record and discard it.
519 /// Read the current record and discard it.
534520 void skipRecord(unsigned AbbrevID);
535521
536522 unsigned readRecord(unsigned AbbrevID, SmallVectorImpl &Vals,