blob: dff6d181486a5320fa1f34a8fea063ed73036b24 [file] [log] [blame]
Chris Lattner59c3abc2013-01-19 18:19:39 +00001//===- BitstreamReader.cpp - BitstreamReader implementation ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Bitcode/BitstreamReader.h"
11
12using namespace llvm;
13
14//===----------------------------------------------------------------------===//
15// BitstreamCursor implementation
16//===----------------------------------------------------------------------===//
17
Chris Lattner59c3abc2013-01-19 18:19:39 +000018void BitstreamCursor::freeState() {
19 // Free all the Abbrevs.
Chris Lattner59c3abc2013-01-19 18:19:39 +000020 CurAbbrevs.clear();
Joe Abbey97b7a172013-02-06 22:14:06 +000021
Chris Lattner59c3abc2013-01-19 18:19:39 +000022 // Free all the Abbrevs in the block scope.
Chris Lattner59c3abc2013-01-19 18:19:39 +000023 BlockScope.clear();
24}
25
26/// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter
27/// the block, and return true if the block has an error.
28bool BitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) {
29 // Save the current block's state on BlockScope.
30 BlockScope.push_back(Block(CurCodeSize));
31 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
Joe Abbey97b7a172013-02-06 22:14:06 +000032
Chris Lattner59c3abc2013-01-19 18:19:39 +000033 // Add the abbrevs specific to this block to the CurAbbrevs list.
34 if (const BitstreamReader::BlockInfo *Info =
35 BitStream->getBlockInfo(BlockID)) {
Benjamin Kramer6891ba02014-09-15 15:44:14 +000036 CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
37 Info->Abbrevs.end());
Chris Lattner59c3abc2013-01-19 18:19:39 +000038 }
Joe Abbey97b7a172013-02-06 22:14:06 +000039
Chris Lattner59c3abc2013-01-19 18:19:39 +000040 // Get the codesize of this block.
41 CurCodeSize = ReadVBR(bitc::CodeLenWidth);
Chris Lattnere1817aa2013-01-21 18:04:19 +000042 SkipToFourByteBoundary();
Chris Lattner59c3abc2013-01-19 18:19:39 +000043 unsigned NumWords = Read(bitc::BlockSizeWidth);
44 if (NumWordsP) *NumWordsP = NumWords;
Joe Abbey97b7a172013-02-06 22:14:06 +000045
Chris Lattner59c3abc2013-01-19 18:19:39 +000046 // Validate that this block is sane.
47 if (CurCodeSize == 0 || AtEndOfStream())
48 return true;
Joe Abbey97b7a172013-02-06 22:14:06 +000049
Chris Lattner59c3abc2013-01-19 18:19:39 +000050 return false;
51}
52
Rafael Espindolaf8950452014-11-13 22:29:02 +000053static uint64_t readAbbreviatedField(BitstreamCursor &Cursor,
54 const BitCodeAbbrevOp &Op) {
55 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000056
Chris Lattner5ba7bca2013-01-20 00:00:00 +000057 // Decode the value as we are commanded.
58 switch (Op.getEncoding()) {
59 case BitCodeAbbrevOp::Array:
60 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000061 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000062 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000063 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000064 return Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000065 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000066 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000067 return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000068 case BitCodeAbbrevOp::Char6:
Rafael Espindolaf8950452014-11-13 22:29:02 +000069 return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));
Chris Lattner5ba7bca2013-01-20 00:00:00 +000070 }
Reid Kleckner9651f01a82014-11-13 23:07:22 +000071 llvm_unreachable("invalid abbreviation encoding");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000072}
73
Rafael Espindola76d41f82014-11-13 21:54:59 +000074static void skipAbbreviatedField(BitstreamCursor &Cursor,
75 const BitCodeAbbrevOp &Op) {
Rafael Espindolaf8950452014-11-13 22:29:02 +000076 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000077
Chris Lattner5ba7bca2013-01-20 00:00:00 +000078 // Decode the value as we are commanded.
79 switch (Op.getEncoding()) {
80 case BitCodeAbbrevOp::Array:
81 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000082 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000083 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000084 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000085 Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000086 break;
87 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000088 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000089 Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000090 break;
91 case BitCodeAbbrevOp::Char6:
Rafael Espindola76d41f82014-11-13 21:54:59 +000092 Cursor.Read(6);
Chris Lattner5ba7bca2013-01-20 00:00:00 +000093 break;
94 }
95}
96
97
98
99/// skipRecord - Read the current record and discard it.
100void BitstreamCursor::skipRecord(unsigned AbbrevID) {
101 // Skip unabbreviated records by reading past their entries.
102 if (AbbrevID == bitc::UNABBREV_RECORD) {
103 unsigned Code = ReadVBR(6);
104 (void)Code;
105 unsigned NumElts = ReadVBR(6);
106 for (unsigned i = 0; i != NumElts; ++i)
107 (void)ReadVBR64(6);
108 return;
109 }
110
111 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000112
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000113 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
114 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
115 if (Op.isLiteral())
116 continue;
Joe Abbey97b7a172013-02-06 22:14:06 +0000117
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000118 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
119 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindola76d41f82014-11-13 21:54:59 +0000120 skipAbbreviatedField(*this, Op);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000121 continue;
122 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000123
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000124 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
125 // Array case. Read the number of elements as a vbr6.
126 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000127
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000128 // Get the element encoding.
129 assert(i+2 == e && "array op not second to last?");
130 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Joe Abbey97b7a172013-02-06 22:14:06 +0000131
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000132 // Read all the elements.
133 for (; NumElts; --NumElts)
Rafael Espindola76d41f82014-11-13 21:54:59 +0000134 skipAbbreviatedField(*this, EltEnc);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000135 continue;
136 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000137
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000138 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
139 // Blob case. Read the number of bytes as a vbr6.
140 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000141 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000142
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000143 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000144 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000145
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000146 // If this would read off the end of the bitcode file, just set the
147 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000148 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000149 NextChar = BitStream->getBitcodeBytes().getExtent();
150 break;
151 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000152
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000153 // Skip over the blob.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000154 JumpToBit(NewEnd);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000155 }
156}
Chris Lattner59c3abc2013-01-19 18:19:39 +0000157
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000158unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
Chris Lattner59c3abc2013-01-19 18:19:39 +0000159 SmallVectorImpl<uint64_t> &Vals,
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000160 StringRef *Blob) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000161 if (AbbrevID == bitc::UNABBREV_RECORD) {
162 unsigned Code = ReadVBR(6);
163 unsigned NumElts = ReadVBR(6);
164 for (unsigned i = 0; i != NumElts; ++i)
165 Vals.push_back(ReadVBR64(6));
166 return Code;
167 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000168
Chris Lattner59c3abc2013-01-19 18:19:39 +0000169 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000170
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000171 // Read the record code first.
172 assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
173 const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
Rafael Espindolaf8950452014-11-13 22:29:02 +0000174 unsigned Code;
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000175 if (CodeOp.isLiteral())
Rafael Espindolaf8950452014-11-13 22:29:02 +0000176 Code = CodeOp.getLiteralValue();
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000177 else {
178 if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
179 CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
180 report_fatal_error("Abbreviation starts with an Array or a Blob");
Rafael Espindolaf8950452014-11-13 22:29:02 +0000181 Code = readAbbreviatedField(*this, CodeOp);
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000182 }
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000183
184 for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000185 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
186 if (Op.isLiteral()) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000187 Vals.push_back(Op.getLiteralValue());
Chris Lattner59c3abc2013-01-19 18:19:39 +0000188 continue;
189 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000190
Chris Lattner59c3abc2013-01-19 18:19:39 +0000191 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
192 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000193 Vals.push_back(readAbbreviatedField(*this, Op));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000194 continue;
195 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000196
Chris Lattner59c3abc2013-01-19 18:19:39 +0000197 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
198 // Array case. Read the number of elements as a vbr6.
199 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000200
Chris Lattner59c3abc2013-01-19 18:19:39 +0000201 // Get the element encoding.
Filipe Cabecinhas1351cba2015-04-29 01:58:31 +0000202 if (i+2 != e)
203 report_fatal_error("Array op not second to last");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000204 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Filipe Cabecinhas6621cb72015-04-23 13:38:21 +0000205 if (EltEnc.getEncoding() == BitCodeAbbrevOp::Array ||
206 EltEnc.getEncoding() == BitCodeAbbrevOp::Blob)
207 report_fatal_error("Array element type can't be an Array or a Blob");
Joe Abbey97b7a172013-02-06 22:14:06 +0000208
Chris Lattner59c3abc2013-01-19 18:19:39 +0000209 // Read all the elements.
210 for (; NumElts; --NumElts)
Rafael Espindolaf8950452014-11-13 22:29:02 +0000211 Vals.push_back(readAbbreviatedField(*this, EltEnc));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000212 continue;
213 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000214
Chris Lattner59c3abc2013-01-19 18:19:39 +0000215 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
216 // Blob case. Read the number of bytes as a vbr6.
217 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000218 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000219
Chris Lattner59c3abc2013-01-19 18:19:39 +0000220 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000221 size_t CurBitPos = GetCurrentBitNo();
222 size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000223
Chris Lattner59c3abc2013-01-19 18:19:39 +0000224 // If this would read off the end of the bitcode file, just set the
225 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000226 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000227 Vals.append(NumElts, 0);
228 NextChar = BitStream->getBitcodeBytes().getExtent();
229 break;
230 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000231
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000232 // Otherwise, inform the streamer that we need these bytes in memory.
233 const char *Ptr = (const char*)
234 BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
Joe Abbey97b7a172013-02-06 22:14:06 +0000235
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000236 // If we can return a reference to the data, do so to avoid copying it.
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000237 if (Blob) {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000238 *Blob = StringRef(Ptr, NumElts);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000239 } else {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000240 // Otherwise, unpack into Vals with zero extension.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000241 for (; NumElts; --NumElts)
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000242 Vals.push_back((unsigned char)*Ptr++);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000243 }
244 // Skip over tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000245 JumpToBit(NewEnd);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000246 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000247
Chris Lattner59c3abc2013-01-19 18:19:39 +0000248 return Code;
249}
250
251
252void BitstreamCursor::ReadAbbrevRecord() {
253 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
254 unsigned NumOpInfo = ReadVBR(5);
255 for (unsigned i = 0; i != NumOpInfo; ++i) {
David Blaikiedc3f01e2015-03-09 01:57:13 +0000256 bool IsLiteral = Read(1);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000257 if (IsLiteral) {
258 Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
259 continue;
260 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000261
Chris Lattner59c3abc2013-01-19 18:19:39 +0000262 BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000263 if (BitCodeAbbrevOp::hasEncodingData(E)) {
Richard Smith7b408022015-02-13 21:05:11 +0000264 uint64_t Data = ReadVBR64(5);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000265
266 // As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
267 // and vbr(0) as a literal zero. This is decoded the same way, and avoids
268 // a slow path in Read() to have to handle reading zero bits.
269 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
270 Data == 0) {
271 Abbv->Add(BitCodeAbbrevOp(0));
272 continue;
273 }
Joe Abbeybc6f4ba2013-04-01 02:28:07 +0000274
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +0000275 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
276 Data > MaxChunkSize)
277 report_fatal_error(
278 "Fixed or VBR abbrev record with size > MaxChunkData");
279
Chris Lattner6c29cb32013-02-09 07:07:29 +0000280 Abbv->Add(BitCodeAbbrevOp(E, Data));
281 } else
Chris Lattner59c3abc2013-01-19 18:19:39 +0000282 Abbv->Add(BitCodeAbbrevOp(E));
283 }
284 CurAbbrevs.push_back(Abbv);
285}
286
287bool BitstreamCursor::ReadBlockInfoBlock() {
288 // If this is the second stream to get to the block info block, skip it.
289 if (BitStream->hasBlockInfoRecords())
290 return SkipBlock();
Joe Abbey97b7a172013-02-06 22:14:06 +0000291
Chris Lattner59c3abc2013-01-19 18:19:39 +0000292 if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
Joe Abbey97b7a172013-02-06 22:14:06 +0000293
Chris Lattner59c3abc2013-01-19 18:19:39 +0000294 SmallVector<uint64_t, 64> Record;
Craig Topper2617dcc2014-04-15 06:32:26 +0000295 BitstreamReader::BlockInfo *CurBlockInfo = nullptr;
Joe Abbey97b7a172013-02-06 22:14:06 +0000296
Chris Lattner59c3abc2013-01-19 18:19:39 +0000297 // Read all the records for this module.
298 while (1) {
Chris Lattner27d38752013-01-20 02:13:19 +0000299 BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
Joe Abbey97b7a172013-02-06 22:14:06 +0000300
Chris Lattner27d38752013-01-20 02:13:19 +0000301 switch (Entry.Kind) {
302 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
303 case llvm::BitstreamEntry::Error:
304 return true;
305 case llvm::BitstreamEntry::EndBlock:
306 return false;
307 case llvm::BitstreamEntry::Record:
308 // The interesting case.
309 break;
310 }
311
Chris Lattner59c3abc2013-01-19 18:19:39 +0000312 // Read abbrev records, associate them with CurBID.
Chris Lattner27d38752013-01-20 02:13:19 +0000313 if (Entry.ID == bitc::DEFINE_ABBREV) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000314 if (!CurBlockInfo) return true;
315 ReadAbbrevRecord();
Joe Abbey97b7a172013-02-06 22:14:06 +0000316
Chris Lattner59c3abc2013-01-19 18:19:39 +0000317 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
318 // appropriate BlockInfo.
Benjamin Kramer6891ba02014-09-15 15:44:14 +0000319 CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000320 CurAbbrevs.pop_back();
Chris Lattner59c3abc2013-01-19 18:19:39 +0000321 continue;
322 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000323
Chris Lattner59c3abc2013-01-19 18:19:39 +0000324 // Read a record.
325 Record.clear();
Chris Lattner27d38752013-01-20 02:13:19 +0000326 switch (readRecord(Entry.ID, Record)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000327 default: break; // Default behavior, ignore unknown content.
328 case bitc::BLOCKINFO_CODE_SETBID:
329 if (Record.size() < 1) return true;
330 CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
331 break;
332 case bitc::BLOCKINFO_CODE_BLOCKNAME: {
333 if (!CurBlockInfo) return true;
334 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
335 std::string Name;
336 for (unsigned i = 0, e = Record.size(); i != e; ++i)
337 Name += (char)Record[i];
338 CurBlockInfo->Name = Name;
339 break;
340 }
341 case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
342 if (!CurBlockInfo) return true;
343 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
344 std::string Name;
345 for (unsigned i = 1, e = Record.size(); i != e; ++i)
346 Name += (char)Record[i];
347 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
348 Name));
349 break;
350 }
351 }
352 }
353}
354