Skip to content

Refactor extractBytes function to handle various input sizes correctly #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions lifter/GEPTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,35 +234,26 @@ class lifterMemoryBuffer {
}

private:
Value* extractBytes(IRBuilder<>& builder, Value* value, uint64_t startOffset,
uint64_t endOffset) {
Value* extractBytes(IRBuilder<>& builder, Value* value, uint64_t startOffset, uint64_t endOffset) {
LLVMContext& context = builder.getContext();

if (!value) {
return ConstantInt::get(
Type::getIntNTy(context, (endOffset - startOffset) * 8), 0);
}

uint64_t byteCount = endOffset - startOffset;
Type* resultType = Type::getIntNTy(context, byteCount * 8);

uint64_t shiftAmount = startOffset * 8;

printvalue2(endOffset);
printvalue(value);

printvalue2(startOffset);
printvalue2(byteCount);
printvalue2(shiftAmount);
// Shift right if needed
if (startOffset > 0) {
uint64_t shiftAmount = startOffset * 8;
value = createLShrFolder(builder, value, APInt(value->getType()->getIntegerBitWidth(), shiftAmount), "shiftedValue");
}

Value* shiftedValue = createLShrFolder(
builder, value,
APInt(value->getType()->getIntegerBitWidth(), shiftAmount),
"extractbytes");
printvalue(value);
printvalue(shiftedValue);

Value* truncatedValue = createTruncFolder(
builder, shiftedValue, Type::getIntNTy(context, byteCount * 8));
return truncatedValue;
// Extend or truncate to the required size
value = createZExtOrTruncFolder(builder, value, resultType);

printvalue(value);
return value;
}
};

Expand Down