blob: 60360d2ef78fe597adf8aa277d64b7f01c21727b [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 =
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +000035 getBitStreamReader()->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.
Mehdi Amini67dfe092016-03-07 00:38:09 +0000134 // Decode the value as we are commanded.
135 switch (EltEnc.getEncoding()) {
136 default:
137 report_fatal_error("Array element type can't be an Array or a Blob");
138 case BitCodeAbbrevOp::Fixed:
139 assert((unsigned)Op.getEncodingData() <= MaxChunkSize);
140 for (; NumElts; --NumElts)
141 Read((unsigned)EltEnc.getEncodingData());
142 break;
143 case BitCodeAbbrevOp::VBR:
144 assert((unsigned)Op.getEncodingData() <= MaxChunkSize);
145 for (; NumElts; --NumElts)
146 ReadVBR64((unsigned)EltEnc.getEncodingData());
147 break;
148 case BitCodeAbbrevOp::Char6:
149 for (; NumElts; --NumElts)
150 Read(6);
151 break;
152 }
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000153 continue;
154 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000155
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000156 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
157 // Blob case. Read the number of bytes as a vbr6.
158 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000159 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000160
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000161 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000162 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000163
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000164 // If this would read off the end of the bitcode file, just set the
165 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000166 if (!canSkipToPos(NewEnd/8)) {
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000167 skipToEnd();
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000168 break;
169 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000170
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000171 // Skip over the blob.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000172 JumpToBit(NewEnd);
Chris Lattner5ba7bca2013-01-20 00:00:00 +0000173 }
174}
Chris Lattner59c3abc2013-01-19 18:19:39 +0000175
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000176unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
Chris Lattner59c3abc2013-01-19 18:19:39 +0000177 SmallVectorImpl<uint64_t> &Vals,
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000178 StringRef *Blob) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000179 if (AbbrevID == bitc::UNABBREV_RECORD) {
180 unsigned Code = ReadVBR(6);
181 unsigned NumElts = ReadVBR(6);
182 for (unsigned i = 0; i != NumElts; ++i)
183 Vals.push_back(ReadVBR64(6));
184 return Code;
185 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000186
Chris Lattner59c3abc2013-01-19 18:19:39 +0000187 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
Joe Abbey97b7a172013-02-06 22:14:06 +0000188
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000189 // Read the record code first.
190 assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
191 const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
Rafael Espindolaf8950452014-11-13 22:29:02 +0000192 unsigned Code;
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000193 if (CodeOp.isLiteral())
Rafael Espindolaf8950452014-11-13 22:29:02 +0000194 Code = CodeOp.getLiteralValue();
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000195 else {
196 if (CodeOp.getEncoding() == BitCodeAbbrevOp::Array ||
197 CodeOp.getEncoding() == BitCodeAbbrevOp::Blob)
198 report_fatal_error("Abbreviation starts with an Array or a Blob");
Rafael Espindolaf8950452014-11-13 22:29:02 +0000199 Code = readAbbreviatedField(*this, CodeOp);
Filipe Cabecinhasde968ec2015-01-24 04:15:05 +0000200 }
Jordan Rose6ac4ba22013-05-10 22:17:10 +0000201
202 for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000203 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
204 if (Op.isLiteral()) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000205 Vals.push_back(Op.getLiteralValue());
Chris Lattner59c3abc2013-01-19 18:19:39 +0000206 continue;
207 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000208
Chris Lattner59c3abc2013-01-19 18:19:39 +0000209 if (Op.getEncoding() != BitCodeAbbrevOp::Array &&
210 Op.getEncoding() != BitCodeAbbrevOp::Blob) {
Rafael Espindolaf8950452014-11-13 22:29:02 +0000211 Vals.push_back(readAbbreviatedField(*this, Op));
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 if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
216 // Array case. Read the number of elements as a vbr6.
217 unsigned NumElts = ReadVBR(6);
Joe Abbey97b7a172013-02-06 22:14:06 +0000218
Chris Lattner59c3abc2013-01-19 18:19:39 +0000219 // Get the element encoding.
Filipe Cabecinhasa872a472015-05-27 00:48:37 +0000220 if (i + 2 != e)
221 report_fatal_error("Array op not second to last");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000222 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
Filipe Cabecinhas8cd99e92015-05-27 00:48:43 +0000223 if (!EltEnc.isEncoding())
224 report_fatal_error(
225 "Array element type has to be an encoding of a type");
Joe Abbey97b7a172013-02-06 22:14:06 +0000226
Chris Lattner59c3abc2013-01-19 18:19:39 +0000227 // Read all the elements.
Mehdi Amini67dfe092016-03-07 00:38:09 +0000228 switch (EltEnc.getEncoding()) {
229 default:
230 report_fatal_error("Array element type can't be an Array or a Blob");
231 case BitCodeAbbrevOp::Fixed:
232 for (; NumElts; --NumElts)
233 Vals.push_back(Read((unsigned)EltEnc.getEncodingData()));
234 break;
235 case BitCodeAbbrevOp::VBR:
236 for (; NumElts; --NumElts)
237 Vals.push_back(ReadVBR64((unsigned)EltEnc.getEncodingData()));
238 break;
239 case BitCodeAbbrevOp::Char6:
240 for (; NumElts; --NumElts)
241 Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
242 }
Chris Lattner59c3abc2013-01-19 18:19:39 +0000243 continue;
244 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000245
Chris Lattner59c3abc2013-01-19 18:19:39 +0000246 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob);
247 // Blob case. Read the number of bytes as a vbr6.
248 unsigned NumElts = ReadVBR(6);
Chris Lattnere1817aa2013-01-21 18:04:19 +0000249 SkipToFourByteBoundary(); // 32-bit alignment
Joe Abbey97b7a172013-02-06 22:14:06 +0000250
Chris Lattner59c3abc2013-01-19 18:19:39 +0000251 // Figure out where the end of this blob will be including tail padding.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000252 size_t CurBitPos = GetCurrentBitNo();
253 size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8;
Joe Abbey97b7a172013-02-06 22:14:06 +0000254
Chris Lattner59c3abc2013-01-19 18:19:39 +0000255 // If this would read off the end of the bitcode file, just set the
256 // record to empty and return.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000257 if (!canSkipToPos(NewEnd/8)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000258 Vals.append(NumElts, 0);
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000259 skipToEnd();
Chris Lattner59c3abc2013-01-19 18:19:39 +0000260 break;
261 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000262
Duncan P. N. Exon Smith456c9962016-03-27 23:00:59 +0000263 // Otherwise, inform the streamer that we need these bytes in memory. Skip
264 // over tail padding first, in case jumping to NewEnd invalidates the Blob
265 // pointer.
266 JumpToBit(NewEnd);
Duncan P. N. Exon Smithd3be62d2016-03-27 22:45:25 +0000267 const char *Ptr = (const char *)getPointerToBit(CurBitPos, NumElts);
Joe Abbey97b7a172013-02-06 22:14:06 +0000268
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000269 // If we can return a reference to the data, do so to avoid copying it.
Chris Lattner3cf49cf2013-01-20 01:06:48 +0000270 if (Blob) {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000271 *Blob = StringRef(Ptr, NumElts);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000272 } else {
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000273 // Otherwise, unpack into Vals with zero extension.
Chris Lattner9221b8f2013-01-21 18:18:25 +0000274 for (; NumElts; --NumElts)
Chris Lattner1aeca1e2013-01-21 18:24:49 +0000275 Vals.push_back((unsigned char)*Ptr++);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000276 }
Chris Lattner59c3abc2013-01-19 18:19:39 +0000277 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000278
Chris Lattner59c3abc2013-01-19 18:19:39 +0000279 return Code;
280}
281
282
283void BitstreamCursor::ReadAbbrevRecord() {
284 BitCodeAbbrev *Abbv = new BitCodeAbbrev();
285 unsigned NumOpInfo = ReadVBR(5);
286 for (unsigned i = 0; i != NumOpInfo; ++i) {
David Blaikiedc3f01e2015-03-09 01:57:13 +0000287 bool IsLiteral = Read(1);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000288 if (IsLiteral) {
289 Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8)));
290 continue;
291 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000292
Chris Lattner59c3abc2013-01-19 18:19:39 +0000293 BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000294 if (BitCodeAbbrevOp::hasEncodingData(E)) {
Richard Smith7b408022015-02-13 21:05:11 +0000295 uint64_t Data = ReadVBR64(5);
Chris Lattner6c29cb32013-02-09 07:07:29 +0000296
297 // As a special case, handle fixed(0) (i.e., a fixed field with zero bits)
298 // and vbr(0) as a literal zero. This is decoded the same way, and avoids
299 // a slow path in Read() to have to handle reading zero bits.
300 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
301 Data == 0) {
302 Abbv->Add(BitCodeAbbrevOp(0));
303 continue;
304 }
Joe Abbeybc6f4ba2013-04-01 02:28:07 +0000305
Filipe Cabecinhasee48fea2015-04-23 13:25:35 +0000306 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) &&
307 Data > MaxChunkSize)
308 report_fatal_error(
309 "Fixed or VBR abbrev record with size > MaxChunkData");
310
Chris Lattner6c29cb32013-02-09 07:07:29 +0000311 Abbv->Add(BitCodeAbbrevOp(E, Data));
312 } else
Chris Lattner59c3abc2013-01-19 18:19:39 +0000313 Abbv->Add(BitCodeAbbrevOp(E));
314 }
Filipe Cabecinhasbc6a9092015-05-26 23:52:21 +0000315
316 if (Abbv->getNumOperandInfos() == 0)
317 report_fatal_error("Abbrev record with no operands");
Chris Lattner59c3abc2013-01-19 18:19:39 +0000318 CurAbbrevs.push_back(Abbv);
319}
320
321bool BitstreamCursor::ReadBlockInfoBlock() {
322 // If this is the second stream to get to the block info block, skip it.
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000323 if (getBitStreamReader()->hasBlockInfoRecords())
Chris Lattner59c3abc2013-01-19 18:19:39 +0000324 return SkipBlock();
Joe Abbey97b7a172013-02-06 22:14:06 +0000325
Chris Lattner59c3abc2013-01-19 18:19:39 +0000326 if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true;
Joe Abbey97b7a172013-02-06 22:14:06 +0000327
Chris Lattner59c3abc2013-01-19 18:19:39 +0000328 SmallVector<uint64_t, 64> Record;
Craig Topper2617dcc2014-04-15 06:32:26 +0000329 BitstreamReader::BlockInfo *CurBlockInfo = nullptr;
Joe Abbey97b7a172013-02-06 22:14:06 +0000330
Chris Lattner59c3abc2013-01-19 18:19:39 +0000331 // Read all the records for this module.
332 while (1) {
Chris Lattner27d38752013-01-20 02:13:19 +0000333 BitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrevs);
Joe Abbey97b7a172013-02-06 22:14:06 +0000334
Chris Lattner27d38752013-01-20 02:13:19 +0000335 switch (Entry.Kind) {
336 case llvm::BitstreamEntry::SubBlock: // Handled for us already.
337 case llvm::BitstreamEntry::Error:
338 return true;
339 case llvm::BitstreamEntry::EndBlock:
340 return false;
341 case llvm::BitstreamEntry::Record:
342 // The interesting case.
343 break;
344 }
345
Chris Lattner59c3abc2013-01-19 18:19:39 +0000346 // Read abbrev records, associate them with CurBID.
Chris Lattner27d38752013-01-20 02:13:19 +0000347 if (Entry.ID == bitc::DEFINE_ABBREV) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000348 if (!CurBlockInfo) return true;
349 ReadAbbrevRecord();
Joe Abbey97b7a172013-02-06 22:14:06 +0000350
Chris Lattner59c3abc2013-01-19 18:19:39 +0000351 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the
352 // appropriate BlockInfo.
Benjamin Kramer6891ba02014-09-15 15:44:14 +0000353 CurBlockInfo->Abbrevs.push_back(std::move(CurAbbrevs.back()));
Chris Lattner59c3abc2013-01-19 18:19:39 +0000354 CurAbbrevs.pop_back();
Chris Lattner59c3abc2013-01-19 18:19:39 +0000355 continue;
356 }
Joe Abbey97b7a172013-02-06 22:14:06 +0000357
Chris Lattner59c3abc2013-01-19 18:19:39 +0000358 // Read a record.
359 Record.clear();
Chris Lattner27d38752013-01-20 02:13:19 +0000360 switch (readRecord(Entry.ID, Record)) {
Chris Lattner59c3abc2013-01-19 18:19:39 +0000361 default: break; // Default behavior, ignore unknown content.
362 case bitc::BLOCKINFO_CODE_SETBID:
363 if (Record.size() < 1) return true;
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000364 CurBlockInfo =
365 &getBitStreamReader()->getOrCreateBlockInfo((unsigned)Record[0]);
Chris Lattner59c3abc2013-01-19 18:19:39 +0000366 break;
367 case bitc::BLOCKINFO_CODE_BLOCKNAME: {
368 if (!CurBlockInfo) return true;
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000369 if (getBitStreamReader()->isIgnoringBlockInfoNames())
370 break; // Ignore name.
Chris Lattner59c3abc2013-01-19 18:19:39 +0000371 std::string Name;
372 for (unsigned i = 0, e = Record.size(); i != e; ++i)
373 Name += (char)Record[i];
374 CurBlockInfo->Name = Name;
375 break;
376 }
377 case bitc::BLOCKINFO_CODE_SETRECORDNAME: {
378 if (!CurBlockInfo) return true;
Duncan P. N. Exon Smithd766d132016-03-27 22:40:55 +0000379 if (getBitStreamReader()->isIgnoringBlockInfoNames())
380 break; // Ignore name.
Chris Lattner59c3abc2013-01-19 18:19:39 +0000381 std::string Name;
382 for (unsigned i = 1, e = Record.size(); i != e; ++i)
383 Name += (char)Record[i];
384 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0],
385 Name));
386 break;
387 }
388 }
389 }
390}
391