blob: 450bbbc4558772051f9ab01cad436f3fd9ee0211 [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);
Filipe Cabecinhasf3fa99c2015-05-19 00:34:17 +000042 // We can't read more than MaxChunkSize at a time
43 if (CurCodeSize > MaxChunkSize)
44 return true;
45
Chris Lattnere1817aa2013-01-21 18:04:19 +000046 SkipToFourByteBoundary();
Chris Lattner59c3abc2013-01-19 18:19:39 +000047 unsigned NumWords = Read(bitc::BlockSizeWidth);
48 if (NumWordsP) *NumWordsP = NumWords;
Joe Abbey97b7a172013-02-06 22:14:06 +000049
Chris Lattner59c3abc2013-01-19 18:19:39 +000050 // Validate that this block is sane.
51 if (CurCodeSize == 0 || AtEndOfStream())
52 return true;
Joe Abbey97b7a172013-02-06 22:14:06 +000053
Chris Lattner59c3abc2013-01-19 18:19:39 +000054 return false;
55}
56
Rafael Espindolaf8950452014-11-13 22:29:02 +000057static uint64_t readAbbreviatedField(BitstreamCursor &Cursor,
58 const BitCodeAbbrevOp &Op) {
59 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000060
Chris Lattner5ba7bca2013-01-20 00:00:00 +000061 // Decode the value as we are commanded.
62 switch (Op.getEncoding()) {
63 case BitCodeAbbrevOp::Array:
64 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000065 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000066 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000067 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000068 return Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000069 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000070 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000071 return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000072 case BitCodeAbbrevOp::Char6:
Rafael Espindolaf8950452014-11-13 22:29:02 +000073 return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));
Chris Lattner5ba7bca2013-01-20 00:00:00 +000074 }
Reid Kleckner9651f01a82014-11-13 23:07:22 +000075 llvm_unreachable("invalid abbreviation encoding");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000076}
77
Rafael Espindola76d41f82014-11-13 21:54:59 +000078static void skipAbbreviatedField(BitstreamCursor &Cursor,
79 const BitCodeAbbrevOp &Op) {
Rafael Espindolaf8950452014-11-13 22:29:02 +000080 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000081
Chris Lattner5ba7bca2013-01-20 00:00:00 +000082 // Decode the value as we are commanded.
83 switch (Op.getEncoding()) {
84 case BitCodeAbbrevOp::Array:
85 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000086 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000087 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000088 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000089 Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000090 break;
91 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000092 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000093 Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000094 break;
95 case BitCodeAbbrevOp::Char6:
Rafael Espindola76d41f82014-11-13 21:54:59 +000096 Cursor.Read(6);
Chris Lattner5ba7bca2013-01-20 00:00:00 +000097 break;
98 }
99}
100
101
102
103/// skipRecord - Read the current record and discard it.
104void BitstreamCursor::skipRecord(unsigned AbbrevID) {
105 // Skip unabbreviated records by reading past their entries.
106 if (AbbrevID == bitc::UNABBREV_RECORD) {
107 unsigned Code = ReadVBR(6);
108 (void)Code;
109 unsigned NumElts = ReadVBR(6);
110 for (unsigned i = 0; i != NumElts; ++i)
111 (void)ReadVBR64(6);
112 return;
113 }
114
115 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000116
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000117 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
118 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
119 if (Op.isLiteral())
120 continue;
Joe Abbey97b7a172013-02-06 22:14:06 +0000121
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000122 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
123 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindola76d41f82014-11-13 21:54:59 +0000124 skipAbbreviatedField(*this, Op);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000125 continue;
126 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000127
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000128 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
129 // Array case. Read the number of elements as a vbr6.
130 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000131
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000132 // Get the element encoding.
133 assert(i+2 == e && "array op not second to last?");
134 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Joe Abbey97b7a172013-02-06 22:14:06 +0000135
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000136 // Read all the elements.
137 for (; NumElts; --NumElts)
Rafael Espindola76d41f82014-11-13 21:54:59 +0000138 skipAbbreviatedField(*this, EltEnc);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000139 continue;
140 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000141
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000142 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
143 // Blob case. Read the number of bytes as a vbr6.
144 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000145 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000146
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000147 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000148 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000149
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000150 // If this would read off the end of the bitcode file, just set the
151 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000152 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000153 NextChar = BitStream->getBitcodeBytes().getExtent();
154 break;
155 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000156
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000157 // Skip over the blob.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000158 JumpToBit(NewEnd);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000159 }
160}
Chris Lattner59c3abc2013-01-19 18:19:39 +0000161
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000162unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
Chris Lattner59c3abc2013-01-19 18:19:39 +0000163 SmallVectorImpl<uint64_t> &Vals,
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000164 StringRef *Blob) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000165 if (AbbrevID == bitc::UNABBREV_RECORD) {
166 unsigned Code = ReadVBR(6);
167 unsigned NumElts = ReadVBR(6);
168 for (unsigned i = 0; i != NumElts; ++i)
169 Vals.push_back(ReadVBR64(6));
170 return Code;
171 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000172
Chris Lattner59c3abc2013-01-19 18:19:39 +0000173 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000174
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000175 // Read the record code first.
176 assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
177 const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
Rafael Espindolaf8950452014-11-13 22:29:02 +0000178 unsigned Code;
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000179 if (CodeOp.isLiteral())
Rafael Espindolaf8950452014-11-13 22:29:02 +0000180 Code = CodeOp.getLiteralValue();
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000181 else {
182 if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
183 CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
184 report_fatal_error("Abbreviation starts with an Array or a Blob");
Rafael Espindolaf8950452014-11-13 22:29:02 +0000185 Code = readAbbreviatedField(*this, CodeOp);
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000186 }
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000187
188 for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000189 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
190 if (Op.isLiteral()) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000191 Vals.push_back(Op.getLiteralValue());
Chris Lattner59c3abc2013-01-19 18:19:39 +0000192 continue;
193 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000194
Chris Lattner59c3abc2013-01-19 18:19:39 +0000195 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
196 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000197 Vals.push_back(readAbbreviatedField(*this, Op));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000198 continue;
199 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000200
Chris Lattner59c3abc2013-01-19 18:19:39 +0000201 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
202 // Array case. Read the number of elements as a vbr6.
203 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000204
Chris Lattner59c3abc2013-01-19 18:19:39 +0000205 // Get the element encoding.
Filipe Cabecinhas1351cba2015-04-29 01:58:31 +0000206 if (i+2 != e)
207 report_fatal_error("Array op not second to last");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000208 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Filipe Cabecinhas6621cb72015-04-23 13:38:21 +0000209 if (EltEnc.getEncoding() == BitCodeAbbrevOp::Array ||
210 EltEnc.getEncoding() == BitCodeAbbrevOp::Blob)
211 report_fatal_error("Array element type can't be an Array or a Blob");
Joe Abbey97b7a172013-02-06 22:14:06 +0000212
Chris Lattner59c3abc2013-01-19 18:19:39 +0000213 // Read all the elements.
214 for (; NumElts; --NumElts)
Rafael Espindolaf8950452014-11-13 22:29:02 +0000215 Vals.push_back(readAbbreviatedField(*this, EltEnc));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000216 continue;
217 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000218
Chris Lattner59c3abc2013-01-19 18:19:39 +0000219 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
220 // Blob case. Read the number of bytes as a vbr6.
221 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000222 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000223
Chris Lattner59c3abc2013-01-19 18:19:39 +0000224 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000225 size_t CurBitPos = GetCurrentBitNo();
226 size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000227
Chris Lattner59c3abc2013-01-19 18:19:39 +0000228 // If this would read off the end of the bitcode file, just set the
229 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000230 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000231 Vals.append(NumElts, 0);
232 NextChar = BitStream->getBitcodeBytes().getExtent();
233 break;
234 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000235
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000236 // Otherwise, inform the streamer that we need these bytes in memory.
237 const char *Ptr = (const char*)
238 BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
Joe Abbey97b7a172013-02-06 22:14:06 +0000239
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000240 // If we can return a reference to the data, do so to avoid copying it.
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000241 if (Blob) {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000242 *Blob = StringRef(Ptr, NumElts);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000243 } else {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000244 // Otherwise, unpack into Vals with zero extension.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000245 for (; NumElts; --NumElts)
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000246 Vals.push_back((unsigned char)*Ptr++);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000247 }
248 // Skip over tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000249 JumpToBit(NewEnd);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000250 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000251
Chris Lattner59c3abc2013-01-19 18:19:39 +0000252 return Code;
253}
254
255
256void BitstreamCursor::ReadAbbrevRecord() {
257 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
258 unsigned NumOpInfo = ReadVBR(5);
259 for (unsigned i = 0; i != NumOpInfo; ++i) {
David Blaikiedc3f01e2015-03-09 01:57:13 +0000260 bool IsLiteral = Read(1);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000261 if (IsLiteral) {
262 Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
263 continue;
264 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000265
Chris Lattner59c3abc2013-01-19 18:19:39 +0000266 BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000267 if (BitCodeAbbrevOp::hasEncodingData(E)) {
Richard Smith7b408022015-02-13 21:05:11 +0000268 uint64_t Data = ReadVBR64(5);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000269
270 // As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
271 // and vbr(0) as a literal zero. This is decoded the same way, and avoids
272 // a slow path in Read() to have to handle reading zero bits.
273 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
274 Data == 0) {
275 Abbv->Add(BitCodeAbbrevOp(0));
276 continue;
277 }
Joe Abbeybc6f4ba2013-04-01 02:28:07 +0000278
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +0000279 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
280 Data > MaxChunkSize)
281 report_fatal_error(
282 "Fixed or VBR abbrev record with size > MaxChunkData");
283
Chris Lattner6c29cb32013-02-09 07:07:29 +0000284 Abbv->Add(BitCodeAbbrevOp(E, Data));
285 } else
Chris Lattner59c3abc2013-01-19 18:19:39 +0000286 Abbv->Add(BitCodeAbbrevOp(E));
287 }
288 CurAbbrevs.push_back(Abbv);
289}
290
291bool BitstreamCursor::ReadBlockInfoBlock() {
292 // If this is the second stream to get to the block info block, skip it.
293 if (BitStream->hasBlockInfoRecords())
294 return SkipBlock();
Joe Abbey97b7a172013-02-06 22:14:06 +0000295
Chris Lattner59c3abc2013-01-19 18:19:39 +0000296 if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
Joe Abbey97b7a172013-02-06 22:14:06 +0000297
Chris Lattner59c3abc2013-01-19 18:19:39 +0000298 SmallVector<uint64_t, 64> Record;
Craig Topper2617dcc2014-04-15 06:32:26 +0000299 BitstreamReader::BlockInfo *CurBlockInfo = nullptr;
Joe Abbey97b7a172013-02-06 22:14:06 +0000300
Chris Lattner59c3abc2013-01-19 18:19:39 +0000301 // Read all the records for this module.
302 while (1) {
Chris Lattner27d38752013-01-20 02:13:19 +0000303 BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
Joe Abbey97b7a172013-02-06 22:14:06 +0000304
Chris Lattner27d38752013-01-20 02:13:19 +0000305 switch (Entry.Kind) {
306 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
307 case llvm::BitstreamEntry::Error:
308 return true;
309 case llvm::BitstreamEntry::EndBlock:
310 return false;
311 case llvm::BitstreamEntry::Record:
312 // The interesting case.
313 break;
314 }
315
Chris Lattner59c3abc2013-01-19 18:19:39 +0000316 // Read abbrev records, associate them with CurBID.
Chris Lattner27d38752013-01-20 02:13:19 +0000317 if (Entry.ID == bitc::DEFINE_ABBREV) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000318 if (!CurBlockInfo) return true;
319 ReadAbbrevRecord();
Joe Abbey97b7a172013-02-06 22:14:06 +0000320
Chris Lattner59c3abc2013-01-19 18:19:39 +0000321 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
322 // appropriate BlockInfo.
Benjamin Kramer6891ba02014-09-15 15:44:14 +0000323 CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000324 CurAbbrevs.pop_back();
Chris Lattner59c3abc2013-01-19 18:19:39 +0000325 continue;
326 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000327
Chris Lattner59c3abc2013-01-19 18:19:39 +0000328 // Read a record.
329 Record.clear();
Chris Lattner27d38752013-01-20 02:13:19 +0000330 switch (readRecord(Entry.ID, Record)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000331 default: break; // Default behavior, ignore unknown content.
332 case bitc::BLOCKINFO_CODE_SETBID:
333 if (Record.size() < 1) return true;
334 CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
335 break;
336 case bitc::BLOCKINFO_CODE_BLOCKNAME: {
337 if (!CurBlockInfo) return true;
338 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
339 std::string Name;
340 for (unsigned i = 0, e = Record.size(); i != e; ++i)
341 Name += (char)Record[i];
342 CurBlockInfo->Name = Name;
343 break;
344 }
345 case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
346 if (!CurBlockInfo) return true;
347 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
348 std::string Name;
349 for (unsigned i = 1, e = Record.size(); i != e; ++i)
350 Name += (char)Record[i];
351 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
352 Name));
353 break;
354 }
355 }
356 }
357}
358