1139f7f9bSDimitry Andric //===- BitstreamReader.cpp - BitstreamReader implementation ---------------===// 2139f7f9bSDimitry Andric // 3139f7f9bSDimitry Andric // The LLVM Compiler Infrastructure 4139f7f9bSDimitry Andric // 5139f7f9bSDimitry Andric // This file is distributed under the University of Illinois Open Source 6139f7f9bSDimitry Andric // License. See LICENSE.TXT for details. 7139f7f9bSDimitry Andric // 8139f7f9bSDimitry Andric //===----------------------------------------------------------------------===// 9139f7f9bSDimitry Andric 10139f7f9bSDimitry Andric #include "llvm/Bitcode/BitstreamReader.h" 11139f7f9bSDimitry Andric 12139f7f9bSDimitry Andric using namespace llvm; 13139f7f9bSDimitry Andric 14139f7f9bSDimitry Andric //===----------------------------------------------------------------------===// 15139f7f9bSDimitry Andric // BitstreamCursor implementation 16139f7f9bSDimitry Andric //===----------------------------------------------------------------------===// 17139f7f9bSDimitry Andric 18139f7f9bSDimitry Andric void BitstreamCursor::operator=(const BitstreamCursor &RHS) { 19139f7f9bSDimitry Andric freeState(); 20139f7f9bSDimitry Andric 21139f7f9bSDimitry Andric BitStream = RHS.BitStream; 22139f7f9bSDimitry Andric NextChar = RHS.NextChar; 23139f7f9bSDimitry Andric CurWord = RHS.CurWord; 24139f7f9bSDimitry Andric BitsInCurWord = RHS.BitsInCurWord; 25139f7f9bSDimitry Andric CurCodeSize = RHS.CurCodeSize; 26139f7f9bSDimitry Andric 27139f7f9bSDimitry Andric // Copy abbreviations, and bump ref counts. 28139f7f9bSDimitry Andric CurAbbrevs = RHS.CurAbbrevs; 29139f7f9bSDimitry Andric for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) 30139f7f9bSDimitry Andric CurAbbrevs[i]->addRef(); 31139f7f9bSDimitry Andric 32139f7f9bSDimitry Andric // Copy block scope and bump ref counts. 33139f7f9bSDimitry Andric BlockScope = RHS.BlockScope; 34139f7f9bSDimitry Andric for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { 35139f7f9bSDimitry Andric std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; 36139f7f9bSDimitry Andric for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) 37139f7f9bSDimitry Andric Abbrevs[i]->addRef(); 38139f7f9bSDimitry Andric } 39139f7f9bSDimitry Andric } 40139f7f9bSDimitry Andric 41139f7f9bSDimitry Andric void BitstreamCursor::freeState() { 42139f7f9bSDimitry Andric // Free all the Abbrevs. 43139f7f9bSDimitry Andric for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) 44139f7f9bSDimitry Andric CurAbbrevs[i]->dropRef(); 45139f7f9bSDimitry Andric CurAbbrevs.clear(); 46139f7f9bSDimitry Andric 47139f7f9bSDimitry Andric // Free all the Abbrevs in the block scope. 48139f7f9bSDimitry Andric for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { 49139f7f9bSDimitry Andric std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; 50139f7f9bSDimitry Andric for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) 51139f7f9bSDimitry Andric Abbrevs[i]->dropRef(); 52139f7f9bSDimitry Andric } 53139f7f9bSDimitry Andric BlockScope.clear(); 54139f7f9bSDimitry Andric } 55139f7f9bSDimitry Andric 56139f7f9bSDimitry Andric /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter 57139f7f9bSDimitry Andric /// the block, and return true if the block has an error. 58139f7f9bSDimitry Andric bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { 59139f7f9bSDimitry Andric // Save the current block's state on BlockScope. 60139f7f9bSDimitry Andric BlockScope.push_back(Block(CurCodeSize)); 61139f7f9bSDimitry Andric BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); 62139f7f9bSDimitry Andric 63139f7f9bSDimitry Andric // Add the abbrevs specific to this block to the CurAbbrevs list. 64139f7f9bSDimitry Andric if (const BitstreamReader::BlockInfo *Info = 65139f7f9bSDimitry Andric BitStream->getBlockInfo(BlockID)) { 66139f7f9bSDimitry Andric for (size_t i = 0, e = Info->Abbrevs.size(); i != e; ++i) { 67139f7f9bSDimitry Andric CurAbbrevs.push_back(Info->Abbrevs[i]); 68139f7f9bSDimitry Andric CurAbbrevs.back()->addRef(); 69139f7f9bSDimitry Andric } 70139f7f9bSDimitry Andric } 71139f7f9bSDimitry Andric 72139f7f9bSDimitry Andric // Get the codesize of this block. 73139f7f9bSDimitry Andric CurCodeSize = ReadVBR(bitc::CodeLenWidth); 74139f7f9bSDimitry Andric SkipToFourByteBoundary(); 75139f7f9bSDimitry Andric unsigned NumWords = Read(bitc::BlockSizeWidth); 76139f7f9bSDimitry Andric if (NumWordsP) *NumWordsP = NumWords; 77139f7f9bSDimitry Andric 78139f7f9bSDimitry Andric // Validate that this block is sane. 79139f7f9bSDimitry Andric if (CurCodeSize == 0 || AtEndOfStream()) 80139f7f9bSDimitry Andric return true; 81139f7f9bSDimitry Andric 82139f7f9bSDimitry Andric return false; 83139f7f9bSDimitry Andric } 84139f7f9bSDimitry Andric 85139f7f9bSDimitry Andric void BitstreamCursor::readAbbreviatedLiteral(const BitCodeAbbrevOp &Op, 86139f7f9bSDimitry Andric SmallVectorImpl<uint64_t> &Vals) { 87139f7f9bSDimitry Andric assert(Op.isLiteral() && "Not a literal"); 88139f7f9bSDimitry Andric // If the abbrev specifies the literal value to use, use it. 89139f7f9bSDimitry Andric Vals.push_back(Op.getLiteralValue()); 90139f7f9bSDimitry Andric } 91139f7f9bSDimitry Andric 92139f7f9bSDimitry Andric void BitstreamCursor::readAbbreviatedField(const BitCodeAbbrevOp &Op, 93139f7f9bSDimitry Andric SmallVectorImpl<uint64_t> &Vals) { 94139f7f9bSDimitry Andric assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); 95139f7f9bSDimitry Andric 96139f7f9bSDimitry Andric // Decode the value as we are commanded. 97139f7f9bSDimitry Andric switch (Op.getEncoding()) { 98139f7f9bSDimitry Andric case BitCodeAbbrevOp::Array: 99139f7f9bSDimitry Andric case BitCodeAbbrevOp::Blob: 100*91bc56edSDimitry Andric llvm_unreachable("Should not reach here"); 101139f7f9bSDimitry Andric case BitCodeAbbrevOp::Fixed: 102139f7f9bSDimitry Andric Vals.push_back(Read((unsigned)Op.getEncodingData())); 103139f7f9bSDimitry Andric break; 104139f7f9bSDimitry Andric case BitCodeAbbrevOp::VBR: 105139f7f9bSDimitry Andric Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData())); 106139f7f9bSDimitry Andric break; 107139f7f9bSDimitry Andric case BitCodeAbbrevOp::Char6: 108139f7f9bSDimitry Andric Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6))); 109139f7f9bSDimitry Andric break; 110139f7f9bSDimitry Andric } 111139f7f9bSDimitry Andric } 112139f7f9bSDimitry Andric 113139f7f9bSDimitry Andric void BitstreamCursor::skipAbbreviatedField(const BitCodeAbbrevOp &Op) { 114139f7f9bSDimitry Andric assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); 115139f7f9bSDimitry Andric 116139f7f9bSDimitry Andric // Decode the value as we are commanded. 117139f7f9bSDimitry Andric switch (Op.getEncoding()) { 118139f7f9bSDimitry Andric case BitCodeAbbrevOp::Array: 119139f7f9bSDimitry Andric case BitCodeAbbrevOp::Blob: 120*91bc56edSDimitry Andric llvm_unreachable("Should not reach here"); 121139f7f9bSDimitry Andric case BitCodeAbbrevOp::Fixed: 122139f7f9bSDimitry Andric (void)Read((unsigned)Op.getEncodingData()); 123139f7f9bSDimitry Andric break; 124139f7f9bSDimitry Andric case BitCodeAbbrevOp::VBR: 125139f7f9bSDimitry Andric (void)ReadVBR64((unsigned)Op.getEncodingData()); 126139f7f9bSDimitry Andric break; 127139f7f9bSDimitry Andric case BitCodeAbbrevOp::Char6: 128139f7f9bSDimitry Andric (void)Read(6); 129139f7f9bSDimitry Andric break; 130139f7f9bSDimitry Andric } 131139f7f9bSDimitry Andric } 132139f7f9bSDimitry Andric 133139f7f9bSDimitry Andric 134139f7f9bSDimitry Andric 135139f7f9bSDimitry Andric /// skipRecord - Read the current record and discard it. 136139f7f9bSDimitry Andric void BitstreamCursor::skipRecord(unsigned AbbrevID) { 137139f7f9bSDimitry Andric // Skip unabbreviated records by reading past their entries. 138139f7f9bSDimitry Andric if (AbbrevID == bitc::UNABBREV_RECORD) { 139139f7f9bSDimitry Andric unsigned Code = ReadVBR(6); 140139f7f9bSDimitry Andric (void)Code; 141139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 142139f7f9bSDimitry Andric for (unsigned i = 0; i != NumElts; ++i) 143139f7f9bSDimitry Andric (void)ReadVBR64(6); 144139f7f9bSDimitry Andric return; 145139f7f9bSDimitry Andric } 146139f7f9bSDimitry Andric 147139f7f9bSDimitry Andric const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); 148139f7f9bSDimitry Andric 149139f7f9bSDimitry Andric for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { 150139f7f9bSDimitry Andric const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); 151139f7f9bSDimitry Andric if (Op.isLiteral()) 152139f7f9bSDimitry Andric continue; 153139f7f9bSDimitry Andric 154139f7f9bSDimitry Andric if (Op.getEncoding() != BitCodeAbbrevOp::Array && 155139f7f9bSDimitry Andric Op.getEncoding() != BitCodeAbbrevOp::Blob) { 156139f7f9bSDimitry Andric skipAbbreviatedField(Op); 157139f7f9bSDimitry Andric continue; 158139f7f9bSDimitry Andric } 159139f7f9bSDimitry Andric 160139f7f9bSDimitry Andric if (Op.getEncoding() == BitCodeAbbrevOp::Array) { 161139f7f9bSDimitry Andric // Array case. Read the number of elements as a vbr6. 162139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 163139f7f9bSDimitry Andric 164139f7f9bSDimitry Andric // Get the element encoding. 165139f7f9bSDimitry Andric assert(i+2 == e && "array op not second to last?"); 166139f7f9bSDimitry Andric const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); 167139f7f9bSDimitry Andric 168139f7f9bSDimitry Andric // Read all the elements. 169139f7f9bSDimitry Andric for (; NumElts; --NumElts) 170139f7f9bSDimitry Andric skipAbbreviatedField(EltEnc); 171139f7f9bSDimitry Andric continue; 172139f7f9bSDimitry Andric } 173139f7f9bSDimitry Andric 174139f7f9bSDimitry Andric assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); 175139f7f9bSDimitry Andric // Blob case. Read the number of bytes as a vbr6. 176139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 177139f7f9bSDimitry Andric SkipToFourByteBoundary(); // 32-bit alignment 178139f7f9bSDimitry Andric 179139f7f9bSDimitry Andric // Figure out where the end of this blob will be including tail padding. 180139f7f9bSDimitry Andric size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8; 181139f7f9bSDimitry Andric 182139f7f9bSDimitry Andric // If this would read off the end of the bitcode file, just set the 183139f7f9bSDimitry Andric // record to empty and return. 184139f7f9bSDimitry Andric if (!canSkipToPos(NewEnd/8)) { 185139f7f9bSDimitry Andric NextChar = BitStream->getBitcodeBytes().getExtent(); 186139f7f9bSDimitry Andric break; 187139f7f9bSDimitry Andric } 188139f7f9bSDimitry Andric 189139f7f9bSDimitry Andric // Skip over the blob. 190139f7f9bSDimitry Andric JumpToBit(NewEnd); 191139f7f9bSDimitry Andric } 192139f7f9bSDimitry Andric } 193139f7f9bSDimitry Andric 194139f7f9bSDimitry Andric unsigned BitstreamCursor::readRecord(unsigned AbbrevID, 195139f7f9bSDimitry Andric SmallVectorImpl<uint64_t> &Vals, 196139f7f9bSDimitry Andric StringRef *Blob) { 197139f7f9bSDimitry Andric if (AbbrevID == bitc::UNABBREV_RECORD) { 198139f7f9bSDimitry Andric unsigned Code = ReadVBR(6); 199139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 200139f7f9bSDimitry Andric for (unsigned i = 0; i != NumElts; ++i) 201139f7f9bSDimitry Andric Vals.push_back(ReadVBR64(6)); 202139f7f9bSDimitry Andric return Code; 203139f7f9bSDimitry Andric } 204139f7f9bSDimitry Andric 205139f7f9bSDimitry Andric const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); 206139f7f9bSDimitry Andric 207f785676fSDimitry Andric // Read the record code first. 208f785676fSDimitry Andric assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?"); 209f785676fSDimitry Andric const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0); 210f785676fSDimitry Andric if (CodeOp.isLiteral()) 211f785676fSDimitry Andric readAbbreviatedLiteral(CodeOp, Vals); 212f785676fSDimitry Andric else 213f785676fSDimitry Andric readAbbreviatedField(CodeOp, Vals); 214f785676fSDimitry Andric unsigned Code = (unsigned)Vals.pop_back_val(); 215f785676fSDimitry Andric 216f785676fSDimitry Andric for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) { 217139f7f9bSDimitry Andric const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); 218139f7f9bSDimitry Andric if (Op.isLiteral()) { 219139f7f9bSDimitry Andric readAbbreviatedLiteral(Op, Vals); 220139f7f9bSDimitry Andric continue; 221139f7f9bSDimitry Andric } 222139f7f9bSDimitry Andric 223139f7f9bSDimitry Andric if (Op.getEncoding() != BitCodeAbbrevOp::Array && 224139f7f9bSDimitry Andric Op.getEncoding() != BitCodeAbbrevOp::Blob) { 225139f7f9bSDimitry Andric readAbbreviatedField(Op, Vals); 226139f7f9bSDimitry Andric continue; 227139f7f9bSDimitry Andric } 228139f7f9bSDimitry Andric 229139f7f9bSDimitry Andric if (Op.getEncoding() == BitCodeAbbrevOp::Array) { 230139f7f9bSDimitry Andric // Array case. Read the number of elements as a vbr6. 231139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 232139f7f9bSDimitry Andric 233139f7f9bSDimitry Andric // Get the element encoding. 234139f7f9bSDimitry Andric assert(i+2 == e && "array op not second to last?"); 235139f7f9bSDimitry Andric const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); 236139f7f9bSDimitry Andric 237139f7f9bSDimitry Andric // Read all the elements. 238139f7f9bSDimitry Andric for (; NumElts; --NumElts) 239139f7f9bSDimitry Andric readAbbreviatedField(EltEnc, Vals); 240139f7f9bSDimitry Andric continue; 241139f7f9bSDimitry Andric } 242139f7f9bSDimitry Andric 243139f7f9bSDimitry Andric assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); 244139f7f9bSDimitry Andric // Blob case. Read the number of bytes as a vbr6. 245139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 246139f7f9bSDimitry Andric SkipToFourByteBoundary(); // 32-bit alignment 247139f7f9bSDimitry Andric 248139f7f9bSDimitry Andric // Figure out where the end of this blob will be including tail padding. 249139f7f9bSDimitry Andric size_t CurBitPos = GetCurrentBitNo(); 250139f7f9bSDimitry Andric size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8; 251139f7f9bSDimitry Andric 252139f7f9bSDimitry Andric // If this would read off the end of the bitcode file, just set the 253139f7f9bSDimitry Andric // record to empty and return. 254139f7f9bSDimitry Andric if (!canSkipToPos(NewEnd/8)) { 255139f7f9bSDimitry Andric Vals.append(NumElts, 0); 256139f7f9bSDimitry Andric NextChar = BitStream->getBitcodeBytes().getExtent(); 257139f7f9bSDimitry Andric break; 258139f7f9bSDimitry Andric } 259139f7f9bSDimitry Andric 260139f7f9bSDimitry Andric // Otherwise, inform the streamer that we need these bytes in memory. 261139f7f9bSDimitry Andric const char *Ptr = (const char*) 262139f7f9bSDimitry Andric BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts); 263139f7f9bSDimitry Andric 264139f7f9bSDimitry Andric // If we can return a reference to the data, do so to avoid copying it. 265139f7f9bSDimitry Andric if (Blob) { 266139f7f9bSDimitry Andric *Blob = StringRef(Ptr, NumElts); 267139f7f9bSDimitry Andric } else { 268139f7f9bSDimitry Andric // Otherwise, unpack into Vals with zero extension. 269139f7f9bSDimitry Andric for (; NumElts; --NumElts) 270139f7f9bSDimitry Andric Vals.push_back((unsigned char)*Ptr++); 271139f7f9bSDimitry Andric } 272139f7f9bSDimitry Andric // Skip over tail padding. 273139f7f9bSDimitry Andric JumpToBit(NewEnd); 274139f7f9bSDimitry Andric } 275139f7f9bSDimitry Andric 276139f7f9bSDimitry Andric return Code; 277139f7f9bSDimitry Andric } 278139f7f9bSDimitry Andric 279139f7f9bSDimitry Andric 280139f7f9bSDimitry Andric void BitstreamCursor::ReadAbbrevRecord() { 281139f7f9bSDimitry Andric BitCodeAbbrev *Abbv = new BitCodeAbbrev(); 282139f7f9bSDimitry Andric unsigned NumOpInfo = ReadVBR(5); 283139f7f9bSDimitry Andric for (unsigned i = 0; i != NumOpInfo; ++i) { 284139f7f9bSDimitry Andric bool IsLiteral = Read(1) ? true : false; 285139f7f9bSDimitry Andric if (IsLiteral) { 286139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8))); 287139f7f9bSDimitry Andric continue; 288139f7f9bSDimitry Andric } 289139f7f9bSDimitry Andric 290139f7f9bSDimitry Andric BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); 291139f7f9bSDimitry Andric if (BitCodeAbbrevOp::hasEncodingData(E)) { 292139f7f9bSDimitry Andric unsigned Data = ReadVBR64(5); 293139f7f9bSDimitry Andric 294139f7f9bSDimitry Andric // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) 295139f7f9bSDimitry Andric // and vbr(0) as a literal zero. This is decoded the same way, and avoids 296139f7f9bSDimitry Andric // a slow path in Read() to have to handle reading zero bits. 297139f7f9bSDimitry Andric if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && 298139f7f9bSDimitry Andric Data == 0) { 299139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(0)); 300139f7f9bSDimitry Andric continue; 301139f7f9bSDimitry Andric } 302139f7f9bSDimitry Andric 303139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(E, Data)); 304139f7f9bSDimitry Andric } else 305139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(E)); 306139f7f9bSDimitry Andric } 307139f7f9bSDimitry Andric CurAbbrevs.push_back(Abbv); 308139f7f9bSDimitry Andric } 309139f7f9bSDimitry Andric 310139f7f9bSDimitry Andric bool BitstreamCursor::ReadBlockInfoBlock() { 311139f7f9bSDimitry Andric // If this is the second stream to get to the block info block, skip it. 312139f7f9bSDimitry Andric if (BitStream->hasBlockInfoRecords()) 313139f7f9bSDimitry Andric return SkipBlock(); 314139f7f9bSDimitry Andric 315139f7f9bSDimitry Andric if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; 316139f7f9bSDimitry Andric 317139f7f9bSDimitry Andric SmallVector<uint64_t, 64> Record; 318*91bc56edSDimitry Andric BitstreamReader::BlockInfo *CurBlockInfo = nullptr; 319139f7f9bSDimitry Andric 320139f7f9bSDimitry Andric // Read all the records for this module. 321139f7f9bSDimitry Andric while (1) { 322139f7f9bSDimitry Andric BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs); 323139f7f9bSDimitry Andric 324139f7f9bSDimitry Andric switch (Entry.Kind) { 325139f7f9bSDimitry Andric case llvm::BitstreamEntry::SubBlock: // Handled for us already. 326139f7f9bSDimitry Andric case llvm::BitstreamEntry::Error: 327139f7f9bSDimitry Andric return true; 328139f7f9bSDimitry Andric case llvm::BitstreamEntry::EndBlock: 329139f7f9bSDimitry Andric return false; 330139f7f9bSDimitry Andric case llvm::BitstreamEntry::Record: 331139f7f9bSDimitry Andric // The interesting case. 332139f7f9bSDimitry Andric break; 333139f7f9bSDimitry Andric } 334139f7f9bSDimitry Andric 335139f7f9bSDimitry Andric // Read abbrev records, associate them with CurBID. 336139f7f9bSDimitry Andric if (Entry.ID == bitc::DEFINE_ABBREV) { 337139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 338139f7f9bSDimitry Andric ReadAbbrevRecord(); 339139f7f9bSDimitry Andric 340139f7f9bSDimitry Andric // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the 341139f7f9bSDimitry Andric // appropriate BlockInfo. 342139f7f9bSDimitry Andric BitCodeAbbrev *Abbv = CurAbbrevs.back(); 343139f7f9bSDimitry Andric CurAbbrevs.pop_back(); 344139f7f9bSDimitry Andric CurBlockInfo->Abbrevs.push_back(Abbv); 345139f7f9bSDimitry Andric continue; 346139f7f9bSDimitry Andric } 347139f7f9bSDimitry Andric 348139f7f9bSDimitry Andric // Read a record. 349139f7f9bSDimitry Andric Record.clear(); 350139f7f9bSDimitry Andric switch (readRecord(Entry.ID, Record)) { 351139f7f9bSDimitry Andric default: break; // Default behavior, ignore unknown content. 352139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_SETBID: 353139f7f9bSDimitry Andric if (Record.size() < 1) return true; 354139f7f9bSDimitry Andric CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); 355139f7f9bSDimitry Andric break; 356139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_BLOCKNAME: { 357139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 358139f7f9bSDimitry Andric if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. 359139f7f9bSDimitry Andric std::string Name; 360139f7f9bSDimitry Andric for (unsigned i = 0, e = Record.size(); i != e; ++i) 361139f7f9bSDimitry Andric Name += (char)Record[i]; 362139f7f9bSDimitry Andric CurBlockInfo->Name = Name; 363139f7f9bSDimitry Andric break; 364139f7f9bSDimitry Andric } 365139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_SETRECORDNAME: { 366139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 367139f7f9bSDimitry Andric if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. 368139f7f9bSDimitry Andric std::string Name; 369139f7f9bSDimitry Andric for (unsigned i = 1, e = Record.size(); i != e; ++i) 370139f7f9bSDimitry Andric Name += (char)Record[i]; 371139f7f9bSDimitry Andric CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0], 372139f7f9bSDimitry Andric Name)); 373139f7f9bSDimitry Andric break; 374139f7f9bSDimitry Andric } 375139f7f9bSDimitry Andric } 376139f7f9bSDimitry Andric } 377139f7f9bSDimitry Andric } 378139f7f9bSDimitry Andric 379