mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed sized array size inference, primitive type handling in ir
This commit is contained in:
parent
8894430f98
commit
a20519ee04
8 changed files with 92 additions and 21 deletions
|
@ -633,6 +633,14 @@ void BeIRCodeGen::Read(BeType*& beType)
|
|||
}
|
||||
|
||||
int typeId = (int)ReadSLEB128();
|
||||
|
||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||
{
|
||||
bool isSigned = false;
|
||||
beType = GetBeType((BfTypeCode)typeId, isSigned);
|
||||
return;
|
||||
}
|
||||
|
||||
auto& typeEntry = GetTypeEntry(typeId);
|
||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
||||
beType = typeEntry.mBeType;
|
||||
|
|
|
@ -2462,6 +2462,13 @@ public:
|
|||
BfTokenNode* mOpenBracket;
|
||||
BfSizedArray<ASTREF(BfAstNode*)> mParams; // Either commas or constant size expression
|
||||
BfTokenNode* mCloseBracket;
|
||||
|
||||
bool IsInferredSize()
|
||||
{
|
||||
if (mParams.mSize > 0)
|
||||
return BfNodeIsA<BfUninitializedExpression>(mParams[0]);
|
||||
return false;
|
||||
}
|
||||
}; BF_AST_DECL(BfArrayTypeRef, BfElementedTypeRef);
|
||||
|
||||
class BfNullableTypeRef : public BfElementedTypeRef
|
||||
|
|
|
@ -66,6 +66,11 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
|
|||
if (memberRefExpr->mTarget == NULL)
|
||||
arraySize = (int)invocationExpr->mArguments.size();
|
||||
}
|
||||
else if (auto indexerExpr = BfNodeDynCast<BfIndexerExpression>(invocationExpr->mTarget))
|
||||
{
|
||||
// Sized array initializer
|
||||
arraySize = (int)invocationExpr->mArguments.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1368,6 +1368,11 @@ String BfIRBuilder::ToString(BfIRType irType)
|
|||
{
|
||||
llvmType = mBfIRCodeGen->GetLLVMType(irType.mId);
|
||||
}
|
||||
else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||
{
|
||||
bool isSigned = false;
|
||||
llvmType = mBfIRCodeGen->GetLLVMType((BfTypeCode)irType.mId, isSigned);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& typeEntry = mBfIRCodeGen->GetTypeEntry(irType.mId);
|
||||
|
@ -1400,6 +1405,11 @@ String BfIRBuilder::ToString(BfIRType irType)
|
|||
{
|
||||
beType = mBeIRCodeGen->GetBeType(irType.mId);
|
||||
}
|
||||
else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||
{
|
||||
bool isSigned = false;
|
||||
beType = mBeIRCodeGen->GetBeType((BfTypeCode)irType.mId, isSigned);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& typeEntry = mBeIRCodeGen->GetTypeEntry(irType.mId);
|
||||
|
@ -3469,9 +3479,11 @@ BfIRFunction BfIRBuilder::GetFakeFunction()
|
|||
BfIRType BfIRBuilder::GetPrimitiveType(BfTypeCode typeCode)
|
||||
{
|
||||
FixTypeCode(typeCode);
|
||||
BfIRType retType = WriteCmd(BfIRCmd_PrimitiveType, typeCode);
|
||||
NEW_CMD_INSERTED_IRTYPE;
|
||||
return retType;
|
||||
|
||||
BfIRType irType;
|
||||
irType.mKind = BfIRTypeData::TypeKind_TypeCode;
|
||||
irType.mId = (int)typeCode;
|
||||
return irType;
|
||||
}
|
||||
|
||||
BfIRType BfIRBuilder::CreateStructType(const StringImpl& name)
|
||||
|
|
|
@ -580,6 +580,7 @@ struct BfIRTypeData
|
|||
{
|
||||
TypeKind_None,
|
||||
TypeKind_TypeId,
|
||||
TypeKind_TypeCode,
|
||||
TypeKind_TypeInstId,
|
||||
TypeKind_TypeInstPtrId,
|
||||
TypeKind_Stream,
|
||||
|
|
|
@ -744,6 +744,14 @@ void BfIRCodeGen::Read(llvm::Type*& llvmType)
|
|||
}
|
||||
|
||||
int typeId = (int)ReadSLEB128();
|
||||
|
||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||
{
|
||||
bool isSigned = false;
|
||||
llvmType = GetLLVMType((BfTypeCode)typeId, isSigned);
|
||||
return;
|
||||
}
|
||||
|
||||
auto& typeEntry = GetTypeEntry(typeId);
|
||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
||||
llvmType = typeEntry.mLLVMType;
|
||||
|
|
|
@ -1134,7 +1134,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
|
|||
// code as we walk the AST
|
||||
//mBfIRBuilder->mDbgVerifyCodeGen = true;
|
||||
if (
|
||||
(mModuleName == "System_StringView")
|
||||
(mModuleName == "-")
|
||||
//|| (mModuleName == "BeefTest2_ClearColorValue")
|
||||
//|| (mModuleName == "Tests_FuncRefs")
|
||||
)
|
||||
|
@ -4081,9 +4081,16 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance,
|
|||
|
||||
if ((doStore) && (result))
|
||||
{
|
||||
result = LoadValue(result);
|
||||
if (!result.mType->IsValuelessType())
|
||||
mBfIRBuilder->CreateStore(result.mValue, staticVarRef.mValue);
|
||||
if (fieldInstance->mResolvedType->IsUnknownSizedArray())
|
||||
{
|
||||
AssertErrorState();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = LoadValue(result);
|
||||
if (!result.mType->IsValuelessType())
|
||||
mBfIRBuilder->CreateStore(result.mValue, staticVarRef.mValue);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -13613,14 +13620,14 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli
|
|||
mBfIRBuilder->PopulateType(localVarDef->mResolvedType);
|
||||
auto constMem = mBfIRBuilder->ConstToMemory(localVarDef->mConstValue);
|
||||
|
||||
if (IsTargetingBeefBackend())
|
||||
{
|
||||
diValue = mBfIRBuilder->CreateAliasValue(constMem);
|
||||
didConstToMem = true;
|
||||
|
||||
diType = mBfIRBuilder->DbgCreateReferenceType(diType);
|
||||
}
|
||||
else
|
||||
// if (IsTargetingBeefBackend())
|
||||
// {
|
||||
// diValue = mBfIRBuilder->CreateAliasValue(constMem);
|
||||
// didConstToMem = true;
|
||||
//
|
||||
// diType = mBfIRBuilder->DbgCreateReferenceType(diType);
|
||||
// }
|
||||
//else
|
||||
{
|
||||
isByAddr = true;
|
||||
mBfIRBuilder->SaveDebugLocation();
|
||||
|
|
|
@ -2948,6 +2948,29 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
}
|
||||
}
|
||||
|
||||
if (resolvedFieldType->IsUndefSizedArray())
|
||||
{
|
||||
if (auto arrayTypeRef = BfNodeDynCast<BfArrayTypeRef>(field->mTypeRef))
|
||||
{
|
||||
if (arrayTypeRef->IsInferredSize())
|
||||
{
|
||||
if (field->mInitializer != NULL)
|
||||
{
|
||||
DeferredResolveEntry resolveEntry;
|
||||
resolveEntry.mFieldDef = field;
|
||||
resolveEntry.mTypeArrayIdx = (int)llvmFieldTypes.size();
|
||||
deferredVarResolves.push_back(resolveEntry);
|
||||
|
||||
fieldInstance->mIsInferredType = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AssertErrorState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resolvedFieldType->IsMethodRef())
|
||||
{
|
||||
auto methodRefType = (BfMethodRefType*)resolvedFieldType;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue