@@ -129,20 +129,20 @@ class BitstreamWriter {
129129 // Basic Primitives for emitting bits to the stream.
130130 // ===--------------------------------------------------------------------===//
131131
132- // / Backpatch a 32-bit word in the output at the given bit offset
133- // / with the specified value.
134- void BackpatchWord (uint64_t BitNo, unsigned NewWord ) {
132+ // / Backpatch a byte in the output at the given bit offset with the specified
133+ // / value.
134+ void BackpatchByte (uint64_t BitNo, uint8_t NewByte ) {
135135 using namespace llvm ::support;
136136 uint64_t ByteNo = BitNo / 8 ;
137137 uint64_t StartBit = BitNo & 7 ;
138138 uint64_t NumOfFlushedBytes = GetNumOfFlushedBytes ();
139139
140140 if (ByteNo >= NumOfFlushedBytes) {
141- assert ((!endian::readAtBitAlignment<uint32_t , little, unaligned>(
141+ assert ((!endian::readAtBitAlignment<uint8_t , little, unaligned>(
142142 &Out[ByteNo - NumOfFlushedBytes], StartBit)) &&
143143 " Expected to be patching over 0-value placeholders" );
144- endian::writeAtBitAlignment<uint32_t , little, unaligned>(
145- &Out[ByteNo - NumOfFlushedBytes], NewWord , StartBit);
144+ endian::writeAtBitAlignment<uint8_t , little, unaligned>(
145+ &Out[ByteNo - NumOfFlushedBytes], NewByte , StartBit);
146146 return ;
147147 }
148148
@@ -151,8 +151,8 @@ class BitstreamWriter {
151151 uint64_t CurPos = FS->tell ();
152152
153153 // Copy data to update into Bytes from the file FS and the buffer Out.
154- char Bytes[9 ]; // Use one more byte to silence a warning from Visual C++.
155- size_t BytesNum = StartBit ? 8 : 4 ;
154+ char Bytes[3 ]; // Use one more byte to silence a warning from Visual C++.
155+ size_t BytesNum = StartBit ? 2 : 1 ;
156156 size_t BytesFromDisk = std::min (static_cast <uint64_t >(BytesNum), NumOfFlushedBytes - ByteNo);
157157 size_t BytesFromBuffer = BytesNum - BytesFromDisk;
158158
@@ -170,14 +170,14 @@ class BitstreamWriter {
170170 assert (BytesRead >= 0 && static_cast <size_t >(BytesRead) == BytesFromDisk);
171171 for (size_t i = 0 ; i < BytesFromBuffer; ++i)
172172 Bytes[BytesFromDisk + i] = Out[i];
173- assert ((!endian::readAtBitAlignment<uint32_t , little, unaligned>(
173+ assert ((!endian::readAtBitAlignment<uint8_t , little, unaligned>(
174174 Bytes, StartBit)) &&
175175 " Expected to be patching over 0-value placeholders" );
176176 }
177177
178178 // Update Bytes in terms of bit offset and value.
179- endian::writeAtBitAlignment<uint32_t , little, unaligned>(Bytes, NewWord ,
180- StartBit);
179+ endian::writeAtBitAlignment<uint8_t , little, unaligned>(Bytes, NewByte ,
180+ StartBit);
181181
182182 // Copy updated data back to the file FS and the buffer Out.
183183 FS->seek (ByteNo);
@@ -189,6 +189,16 @@ class BitstreamWriter {
189189 FS->seek (CurPos);
190190 }
191191
192+ void BackpatchHalfWord (uint64_t BitNo, uint16_t Val) {
193+ BackpatchByte (BitNo, (uint8_t )Val);
194+ BackpatchByte (BitNo + 8 , (uint8_t )(Val >> 8 ));
195+ }
196+
197+ void BackpatchWord (uint64_t BitNo, unsigned Val) {
198+ BackpatchHalfWord (BitNo, (uint16_t )Val);
199+ BackpatchHalfWord (BitNo + 16 , (uint16_t )(Val >> 16 ));
200+ }
201+
192202 void BackpatchWord64 (uint64_t BitNo, uint64_t Val) {
193203 BackpatchWord (BitNo, (uint32_t )Val);
194204 BackpatchWord (BitNo + 32 , (uint32_t )(Val >> 32 ));
0 commit comments