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::freeState() { 19139f7f9bSDimitry Andric // Free all the Abbrevs. 20139f7f9bSDimitry Andric CurAbbrevs.clear(); 21139f7f9bSDimitry Andric 22139f7f9bSDimitry Andric // Free all the Abbrevs in the block scope. 23139f7f9bSDimitry Andric BlockScope.clear(); 24139f7f9bSDimitry Andric } 25139f7f9bSDimitry Andric 26139f7f9bSDimitry Andric /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter 27139f7f9bSDimitry Andric /// the block, and return true if the block has an error. 28139f7f9bSDimitry Andric bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { 29139f7f9bSDimitry Andric // Save the current block's state on BlockScope. 30139f7f9bSDimitry Andric BlockScope.push_back(Block(CurCodeSize)); 31139f7f9bSDimitry Andric BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); 32139f7f9bSDimitry Andric 33139f7f9bSDimitry Andric // Add the abbrevs specific to this block to the CurAbbrevs list. 34139f7f9bSDimitry Andric if (const BitstreamReader::BlockInfo *Info = 35139f7f9bSDimitry Andric BitStream->getBlockInfo(BlockID)) { 3639d628a0SDimitry Andric CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(), 3739d628a0SDimitry Andric Info->Abbrevs.end()); 38139f7f9bSDimitry Andric } 39139f7f9bSDimitry Andric 40139f7f9bSDimitry Andric // Get the codesize of this block. 41139f7f9bSDimitry Andric CurCodeSize = ReadVBR(bitc::CodeLenWidth); 42*ff0cc061SDimitry Andric // We can't read more than MaxChunkSize at a time 43*ff0cc061SDimitry Andric if (CurCodeSize > MaxChunkSize) 44*ff0cc061SDimitry Andric return true; 45*ff0cc061SDimitry Andric 46139f7f9bSDimitry Andric SkipToFourByteBoundary(); 47139f7f9bSDimitry Andric unsigned NumWords = Read(bitc::BlockSizeWidth); 48139f7f9bSDimitry Andric if (NumWordsP) *NumWordsP = NumWords; 49139f7f9bSDimitry Andric 50139f7f9bSDimitry Andric // Validate that this block is sane. 51*ff0cc061SDimitry Andric return CurCodeSize == 0 || AtEndOfStream(); 52139f7f9bSDimitry Andric } 53139f7f9bSDimitry Andric 5439d628a0SDimitry Andric static uint64_t readAbbreviatedField(BitstreamCursor &Cursor, 5539d628a0SDimitry Andric const BitCodeAbbrevOp &Op) { 5639d628a0SDimitry Andric assert(!Op.isLiteral() && "Not to be used with literals!"); 57139f7f9bSDimitry Andric 58139f7f9bSDimitry Andric // Decode the value as we are commanded. 59139f7f9bSDimitry Andric switch (Op.getEncoding()) { 60139f7f9bSDimitry Andric case BitCodeAbbrevOp::Array: 61139f7f9bSDimitry Andric case BitCodeAbbrevOp::Blob: 6291bc56edSDimitry Andric llvm_unreachable("Should not reach here"); 63139f7f9bSDimitry Andric case BitCodeAbbrevOp::Fixed: 64*ff0cc061SDimitry Andric assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize); 6539d628a0SDimitry Andric return Cursor.Read((unsigned)Op.getEncodingData()); 66139f7f9bSDimitry Andric case BitCodeAbbrevOp::VBR: 67*ff0cc061SDimitry Andric assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize); 6839d628a0SDimitry Andric return Cursor.ReadVBR64((unsigned)Op.getEncodingData()); 69139f7f9bSDimitry Andric case BitCodeAbbrevOp::Char6: 7039d628a0SDimitry Andric return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6)); 71139f7f9bSDimitry Andric } 7239d628a0SDimitry Andric llvm_unreachable("invalid abbreviation encoding"); 73139f7f9bSDimitry Andric } 74139f7f9bSDimitry Andric 7539d628a0SDimitry Andric static void skipAbbreviatedField(BitstreamCursor &Cursor, 7639d628a0SDimitry Andric const BitCodeAbbrevOp &Op) { 7739d628a0SDimitry Andric assert(!Op.isLiteral() && "Not to be used with literals!"); 78139f7f9bSDimitry Andric 79139f7f9bSDimitry Andric // Decode the value as we are commanded. 80139f7f9bSDimitry Andric switch (Op.getEncoding()) { 81139f7f9bSDimitry Andric case BitCodeAbbrevOp::Array: 82139f7f9bSDimitry Andric case BitCodeAbbrevOp::Blob: 8391bc56edSDimitry Andric llvm_unreachable("Should not reach here"); 84139f7f9bSDimitry Andric case BitCodeAbbrevOp::Fixed: 85*ff0cc061SDimitry Andric assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize); 8639d628a0SDimitry Andric Cursor.Read((unsigned)Op.getEncodingData()); 87139f7f9bSDimitry Andric break; 88139f7f9bSDimitry Andric case BitCodeAbbrevOp::VBR: 89*ff0cc061SDimitry Andric assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize); 9039d628a0SDimitry Andric Cursor.ReadVBR64((unsigned)Op.getEncodingData()); 91139f7f9bSDimitry Andric break; 92139f7f9bSDimitry Andric case BitCodeAbbrevOp::Char6: 9339d628a0SDimitry Andric Cursor.Read(6); 94139f7f9bSDimitry Andric break; 95139f7f9bSDimitry Andric } 96139f7f9bSDimitry Andric } 97139f7f9bSDimitry Andric 98139f7f9bSDimitry Andric 99139f7f9bSDimitry Andric 100139f7f9bSDimitry Andric /// skipRecord - Read the current record and discard it. 101139f7f9bSDimitry Andric void BitstreamCursor::skipRecord(unsigned AbbrevID) { 102139f7f9bSDimitry Andric // Skip unabbreviated records by reading past their entries. 103139f7f9bSDimitry Andric if (AbbrevID == bitc::UNABBREV_RECORD) { 104139f7f9bSDimitry Andric unsigned Code = ReadVBR(6); 105139f7f9bSDimitry Andric (void)Code; 106139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 107139f7f9bSDimitry Andric for (unsigned i = 0; i != NumElts; ++i) 108139f7f9bSDimitry Andric (void)ReadVBR64(6); 109139f7f9bSDimitry Andric return; 110139f7f9bSDimitry Andric } 111139f7f9bSDimitry Andric 112139f7f9bSDimitry Andric const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); 113139f7f9bSDimitry Andric 114139f7f9bSDimitry Andric for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { 115139f7f9bSDimitry Andric const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); 116139f7f9bSDimitry Andric if (Op.isLiteral()) 117139f7f9bSDimitry Andric continue; 118139f7f9bSDimitry Andric 119139f7f9bSDimitry Andric if (Op.getEncoding() != BitCodeAbbrevOp::Array && 120139f7f9bSDimitry Andric Op.getEncoding() != BitCodeAbbrevOp::Blob) { 12139d628a0SDimitry Andric skipAbbreviatedField(*this, Op); 122139f7f9bSDimitry Andric continue; 123139f7f9bSDimitry Andric } 124139f7f9bSDimitry Andric 125139f7f9bSDimitry Andric if (Op.getEncoding() == BitCodeAbbrevOp::Array) { 126139f7f9bSDimitry Andric // Array case. Read the number of elements as a vbr6. 127139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 128139f7f9bSDimitry Andric 129139f7f9bSDimitry Andric // Get the element encoding. 130139f7f9bSDimitry Andric assert(i+2 == e && "array op not second to last?"); 131139f7f9bSDimitry Andric const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); 132139f7f9bSDimitry Andric 133139f7f9bSDimitry Andric // Read all the elements. 134139f7f9bSDimitry Andric for (; NumElts; --NumElts) 13539d628a0SDimitry Andric skipAbbreviatedField(*this, EltEnc); 136139f7f9bSDimitry Andric continue; 137139f7f9bSDimitry Andric } 138139f7f9bSDimitry Andric 139139f7f9bSDimitry Andric assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); 140139f7f9bSDimitry Andric // Blob case. Read the number of bytes as a vbr6. 141139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 142139f7f9bSDimitry Andric SkipToFourByteBoundary(); // 32-bit alignment 143139f7f9bSDimitry Andric 144139f7f9bSDimitry Andric // Figure out where the end of this blob will be including tail padding. 145139f7f9bSDimitry Andric size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8; 146139f7f9bSDimitry Andric 147139f7f9bSDimitry Andric // If this would read off the end of the bitcode file, just set the 148139f7f9bSDimitry Andric // record to empty and return. 149139f7f9bSDimitry Andric if (!canSkipToPos(NewEnd/8)) { 150139f7f9bSDimitry Andric NextChar = BitStream->getBitcodeBytes().getExtent(); 151139f7f9bSDimitry Andric break; 152139f7f9bSDimitry Andric } 153139f7f9bSDimitry Andric 154139f7f9bSDimitry Andric // Skip over the blob. 155139f7f9bSDimitry Andric JumpToBit(NewEnd); 156139f7f9bSDimitry Andric } 157139f7f9bSDimitry Andric } 158139f7f9bSDimitry Andric 159139f7f9bSDimitry Andric unsigned BitstreamCursor::readRecord(unsigned AbbrevID, 160139f7f9bSDimitry Andric SmallVectorImpl<uint64_t> &Vals, 161139f7f9bSDimitry Andric StringRef *Blob) { 162139f7f9bSDimitry Andric if (AbbrevID == bitc::UNABBREV_RECORD) { 163139f7f9bSDimitry Andric unsigned Code = ReadVBR(6); 164139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 165139f7f9bSDimitry Andric for (unsigned i = 0; i != NumElts; ++i) 166139f7f9bSDimitry Andric Vals.push_back(ReadVBR64(6)); 167139f7f9bSDimitry Andric return Code; 168139f7f9bSDimitry Andric } 169139f7f9bSDimitry Andric 170139f7f9bSDimitry Andric const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); 171139f7f9bSDimitry Andric 172f785676fSDimitry Andric // Read the record code first. 173f785676fSDimitry Andric assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?"); 174f785676fSDimitry Andric const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0); 17539d628a0SDimitry Andric unsigned Code; 176f785676fSDimitry Andric if (CodeOp.isLiteral()) 17739d628a0SDimitry Andric Code = CodeOp.getLiteralValue(); 178*ff0cc061SDimitry Andric else { 179*ff0cc061SDimitry Andric if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array || 180*ff0cc061SDimitry Andric CodeOp.getEncoding() == BitCodeAbbrevOp::Blob) 181*ff0cc061SDimitry Andric report_fatal_error("Abbreviation starts with an Array or a Blob"); 18239d628a0SDimitry Andric Code = readAbbreviatedField(*this, CodeOp); 183*ff0cc061SDimitry Andric } 184f785676fSDimitry Andric 185f785676fSDimitry Andric for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) { 186139f7f9bSDimitry Andric const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); 187139f7f9bSDimitry Andric if (Op.isLiteral()) { 18839d628a0SDimitry Andric Vals.push_back(Op.getLiteralValue()); 189139f7f9bSDimitry Andric continue; 190139f7f9bSDimitry Andric } 191139f7f9bSDimitry Andric 192139f7f9bSDimitry Andric if (Op.getEncoding() != BitCodeAbbrevOp::Array && 193139f7f9bSDimitry Andric Op.getEncoding() != BitCodeAbbrevOp::Blob) { 19439d628a0SDimitry Andric Vals.push_back(readAbbreviatedField(*this, Op)); 195139f7f9bSDimitry Andric continue; 196139f7f9bSDimitry Andric } 197139f7f9bSDimitry Andric 198139f7f9bSDimitry Andric if (Op.getEncoding() == BitCodeAbbrevOp::Array) { 199139f7f9bSDimitry Andric // Array case. Read the number of elements as a vbr6. 200139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 201139f7f9bSDimitry Andric 202139f7f9bSDimitry Andric // Get the element encoding. 203*ff0cc061SDimitry Andric if (i + 2 != e) 204*ff0cc061SDimitry Andric report_fatal_error("Array op not second to last"); 205139f7f9bSDimitry Andric const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); 206*ff0cc061SDimitry Andric if (!EltEnc.isEncoding()) 207*ff0cc061SDimitry Andric report_fatal_error( 208*ff0cc061SDimitry Andric "Array element type has to be an encoding of a type"); 209*ff0cc061SDimitry Andric if (EltEnc.getEncoding() == BitCodeAbbrevOp::Array || 210*ff0cc061SDimitry Andric EltEnc.getEncoding() == BitCodeAbbrevOp::Blob) 211*ff0cc061SDimitry Andric report_fatal_error("Array element type can't be an Array or a Blob"); 212139f7f9bSDimitry Andric 213139f7f9bSDimitry Andric // Read all the elements. 214139f7f9bSDimitry Andric for (; NumElts; --NumElts) 21539d628a0SDimitry Andric Vals.push_back(readAbbreviatedField(*this, EltEnc)); 216139f7f9bSDimitry Andric continue; 217139f7f9bSDimitry Andric } 218139f7f9bSDimitry Andric 219139f7f9bSDimitry Andric assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); 220139f7f9bSDimitry Andric // Blob case. Read the number of bytes as a vbr6. 221139f7f9bSDimitry Andric unsigned NumElts = ReadVBR(6); 222139f7f9bSDimitry Andric SkipToFourByteBoundary(); // 32-bit alignment 223139f7f9bSDimitry Andric 224139f7f9bSDimitry Andric // Figure out where the end of this blob will be including tail padding. 225139f7f9bSDimitry Andric size_t CurBitPos = GetCurrentBitNo(); 226139f7f9bSDimitry Andric size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8; 227139f7f9bSDimitry Andric 228139f7f9bSDimitry Andric // If this would read off the end of the bitcode file, just set the 229139f7f9bSDimitry Andric // record to empty and return. 230139f7f9bSDimitry Andric if (!canSkipToPos(NewEnd/8)) { 231139f7f9bSDimitry Andric Vals.append(NumElts, 0); 232139f7f9bSDimitry Andric NextChar = BitStream->getBitcodeBytes().getExtent(); 233139f7f9bSDimitry Andric break; 234139f7f9bSDimitry Andric } 235139f7f9bSDimitry Andric 236139f7f9bSDimitry Andric // Otherwise, inform the streamer that we need these bytes in memory. 237139f7f9bSDimitry Andric const char *Ptr = (const char*) 238139f7f9bSDimitry Andric BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts); 239139f7f9bSDimitry Andric 240139f7f9bSDimitry Andric // If we can return a reference to the data, do so to avoid copying it. 241139f7f9bSDimitry Andric if (Blob) { 242139f7f9bSDimitry Andric *Blob = StringRef(Ptr, NumElts); 243139f7f9bSDimitry Andric } else { 244139f7f9bSDimitry Andric // Otherwise, unpack into Vals with zero extension. 245139f7f9bSDimitry Andric for (; NumElts; --NumElts) 246139f7f9bSDimitry Andric Vals.push_back((unsigned char)*Ptr++); 247139f7f9bSDimitry Andric } 248139f7f9bSDimitry Andric // Skip over tail padding. 249139f7f9bSDimitry Andric JumpToBit(NewEnd); 250139f7f9bSDimitry Andric } 251139f7f9bSDimitry Andric 252139f7f9bSDimitry Andric return Code; 253139f7f9bSDimitry Andric } 254139f7f9bSDimitry Andric 255139f7f9bSDimitry Andric 256139f7f9bSDimitry Andric void BitstreamCursor::ReadAbbrevRecord() { 257139f7f9bSDimitry Andric BitCodeAbbrev *Abbv = new BitCodeAbbrev(); 258139f7f9bSDimitry Andric unsigned NumOpInfo = ReadVBR(5); 259139f7f9bSDimitry Andric for (unsigned i = 0; i != NumOpInfo; ++i) { 260*ff0cc061SDimitry Andric bool IsLiteral = Read(1); 261139f7f9bSDimitry Andric if (IsLiteral) { 262139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8))); 263139f7f9bSDimitry Andric continue; 264139f7f9bSDimitry Andric } 265139f7f9bSDimitry Andric 266139f7f9bSDimitry Andric BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); 267139f7f9bSDimitry Andric if (BitCodeAbbrevOp::hasEncodingData(E)) { 268*ff0cc061SDimitry Andric uint64_t Data = ReadVBR64(5); 269139f7f9bSDimitry Andric 270139f7f9bSDimitry Andric // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) 271139f7f9bSDimitry Andric // and vbr(0) as a literal zero. This is decoded the same way, and avoids 272139f7f9bSDimitry Andric // a slow path in Read() to have to handle reading zero bits. 273139f7f9bSDimitry Andric if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && 274139f7f9bSDimitry Andric Data == 0) { 275139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(0)); 276139f7f9bSDimitry Andric continue; 277139f7f9bSDimitry Andric } 278139f7f9bSDimitry Andric 279*ff0cc061SDimitry Andric if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && 280*ff0cc061SDimitry Andric Data > MaxChunkSize) 281*ff0cc061SDimitry Andric report_fatal_error( 282*ff0cc061SDimitry Andric "Fixed or VBR abbrev record with size > MaxChunkData"); 283*ff0cc061SDimitry Andric 284139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(E, Data)); 285139f7f9bSDimitry Andric } else 286139f7f9bSDimitry Andric Abbv->Add(BitCodeAbbrevOp(E)); 287139f7f9bSDimitry Andric } 288*ff0cc061SDimitry Andric 289*ff0cc061SDimitry Andric if (Abbv->getNumOperandInfos() == 0) 290*ff0cc061SDimitry Andric report_fatal_error("Abbrev record with no operands"); 291139f7f9bSDimitry Andric CurAbbrevs.push_back(Abbv); 292139f7f9bSDimitry Andric } 293139f7f9bSDimitry Andric 294139f7f9bSDimitry Andric bool BitstreamCursor::ReadBlockInfoBlock() { 295139f7f9bSDimitry Andric // If this is the second stream to get to the block info block, skip it. 296139f7f9bSDimitry Andric if (BitStream->hasBlockInfoRecords()) 297139f7f9bSDimitry Andric return SkipBlock(); 298139f7f9bSDimitry Andric 299139f7f9bSDimitry Andric if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; 300139f7f9bSDimitry Andric 301139f7f9bSDimitry Andric SmallVector<uint64_t, 64> Record; 30291bc56edSDimitry Andric BitstreamReader::BlockInfo *CurBlockInfo = nullptr; 303139f7f9bSDimitry Andric 304139f7f9bSDimitry Andric // Read all the records for this module. 305139f7f9bSDimitry Andric while (1) { 306139f7f9bSDimitry Andric BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs); 307139f7f9bSDimitry Andric 308139f7f9bSDimitry Andric switch (Entry.Kind) { 309139f7f9bSDimitry Andric case llvm::BitstreamEntry::SubBlock: // Handled for us already. 310139f7f9bSDimitry Andric case llvm::BitstreamEntry::Error: 311139f7f9bSDimitry Andric return true; 312139f7f9bSDimitry Andric case llvm::BitstreamEntry::EndBlock: 313139f7f9bSDimitry Andric return false; 314139f7f9bSDimitry Andric case llvm::BitstreamEntry::Record: 315139f7f9bSDimitry Andric // The interesting case. 316139f7f9bSDimitry Andric break; 317139f7f9bSDimitry Andric } 318139f7f9bSDimitry Andric 319139f7f9bSDimitry Andric // Read abbrev records, associate them with CurBID. 320139f7f9bSDimitry Andric if (Entry.ID == bitc::DEFINE_ABBREV) { 321139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 322139f7f9bSDimitry Andric ReadAbbrevRecord(); 323139f7f9bSDimitry Andric 324139f7f9bSDimitry Andric // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the 325139f7f9bSDimitry Andric // appropriate BlockInfo. 32639d628a0SDimitry Andric CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back())); 327139f7f9bSDimitry Andric CurAbbrevs.pop_back(); 328139f7f9bSDimitry Andric continue; 329139f7f9bSDimitry Andric } 330139f7f9bSDimitry Andric 331139f7f9bSDimitry Andric // Read a record. 332139f7f9bSDimitry Andric Record.clear(); 333139f7f9bSDimitry Andric switch (readRecord(Entry.ID, Record)) { 334139f7f9bSDimitry Andric default: break; // Default behavior, ignore unknown content. 335139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_SETBID: 336139f7f9bSDimitry Andric if (Record.size() < 1) return true; 337139f7f9bSDimitry Andric CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); 338139f7f9bSDimitry Andric break; 339139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_BLOCKNAME: { 340139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 341139f7f9bSDimitry Andric if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. 342139f7f9bSDimitry Andric std::string Name; 343139f7f9bSDimitry Andric for (unsigned i = 0, e = Record.size(); i != e; ++i) 344139f7f9bSDimitry Andric Name += (char)Record[i]; 345139f7f9bSDimitry Andric CurBlockInfo->Name = Name; 346139f7f9bSDimitry Andric break; 347139f7f9bSDimitry Andric } 348139f7f9bSDimitry Andric case bitc::BLOCKINFO_CODE_SETRECORDNAME: { 349139f7f9bSDimitry Andric if (!CurBlockInfo) return true; 350139f7f9bSDimitry Andric if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. 351139f7f9bSDimitry Andric std::string Name; 352139f7f9bSDimitry Andric for (unsigned i = 1, e = Record.size(); i != e; ++i) 353139f7f9bSDimitry Andric Name += (char)Record[i]; 354139f7f9bSDimitry Andric CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0], 355139f7f9bSDimitry Andric Name)); 356139f7f9bSDimitry Andric break; 357139f7f9bSDimitry Andric } 358139f7f9bSDimitry Andric } 359139f7f9bSDimitry Andric } 360139f7f9bSDimitry Andric } 361139f7f9bSDimitry Andric 362