diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index b078d51c..cc43725c 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -716,6 +716,29 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f else return CreateConstNull(); } + else if (fromConst->mConstType == BfConstType_PtrToInt) + { + auto fromPtrToInt = (BfConstantPtrToInt*)fromConst; + auto fromTarget = fromHolder->GetConstantById(fromPtrToInt->mTarget); + auto copiedTarget = CreateConst(fromTarget, fromHolder); + auto ptrToInt = mTempAlloc.Alloc(); + ptrToInt->mConstType = BfConstType_PtrToInt; + ptrToInt->mTarget = copiedTarget.mId; + ptrToInt->mToTypeCode = fromPtrToInt->mToTypeCode; + copiedConst = (BfConstant*)ptrToInt; + } + else if (fromConst->mConstType == BfConstType_IntToPtr) + { + auto fromPtrToInt = (BfConstantIntToPtr*)fromConst; + auto fromTarget = fromHolder->GetConstantById(fromPtrToInt->mTarget); + auto copiedTarget = CreateConst(fromTarget, fromHolder); + auto ptrToInt = mTempAlloc.Alloc(); + ptrToInt->mConstType = BfConstType_IntToPtr; + ptrToInt->mTarget = copiedTarget.mId; + ptrToInt->mToType = fromPtrToInt->mToType; + copiedConst = (BfConstant*)ptrToInt; + } + else { BF_FATAL("not handled"); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index f9a1d9cd..1b3558af 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -10999,6 +10999,26 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con return CreateTypeDataRef(constTypeOf->mType); } + if (constant->mConstType == BfConstType_PtrToInt) + { + auto fromPtrToInt = (BfConstantPtrToInt*)constant; + auto fromTarget = constHolder->GetConstantById(fromPtrToInt->mTarget); + return mBfIRBuilder->CreatePtrToInt(ConstantToCurrent(fromTarget, constHolder, NULL), fromPtrToInt->mToTypeCode); + } + + if (constant->mConstType == BfConstType_IntToPtr) + { + auto fromPtrToInt = (BfConstantIntToPtr*)constant; + auto fromTarget = constHolder->GetConstantById(fromPtrToInt->mTarget); + BfIRType toIRType = fromPtrToInt->mToType; + if (toIRType.mKind == BfIRTypeData::TypeKind_TypeId) + { + auto toType = mContext->mTypes[toIRType.mId]; + toIRType = mBfIRBuilder->MapType(toType); + } + return mBfIRBuilder->CreateIntToPtr(ConstantToCurrent(fromTarget, constHolder, NULL), toIRType); + } + if (constant->mConstType == BfConstType_Agg) { auto constArray = (BfConstantAgg*)constant;