OLD | NEW |
1 //===- NaClBitstreamReader.cpp --------------------------------------------===// | 1 //===- NaClBitstreamReader.cpp --------------------------------------------===// |
2 // NaClBitstreamReader implementation | 2 // NaClBitstreamReader implementation |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 CurCodeSize = RHS.CurCodeSize; | 26 CurCodeSize = RHS.CurCodeSize; |
27 | 27 |
28 // Copy abbreviations, and bump ref counts. | 28 // Copy abbreviations, and bump ref counts. |
29 CurAbbrevs = RHS.CurAbbrevs; | 29 CurAbbrevs = RHS.CurAbbrevs; |
30 for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) | 30 for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) |
31 CurAbbrevs[i]->addRef(); | 31 CurAbbrevs[i]->addRef(); |
32 | 32 |
33 // Copy block scope and bump ref counts. | 33 // Copy block scope and bump ref counts. |
34 BlockScope = RHS.BlockScope; | 34 BlockScope = RHS.BlockScope; |
35 for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { | 35 for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { |
36 std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; | 36 std::vector<NaClBitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; |
37 for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) | 37 for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) |
38 Abbrevs[i]->addRef(); | 38 Abbrevs[i]->addRef(); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 void NaClBitstreamCursor::freeState() { | 42 void NaClBitstreamCursor::freeState() { |
43 // Free all the Abbrevs. | 43 // Free all the Abbrevs. |
44 for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) | 44 for (size_t i = 0, e = CurAbbrevs.size(); i != e; ++i) |
45 CurAbbrevs[i]->dropRef(); | 45 CurAbbrevs[i]->dropRef(); |
46 CurAbbrevs.clear(); | 46 CurAbbrevs.clear(); |
47 | 47 |
48 // Free all the Abbrevs in the block scope. | 48 // Free all the Abbrevs in the block scope. |
49 for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { | 49 for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { |
50 std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; | 50 std::vector<NaClBitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; |
51 for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) | 51 for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) |
52 Abbrevs[i]->dropRef(); | 52 Abbrevs[i]->dropRef(); |
53 } | 53 } |
54 BlockScope.clear(); | 54 BlockScope.clear(); |
55 } | 55 } |
56 | 56 |
57 /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter | 57 /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, enter |
58 /// the block, and return true if the block has an error. | 58 /// the block, and return true if the block has an error. |
59 bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { | 59 bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { |
60 // Save the current block's state on BlockScope. | 60 // Save the current block's state on BlockScope. |
61 BlockScope.push_back(Block(CurCodeSize)); | 61 BlockScope.push_back(Block(CurCodeSize)); |
62 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); | 62 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs); |
63 | 63 |
64 // Add the abbrevs specific to this block to the CurAbbrevs list. | 64 // Add the abbrevs specific to this block to the CurAbbrevs list. |
65 if (const NaClBitstreamReader::BlockInfo *Info = | 65 if (const NaClBitstreamReader::BlockInfo *Info = |
66 BitStream->getBlockInfo(BlockID)) { | 66 BitStream->getBlockInfo(BlockID)) { |
67 for (size_t i = 0, e = Info->Abbrevs.size(); i != e; ++i) { | 67 for (size_t i = 0, e = Info->Abbrevs.size(); i != e; ++i) { |
68 CurAbbrevs.push_back(Info->Abbrevs[i]); | 68 CurAbbrevs.push_back(Info->Abbrevs[i]); |
69 CurAbbrevs.back()->addRef(); | 69 CurAbbrevs.back()->addRef(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 // Get the codesize of this block. | 73 // Get the codesize of this block. |
74 CurCodeSize = ReadVBR(bitc::CodeLenWidth); | 74 CurCodeSize = ReadVBR(naclbitc::CodeLenWidth); |
75 SkipToFourByteBoundary(); | 75 SkipToFourByteBoundary(); |
76 unsigned NumWords = Read(bitc::BlockSizeWidth); | 76 unsigned NumWords = Read(naclbitc::BlockSizeWidth); |
77 if (NumWordsP) *NumWordsP = NumWords; | 77 if (NumWordsP) *NumWordsP = NumWords; |
78 | 78 |
79 // Validate that this block is sane. | 79 // Validate that this block is sane. |
80 if (CurCodeSize == 0 || AtEndOfStream()) | 80 if (CurCodeSize == 0 || AtEndOfStream()) |
81 return true; | 81 return true; |
82 | 82 |
83 return false; | 83 return false; |
84 } | 84 } |
85 | 85 |
86 void NaClBitstreamCursor::readAbbreviatedLiteral( | 86 void NaClBitstreamCursor::readAbbreviatedLiteral( |
87 const BitCodeAbbrevOp &Op, | 87 const NaClBitCodeAbbrevOp &Op, |
88 SmallVectorImpl<uint64_t> &Vals) { | 88 SmallVectorImpl<uint64_t> &Vals) { |
89 assert(Op.isLiteral() && "Not a literal"); | 89 assert(Op.isLiteral() && "Not a literal"); |
90 // If the abbrev specifies the literal value to use, use it. | 90 // If the abbrev specifies the literal value to use, use it. |
91 Vals.push_back(Op.getLiteralValue()); | 91 Vals.push_back(Op.getLiteralValue()); |
92 } | 92 } |
93 | 93 |
94 void NaClBitstreamCursor::readAbbreviatedField( | 94 void NaClBitstreamCursor::readAbbreviatedField( |
95 const BitCodeAbbrevOp &Op, | 95 const NaClBitCodeAbbrevOp &Op, |
96 SmallVectorImpl<uint64_t> &Vals) { | 96 SmallVectorImpl<uint64_t> &Vals) { |
97 assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); | 97 assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); |
98 | 98 |
99 // Decode the value as we are commanded. | 99 // Decode the value as we are commanded. |
100 switch (Op.getEncoding()) { | 100 switch (Op.getEncoding()) { |
101 case BitCodeAbbrevOp::Array: | 101 case NaClBitCodeAbbrevOp::Array: |
102 case BitCodeAbbrevOp::Blob: | 102 case NaClBitCodeAbbrevOp::Blob: |
103 assert(0 && "Should not reach here"); | 103 assert(0 && "Should not reach here"); |
104 case BitCodeAbbrevOp::Fixed: | 104 case NaClBitCodeAbbrevOp::Fixed: |
105 Vals.push_back(Read((unsigned)Op.getEncodingData())); | 105 Vals.push_back(Read((unsigned)Op.getEncodingData())); |
106 break; | 106 break; |
107 case BitCodeAbbrevOp::VBR: | 107 case NaClBitCodeAbbrevOp::VBR: |
108 Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData())); | 108 Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData())); |
109 break; | 109 break; |
110 case BitCodeAbbrevOp::Char6: | 110 case NaClBitCodeAbbrevOp::Char6: |
111 Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6))); | 111 Vals.push_back(NaClBitCodeAbbrevOp::DecodeChar6(Read(6))); |
112 break; | 112 break; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 void NaClBitstreamCursor::skipAbbreviatedField(const BitCodeAbbrevOp &Op) { | 116 void NaClBitstreamCursor::skipAbbreviatedField(const NaClBitCodeAbbrevOp &Op) { |
117 assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); | 117 assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); |
118 | 118 |
119 // Decode the value as we are commanded. | 119 // Decode the value as we are commanded. |
120 switch (Op.getEncoding()) { | 120 switch (Op.getEncoding()) { |
121 case BitCodeAbbrevOp::Array: | 121 case NaClBitCodeAbbrevOp::Array: |
122 case BitCodeAbbrevOp::Blob: | 122 case NaClBitCodeAbbrevOp::Blob: |
123 assert(0 && "Should not reach here"); | 123 assert(0 && "Should not reach here"); |
124 case BitCodeAbbrevOp::Fixed: | 124 case NaClBitCodeAbbrevOp::Fixed: |
125 (void)Read((unsigned)Op.getEncodingData()); | 125 (void)Read((unsigned)Op.getEncodingData()); |
126 break; | 126 break; |
127 case BitCodeAbbrevOp::VBR: | 127 case NaClBitCodeAbbrevOp::VBR: |
128 (void)ReadVBR64((unsigned)Op.getEncodingData()); | 128 (void)ReadVBR64((unsigned)Op.getEncodingData()); |
129 break; | 129 break; |
130 case BitCodeAbbrevOp::Char6: | 130 case NaClBitCodeAbbrevOp::Char6: |
131 (void)Read(6); | 131 (void)Read(6); |
132 break; | 132 break; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 | 137 |
138 /// skipRecord - Read the current record and discard it. | 138 /// skipRecord - Read the current record and discard it. |
139 void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { | 139 void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { |
140 // Skip unabbreviated records by reading past their entries. | 140 // Skip unabbreviated records by reading past their entries. |
141 if (AbbrevID == bitc::UNABBREV_RECORD) { | 141 if (AbbrevID == naclbitc::UNABBREV_RECORD) { |
142 unsigned Code = ReadVBR(6); | 142 unsigned Code = ReadVBR(6); |
143 (void)Code; | 143 (void)Code; |
144 unsigned NumElts = ReadVBR(6); | 144 unsigned NumElts = ReadVBR(6); |
145 for (unsigned i = 0; i != NumElts; ++i) | 145 for (unsigned i = 0; i != NumElts; ++i) |
146 (void)ReadVBR64(6); | 146 (void)ReadVBR64(6); |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); | 150 const NaClBitCodeAbbrev *Abbv = getAbbrev(AbbrevID); |
151 | 151 |
152 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { | 152 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { |
153 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); | 153 const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); |
154 if (Op.isLiteral()) | 154 if (Op.isLiteral()) |
155 continue; | 155 continue; |
156 | 156 |
157 if (Op.getEncoding() != BitCodeAbbrevOp::Array && | 157 if (Op.getEncoding() != NaClBitCodeAbbrevOp::Array && |
158 Op.getEncoding() != BitCodeAbbrevOp::Blob) { | 158 Op.getEncoding() != NaClBitCodeAbbrevOp::Blob) { |
159 skipAbbreviatedField(Op); | 159 skipAbbreviatedField(Op); |
160 continue; | 160 continue; |
161 } | 161 } |
162 | 162 |
163 if (Op.getEncoding() == BitCodeAbbrevOp::Array) { | 163 if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) { |
164 // Array case. Read the number of elements as a vbr6. | 164 // Array case. Read the number of elements as a vbr6. |
165 unsigned NumElts = ReadVBR(6); | 165 unsigned NumElts = ReadVBR(6); |
166 | 166 |
167 // Get the element encoding. | 167 // Get the element encoding. |
168 assert(i+2 == e && "array op not second to last?"); | 168 assert(i+2 == e && "array op not second to last?"); |
169 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); | 169 const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); |
170 | 170 |
171 // Read all the elements. | 171 // Read all the elements. |
172 for (; NumElts; --NumElts) | 172 for (; NumElts; --NumElts) |
173 skipAbbreviatedField(EltEnc); | 173 skipAbbreviatedField(EltEnc); |
174 continue; | 174 continue; |
175 } | 175 } |
176 | 176 |
177 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); | 177 assert(Op.getEncoding() == NaClBitCodeAbbrevOp::Blob); |
178 // Blob case. Read the number of bytes as a vbr6. | 178 // Blob case. Read the number of bytes as a vbr6. |
179 unsigned NumElts = ReadVBR(6); | 179 unsigned NumElts = ReadVBR(6); |
180 SkipToFourByteBoundary(); // 32-bit alignment | 180 SkipToFourByteBoundary(); // 32-bit alignment |
181 | 181 |
182 // Figure out where the end of this blob will be including tail padding. | 182 // Figure out where the end of this blob will be including tail padding. |
183 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8; | 183 size_t NewEnd = GetCurrentBitNo()+((NumElts+3)&~3)*8; |
184 | 184 |
185 // If this would read off the end of the bitcode file, just set the | 185 // If this would read off the end of the bitcode file, just set the |
186 // record to empty and return. | 186 // record to empty and return. |
187 if (!canSkipToPos(NewEnd/8)) { | 187 if (!canSkipToPos(NewEnd/8)) { |
188 NextChar = BitStream->getBitcodeBytes().getExtent(); | 188 NextChar = BitStream->getBitcodeBytes().getExtent(); |
189 break; | 189 break; |
190 } | 190 } |
191 | 191 |
192 // Skip over the blob. | 192 // Skip over the blob. |
193 JumpToBit(NewEnd); | 193 JumpToBit(NewEnd); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, | 197 unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, |
198 SmallVectorImpl<uint64_t> &Vals, | 198 SmallVectorImpl<uint64_t> &Vals, |
199 StringRef *Blob) { | 199 StringRef *Blob) { |
200 if (AbbrevID == bitc::UNABBREV_RECORD) { | 200 if (AbbrevID == naclbitc::UNABBREV_RECORD) { |
201 unsigned Code = ReadVBR(6); | 201 unsigned Code = ReadVBR(6); |
202 unsigned NumElts = ReadVBR(6); | 202 unsigned NumElts = ReadVBR(6); |
203 for (unsigned i = 0; i != NumElts; ++i) | 203 for (unsigned i = 0; i != NumElts; ++i) |
204 Vals.push_back(ReadVBR64(6)); | 204 Vals.push_back(ReadVBR64(6)); |
205 return Code; | 205 return Code; |
206 } | 206 } |
207 | 207 |
208 const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); | 208 const NaClBitCodeAbbrev *Abbv = getAbbrev(AbbrevID); |
209 | 209 |
210 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { | 210 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { |
211 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); | 211 const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); |
212 if (Op.isLiteral()) { | 212 if (Op.isLiteral()) { |
213 readAbbreviatedLiteral(Op, Vals); | 213 readAbbreviatedLiteral(Op, Vals); |
214 continue; | 214 continue; |
215 } | 215 } |
216 | 216 |
217 if (Op.getEncoding() != BitCodeAbbrevOp::Array && | 217 if (Op.getEncoding() != NaClBitCodeAbbrevOp::Array && |
218 Op.getEncoding() != BitCodeAbbrevOp::Blob) { | 218 Op.getEncoding() != NaClBitCodeAbbrevOp::Blob) { |
219 readAbbreviatedField(Op, Vals); | 219 readAbbreviatedField(Op, Vals); |
220 continue; | 220 continue; |
221 } | 221 } |
222 | 222 |
223 if (Op.getEncoding() == BitCodeAbbrevOp::Array) { | 223 if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) { |
224 // Array case. Read the number of elements as a vbr6. | 224 // Array case. Read the number of elements as a vbr6. |
225 unsigned NumElts = ReadVBR(6); | 225 unsigned NumElts = ReadVBR(6); |
226 | 226 |
227 // Get the element encoding. | 227 // Get the element encoding. |
228 assert(i+2 == e && "array op not second to last?"); | 228 assert(i+2 == e && "array op not second to last?"); |
229 const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); | 229 const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); |
230 | 230 |
231 // Read all the elements. | 231 // Read all the elements. |
232 for (; NumElts; --NumElts) | 232 for (; NumElts; --NumElts) |
233 readAbbreviatedField(EltEnc, Vals); | 233 readAbbreviatedField(EltEnc, Vals); |
234 continue; | 234 continue; |
235 } | 235 } |
236 | 236 |
237 assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); | 237 assert(Op.getEncoding() == NaClBitCodeAbbrevOp::Blob); |
238 // Blob case. Read the number of bytes as a vbr6. | 238 // Blob case. Read the number of bytes as a vbr6. |
239 unsigned NumElts = ReadVBR(6); | 239 unsigned NumElts = ReadVBR(6); |
240 SkipToFourByteBoundary(); // 32-bit alignment | 240 SkipToFourByteBoundary(); // 32-bit alignment |
241 | 241 |
242 // Figure out where the end of this blob will be including tail padding. | 242 // Figure out where the end of this blob will be including tail padding. |
243 size_t CurBitPos = GetCurrentBitNo(); | 243 size_t CurBitPos = GetCurrentBitNo(); |
244 size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8; | 244 size_t NewEnd = CurBitPos+((NumElts+3)&~3)*8; |
245 | 245 |
246 // If this would read off the end of the bitcode file, just set the | 246 // If this would read off the end of the bitcode file, just set the |
247 // record to empty and return. | 247 // record to empty and return. |
(...skipping 19 matching lines...) Expand all Loading... |
267 JumpToBit(NewEnd); | 267 JumpToBit(NewEnd); |
268 } | 268 } |
269 | 269 |
270 unsigned Code = (unsigned)Vals[0]; | 270 unsigned Code = (unsigned)Vals[0]; |
271 Vals.erase(Vals.begin()); | 271 Vals.erase(Vals.begin()); |
272 return Code; | 272 return Code; |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 void NaClBitstreamCursor::ReadAbbrevRecord() { | 276 void NaClBitstreamCursor::ReadAbbrevRecord() { |
277 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 277 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
278 unsigned NumOpInfo = ReadVBR(5); | 278 unsigned NumOpInfo = ReadVBR(5); |
279 for (unsigned i = 0; i != NumOpInfo; ++i) { | 279 for (unsigned i = 0; i != NumOpInfo; ++i) { |
280 bool IsLiteral = Read(1) ? true : false; | 280 bool IsLiteral = Read(1) ? true : false; |
281 if (IsLiteral) { | 281 if (IsLiteral) { |
282 Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8))); | 282 Abbv->Add(NaClBitCodeAbbrevOp(ReadVBR64(8))); |
283 continue; | 283 continue; |
284 } | 284 } |
285 | 285 |
286 BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); | 286 NaClBitCodeAbbrevOp::Encoding E = (NaClBitCodeAbbrevOp::Encoding)Read(3); |
287 if (BitCodeAbbrevOp::hasEncodingData(E)) { | 287 if (NaClBitCodeAbbrevOp::hasEncodingData(E)) { |
288 unsigned Data = ReadVBR64(5); | 288 unsigned Data = ReadVBR64(5); |
289 | 289 |
290 // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) | 290 // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) |
291 // and vbr(0) as a literal zero. This is decoded the same way, and avoids | 291 // and vbr(0) as a literal zero. This is decoded the same way, and avoids |
292 // a slow path in Read() to have to handle reading zero bits. | 292 // a slow path in Read() to have to handle reading zero bits. |
293 if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && | 293 if ((E == NaClBitCodeAbbrevOp::Fixed || E == NaClBitCodeAbbrevOp::VBR) && |
294 Data == 0) { | 294 Data == 0) { |
295 Abbv->Add(BitCodeAbbrevOp(0)); | 295 Abbv->Add(NaClBitCodeAbbrevOp(0)); |
296 continue; | 296 continue; |
297 } | 297 } |
298 | 298 |
299 Abbv->Add(BitCodeAbbrevOp(E, Data)); | 299 Abbv->Add(NaClBitCodeAbbrevOp(E, Data)); |
300 } else | 300 } else |
301 Abbv->Add(BitCodeAbbrevOp(E)); | 301 Abbv->Add(NaClBitCodeAbbrevOp(E)); |
302 } | 302 } |
303 CurAbbrevs.push_back(Abbv); | 303 CurAbbrevs.push_back(Abbv); |
304 } | 304 } |
305 | 305 |
306 bool NaClBitstreamCursor::ReadBlockInfoBlock() { | 306 bool NaClBitstreamCursor::ReadBlockInfoBlock() { |
307 // If this is the second stream to get to the block info block, skip it. | 307 // If this is the second stream to get to the block info block, skip it. |
308 if (BitStream->hasBlockInfoRecords()) | 308 if (BitStream->hasBlockInfoRecords()) |
309 return SkipBlock(); | 309 return SkipBlock(); |
310 | 310 |
311 if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; | 311 if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID)) return true; |
312 | 312 |
313 SmallVector<uint64_t, 64> Record; | 313 SmallVector<uint64_t, 64> Record; |
314 NaClBitstreamReader::BlockInfo *CurBlockInfo = 0; | 314 NaClBitstreamReader::BlockInfo *CurBlockInfo = 0; |
315 | 315 |
316 // Read all the records for this module. | 316 // Read all the records for this module. |
317 while (1) { | 317 while (1) { |
318 NaClBitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrev
s); | 318 NaClBitstreamEntry Entry = advanceSkippingSubblocks(AF_DontAutoprocessAbbrev
s); |
319 | 319 |
320 switch (Entry.Kind) { | 320 switch (Entry.Kind) { |
321 case llvm::NaClBitstreamEntry::SubBlock: // Handled for us already. | 321 case llvm::NaClBitstreamEntry::SubBlock: // Handled for us already. |
322 case llvm::NaClBitstreamEntry::Error: | 322 case llvm::NaClBitstreamEntry::Error: |
323 return true; | 323 return true; |
324 case llvm::NaClBitstreamEntry::EndBlock: | 324 case llvm::NaClBitstreamEntry::EndBlock: |
325 return false; | 325 return false; |
326 case llvm::NaClBitstreamEntry::Record: | 326 case llvm::NaClBitstreamEntry::Record: |
327 // The interesting case. | 327 // The interesting case. |
328 break; | 328 break; |
329 } | 329 } |
330 | 330 |
331 // Read abbrev records, associate them with CurBID. | 331 // Read abbrev records, associate them with CurBID. |
332 if (Entry.ID == bitc::DEFINE_ABBREV) { | 332 if (Entry.ID == naclbitc::DEFINE_ABBREV) { |
333 if (!CurBlockInfo) return true; | 333 if (!CurBlockInfo) return true; |
334 ReadAbbrevRecord(); | 334 ReadAbbrevRecord(); |
335 | 335 |
336 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the | 336 // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the |
337 // appropriate BlockInfo. | 337 // appropriate BlockInfo. |
338 BitCodeAbbrev *Abbv = CurAbbrevs.back(); | 338 NaClBitCodeAbbrev *Abbv = CurAbbrevs.back(); |
339 CurAbbrevs.pop_back(); | 339 CurAbbrevs.pop_back(); |
340 CurBlockInfo->Abbrevs.push_back(Abbv); | 340 CurBlockInfo->Abbrevs.push_back(Abbv); |
341 continue; | 341 continue; |
342 } | 342 } |
343 | 343 |
344 // Read a record. | 344 // Read a record. |
345 Record.clear(); | 345 Record.clear(); |
346 switch (readRecord(Entry.ID, Record)) { | 346 switch (readRecord(Entry.ID, Record)) { |
347 default: break; // Default behavior, ignore unknown content. | 347 default: break; // Default behavior, ignore unknown content. |
348 case bitc::BLOCKINFO_CODE_SETBID: | 348 case naclbitc::BLOCKINFO_CODE_SETBID: |
349 if (Record.size() < 1) return true; | 349 if (Record.size() < 1) return true; |
350 CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); | 350 CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); |
351 break; | 351 break; |
352 case bitc::BLOCKINFO_CODE_BLOCKNAME: { | 352 case naclbitc::BLOCKINFO_CODE_BLOCKNAME: { |
353 if (!CurBlockInfo) return true; | 353 if (!CurBlockInfo) return true; |
354 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. | 354 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. |
355 std::string Name; | 355 std::string Name; |
356 for (unsigned i = 0, e = Record.size(); i != e; ++i) | 356 for (unsigned i = 0, e = Record.size(); i != e; ++i) |
357 Name += (char)Record[i]; | 357 Name += (char)Record[i]; |
358 CurBlockInfo->Name = Name; | 358 CurBlockInfo->Name = Name; |
359 break; | 359 break; |
360 } | 360 } |
361 case bitc::BLOCKINFO_CODE_SETRECORDNAME: { | 361 case naclbitc::BLOCKINFO_CODE_SETRECORDNAME: { |
362 if (!CurBlockInfo) return true; | 362 if (!CurBlockInfo) return true; |
363 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. | 363 if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. |
364 std::string Name; | 364 std::string Name; |
365 for (unsigned i = 1, e = Record.size(); i != e; ++i) | 365 for (unsigned i = 1, e = Record.size(); i != e; ++i) |
366 Name += (char)Record[i]; | 366 Name += (char)Record[i]; |
367 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0], | 367 CurBlockInfo->RecordNames.push_back(std::make_pair((unsigned)Record[0], |
368 Name)); | 368 Name)); |
369 break; | 369 break; |
370 } | 370 } |
371 } | 371 } |
372 } | 372 } |
373 } | 373 } |
OLD | NEW |