diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index d8ee125c..b89ea446 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -5624,13 +5624,7 @@ BfTypedValue BfExprEvaluator::MatchConstructor(BfAstNode* targetSrc, BfMethodBou resolvedArg.mTypedValue = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), intPtrType); } 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"); } } @@ -16589,10 +16583,11 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr, BfPointerType* ptrType = (BfPointerType*)ptr.mType; BfType* intPtrType = mModule->GetPrimitiveType(BfTypeCode_IntPtr); constValue = mModule->GetConstValue(ptrType->mElementType->GetStride(), intPtrType); - - BfIRValue origIntValue = mModule->mBfIRBuilder->CreatePtrToInt(origVal, BfTypeCode_IntPtr); - BfIRValue newIntValue = mModule->mBfIRBuilder->CreateAdd(origIntValue, constValue/*, "inc"*/); - resultValue = mModule->mBfIRBuilder->CreateIntToPtr(newIntValue, mModule->mBfIRBuilder->MapType(ptr.mType)); + + auto i8PtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8)); + BfIRValue origPtrValue = mModule->mBfIRBuilder->CreateBitCast(origVal, i8PtrType); + BfIRValue newPtrValue = mModule->mBfIRBuilder->CreateInBoundsGEP(origPtrValue, constValue); + resultValue = mModule->mBfIRBuilder->CreateBitCast(newPtrValue, mModule->mBfIRBuilder->MapType(ptr.mType)); } else { @@ -16640,11 +16635,12 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr, { BfPointerType* ptrType = (BfPointerType*)ptr.mType; 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); - BfIRValue newIntValue = mModule->mBfIRBuilder->CreateSub(origIntValue, constValue); - resultValue = mModule->mBfIRBuilder->CreateIntToPtr(newIntValue, mModule->mBfIRBuilder->MapType(ptr.mType)); + auto i8PtrType = mModule->mBfIRBuilder->GetPointerTo(mModule->mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8)); + BfIRValue origPtrValue = mModule->mBfIRBuilder->CreateBitCast(origVal, i8PtrType); + BfIRValue newPtrValue = mModule->mBfIRBuilder->CreateInBoundsGEP(origPtrValue, constValue); + resultValue = mModule->mBfIRBuilder->CreateBitCast(newPtrValue, mModule->mBfIRBuilder->MapType(ptr.mType)); } else { @@ -17781,6 +17777,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod addValue = mModule->mBfIRBuilder->CreateNeg(addValue); } + mModule->PopulateType(underlyingType); if (underlyingType->IsValuelessType()) { if (!mModule->IsInSpecializedSection()) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 78dc1880..a766de23 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -10665,9 +10665,10 @@ BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, BfI auto ptrType = CreatePointerType(elementType); auto ofsVal = mBfIRBuilder->CreateNumericCast(indexValue, true, BfTypeCode_IntPtr); auto ofsScaledVal = mBfIRBuilder->CreateMul(ofsVal, mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, elementType->GetStride())); - auto intVal = mBfIRBuilder->CreatePtrToInt(value, BfTypeCode_IntPtr); - auto newIntVal = mBfIRBuilder->CreateAdd(intVal, ofsScaledVal); - return mBfIRBuilder->CreateIntToPtr(newIntVal, mBfIRBuilder->MapType(ptrType)); + auto i8PtrType = mBfIRBuilder->GetPointerTo(mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8)); + BfIRValue origPtrValue = mBfIRBuilder->CreateBitCast(value, i8PtrType); + BfIRValue newPtrValue = mBfIRBuilder->CreateInBoundsGEP(origPtrValue, ofsScaledVal); + return mBfIRBuilder->CreateBitCast(newPtrValue, mBfIRBuilder->MapType(ptrType)); } BfIRValue BfModule::CreateIndexedValue(BfType* elementType, BfIRValue value, int indexValue, bool isElementIndex)