blob: a103fbdf4a93a317710d171058b9788fb1f46148 [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.
Rafael Espindolae7134b22015-05-25 13:50:21 +000051 return CurCodeSize == 0 || AtEndOfStream();
Chris Lattner59c3abc2013-01-19 18:19:39 +000052}
53
Rafael Espindolaf8950452014-11-13 22:29:02 +000054static uint64_t readAbbreviatedField(BitstreamCursor &Cursor,
55 const BitCodeAbbrevOp &Op) {
56 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000057
Chris Lattner5ba7bca2013-01-20 00:00:00 +000058 // Decode the value as we are commanded.
59 switch (Op.getEncoding()) {
60 case BitCodeAbbrevOp::Array:
61 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000062 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000063 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000064 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000065 return Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000066 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000067 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindolaf8950452014-11-13 22:29:02 +000068 return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000069 case BitCodeAbbrevOp::Char6:
Rafael Espindolaf8950452014-11-13 22:29:02 +000070 return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));
Chris Lattner5ba7bca2013-01-20 00:00:00 +000071 }
Reid Kleckner9651f01a82014-11-13 23:07:22 +000072 llvm_unreachable("invalid abbreviation encoding");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000073}
74
Rafael Espindola76d41f82014-11-13 21:54:59 +000075static void skipAbbreviatedField(BitstreamCursor &Cursor,
76 const BitCodeAbbrevOp &Op) {
Rafael Espindolaf8950452014-11-13 22:29:02 +000077 assert(!Op.isLiteral() && "Not to be used with literals!");
Joe Abbey97b7a172013-02-06 22:14:06 +000078
Chris Lattner5ba7bca2013-01-20 00:00:00 +000079 // Decode the value as we are commanded.
80 switch (Op.getEncoding()) {
81 case BitCodeAbbrevOp::Array:
82 case BitCodeAbbrevOp::Blob:
Craig Topper2a30d782014-06-18 05:05:13 +000083 llvm_unreachable("Should not reach here");
Chris Lattner5ba7bca2013-01-20 00:00:00 +000084 case BitCodeAbbrevOp::Fixed:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000085 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000086 Cursor.Read((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000087 break;
88 case BitCodeAbbrevOp::VBR:
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +000089 assert((unsigned)Op.getEncodingData() <= Cursor.MaxChunkSize);
Rafael Espindola76d41f82014-11-13 21:54:59 +000090 Cursor.ReadVBR64((unsigned)Op.getEncodingData());
Chris Lattner5ba7bca2013-01-20 00:00:00 +000091 break;
92 case BitCodeAbbrevOp::Char6:
Rafael Espindola76d41f82014-11-13 21:54:59 +000093 Cursor.Read(6);
Chris Lattner5ba7bca2013-01-20 00:00:00 +000094 break;
95 }
96}
97
98
99
100/// skipRecord - Read the current record and discard it.
101void BitstreamCursor::skipRecord(unsigned AbbrevID) {
102 // Skip unabbreviated records by reading past their entries.
103 if (AbbrevID == bitc::UNABBREV_RECORD) {
104 unsigned Code = ReadVBR(6);
105 (void)Code;
106 unsigned NumElts = ReadVBR(6);
107 for (unsigned i = 0; i != NumElts; ++i)
108 (void)ReadVBR64(6);
109 return;
110 }
111
112 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000113
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000114 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
115 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
116 if (Op.isLiteral())
117 continue;
Joe Abbey97b7a172013-02-06 22:14:06 +0000118
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000119 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
120 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindola76d41f82014-11-13 21:54:59 +0000121 skipAbbreviatedField(*this, Op);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000122 continue;
123 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000124
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000125 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
126 // Array case. Read the number of elements as a vbr6.
127 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000128
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000129 // Get the element encoding.
130 assert(i+2 == e && "array op not second to last?");
131 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Joe Abbey97b7a172013-02-06 22:14:06 +0000132
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000133 // Read all the elements.
134 for (; NumElts; --NumElts)
Rafael Espindola76d41f82014-11-13 21:54:59 +0000135 skipAbbreviatedField(*this, EltEnc);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000136 continue;
137 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000138
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000139 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
140 // Blob case. Read the number of bytes as a vbr6.
141 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000142 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000143
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000144 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000145 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000146
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000147 // If this would read off the end of the bitcode file, just set the
148 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000149 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000150 NextChar = BitStream->getBitcodeBytes().getExtent();
151 break;
152 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000153
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000154 // Skip over the blob.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000155 JumpToBit(NewEnd);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000156 }
157}
Chris Lattner59c3abc2013-01-19 18:19:39 +0000158
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000159unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
Chris Lattner59c3abc2013-01-19 18:19:39 +0000160 SmallVectorImpl<uint64_t> &Vals,
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000161 StringRef *Blob) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000162 if (AbbrevID == bitc::UNABBREV_RECORD) {
163 unsigned Code = ReadVBR(6);
164 unsigned NumElts = ReadVBR(6);
165 for (unsigned i = 0; i != NumElts; ++i)
166 Vals.push_back(ReadVBR64(6));
167 return Code;
168 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000169
Chris Lattner59c3abc2013-01-19 18:19:39 +0000170 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000171
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000172 // Read the record code first.
173 assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
174 const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
Rafael Espindolaf8950452014-11-13 22:29:02 +0000175 unsigned Code;
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000176 if (CodeOp.isLiteral())
Rafael Espindolaf8950452014-11-13 22:29:02 +0000177 Code = CodeOp.getLiteralValue();
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000178 else {
179 if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
180 CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
181 report_fatal_error("Abbreviation starts with an Array or a Blob");
Rafael Espindolaf8950452014-11-13 22:29:02 +0000182 Code = readAbbreviatedField(*this, CodeOp);
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000183 }
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000184
185 for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000186 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
187 if (Op.isLiteral()) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000188 Vals.push_back(Op.getLiteralValue());
Chris Lattner59c3abc2013-01-19 18:19:39 +0000189 continue;
190 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000191
Chris Lattner59c3abc2013-01-19 18:19:39 +0000192 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
193 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000194 Vals.push_back(readAbbreviatedField(*this, Op));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000195 continue;
196 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000197
Chris Lattner59c3abc2013-01-19 18:19:39 +0000198 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
199 // Array case. Read the number of elements as a vbr6.
200 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000201
Chris Lattner59c3abc2013-01-19 18:19:39 +0000202 // Get the element encoding.
Filipe Cabecinhasa872a472015-05-27 00:48:37 +0000203 if (i + 2 != e)
204 report_fatal_error("Array op not second to last");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000205 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Filipe Cabecinhas8cd99e92015-05-27 00:48:43 +0000206 if (!EltEnc.isEncoding())
207 report_fatal_error(
208 "Array element type has to be an encoding of a type");
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 }
Filipe Cabecinhasbc6a9092015-05-26 23:52:21 +0000288
289 if (Abbv->getNumOperandInfos() == 0)
290 report_fatal_error("Abbrev record with no operands");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000291 CurAbbrevs.push_back(Abbv);
292}
293
294bool BitstreamCursor::ReadBlockInfoBlock() {
295 // If this is the second stream to get to the block info block, skip it.
296 if (BitStream->hasBlockInfoRecords())
297 return SkipBlock();
Joe Abbey97b7a172013-02-06 22:14:06 +0000298
Chris Lattner59c3abc2013-01-19 18:19:39 +0000299 if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
Joe Abbey97b7a172013-02-06 22:14:06 +0000300
Chris Lattner59c3abc2013-01-19 18:19:39 +0000301 SmallVector<uint64_t, 64> Record;
Craig Topper2617dcc2014-04-15 06:32:26 +0000302 BitstreamReader::BlockInfo *CurBlockInfo = nullptr;
Joe Abbey97b7a172013-02-06 22:14:06 +0000303
Chris Lattner59c3abc2013-01-19 18:19:39 +0000304 // Read all the records for this module.
305 while (1) {
Chris Lattner27d38752013-01-20 02:13:19 +0000306 BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
Joe Abbey97b7a172013-02-06 22:14:06 +0000307
Chris Lattner27d38752013-01-20 02:13:19 +0000308 switch (Entry.Kind) {
309 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
310 case llvm::BitstreamEntry::Error:
311 return true;
312 case llvm::BitstreamEntry::EndBlock:
313 return false;
314 case llvm::BitstreamEntry::Record:
315 // The interesting case.
316 break;
317 }
318
Chris Lattner59c3abc2013-01-19 18:19:39 +0000319 // Read abbrev records, associate them with CurBID.
Chris Lattner27d38752013-01-20 02:13:19 +0000320 if (Entry.ID == bitc::DEFINE_ABBREV) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000321 if (!CurBlockInfo) return true;
322 ReadAbbrevRecord();
Joe Abbey97b7a172013-02-06 22:14:06 +0000323
Chris Lattner59c3abc2013-01-19 18:19:39 +0000324 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
325 // appropriate BlockInfo.
Benjamin Kramer6891ba02014-09-15 15:44:14 +0000326 CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000327 CurAbbrevs.pop_back();
Chris Lattner59c3abc2013-01-19 18:19:39 +0000328 continue;
329 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000330
Chris Lattner59c3abc2013-01-19 18:19:39 +0000331 // Read a record.
332 Record.clear();
Chris Lattner27d38752013-01-20 02:13:19 +0000333 switch (readRecord(Entry.ID, Record)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000334 default: break; // Default behavior, ignore unknown content.
335 case bitc::BLOCKINFO_CODE_SETBID:
336 if (Record.size() < 1) return true;
337 CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]);
338 break;
339 case bitc::BLOCKINFO_CODE_BLOCKNAME: {
340 if (!CurBlockInfo) return true;
341 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
342 std::string Name;
343 for (unsigned i = 0, e = Record.size(); i != e; ++i)
344 Name += (char)Record[i];
345 CurBlockInfo->Name = Name;
346 break;
347 }
348 case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
349 if (!CurBlockInfo) return true;
350 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name.
351 std::string Name;
352 for (unsigned i = 1, e = Record.size(); i != e; ++i)
353 Name += (char)Record[i];
354 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
355 Name));
356 break;
357 }
358 }
359 }
360}
361