@@ -234,35 +234,26 @@ class lifterMemoryBuffer {
234
234
}
235
235
236
236
private:
237
- Value* extractBytes (IRBuilder<>& builder, Value* value, uint64_t startOffset,
238
- uint64_t endOffset) {
237
+ Value* extractBytes (IRBuilder<>& builder, Value* value, uint64_t startOffset, uint64_t endOffset) {
239
238
LLVMContext& context = builder.getContext ();
240
-
241
- if (!value) {
242
- return ConstantInt::get (
243
- Type::getIntNTy (context, (endOffset - startOffset) * 8 ), 0 );
244
- }
245
-
246
239
uint64_t byteCount = endOffset - startOffset;
240
+ Type* resultType = Type::getIntNTy (context, byteCount * 8 );
247
241
248
- uint64_t shiftAmount = startOffset * 8 ;
249
-
250
- printvalue2 (endOffset);
242
+ printvalue (value);
251
243
252
- printvalue2 (startOffset);
253
- printvalue2 (byteCount);
254
- printvalue2 (shiftAmount);
244
+ // Shift right if needed
245
+ if (startOffset > 0 ) {
246
+ uint64_t shiftAmount = startOffset * 8 ;
247
+ value = createLShrFolder (builder, value, APInt (value->getType ()->getIntegerBitWidth (), shiftAmount), " shiftedValue" );
248
+ }
255
249
256
- Value* shiftedValue = createLShrFolder (
257
- builder, value,
258
- APInt (value->getType ()->getIntegerBitWidth (), shiftAmount),
259
- " extractbytes" );
260
250
printvalue (value);
261
- printvalue (shiftedValue);
262
251
263
- Value* truncatedValue = createTruncFolder (
264
- builder, shiftedValue, Type::getIntNTy (context, byteCount * 8 ));
265
- return truncatedValue;
252
+ // Extend or truncate to the required size
253
+ value = createZExtOrTruncFolder (builder, value, resultType);
254
+
255
+ printvalue (value);
256
+ return value;
266
257
}
267
258
};
268
259
0 commit comments