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

Unified Diff: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.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/NaClBitstreamReader.h ('k') | lib/Bitcode/NaCl/Analysis/NaClBitcodeAnalyzer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h
diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h
index 6b2a54351ce1b498375b5f478fcbe9eccbd2a05d..01c490627594fb4d7fcc017cb691243c514d9579 100644
--- a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h
+++ b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h
@@ -18,6 +18,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/NaCl/NaClBitCodes.h"
+#include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h"
#include <vector>
namespace llvm {
@@ -61,6 +62,9 @@ class NaClBitstreamWriter {
};
std::vector<BlockInfo> BlockInfoRecords;
+ // True if filler should be added to byte align records.
+ bool AlignBitcodeRecords = false;
+
/// AbbrevValues - Wrapper class that allows the bitstream writer to
/// prefix a code to the set of values, associated with a record to
/// emit, without having to destructively change the contents of
@@ -137,6 +141,10 @@ public:
}
}
+ void initFromHeader(const NaClBitcodeHeader &Header) {
+ AlignBitcodeRecords = Header.getAlignBitcodeRecords();
+ }
+
/// \brief Retrieve the current position in the stream, in bits.
uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; }
@@ -172,6 +180,17 @@ public:
}
}
+ void flushToByte() {
+ unsigned BitsToFlush = (32 - CurBit) % CHAR_BIT;
+ if (BitsToFlush)
+ Emit(0, BitsToFlush);
+ }
+
+ void flushToByteIfAligned() {
+ if (AlignBitcodeRecords)
+ flushToByte();
+ }
+
void FlushToWord() {
if (CurBit) {
WriteWord(CurValue);
@@ -416,12 +435,14 @@ public:
EmitVBR(static_cast<uint32_t>(Vals.size()), 6);
for (unsigned i = 0, e = static_cast<unsigned>(Vals.size()); i != e; ++i)
EmitVBR64(Vals[i], 6);
+ flushToByteIfAligned();
return;
}
// combine code and values, and then emit.
AbbrevValues<uintty> AbbrevVals(Code, Vals);
EmitRecordWithAbbrevImpl(Abbrev, AbbrevVals);
+ flushToByteIfAligned();
}
//===--------------------------------------------------------------------===//
@@ -446,6 +467,7 @@ private:
EmitVBR64(Op.getValue(), 5);
}
}
+ flushToByteIfAligned();
}
public:
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClBitstreamReader.h ('k') | lib/Bitcode/NaCl/Analysis/NaClBitcodeAnalyzer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698