Chromium Code Reviews| Index: include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| index db6eb6080b730e283e70a16615ff0fa1497d0f81..d9898c71fa37b74a68844c5e66b55c4a6dab303f 100644 |
| --- a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| +++ b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h |
| @@ -17,6 +17,7 @@ |
| #define LLVM_BITCODE_NACL_NACLBITSTREAMREADER_H |
| #include "llvm/ADT/SmallVector.h" |
| +#include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" |
| #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" |
| #include "llvm/Support/Endian.h" |
| #include "llvm/Support/StreamingMemoryObject.h" |
| @@ -61,6 +62,8 @@ public: |
| std::vector<NaClBitCodeAbbrev*> Abbrevs; |
| }; |
| private: |
| + friend class NaClBitstreamCursor; |
| + |
| std::unique_ptr<MemoryObject> BitcodeBytes; |
| std::vector<BlockInfo> BlockInfoRecords; |
| @@ -68,27 +71,40 @@ private: |
| /// \brief Holds the offset of the first byte after the header. |
| size_t InitialAddress; |
| + // True if filler should be added to byte align records. |
| + bool AlignBitcodeRecords = false; |
| + |
| NaClBitstreamReader(const NaClBitstreamReader&) LLVM_DELETED_FUNCTION; |
| void operator=(const NaClBitstreamReader&) LLVM_DELETED_FUNCTION; |
| -public: |
| - NaClBitstreamReader() : InitialAddress(0) {} |
| + void initFromHeader(NaClBitcodeHeader &Header) { |
| + InitialAddress = Header.getHeaderSize(); |
| + AlignBitcodeRecords = Header.getAlignBitcodeRecords(); |
| + } |
| + |
| +public: |
| + /// Read stream from sequence of bytes [Start .. End) after parsing |
| + /// the given bitcode header. |
| NaClBitstreamReader(const unsigned char *Start, const unsigned char *End, |
| - size_t MyInitialAddress=0) { |
| - InitialAddress = MyInitialAddress; |
| - init(Start, End); |
| + NaClBitcodeHeader &Header) |
| + : BitcodeBytes(getNonStreamedMemoryObject(Start, End)) { |
| + initFromHeader(Header); |
| } |
| - NaClBitstreamReader(MemoryObject *Bytes, size_t MyInitialAddress=0) |
| - : InitialAddress(MyInitialAddress) { |
| - BitcodeBytes.reset(Bytes); |
| + /// Read stream from Bytes, after parsing the given bitcode header. |
| + NaClBitstreamReader(MemoryObject *Bytes, NaClBitcodeHeader &Header) |
| + : BitcodeBytes(Bytes) |
| + { |
|
jvoung (off chromium)
2015/05/11 17:51:39
nit: seems like the other cases put the { on the p
Karl
2015/05/11 19:41:09
Done.
|
| + initFromHeader(Header); |
| } |
| - void init(const unsigned char *Start, const unsigned char *End) { |
| - assert(((End-Start) & 3) == 0 &&"Bitcode stream not a multiple of 4 bytes"); |
| - BitcodeBytes.reset(getNonStreamedMemoryObject(Start, End)); |
| + /// Read stream from bytes, starting at the given initial address. |
| + /// Provides simple API for unit testing. |
| + NaClBitstreamReader(MemoryObject *Bytes, size_t InitialAddress) |
| + : BitcodeBytes(Bytes), InitialAddress(InitialAddress) { |
| } |
| + // Read stream from Bytes, starting at the given initial address |
|
jvoung (off chromium)
2015/05/11 17:51:39
ctor-like comment for non-ctor?
Karl
2015/05/11 19:41:09
Done.
|
| MemoryObject &getBitcodeBytes() { return *BitcodeBytes; } |
| ~NaClBitstreamReader() { |
| @@ -516,6 +532,19 @@ public: |
| } |
| private: |
| + void SkipToByteBoundary() { |
| + unsigned BitsToSkip = BitsInCurWord % CHAR_BIT; |
| + if (BitsToSkip) { |
| + CurWord >>= BitsToSkip; |
| + BitsInCurWord -= BitsToSkip; |
| + } |
| + } |
| + |
| + void SkipToByteBoundaryIfAligned() { |
| + if (BitStream->AlignBitcodeRecords) |
| + SkipToByteBoundary(); |
| + } |
| + |
| void SkipToFourByteBoundary() { |
| // If word_t is 64-bits and if we've read less than 32 bits, just dump |
| // the bits we have up to the next 32-bit boundary. |