Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitstreamReader.h

Issue 1851163002: Correct error reporting bit for parallel PNaCl bitcode parses. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nit. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===// 1 //===- NaClBitstreamReader.h -----------------------------------*- C++ -*-===//
2 // Low-level bitstream reader interface 2 // Low-level bitstream reader interface
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 private: 222 private:
223 friend class NaClBitstreamCursor; 223 friend class NaClBitstreamCursor;
224 224
225 std::unique_ptr<MemoryObject> BitcodeBytes; 225 std::unique_ptr<MemoryObject> BitcodeBytes;
226 226
227 SharedBlockInfoMap BlockInfoRecords; 227 SharedBlockInfoMap BlockInfoRecords;
228 228
229 /// \brief Holds the offset of the first byte after the header. 229 /// \brief Holds the offset of the first byte after the header.
230 size_t InitialAddress; 230 size_t InitialAddress;
231 231
232 // Holds the number of bytes to add to the bitcode position, when reporting
233 // errors. Useful when using parallel parses of function blocks.
234 size_t ErrorOffset = 0;
235
232 // True if filler should be added to byte align records. 236 // True if filler should be added to byte align records.
233 bool AlignBitcodeRecords = false; 237 bool AlignBitcodeRecords = false;
234 NaClBitstreamReader(const NaClBitstreamReader&) = delete; 238 NaClBitstreamReader(const NaClBitstreamReader&) = delete;
235 void operator=(const NaClBitstreamReader&) = delete; 239 void operator=(const NaClBitstreamReader&) = delete;
236 240
237 241
238 void initFromHeader(NaClBitcodeHeader &Header) { 242 void initFromHeader(NaClBitcodeHeader &Header) {
239 InitialAddress = Header.getHeaderSize(); 243 InitialAddress = Header.getHeaderSize();
240 AlignBitcodeRecords = Header.getAlignBitcodeRecords(); 244 AlignBitcodeRecords = Header.getAlignBitcodeRecords();
241 } 245 }
242 246
243 public: 247 public:
244 /// Read stream from sequence of bytes [Start .. End) after parsing 248 /// Read stream from sequence of bytes [Start .. End) after parsing
245 /// the given bitcode header. 249 /// the given bitcode header.
246 NaClBitstreamReader(const unsigned char *Start, const unsigned char *End, 250 NaClBitstreamReader(const unsigned char *Start, const unsigned char *End,
247 NaClBitcodeHeader &Header) 251 NaClBitcodeHeader &Header)
248 : BitcodeBytes(getNonStreamedMemoryObject(Start, End)), 252 : BitcodeBytes(getNonStreamedMemoryObject(Start, End)),
249 BlockInfoRecords(BlockInfoRecordsMap::create()) { 253 BlockInfoRecords(BlockInfoRecordsMap::create()) {
250 initFromHeader(Header); 254 initFromHeader(Header);
251 } 255 }
252 256
253 /// Read stream from Bytes, after parsing the given bitcode header. 257 /// Read stream from Bytes, after parsing the given bitcode header.
254 NaClBitstreamReader(MemoryObject *Bytes, NaClBitcodeHeader &Header) 258 NaClBitstreamReader(MemoryObject *Bytes, NaClBitcodeHeader &Header)
255 : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()) { 259 : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create())
256 initFromHeader(Header); 260 { initFromHeader(Header); }
257 }
258 261
259 /// Read stream from bytes, starting at the given initial address. 262 /// Read stream from bytes, starting at the given initial address.
260 /// Provides simple API for unit testing. 263 /// Provides simple API for unit testing.
261 NaClBitstreamReader(MemoryObject *Bytes, size_t InitialAddress) 264 NaClBitstreamReader(MemoryObject *Bytes, size_t InitialAddress)
262 : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()), 265 : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()),
263 InitialAddress(InitialAddress) { 266 InitialAddress(InitialAddress) {}
264 }
265 267
266 /// Read stream from sequence of bytes [Start .. End), using the global 268 /// Read stream from sequence of bytes [Start .. End), using the global
267 /// abbreviations of the given bitstream reader. Assumes that [Start .. End) 269 /// abbreviations of the given bitstream reader. Assumes that [Start .. End)
268 /// is copied from Reader's memory object. 270 /// is copied from Reader's memory object.
269 NaClBitstreamReader(const unsigned char *Start, 271 NaClBitstreamReader(size_t StartAddress, const unsigned char *Start,
270 const unsigned char *End, NaClBitstreamReader *Reader) 272 const unsigned char *End, NaClBitstreamReader *Reader)
271 : BitcodeBytes(getNonStreamedMemoryObject(Start, End)), 273 : BitcodeBytes(getNonStreamedMemoryObject(Start, End)),
272 BlockInfoRecords(Reader->BlockInfoRecords), InitialAddress(0) 274 BlockInfoRecords(Reader->BlockInfoRecords), InitialAddress(0),
273 { BlockInfoRecords->freeze(); } 275 ErrorOffset(StartAddress) { BlockInfoRecords->freeze(); }
274 276
275 // Returns the memory object that is being read. 277 // Returns the memory object that is being read.
276 MemoryObject &getBitcodeBytes() { return *BitcodeBytes; } 278 MemoryObject &getBitcodeBytes() { return *BitcodeBytes; }
277 279
278 ~NaClBitstreamReader() {} 280 ~NaClBitstreamReader() {}
279 281
280 /// \brief Returns the initial address (after the header) of the input stream. 282 /// \brief Returns the initial address (after the header) of the input stream.
281 size_t getInitialAddress() const { 283 size_t getInitialAddress() const {
282 return InitialAddress; 284 return InitialAddress;
283 } 285 }
284 286
287 /// Returns the byte address of the first byte in the bitstream. Used
288 /// for error reporting.
289 size_t getErrorOffset() const { return ErrorOffset; }
290
285 //===--------------------------------------------------------------------===// 291 //===--------------------------------------------------------------------===//
286 // Block Manipulation 292 // Block Manipulation
287 //===--------------------------------------------------------------------===// 293 //===--------------------------------------------------------------------===//
288 294
289 BlockInfo *getBlockInfo(unsigned BlockID) { 295 BlockInfo *getBlockInfo(unsigned BlockID) {
290 return BlockInfoRecords->getBlockInfo(BlockID); 296 return BlockInfoRecords->getBlockInfo(BlockID);
291 } 297 }
292 }; 298 };
293 299
294 /// When advancing through a bitstream cursor, each advance can discover a few 300 /// When advancing through a bitstream cursor, each advance can discover a few
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 /// Return the number of bits used to encode an abbrev #. 534 /// Return the number of bits used to encode an abbrev #.
529 unsigned getAbbrevIDWidth() const { 535 unsigned getAbbrevIDWidth() const {
530 return BlockScope.back().getCodeAbbrev().NumBits; 536 return BlockScope.back().getCodeAbbrev().NumBits;
531 } 537 }
532 538
533 /// Return the bit # of the bit we are reading. 539 /// Return the bit # of the bit we are reading.
534 uint64_t GetCurrentBitNo() const { 540 uint64_t GetCurrentBitNo() const {
535 return NextChar*CHAR_BIT - BitsInCurWord; 541 return NextChar*CHAR_BIT - BitsInCurWord;
536 } 542 }
537 543
544 /// Converts the given position into the corresponding Error position.
545 uint64_t getErrorBitNo(uint64_t Position) const {
546 return BitStream->getErrorOffset() * CHAR_BIT + Position;
547 }
548
549 /// Returns the current bit address for reporting errors.
550 uint64_t getErrorBitNo() const {
551 return getErrorBitNo(GetCurrentBitNo());
552 }
553
538 NaClBitstreamReader *getBitStreamReader() { 554 NaClBitstreamReader *getBitStreamReader() {
539 return BitStream; 555 return BitStream;
540 } 556 }
541 const NaClBitstreamReader *getBitStreamReader() const { 557 const NaClBitstreamReader *getBitStreamReader() const {
542 return BitStream; 558 return BitStream;
543 } 559 }
544 560
545 /// Returns the current bit address (string) of the bit cursor. 561 /// Returns the current bit address (string) of the bit cursor.
546 std::string getCurrentBitAddress() const { 562 std::string getCurrentBitAddress() const {
547 return naclbitc::getBitAddress(GetCurrentBitNo()); 563 return naclbitc::getBitAddress(GetCurrentBitNo());
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord, 902 // Skips over an abbreviation record. Duplicates code of ReadAbbrevRecord,
887 // except that no abbreviation is built. 903 // except that no abbreviation is built.
888 void SkipAbbrevRecord(); 904 void SkipAbbrevRecord();
889 905
890 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener); 906 bool ReadBlockInfoBlock(NaClAbbrevListener *Listener);
891 }; 907 };
892 908
893 } // End llvm namespace 909 } // End llvm namespace
894 910
895 #endif 911 #endif
OLDNEW
« no previous file with comments | « no previous file | lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698