Index: include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
index 550c8c8f5bccd4d1f4eab60b0a569c9f6dfe9fe5..99ce9ac75a25ed9fccc02246e7b2016cf78f067a 100644 |
--- a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
+++ b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
@@ -229,6 +229,11 @@ private: |
/// \brief Holds the offset of the first byte after the header. |
size_t InitialAddress; |
+ // Holds the number of bytes to add to the bitcode position, when |
+ // reporting errors. Useful when using parallel parses of function |
+ // blocks. |
+ size_t ErrorOffset; |
Jim Stichnoth
2016/04/01 23:52:30
Consider "size_t ErrorOffset = 0;" and then you ca
Karl
2016/04/02 17:16:50
Done.
|
+ |
// True if filler should be added to byte align records. |
bool AlignBitcodeRecords = false; |
NaClBitstreamReader(const NaClBitstreamReader&) = delete; |
@@ -246,31 +251,31 @@ public: |
NaClBitstreamReader(const unsigned char *Start, const unsigned char *End, |
NaClBitcodeHeader &Header) |
: BitcodeBytes(getNonStreamedMemoryObject(Start, End)), |
- BlockInfoRecords(BlockInfoRecordsMap::create()) { |
+ BlockInfoRecords(BlockInfoRecordsMap::create()), ErrorOffset(0) { |
initFromHeader(Header); |
} |
/// Read stream from Bytes, after parsing the given bitcode header. |
NaClBitstreamReader(MemoryObject *Bytes, NaClBitcodeHeader &Header) |
- : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()) { |
- initFromHeader(Header); |
+ : BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()), |
+ ErrorOffset(0) { initFromHeader(Header); |
} |
/// Read stream from bytes, starting at the given initial address. |
/// Provides simple API for unit testing. |
NaClBitstreamReader(MemoryObject *Bytes, size_t InitialAddress) |
: BitcodeBytes(Bytes), BlockInfoRecords(BlockInfoRecordsMap::create()), |
- InitialAddress(InitialAddress) { |
- } |
+ InitialAddress(InitialAddress), |
+ ErrorOffset(0) {} |
/// Read stream from sequence of bytes [Start .. End), using the global |
/// abbreviations of the given bitstream reader. Assumes that [Start .. End) |
/// is copied from Reader's memory object. |
- NaClBitstreamReader(const unsigned char *Start, |
+ NaClBitstreamReader(size_t StartAddress, const unsigned char *Start, |
const unsigned char *End, NaClBitstreamReader *Reader) |
: BitcodeBytes(getNonStreamedMemoryObject(Start, End)), |
- BlockInfoRecords(Reader->BlockInfoRecords), InitialAddress(0) |
- { BlockInfoRecords->freeze(); } |
+ BlockInfoRecords(Reader->BlockInfoRecords), InitialAddress(0), |
+ ErrorOffset(StartAddress) { BlockInfoRecords->freeze(); } |
// Returns the memory object that is being read. |
MemoryObject &getBitcodeBytes() { return *BitcodeBytes; } |
@@ -282,6 +287,10 @@ public: |
return InitialAddress; |
} |
+ /// Returns the byte address of the first byte in the bitstream. Used |
+ /// for error reporting. |
+ size_t getErrorOffset() const { return ErrorOffset; } |
+ |
//===--------------------------------------------------------------------===// |
// Block Manipulation |
//===--------------------------------------------------------------------===// |
@@ -535,6 +544,16 @@ public: |
return NextChar*CHAR_BIT - BitsInCurWord; |
} |
+ /// Converts the given position into the corresponding Error position. |
+ uint64_t getErrorBitNo(uint64_t Position) const { |
+ return BitStream->getErrorOffset() * CHAR_BIT + Position; |
+ } |
+ |
+ /// Returns the current bit address for reporting errors. |
+ uint64_t getErrorBitNo() const { |
+ return getErrorBitNo(GetCurrentBitNo()); |
+ } |
+ |
NaClBitstreamReader *getBitStreamReader() { |
return BitStream; |
} |