1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Made a different restricted temp address for return values

This commit is contained in:
Brian Fiete 2020-07-01 06:14:43 -07:00
parent 963f4fedfc
commit a2a1b486a2
3 changed files with 8 additions and 6 deletions

View file

@ -536,6 +536,7 @@ enum BfTypedValueKind
BfTypedValueKind_Addr, BfTypedValueKind_Addr,
BfTypedValueKind_ReadOnlyAddr, BfTypedValueKind_ReadOnlyAddr,
BfTypedValueKind_TempAddr, BfTypedValueKind_TempAddr,
BfTypedValueKind_RestrictedTempAddr,
BfTypedValueKind_ReadOnlyTempAddr, BfTypedValueKind_ReadOnlyTempAddr,
BfTypedValueKind_ThisAddr, BfTypedValueKind_ThisAddr,
BfTypedValueKind_BaseAddr, BfTypedValueKind_BaseAddr,
@ -647,7 +648,7 @@ public:
bool IsTempAddr() const bool IsTempAddr() const
{ {
return ((mKind == BfTypedValueKind_ReadOnlyTempAddr) || (mKind == BfTypedValueKind_TempAddr)); return ((mKind == BfTypedValueKind_ReadOnlyTempAddr) || (mKind == BfTypedValueKind_RestrictedTempAddr) || (mKind == BfTypedValueKind_TempAddr));
} }
bool IsReadOnly() const bool IsReadOnly() const
@ -727,6 +728,7 @@ public:
mKind = BfTypedValueKind_ReadOnlyAddr; mKind = BfTypedValueKind_ReadOnlyAddr;
break; break;
case BfTypedValueKind_TempAddr: case BfTypedValueKind_TempAddr:
case BfTypedValueKind_RestrictedTempAddr:
mKind = BfTypedValueKind_ReadOnlyTempAddr; mKind = BfTypedValueKind_ReadOnlyTempAddr;
break; break;
default: default:

View file

@ -4516,7 +4516,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV
{ {
auto val = mModule->GetDefaultTypedValue(returnType, true, (methodInstance->GetStructRetIdx() != -1) ? BfDefaultValueKind_Addr : BfDefaultValueKind_Value); auto val = mModule->GetDefaultTypedValue(returnType, true, (methodInstance->GetStructRetIdx() != -1) ? BfDefaultValueKind_Addr : BfDefaultValueKind_Value);
if (val.mKind == BfTypedValueKind_Addr) if (val.mKind == BfTypedValueKind_Addr)
val.mKind = BfTypedValueKind_TempAddr; val.mKind = BfTypedValueKind_RestrictedTempAddr;
return val; return val;
} }
}; };
@ -4543,7 +4543,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV
if (sret == NULL) if (sret == NULL)
{ {
sretVal = BfTypedValue(mModule->CreateAlloca(returnType), returnType, BfTypedValueKind_TempAddr); sretVal = BfTypedValue(mModule->CreateAlloca(returnType), returnType, BfTypedValueKind_RestrictedTempAddr);
sret = &sretVal; sret = &sretVal;
} }
} }
@ -5008,7 +5008,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV
loweredIRType = mModule->mBfIRBuilder->GetPointerTo(loweredIRType); loweredIRType = mModule->mBfIRBuilder->GetPointerTo(loweredIRType);
auto castedRetVal = mModule->mBfIRBuilder->CreateBitCast(retVal, loweredIRType); auto castedRetVal = mModule->mBfIRBuilder->CreateBitCast(retVal, loweredIRType);
mModule->mBfIRBuilder->CreateStore(callInst, castedRetVal); mModule->mBfIRBuilder->CreateStore(callInst, castedRetVal);
result = BfTypedValue(retVal, methodInstance->mReturnType, BfTypedValueKind_TempAddr); result = BfTypedValue(retVal, methodInstance->mReturnType, BfTypedValueKind_RestrictedTempAddr);
} }
else else
result = BfTypedValue(callInst, methodInstance->mReturnType); result = BfTypedValue(callInst, methodInstance->mReturnType);
@ -8440,7 +8440,7 @@ void BfExprEvaluator::Visit(BfInitializerExpression* initExpr)
StringT<128> findName; StringT<128> findName;
identifierNode->ToString(findName); identifierNode->ToString(findName);
fieldResult = LookupField(identifierNode, initValue, findName, BfLookupFieldFlag_IsImplicitThis); fieldResult = LookupField(identifierNode, initValue, findName, BfLookupFieldFlag_IsImplicitThis);
if (fieldResult.mKind == BfTypedValueKind_TempAddr) if ((fieldResult.mKind == BfTypedValueKind_TempAddr) || (fieldResult.mKind == BfTypedValueKind_RestrictedTempAddr))
fieldResult.mKind = BfTypedValueKind_Addr; fieldResult.mKind = BfTypedValueKind_Addr;
wasValidInitKind = true; wasValidInitKind = true;

View file

@ -11102,7 +11102,7 @@ bool BfModule::CheckModifyValue(BfTypedValue& typedValue, BfAstNode* refNode, co
return false; return false;
} }
if (typedValue.mKind == BfTypedValueKind_TempAddr) if (typedValue.mKind == BfTypedValueKind_RestrictedTempAddr)
{ {
Fail(StrFormat("Cannot %s temporary value", modifyType), refNode); Fail(StrFormat("Cannot %s temporary value", modifyType), refNode);
return false; return false;