mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Reworked some pointer arithmetic to use gep instead of ptrtoint
This commit is contained in:
parent
8171c842f0
commit
093ae8f9c1
2 changed files with 16 additions and 18 deletions
|
@ -5624,13 +5624,7 @@ BfTypedValue BfExprEvaluator::MatchConstructor(BfAstNode* targetSrc, BfMethodBou
|
||||||
resolvedArg.mTypedValue = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), intPtrType);
|
resolvedArg.mTypedValue = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), intPtrType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// auto thisVal = target;
|
|
||||||
// BfIRValue intPtrVal = mModule->CreateAlloca(intPtrType);
|
|
||||||
// auto intPtrThisVal = mModule->mBfIRBuilder->CreatePtrToInt(thisVal.mValue, (intPtrType->mSize == 4) ? BfTypeCode_Int32 : BfTypeCode_Int64);
|
|
||||||
// auto curValPtr = mModule->mBfIRBuilder->CreateAdd(intPtrThisVal, mModule->GetConstValue(targetType->mInstSize, intPtrType));
|
|
||||||
// mModule->mBfIRBuilder->CreateStore(curValPtr, intPtrVal);
|
|
||||||
// resolvedArg.mTypedValue = BfTypedValue(intPtrVal, intPtrRefType);
|
|
||||||
BF_FATAL("Bad");
|
BF_FATAL("Bad");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16589,10 +16583,11 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
|
||||||
BfPointerType* ptrType = (BfPointerType*)ptr.mType;
|
BfPointerType* ptrType = (BfPointerType*)ptr.mType;
|
||||||
BfType* intPtrType = mModule->GetPrimitiveType(BfTypeCode_IntPtr);
|
BfType* intPtrType = mModule->GetPrimitiveType(BfTypeCode_IntPtr);
|
||||||
constValue = mModule->GetConstValue(ptrType->mElementType->GetStride(), intPtrType);
|
constValue = mModule->GetConstValue(ptrType->mElementType->GetStride(), intPtrType);
|
||||||
|
|
||||||
BfIRValue origIntValue = mModule->mBfIRBuilder->CreatePtrToInt(origVal, BfTypeCode_IntPtr);
|
auto i8PtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8));
|
||||||
BfIRValue newIntValue = mModule->mBfIRBuilder->CreateAdd(origIntValue, constValue/*, "inc"*/);
|
BfIRValue origPtrValue = mModule->mBfIRBuilder->CreateBitCast(origVal, i8PtrType);
|
||||||
resultValue = mModule->mBfIRBuilder->CreateIntToPtr(newIntValue, mModule->mBfIRBuilder->MapType(ptr.mType));
|
BfIRValue newPtrValue = mModule->mBfIRBuilder->CreateInBoundsGEP(origPtrValue, constValue);
|
||||||
|
resultValue = mModule->mBfIRBuilder->CreateBitCast(newPtrValue, mModule->mBfIRBuilder->MapType(ptr.mType));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -16640,11 +16635,12 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
|
||||||
{
|
{
|
||||||
BfPointerType* ptrType = (BfPointerType*)ptr.mType;
|
BfPointerType* ptrType = (BfPointerType*)ptr.mType;
|
||||||
BfType* intPtrType = mModule->GetPrimitiveType(BfTypeCode_IntPtr);
|
BfType* intPtrType = mModule->GetPrimitiveType(BfTypeCode_IntPtr);
|
||||||
constValue = mModule->GetConstValue(ptrType->mElementType->GetStride(), intPtrType);
|
constValue = mModule->GetConstValue(-ptrType->mElementType->GetStride(), intPtrType);
|
||||||
|
|
||||||
BfIRValue origIntValue = mModule->mBfIRBuilder->CreatePtrToInt(origVal, BfTypeCode_IntPtr);
|
auto i8PtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8));
|
||||||
BfIRValue newIntValue = mModule->mBfIRBuilder->CreateSub(origIntValue, constValue);
|
BfIRValue origPtrValue = mModule->mBfIRBuilder->CreateBitCast(origVal, i8PtrType);
|
||||||
resultValue = mModule->mBfIRBuilder->CreateIntToPtr(newIntValue, mModule->mBfIRBuilder->MapType(ptr.mType));
|
BfIRValue newPtrValue = mModule->mBfIRBuilder->CreateInBoundsGEP(origPtrValue, constValue);
|
||||||
|
resultValue = mModule->mBfIRBuilder->CreateBitCast(newPtrValue, mModule->mBfIRBuilder->MapType(ptr.mType));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -17781,6 +17777,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
addValue = mModule->mBfIRBuilder->CreateNeg(addValue);
|
addValue = mModule->mBfIRBuilder->CreateNeg(addValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mModule->PopulateType(underlyingType);
|
||||||
if (underlyingType->IsValuelessType())
|
if (underlyingType->IsValuelessType())
|
||||||
{
|
{
|
||||||
if (!mModule->IsInSpecializedSection())
|
if (!mModule->IsInSpecializedSection())
|
||||||
|
|
|
@ -10665,9 +10665,10 @@ BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, BfI
|
||||||
auto ptrType = CreatePointerType(elementType);
|
auto ptrType = CreatePointerType(elementType);
|
||||||
auto ofsVal = mBfIRBuilder->CreateNumericCast(indexValue, true, BfTypeCode_IntPtr);
|
auto ofsVal = mBfIRBuilder->CreateNumericCast(indexValue, true, BfTypeCode_IntPtr);
|
||||||
auto ofsScaledVal = mBfIRBuilder->CreateMul(ofsVal, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, elementType->GetStride()));
|
auto ofsScaledVal = mBfIRBuilder->CreateMul(ofsVal, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, elementType->GetStride()));
|
||||||
auto intVal = mBfIRBuilder->CreatePtrToInt(value, BfTypeCode_IntPtr);
|
auto i8PtrType = mBfIRBuilder->GetPointerTo(mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8));
|
||||||
auto newIntVal = mBfIRBuilder->CreateAdd(intVal, ofsScaledVal);
|
BfIRValue origPtrValue = mBfIRBuilder->CreateBitCast(value, i8PtrType);
|
||||||
return mBfIRBuilder->CreateIntToPtr(newIntVal, mBfIRBuilder->MapType(ptrType));
|
BfIRValue newPtrValue = mBfIRBuilder->CreateInBoundsGEP(origPtrValue, ofsScaledVal);
|
||||||
|
return mBfIRBuilder->CreateBitCast(newPtrValue, mBfIRBuilder->MapType(ptrType));
|
||||||
}
|
}
|
||||||
|
|
||||||
BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, int indexValue, bool isElementIndex)
|
BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, int indexValue, bool isElementIndex)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue