mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +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();
|
int typeId = (int)ReadSLEB128();
|
||||||
|
|
||||||
|
if (typeKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||||
|
{
|
||||||
|
bool isSigned = false;
|
||||||
|
beType = GetBeType((BfTypeCode)typeId, isSigned);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& typeEntry = GetTypeEntry(typeId);
|
auto& typeEntry = GetTypeEntry(typeId);
|
||||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
||||||
beType = typeEntry.mBeType;
|
beType = typeEntry.mBeType;
|
||||||
|
|
|
@ -2462,6 +2462,13 @@ public:
|
||||||
BfTokenNode* mOpenBracket;
|
BfTokenNode* mOpenBracket;
|
||||||
BfSizedArray<ASTREF(BfAstNode*)> mParams; // Either commas or constant size expression
|
BfSizedArray<ASTREF(BfAstNode*)> mParams; // Either commas or constant size expression
|
||||||
BfTokenNode* mCloseBracket;
|
BfTokenNode* mCloseBracket;
|
||||||
|
|
||||||
|
bool IsInferredSize()
|
||||||
|
{
|
||||||
|
if (mParams.mSize > 0)
|
||||||
|
return BfNodeIsA<BfUninitializedExpression>(mParams[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}; BF_AST_DECL(BfArrayTypeRef, BfElementedTypeRef);
|
}; BF_AST_DECL(BfArrayTypeRef, BfElementedTypeRef);
|
||||||
|
|
||||||
class BfNullableTypeRef : public BfElementedTypeRef
|
class BfNullableTypeRef : public BfElementedTypeRef
|
||||||
|
|
|
@ -66,6 +66,11 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
|
||||||
if (memberRefExpr->mTarget == NULL)
|
if (memberRefExpr->mTarget == NULL)
|
||||||
arraySize = (int)invocationExpr->mArguments.size();
|
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);
|
llvmType = mBfIRCodeGen->GetLLVMType(irType.mId);
|
||||||
}
|
}
|
||||||
|
else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||||
|
{
|
||||||
|
bool isSigned = false;
|
||||||
|
llvmType = mBfIRCodeGen->GetLLVMType((BfTypeCode)irType.mId, isSigned);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto& typeEntry = mBfIRCodeGen->GetTypeEntry(irType.mId);
|
auto& typeEntry = mBfIRCodeGen->GetTypeEntry(irType.mId);
|
||||||
|
@ -1400,6 +1405,11 @@ String BfIRBuilder::ToString(BfIRType irType)
|
||||||
{
|
{
|
||||||
beType = mBeIRCodeGen->GetBeType(irType.mId);
|
beType = mBeIRCodeGen->GetBeType(irType.mId);
|
||||||
}
|
}
|
||||||
|
else if (irType.mKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||||
|
{
|
||||||
|
bool isSigned = false;
|
||||||
|
beType = mBeIRCodeGen->GetBeType((BfTypeCode)irType.mId, isSigned);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto& typeEntry = mBeIRCodeGen->GetTypeEntry(irType.mId);
|
auto& typeEntry = mBeIRCodeGen->GetTypeEntry(irType.mId);
|
||||||
|
@ -3469,9 +3479,11 @@ BfIRFunction BfIRBuilder::GetFakeFunction()
|
||||||
BfIRType BfIRBuilder::GetPrimitiveType(BfTypeCode typeCode)
|
BfIRType BfIRBuilder::GetPrimitiveType(BfTypeCode typeCode)
|
||||||
{
|
{
|
||||||
FixTypeCode(typeCode);
|
FixTypeCode(typeCode);
|
||||||
BfIRType retType = WriteCmd(BfIRCmd_PrimitiveType, typeCode);
|
|
||||||
NEW_CMD_INSERTED_IRTYPE;
|
BfIRType irType;
|
||||||
return retType;
|
irType.mKind = BfIRTypeData::TypeKind_TypeCode;
|
||||||
|
irType.mId = (int)typeCode;
|
||||||
|
return irType;
|
||||||
}
|
}
|
||||||
|
|
||||||
BfIRType BfIRBuilder::CreateStructType(const StringImpl& name)
|
BfIRType BfIRBuilder::CreateStructType(const StringImpl& name)
|
||||||
|
|
|
@ -580,6 +580,7 @@ struct BfIRTypeData
|
||||||
{
|
{
|
||||||
TypeKind_None,
|
TypeKind_None,
|
||||||
TypeKind_TypeId,
|
TypeKind_TypeId,
|
||||||
|
TypeKind_TypeCode,
|
||||||
TypeKind_TypeInstId,
|
TypeKind_TypeInstId,
|
||||||
TypeKind_TypeInstPtrId,
|
TypeKind_TypeInstPtrId,
|
||||||
TypeKind_Stream,
|
TypeKind_Stream,
|
||||||
|
|
|
@ -744,6 +744,14 @@ void BfIRCodeGen::Read(llvm::Type*& llvmType)
|
||||||
}
|
}
|
||||||
|
|
||||||
int typeId = (int)ReadSLEB128();
|
int typeId = (int)ReadSLEB128();
|
||||||
|
|
||||||
|
if (typeKind == BfIRType::TypeKind::TypeKind_TypeCode)
|
||||||
|
{
|
||||||
|
bool isSigned = false;
|
||||||
|
llvmType = GetLLVMType((BfTypeCode)typeId, isSigned);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& typeEntry = GetTypeEntry(typeId);
|
auto& typeEntry = GetTypeEntry(typeId);
|
||||||
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
if (typeKind == BfIRType::TypeKind::TypeKind_TypeId)
|
||||||
llvmType = typeEntry.mLLVMType;
|
llvmType = typeEntry.mLLVMType;
|
||||||
|
|
|
@ -1134,7 +1134,7 @@ void BfModule::EnsureIRBuilder(bool dbgVerifyCodeGen)
|
||||||
// code as we walk the AST
|
// code as we walk the AST
|
||||||
//mBfIRBuilder->mDbgVerifyCodeGen = true;
|
//mBfIRBuilder->mDbgVerifyCodeGen = true;
|
||||||
if (
|
if (
|
||||||
(mModuleName == "System_StringView")
|
(mModuleName == "-")
|
||||||
//|| (mModuleName == "BeefTest2_ClearColorValue")
|
//|| (mModuleName == "BeefTest2_ClearColorValue")
|
||||||
//|| (mModuleName == "Tests_FuncRefs")
|
//|| (mModuleName == "Tests_FuncRefs")
|
||||||
)
|
)
|
||||||
|
@ -4081,9 +4081,16 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance,
|
||||||
|
|
||||||
if ((doStore) && (result))
|
if ((doStore) && (result))
|
||||||
{
|
{
|
||||||
result = LoadValue(result);
|
if (fieldInstance->mResolvedType->IsUnknownSizedArray())
|
||||||
if (!result.mType->IsValuelessType())
|
{
|
||||||
mBfIRBuilder->CreateStore(result.mValue, staticVarRef.mValue);
|
AssertErrorState();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = LoadValue(result);
|
||||||
|
if (!result.mType->IsValuelessType())
|
||||||
|
mBfIRBuilder->CreateStore(result.mValue, staticVarRef.mValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -13613,14 +13620,14 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli
|
||||||
mBfIRBuilder->PopulateType(localVarDef->mResolvedType);
|
mBfIRBuilder->PopulateType(localVarDef->mResolvedType);
|
||||||
auto constMem = mBfIRBuilder->ConstToMemory(localVarDef->mConstValue);
|
auto constMem = mBfIRBuilder->ConstToMemory(localVarDef->mConstValue);
|
||||||
|
|
||||||
if (IsTargetingBeefBackend())
|
// if (IsTargetingBeefBackend())
|
||||||
{
|
// {
|
||||||
diValue = mBfIRBuilder->CreateAliasValue(constMem);
|
// diValue = mBfIRBuilder->CreateAliasValue(constMem);
|
||||||
didConstToMem = true;
|
// didConstToMem = true;
|
||||||
|
//
|
||||||
diType = mBfIRBuilder->DbgCreateReferenceType(diType);
|
// diType = mBfIRBuilder->DbgCreateReferenceType(diType);
|
||||||
}
|
// }
|
||||||
else
|
//else
|
||||||
{
|
{
|
||||||
isByAddr = true;
|
isByAddr = true;
|
||||||
mBfIRBuilder->SaveDebugLocation();
|
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())
|
if (resolvedFieldType->IsMethodRef())
|
||||||
{
|
{
|
||||||
auto methodRefType = (BfMethodRefType*)resolvedFieldType;
|
auto methodRefType = (BfMethodRefType*)resolvedFieldType;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue