llvm.org GIT mirror llvm / d199fc5
Allow BackpatchWord to be called for non-32-bit aligned words, and from outside the BitstreamWriter. Split out of patch D12536 (Function bitcode index in Value Symbol Table and lazy reading support), which will use it to patch in the VST offset. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247847 91177308-0d34-0410-b5e6-96231b3b80d8 Teresa Johnson 5 years ago
1 changed file(s) with 19 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
6262 };
6363 std::vector BlockInfoRecords;
6464
65 // BackpatchWord - Backpatch a 32-bit word in the output with the specified
66 // value.
67 void BackpatchWord(unsigned ByteNo, unsigned NewWord) {
68 support::endian::write32le(&Out[ByteNo], NewWord);
69 }
70
7165 void WriteByte(unsigned char Value) {
7266 Out.push_back(Value);
7367 }
10397 //===--------------------------------------------------------------------===//
10498 // Basic Primitives for emitting bits to the stream.
10599 //===--------------------------------------------------------------------===//
100
101 /// Backpatch a 32-bit word in the output at the given bit offset
102 /// with the specified value.
103 void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
104 unsigned ByteNo = BitNo / 8;
105 if ((BitNo & 7) == 0) {
106 // Already 8-bit aligned
107 support::endian::write32le(&Out[ByteNo], NewWord);
108 } else {
109 uint64_t CurDWord = support::endian::read64le(&Out[ByteNo]);
110 unsigned StartBit = BitNo & 7;
111 // Currently expect to backpatch 0-value placeholders.
112 assert(((CurDWord >> StartBit) & 0xffffffff) == 0);
113 CurDWord |= NewWord << StartBit;
114 support::endian::write64le(&Out[ByteNo], CurDWord);
115 }
116 }
106117
107118 void Emit(uint32_t Val, unsigned NumBits) {
108119 assert(NumBits && NumBits <= 32 && "Invalid value size!");
233244
234245 // Compute the size of the block, in words, not counting the size field.
235246 unsigned SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
236 unsigned ByteNo = B.StartSizeWord*4;
247 uint64_t BitNo = B.StartSizeWord * 32;
237248
238249 // Update the block size field in the header of this sub-block.
239 BackpatchWord(ByteNo, SizeInWords);
250 BackpatchWord(BitNo, SizeInWords);
240251
241252 // Restore the inner block's code size and abbrev table.
242253 CurCodeSize = B.PrevCodeSize;