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

Unified Diff: include/llvm/Bitcode/NaCl/NaClBitstreamReader.h

Issue 1122423005: Add (unsupported experimental) feature allowing byte aligned bitcode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h ('k') | include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f73b1bc2f4595526fdc8246f339b6299b40f206d 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,39 @@ 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) {
+ 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) {
}
+ // Returns the memory object that is being read.
MemoryObject &getBitcodeBytes() { return *BitcodeBytes; }
~NaClBitstreamReader() {
@@ -516,6 +531,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.
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h ('k') | include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698