1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Support for IntToPtr and PtrToInt const copying

This commit is contained in:
Brian Fiete 2021-11-14 18:23:48 -08:00
parent 8d29a35947
commit 5a3c0eaf39
2 changed files with 43 additions and 0 deletions

View file

@ -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<BfConstantPtrToInt>();
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<BfConstantIntToPtr>();
ptrToInt->mConstType = BfConstType_IntToPtr;
ptrToInt->mTarget = copiedTarget.mId;
ptrToInt->mToType = fromPtrToInt->mToType;
copiedConst = (BfConstant*)ptrToInt;
}
else
{
BF_FATAL("not handled");

View file

@ -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;