mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Support for IntToPtr and PtrToInt const copying
This commit is contained in:
parent
8d29a35947
commit
5a3c0eaf39
2 changed files with 43 additions and 0 deletions
|
@ -716,6 +716,29 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f
|
||||||
else
|
else
|
||||||
return CreateConstNull();
|
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
|
else
|
||||||
{
|
{
|
||||||
BF_FATAL("not handled");
|
BF_FATAL("not handled");
|
||||||
|
|
|
@ -10999,6 +10999,26 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con
|
||||||
return CreateTypeDataRef(constTypeOf->mType);
|
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)
|
if (constant->mConstType == BfConstType_Agg)
|
||||||
{
|
{
|
||||||
auto constArray = (BfConstantAgg*)constant;
|
auto constArray = (BfConstantAgg*)constant;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue