mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Allow explicit bool-to-number casts
This commit is contained in:
parent
5c2e0d86c0
commit
d4c78c0799
3 changed files with 10 additions and 8 deletions
|
@ -3734,7 +3734,7 @@ BeMCOperand BeMCContext::AllocVirtualReg(BeType* type, int refCount, bool mustBe
|
|||
|
||||
if (mDebugging)
|
||||
{
|
||||
if (mcOperand.mVRegIdx == 29)
|
||||
if (mcOperand.mVRegIdx == 9)
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
@ -10267,7 +10267,7 @@ bool BeMCContext::DoLegalization()
|
|||
|
||||
}
|
||||
|
||||
if ((arg0Type->IsFloat()) && (arg1Type->IsInt()))
|
||||
if ((arg0Type->IsFloat()) && (arg1Type->IsIntable()))
|
||||
{
|
||||
if ((arg1Type->mTypeCode == BeTypeCode_Int64) && (!isSignedExt))
|
||||
{
|
||||
|
@ -15792,7 +15792,7 @@ void BeMCContext::Generate(BeFunction* function)
|
|||
auto toType = castedInst->mToType;
|
||||
auto toValue = AllocVirtualReg(castedInst->mToType);
|
||||
CreateDefineVReg(toValue);
|
||||
if ((toType->IsInt()) && (fromType->IsInt()) && (toType->mSize < fromType->mSize))
|
||||
if ((toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize < fromType->mSize))
|
||||
{
|
||||
// For truncating values, no actual instructions are needed, so we can just do a vreg relto ref
|
||||
auto vregInfo = mVRegInfo[toValue.mVRegIdx];
|
||||
|
@ -15801,8 +15801,8 @@ void BeMCContext::Generate(BeFunction* function)
|
|||
}
|
||||
else
|
||||
{
|
||||
bool doSignExtension = (toType->IsInt()) && (fromType->IsInt()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);
|
||||
if ((toType->IsFloat()) && (fromType->IsInt()) && (castedInst->mValSigned))
|
||||
bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);
|
||||
if ((toType->IsFloat()) && (fromType->IsIntable()) && (castedInst->mValSigned))
|
||||
doSignExtension = true;
|
||||
if (doSignExtension)
|
||||
{
|
||||
|
|
|
@ -466,6 +466,8 @@ BfTypeCode BfIRCodeGen::GetTypeCode(llvm::Type* type, bool isSigned)
|
|||
{
|
||||
switch (type->getIntegerBitWidth())
|
||||
{
|
||||
case 1:
|
||||
return BfTypeCode_Boolean;
|
||||
case 8:
|
||||
return isSigned ? BfTypeCode_Int8 : BfTypeCode_UInt8;
|
||||
case 16:
|
||||
|
@ -1510,7 +1512,7 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
if (BfIRBuilder::IsInt(typeCode))
|
||||
{
|
||||
// Int -> Int
|
||||
if (BfIRBuilder::IsInt(valTypeCode))
|
||||
if ((BfIRBuilder::IsInt(valTypeCode)) || (valTypeCode == BfTypeCode_Boolean))
|
||||
{
|
||||
retVal = mIRBuilder->CreateIntCast(val, toLLVMType, toSigned && valIsSigned);
|
||||
}
|
||||
|
@ -1525,7 +1527,7 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
else
|
||||
{
|
||||
// Int -> Float
|
||||
if (BfIRBuilder::IsInt(valTypeCode))
|
||||
if ((BfIRBuilder::IsInt(valTypeCode)) || (valTypeCode == BfTypeCode_Boolean))
|
||||
{
|
||||
if (BfIRBuilder::IsSigned(valTypeCode))
|
||||
retVal = mIRBuilder->CreateSIToFP(val, toLLVMType);
|
||||
|
|
|
@ -10343,7 +10343,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
|
||||
if (explicitCast)
|
||||
{
|
||||
if (((fromPrimType->IsIntegral()) || (fromPrimType->IsFloat())) &&
|
||||
if (((fromPrimType->IsIntegral()) || (fromPrimType->IsFloat()) || (fromPrimType->IsBoolean())) &&
|
||||
((toType->IsIntegral()) || (toType->IsFloat())))
|
||||
allowCast = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue