LLVM API Documentation

BitstreamReader.h

Go to the documentation of this file.
00001 //===- BitstreamReader.h - Low-level bitstream reader interface -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This header defines the BitstreamReader class.  This class can be used to
00011 // read an arbitrary bitstream, regardless of its contents.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef BITSTREAM_READER_H
00016 #define BITSTREAM_READER_H
00017 
00018 #include "llvm/Bitcode/BitCodes.h"
00019 #include <climits>
00020 #include <vector>
00021 
00022 namespace llvm {
00023 
00024   class Deserializer;
00025 
00026 class BitstreamReader {
00027 public:
00028   /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks.
00029   /// These describe abbreviations that all blocks of the specified ID inherit.
00030   struct BlockInfo {
00031     unsigned BlockID;
00032     std::vector<BitCodeAbbrev*> Abbrevs;
00033     std::string Name;
00034     
00035     std::vector<std::pair<unsigned, std::string> > RecordNames;
00036   };
00037 private:
00038   /// FirstChar/LastChar - This remembers the first and last bytes of the
00039   /// stream.
00040   const unsigned char *FirstChar, *LastChar;
00041   
00042   std::vector<BlockInfo> BlockInfoRecords;
00043 
00044   /// IgnoreBlockInfoNames - This is set to true if we don't care about the
00045   /// block/record name information in the BlockInfo block. Only llvm-bcanalyzer
00046   /// uses this.
00047   bool IgnoreBlockInfoNames;
00048   
00049   BitstreamReader(const BitstreamReader&);  // NOT IMPLEMENTED
00050   void operator=(const BitstreamReader&);  // NOT IMPLEMENTED
00051 public:
00052   BitstreamReader() : FirstChar(0), LastChar(0), IgnoreBlockInfoNames(true) {
00053   }
00054 
00055   BitstreamReader(const unsigned char *Start, const unsigned char *End) {
00056     IgnoreBlockInfoNames = true;
00057     init(Start, End);
00058   }
00059 
00060   void init(const unsigned char *Start, const unsigned char *End) {
00061     FirstChar = Start;
00062     LastChar = End;
00063     assert(((End-Start) & 3) == 0 &&"Bitcode stream not a multiple of 4 bytes");
00064   }
00065 
00066   ~BitstreamReader() {
00067     // Free the BlockInfoRecords.
00068     while (!BlockInfoRecords.empty()) {
00069       BlockInfo &Info = BlockInfoRecords.back();
00070       // Free blockinfo abbrev info.
00071       for (unsigned i = 0, e = static_cast<unsigned>(Info.Abbrevs.size());
00072            i != e; ++i)
00073         Info.Abbrevs[i]->dropRef();
00074       BlockInfoRecords.pop_back();
00075     }
00076   }
00077   
00078   const unsigned char *getFirstChar() const { return FirstChar; }
00079   const unsigned char *getLastChar() const { return LastChar; }
00080 
00081   /// CollectBlockInfoNames - This is called by clients that want block/record
00082   /// name information.
00083   void CollectBlockInfoNames() { IgnoreBlockInfoNames = false; }
00084   bool isIgnoringBlockInfoNames() { return IgnoreBlockInfoNames; }
00085   
00086   //===--------------------------------------------------------------------===//
00087   // Block Manipulation
00088   //===--------------------------------------------------------------------===//
00089 
00090   /// hasBlockInfoRecords - Return true if we've already read and processed the
00091   /// block info block for this Bitstream.  We only process it for the first
00092   /// cursor that walks over it.
00093   bool hasBlockInfoRecords() const { return !BlockInfoRecords.empty(); }
00094   
00095   /// getBlockInfo - If there is block info for the specified ID, return it,
00096   /// otherwise return null.
00097   const BlockInfo *getBlockInfo(unsigned BlockID) const {
00098     // Common case, the most recent entry matches BlockID.
00099     if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == BlockID)
00100       return &BlockInfoRecords.back();
00101 
00102     for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
00103          i != e; ++i)
00104       if (BlockInfoRecords[i].BlockID == BlockID)
00105         return &BlockInfoRecords[i];
00106     return 0;
00107   }
00108 
00109   BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
00110     if (const BlockInfo *BI = getBlockInfo(BlockID))
00111       return *const_cast<BlockInfo*>(BI);
00112 
00113     // Otherwise, add a new record.
00114     BlockInfoRecords.push_back(BlockInfo());
00115     BlockInfoRecords.back().BlockID = BlockID;
00116     return BlockInfoRecords.back();
00117   }
00118 
00119 };
00120 
00121 class BitstreamCursor {
00122   friend class Deserializer;
00123   BitstreamReader *BitStream;
00124   const unsigned char *NextChar;
00125   
00126   /// CurWord - This is the current data we have pulled from the stream but have
00127   /// not returned to the client.
00128   uint32_t CurWord;
00129   
00130   /// BitsInCurWord - This is the number of bits in CurWord that are valid. This
00131   /// is always from [0...31] inclusive.
00132   unsigned BitsInCurWord;
00133   
00134   // CurCodeSize - This is the declared size of code values used for the current
00135   // block, in bits.
00136   unsigned CurCodeSize;
00137   
00138   /// CurAbbrevs - Abbrevs installed at in this block.
00139   std::vector<BitCodeAbbrev*> CurAbbrevs;
00140   
00141   struct Block {
00142     unsigned PrevCodeSize;
00143     std::vector<BitCodeAbbrev*> PrevAbbrevs;
00144     explicit Block(unsigned PCS) : PrevCodeSize(PCS) {}
00145   };
00146   
00147   /// BlockScope - This tracks the codesize of parent blocks.
00148   SmallVector<Block, 8> BlockScope;
00149   
00150 public:
00151   BitstreamCursor() : BitStream(0), NextChar(0) {
00152   }
00153   BitstreamCursor(const BitstreamCursor &RHS) : BitStream(0), NextChar(0) {
00154     operator=(RHS);
00155   }
00156   
00157   explicit BitstreamCursor(BitstreamReader &R) : BitStream(&R) {
00158     NextChar = R.getFirstChar();
00159     assert(NextChar && "Bitstream not initialized yet");
00160     CurWord = 0;
00161     BitsInCurWord = 0;
00162     CurCodeSize = 2;
00163   }
00164   
00165   void init(BitstreamReader &R) {
00166     freeState();
00167     
00168     BitStream = &R;
00169     NextChar = R.getFirstChar();
00170     assert(NextChar && "Bitstream not initialized yet");
00171     CurWord = 0;
00172     BitsInCurWord = 0;
00173     CurCodeSize = 2;
00174   }
00175   
00176   ~BitstreamCursor() {
00177     freeState();
00178   }
00179   
00180   void operator=(const BitstreamCursor &RHS) {
00181     freeState();
00182     
00183     BitStream = RHS.BitStream;
00184     NextChar = RHS.NextChar;
00185     CurWord = RHS.CurWord;
00186     BitsInCurWord = RHS.BitsInCurWord;
00187     CurCodeSize = RHS.CurCodeSize;
00188     
00189     // Copy abbreviations, and bump ref counts.
00190     CurAbbrevs = RHS.CurAbbrevs;
00191     for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
00192          i != e; ++i)
00193       CurAbbrevs[i]->addRef();
00194     
00195     // Copy block scope and bump ref counts.
00196     for (unsigned S = 0, e = static_cast<unsigned>(BlockScope.size());
00197          S != e; ++S) {
00198       std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
00199       for (unsigned i = 0, e = static_cast<unsigned>(Abbrevs.size());
00200            i != e; ++i)
00201         Abbrevs[i]->addRef();
00202     }
00203   }
00204   
00205   void freeState() {
00206     // Free all the Abbrevs.
00207     for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
00208          i != e; ++i)
00209       CurAbbrevs[i]->dropRef();
00210     CurAbbrevs.clear();
00211     
00212     // Free all the Abbrevs in the block scope.
00213     for (unsigned S = 0, e = static_cast<unsigned>(BlockScope.size());
00214          S != e; ++S) {
00215       std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs;
00216       for (unsigned i = 0, e = static_cast<unsigned>(Abbrevs.size());
00217            i != e; ++i)
00218         Abbrevs[i]->dropRef();
00219     }
00220     BlockScope.clear();
00221   }
00222   
00223   /// GetAbbrevIDWidth - Return the number of bits used to encode an abbrev #.
00224   unsigned GetAbbrevIDWidth() const { return CurCodeSize; }
00225   
00226   bool AtEndOfStream() const {
00227     return NextChar == BitStream->getLastChar() && BitsInCurWord == 0;
00228   }
00229   
00230   /// GetCurrentBitNo - Return the bit # of the bit we are reading.
00231   uint64_t GetCurrentBitNo() const {
00232     return (NextChar-BitStream->getFirstChar())*CHAR_BIT - BitsInCurWord;
00233   }
00234   
00235   BitstreamReader *getBitStreamReader() {
00236     return BitStream;
00237   }
00238   const BitstreamReader *getBitStreamReader() const {
00239     return BitStream;
00240   }
00241   
00242   
00243   /// JumpToBit - Reset the stream to the specified bit number.
00244   void JumpToBit(uint64_t BitNo) {
00245     uintptr_t ByteNo = uintptr_t(BitNo/8) & ~3;
00246     uintptr_t WordBitNo = uintptr_t(BitNo) & 31;
00247     assert(ByteNo <= (uintptr_t)(BitStream->getLastChar()-
00248                                  BitStream->getFirstChar()) &&
00249            "Invalid location");
00250     
00251     // Move the cursor to the right word.
00252     NextChar = BitStream->getFirstChar()+ByteNo;
00253     BitsInCurWord = 0;
00254     CurWord = 0;
00255     
00256     // Skip over any bits that are already consumed.
00257     if (WordBitNo)
00258       Read(static_cast<unsigned>(WordBitNo));
00259   }
00260   
00261   
00262   uint32_t Read(unsigned NumBits) {
00263     assert(NumBits <= 32 && "Cannot return more than 32 bits!");
00264     // If the field is fully contained by CurWord, return it quickly.
00265     if (BitsInCurWord >= NumBits) {
00266       uint32_t R = CurWord & ((1U << NumBits)-1);
00267       CurWord >>= NumBits;
00268       BitsInCurWord -= NumBits;
00269       return R;
00270     }
00271 
00272     // If we run out of data, stop at the end of the stream.
00273     if (NextChar == BitStream->getLastChar()) {
00274       CurWord = 0;
00275       BitsInCurWord = 0;
00276       return 0;
00277     }
00278 
00279     unsigned R = CurWord;
00280 
00281     // Read the next word from the stream.
00282     CurWord = (NextChar[0] <<  0) | (NextChar[1] << 8) |
00283               (NextChar[2] << 16) | (NextChar[3] << 24);
00284     NextChar += 4;
00285 
00286     // Extract NumBits-BitsInCurWord from what we just read.
00287     unsigned BitsLeft = NumBits-BitsInCurWord;
00288 
00289     // Be careful here, BitsLeft is in the range [1..32] inclusive.
00290     R |= (CurWord & (~0U >> (32-BitsLeft))) << BitsInCurWord;
00291 
00292     // BitsLeft bits have just been used up from CurWord.
00293     if (BitsLeft != 32)
00294       CurWord >>= BitsLeft;
00295     else
00296       CurWord = 0;
00297     BitsInCurWord = 32-BitsLeft;
00298     return R;
00299   }
00300 
00301   uint64_t Read64(unsigned NumBits) {
00302     if (NumBits <= 32) return Read(NumBits);
00303 
00304     uint64_t V = Read(32);
00305     return V | (uint64_t)Read(NumBits-32) << 32;
00306   }
00307 
00308   uint32_t ReadVBR(unsigned NumBits) {
00309     uint32_t Piece = Read(NumBits);
00310     if ((Piece & (1U << (NumBits-1))) == 0)
00311       return Piece;
00312 
00313     uint32_t Result = 0;
00314     unsigned NextBit = 0;
00315     while (1) {
00316       Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit;
00317 
00318       if ((Piece & (1U << (NumBits-1))) == 0)
00319         return Result;
00320 
00321       NextBit += NumBits-1;
00322       Piece = Read(NumBits);
00323     }
00324   }
00325 
00326   // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size.  The
00327   // chunk size of the VBR must still be <= 32 bits though.
00328   uint64_t ReadVBR64(unsigned NumBits) {
00329     uint32_t Piece = Read(NumBits);
00330     if ((Piece & (1U << (NumBits-1))) == 0)
00331       return uint64_t(Piece);
00332 
00333     uint64_t Result = 0;
00334     unsigned NextBit = 0;
00335     while (1) {
00336       Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit;
00337 
00338       if ((Piece & (1U << (NumBits-1))) == 0)
00339         return Result;
00340 
00341       NextBit += NumBits-1;
00342       Piece = Read(NumBits);
00343     }
00344   }
00345 
00346   void SkipToWord() {
00347     BitsInCurWord = 0;
00348     CurWord = 0;
00349   }
00350 
00351   unsigned ReadCode() {
00352     return Read(CurCodeSize);
00353   }
00354 
00355 
00356   // Block header:
00357   //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
00358 
00359   /// ReadSubBlockID - Having read the ENTER_SUBBLOCK code, read the BlockID for
00360   /// the block.
00361   unsigned ReadSubBlockID() {
00362     return ReadVBR(bitc::BlockIDWidth);
00363   }
00364 
00365   /// SkipBlock - Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip
00366   /// over the body of this block.  If the block record is malformed, return
00367   /// true.
00368   bool SkipBlock() {
00369     // Read and ignore the codelen value.  Since we are skipping this block, we
00370     // don't care what code widths are used inside of it.
00371     ReadVBR(bitc::CodeLenWidth);
00372     SkipToWord();
00373     unsigned NumWords = Read(bitc::BlockSizeWidth);
00374 
00375     // Check that the block wasn't partially defined, and that the offset isn't
00376     // bogus.
00377     if (AtEndOfStream() || NextChar+NumWords*4 > BitStream->getLastChar())
00378       return true;
00379 
00380     NextChar += NumWords*4;
00381     return false;
00382   }
00383 
00384   /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
00385   /// the block, and return true if the block is valid.
00386   bool EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = 0) {
00387     // Save the current block's state on BlockScope.
00388     BlockScope.push_back(Block(CurCodeSize));
00389     BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
00390 
00391     // Add the abbrevs specific to this block to the CurAbbrevs list.
00392     if (const BitstreamReader::BlockInfo *Info =
00393           BitStream->getBlockInfo(BlockID)) {
00394       for (unsigned i = 0, e = static_cast<unsigned>(Info->Abbrevs.size());
00395            i != e; ++i) {
00396         CurAbbrevs.push_back(Info->Abbrevs[i]);
00397         CurAbbrevs.back()->addRef();
00398       }
00399     }
00400 
00401     // Get the codesize of this block.
00402     CurCodeSize = ReadVBR(bitc::CodeLenWidth);
00403     SkipToWord();
00404     unsigned NumWords = Read(bitc::BlockSizeWidth);
00405     if (NumWordsP) *NumWordsP = NumWords;
00406 
00407     // Validate that this block is sane.
00408     if (CurCodeSize == 0 || AtEndOfStream() ||
00409         NextChar+NumWords*4 > BitStream->getLastChar())
00410       return true;
00411 
00412     return false;
00413   }
00414 
00415   bool ReadBlockEnd() {
00416     if (BlockScope.empty()) return true;
00417 
00418     // Block tail:
00419     //    [END_BLOCK, <align4bytes>]
00420     SkipToWord();
00421 
00422     PopBlockScope();
00423     return false;
00424   }
00425 
00426 private:
00427   void PopBlockScope() {
00428     CurCodeSize = BlockScope.back().PrevCodeSize;
00429 
00430     // Delete abbrevs from popped scope.
00431     for (unsigned i = 0, e = static_cast<unsigned>(CurAbbrevs.size());
00432          i != e; ++i)
00433       CurAbbrevs[i]->dropRef();
00434 
00435     BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
00436     BlockScope.pop_back();
00437   }
00438 
00439  //===--------------------------------------------------------------------===//
00440   // Record Processing
00441   //===--------------------------------------------------------------------===//
00442 
00443 private:
00444   void ReadAbbreviatedLiteral(const BitCodeAbbrevOp &Op,
00445                               SmallVectorImpl<uint64_t> &Vals) {
00446     assert(Op.isLiteral() && "Not a literal");
00447     // If the abbrev specifies the literal value to use, use it.
00448     Vals.push_back(Op.getLiteralValue());
00449   }
00450   
00451   void ReadAbbreviatedField(const BitCodeAbbrevOp &Op,
00452                             SmallVectorImpl<uint64_t> &Vals) {
00453     assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!");
00454     
00455     // Decode the value as we are commanded.
00456     switch (Op.getEncoding()) {
00457     default: assert(0 && "Unknown encoding!");
00458     case BitCodeAbbrevOp::Fixed:
00459       Vals.push_back(Read((unsigned)Op.getEncodingData()));
00460       break;
00461     case BitCodeAbbrevOp::VBR:
00462       Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData()));
00463       break;
00464     case BitCodeAbbrevOp::Char6:
00465       Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
00466       break;
00467     }
00468   }
00469 public:
00470 
00471   /// getAbbrev - Return the abbreviation for the specified AbbrevId. 
00472   const BitCodeAbbrev *getAbbrev(unsigned AbbrevID) {
00473     unsigned AbbrevNo = AbbrevID-bitc::FIRST_APPLICATION_ABBREV;
00474     assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
00475     return CurAbbrevs[AbbrevNo];
00476   }
00477   
00478   unsigned ReadRecord(unsigned AbbrevID, SmallVectorImpl<uint64_t> &Vals,
00479                       const char **BlobStart = 0, unsigned *BlobLen = 0) {
00480     if (AbbrevID == bitc::UNABBREV_RECORD) {
00481       unsigned Code = ReadVBR(6);
00482       unsigned NumElts = ReadVBR(6);
00483       for (unsigned i = 0; i != NumElts; ++i)
00484         Vals.push_back(ReadVBR64(6));
00485       return Code;
00486     }
00487 
00488     const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
00489 
00490     for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
00491       const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
00492       if (Op.isLiteral()) {
00493         ReadAbbreviatedLiteral(Op, Vals); 
00494       } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
00495         // Array case.  Read the number of elements as a vbr6.
00496         unsigned NumElts = ReadVBR(6);
00497 
00498         // Get the element encoding.
00499         assert(i+2 == e && "array op not second to last?");
00500         const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
00501 
00502         // Read all the elements.
00503         for (; NumElts; --NumElts)
00504           ReadAbbreviatedField(EltEnc, Vals);
00505       } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
00506         // Blob case.  Read the number of bytes as a vbr6.
00507         unsigned NumElts = ReadVBR(6);
00508         SkipToWord();  // 32-bit alignment
00509 
00510         // Figure out where the end of this blob will be including tail padding.
00511         const unsigned char *NewEnd = NextChar+((NumElts+3)&~3);
00512         
00513         // If this would read off the end of the bitcode file, just set the
00514         // record to empty and return.
00515         if (NewEnd > BitStream->getLastChar()) {
00516           Vals.append(NumElts, 0);
00517           NextChar = BitStream->getLastChar();
00518           break;
00519         }
00520         
00521         // Otherwise, read the number of bytes.  If we can return a reference to
00522         // the data, do so to avoid copying it.
00523         if (BlobStart) {
00524           *BlobStart = (const char*)NextChar;
00525           *BlobLen = NumElts;
00526         } else {
00527           for (; NumElts; ++NextChar, --NumElts)
00528             Vals.push_back(*NextChar);
00529         }
00530         // Skip over tail padding.
00531         NextChar = NewEnd;
00532       } else {
00533         ReadAbbreviatedField(Op, Vals);
00534       }
00535     }
00536 
00537     unsigned Code = (unsigned)Vals[0];
00538     Vals.erase(Vals.begin());
00539     return Code;
00540   }
00541 
00542   unsigned ReadRecord(unsigned AbbrevID, SmallVectorImpl<uint64_t> &Vals,
00543                       const char *&BlobStart, unsigned &BlobLen) {
00544     return ReadRecord(AbbrevID, Vals, &BlobStart, &BlobLen);
00545   }
00546 
00547   
00548   //===--------------------------------------------------------------------===//
00549   // Abbrev Processing
00550   //===--------------------------------------------------------------------===//
00551 
00552   void ReadAbbrevRecord() {
00553     BitCodeAbbrev *Abbv = new BitCodeAbbrev();
00554     unsigned NumOpInfo = ReadVBR(5);
00555     for (unsigned i = 0; i != NumOpInfo; ++i) {
00556       bool IsLiteral = Read(1) ? true : false;
00557       if (IsLiteral) {
00558         Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
00559         continue;
00560       }
00561 
00562       BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
00563       if (BitCodeAbbrevOp::hasEncodingData(E))
00564         Abbv->Add(BitCodeAbbrevOp(E, ReadVBR64(5)));
00565       else
00566         Abbv->Add(BitCodeAbbrevOp(E));
00567     }
00568     CurAbbrevs.push_back(Abbv);
00569   }
00570   
00571 public:
00572 
00573   bool ReadBlockInfoBlock() {
00574     // If this is the second stream to get to the block info block, skip it.
00575     if (BitStream->hasBlockInfoRecords())
00576       return SkipBlock();
00577     
00578     if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
00579 
00580     SmallVector<uint64_t, 64> Record;
00581     BitstreamReader::BlockInfo *CurBlockInfo = 0;
00582 
00583     // Read all the records for this module.
00584     while (1) {
00585       unsigned Code = ReadCode();
00586       if (Code == bitc::END_BLOCK)
00587         return ReadBlockEnd();
00588       if (Code == bitc::ENTER_SUBBLOCK) {
00589         ReadSubBlockID();
00590         if (SkipBlock()) return true;
00591         continue;
00592       }
00593 
00594       // Read abbrev records, associate them with CurBID.
00595       if (Code == bitc::DEFINE_ABBREV) {
00596         if (!CurBlockInfo) return true;
00597         ReadAbbrevRecord();
00598 
00599         // ReadAbbrevRecord installs the abbrev in CurAbbrevs.  Move it to the
00600         // appropriate BlockInfo.
00601         BitCodeAbbrev *Abbv = CurAbbrevs.back();
00602         CurAbbrevs.pop_back();
00603         CurBlockInfo->Abbrevs.push_back(Abbv);
00604         continue;
00605       }
00606 
00607       // Read a record.
00608       Record.clear();
00609       switch (ReadRecord(Code, Record)) {
00610       default: break;  // Default behavior, ignore unknown content.
00611       case bitc::BLOCKINFO_CODE_SETBID:
00612         if (Record.size() < 1) return true;
00613         CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
00614         break;
00615       case bitc::BLOCKINFO_CODE_BLOCKNAME: {
00616         if (!CurBlockInfo) return true;
00617         if (BitStream->isIgnoringBlockInfoNames()) break;  // Ignore name.
00618         std::string Name;
00619         for (unsigned i = 0, e = Record.size(); i != e; ++i)
00620           Name += (char)Record[i];
00621         CurBlockInfo->Name = Name;
00622         break;
00623       }
00624       case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
00625         if (!CurBlockInfo) return true;
00626         if (BitStream->isIgnoringBlockInfoNames()) break;  // Ignore name.
00627         std::string Name;
00628         for (unsigned i = 1, e = Record.size(); i != e; ++i)
00629           Name += (char)Record[i];
00630         CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
00631                                                            Name));
00632         break;
00633       }
00634       }
00635     }
00636   }
00637 };
00638   
00639 } // End llvm namespace
00640 
00641 #endif