@@ -129,20 +129,20 @@ class BitstreamWriter {
129
129
// Basic Primitives for emitting bits to the stream.
130
130
// ===--------------------------------------------------------------------===//
131
131
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 ) {
135
135
using namespace llvm ::support;
136
136
uint64_t ByteNo = BitNo / 8 ;
137
137
uint64_t StartBit = BitNo & 7 ;
138
138
uint64_t NumOfFlushedBytes = GetNumOfFlushedBytes ();
139
139
140
140
if (ByteNo >= NumOfFlushedBytes) {
141
- assert ((!endian::readAtBitAlignment<uint32_t , little, unaligned>(
141
+ assert ((!endian::readAtBitAlignment<uint8_t , little, unaligned>(
142
142
&Out[ByteNo - NumOfFlushedBytes], StartBit)) &&
143
143
" 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);
146
146
return ;
147
147
}
148
148
@@ -151,8 +151,8 @@ class BitstreamWriter {
151
151
uint64_t CurPos = FS->tell ();
152
152
153
153
// 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 ;
156
156
size_t BytesFromDisk = std::min (static_cast <uint64_t >(BytesNum), NumOfFlushedBytes - ByteNo);
157
157
size_t BytesFromBuffer = BytesNum - BytesFromDisk;
158
158
@@ -170,14 +170,14 @@ class BitstreamWriter {
170
170
assert (BytesRead >= 0 && static_cast <size_t >(BytesRead) == BytesFromDisk);
171
171
for (size_t i = 0 ; i < BytesFromBuffer; ++i)
172
172
Bytes[BytesFromDisk + i] = Out[i];
173
- assert ((!endian::readAtBitAlignment<uint32_t , little, unaligned>(
173
+ assert ((!endian::readAtBitAlignment<uint8_t , little, unaligned>(
174
174
Bytes, StartBit)) &&
175
175
" Expected to be patching over 0-value placeholders" );
176
176
}
177
177
178
178
// 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);
181
181
182
182
// Copy updated data back to the file FS and the buffer Out.
183
183
FS->seek (ByteNo);
@@ -189,6 +189,16 @@ class BitstreamWriter {
189
189
FS->seek (CurPos);
190
190
}
191
191
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
+
192
202
void BackpatchWord64 (uint64_t BitNo, uint64_t Val) {
193
203
BackpatchWord (BitNo, (uint32_t )Val);
194
204
BackpatchWord (BitNo + 32 , (uint32_t )(Val >> 32 ));
0 commit comments