mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
More support for bitcasts with consts
This commit is contained in:
parent
0ee161c314
commit
def7990dbe
4 changed files with 47 additions and 24 deletions
|
@ -857,6 +857,26 @@ BfIRValue BfIRConstHolder::CreateConstArrayZero(int count)
|
|||
return irValue;
|
||||
}
|
||||
|
||||
BfIRValue BfIRConstHolder::CreateConstBitCast(BfIRValue val, BfIRType type)
|
||||
{
|
||||
auto constVal = GetConstant(val);
|
||||
|
||||
auto bitCast = mTempAlloc.Alloc<BfConstantBitCast>();
|
||||
if ((constVal == NULL) || (constVal->IsNull()))
|
||||
bitCast->mConstType = BfConstType_BitCastNull;
|
||||
else
|
||||
bitCast->mConstType = BfConstType_BitCast;
|
||||
bitCast->mTarget = val.mId;
|
||||
bitCast->mToType = type;
|
||||
|
||||
BfIRValue castedVal(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(bitCast));
|
||||
#ifdef CHECK_CONSTHOLDER
|
||||
castedVal.mHolder = this;
|
||||
#endif
|
||||
BF_ASSERT((void*)GetConstant(castedVal) == (void*)bitCast);
|
||||
return castedVal;
|
||||
}
|
||||
|
||||
BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type)
|
||||
{
|
||||
BfTypeOf_Const* typeOf = mTempAlloc.Alloc<BfTypeOf_Const>();
|
||||
|
@ -4414,25 +4434,7 @@ BfIRValue BfIRBuilder::CreateNot(BfIRValue val)
|
|||
BfIRValue BfIRBuilder::CreateBitCast(BfIRValue val, BfIRType type)
|
||||
{
|
||||
if (val.IsConst())
|
||||
{
|
||||
auto constVal = GetConstant(val);
|
||||
|
||||
auto bitCast = mTempAlloc.Alloc<BfConstantBitCast>();
|
||||
if (constVal->IsNull())
|
||||
bitCast->mConstType = BfConstType_BitCastNull;
|
||||
else
|
||||
bitCast->mConstType = BfConstType_BitCast;
|
||||
bitCast->mTarget = val.mId;
|
||||
bitCast->mToType = type;
|
||||
|
||||
BfIRValue castedVal(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(bitCast));
|
||||
#ifdef CHECK_CONSTHOLDER
|
||||
castedVal.mHolder = this;
|
||||
#endif
|
||||
BF_ASSERT((void*)GetConstant(castedVal) == (void*)bitCast);
|
||||
return castedVal;
|
||||
}
|
||||
|
||||
return CreateConstBitCast(val, type);
|
||||
auto retVal = WriteCmd(BfIRCmd_BitCast, val, type);
|
||||
NEW_CMD_INSERTED_IRVALUE;
|
||||
return retVal;
|
||||
|
|
|
@ -934,6 +934,7 @@ public:
|
|||
BfIRValue CreateConstAggCE(BfIRType type, addr_ce ptr);
|
||||
BfIRValue CreateConstArrayZero(BfIRType type, int count);
|
||||
BfIRValue CreateConstArrayZero(int count);
|
||||
BfIRValue CreateConstBitCast(BfIRValue val, BfIRType type);
|
||||
BfIRValue CreateTypeOf(BfType* type);
|
||||
BfIRValue CreateTypeOf(BfType* type, BfIRValue typeData);
|
||||
BfIRValue GetUndefConstValue(BfIRType type);
|
||||
|
|
|
@ -10874,7 +10874,14 @@ void BfModule::CurrentAddToConstHolder(BfIRValue& irVal)
|
|||
if ((constant->mConstType == BfConstType_BitCast) || (constant->mConstType == BfConstType_BitCastNull))
|
||||
{
|
||||
auto bitcast = (BfConstantBitCast*)constant;
|
||||
constant = mBfIRBuilder->GetConstantById(bitcast->mTarget);
|
||||
BfIRValue newVal;
|
||||
if (bitcast->mTarget)
|
||||
{
|
||||
newVal = BfIRValue(BfIRValueFlags_Const, bitcast->mTarget);
|
||||
CurrentAddToConstHolder(newVal);
|
||||
}
|
||||
irVal = mCurTypeInstance->GetOrCreateConstHolder()->CreateConstBitCast(newVal, bitcast->mToType);
|
||||
return;
|
||||
}
|
||||
|
||||
irVal = mCurTypeInstance->CreateConst(constant, mBfIRBuilder);
|
||||
|
@ -10999,7 +11006,7 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con
|
|||
wantType = mContext->mTypes[constant->mIRType.mId];
|
||||
|
||||
if (wantType == NULL)
|
||||
return constHolder->CreateConstNull();
|
||||
return mBfIRBuilder->CreateConstNull();
|
||||
|
||||
return GetDefaultValue(wantType);
|
||||
}
|
||||
|
@ -11047,6 +11054,19 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con
|
|||
return mBfIRBuilder->CreateIntToPtr(ConstantToCurrent(fromTarget, constHolder, NULL), toIRType);
|
||||
}
|
||||
|
||||
if ((constant->mConstType == BfConstType_BitCast) || (constant->mConstType == BfConstType_BitCastNull))
|
||||
{
|
||||
auto bitcast = (BfConstantBitCast*)constant;
|
||||
auto fromTarget = constHolder->GetConstantById(bitcast->mTarget);
|
||||
BfIRType toIRType = bitcast->mToType;
|
||||
if (toIRType.mKind == BfIRTypeData::TypeKind_TypeId)
|
||||
{
|
||||
auto toType = mContext->mTypes[toIRType.mId];
|
||||
toIRType = mBfIRBuilder->MapType(toType);
|
||||
}
|
||||
return mBfIRBuilder->CreateBitCast(ConstantToCurrent(fromTarget, constHolder, NULL), toIRType);
|
||||
}
|
||||
|
||||
if (constant->mConstType == BfConstType_Agg)
|
||||
{
|
||||
auto constArray = (BfConstantAgg*)constant;
|
||||
|
|
|
@ -11811,7 +11811,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
|
||||
if (allowCast)
|
||||
{
|
||||
if (ignoreWrites)
|
||||
if ((ignoreWrites) && (!typedVal.mValue.IsConst()))
|
||||
return mBfIRBuilder->GetFakeVal();
|
||||
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue