mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Added typeof_comptime const type
This commit is contained in:
parent
a82cc0534d
commit
c511773dad
10 changed files with 111 additions and 10 deletions
|
@ -406,6 +406,11 @@ String BfIRConstHolder::ToString(BfIRValue irValue)
|
|||
auto typeofConst = (BfTypeOf_Const*)constant;
|
||||
return "typeof " + mModule->TypeToString(typeofConst->mType);
|
||||
}
|
||||
else if (constant->mConstType == BfConstType_TypeOf_Comptime)
|
||||
{
|
||||
auto typeofConst = (BfTypeOf_Const*)constant;
|
||||
return "typeof_comptime " + mModule->TypeToString(typeofConst->mType);
|
||||
}
|
||||
else if (constant->mConstType == BfConstType_TypeOf_WithData)
|
||||
{
|
||||
auto typeofConst = (BfTypeOf_WithData_Const*)constant;
|
||||
|
@ -687,8 +692,8 @@ int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs)
|
|||
}
|
||||
}
|
||||
|
||||
if (((constLHS->mConstType == BfConstType_TypeOf) || (constLHS->mConstType == BfConstType_TypeOf_WithData)) &&
|
||||
((constRHS->mConstType == BfConstType_TypeOf) || (constRHS->mConstType == BfConstType_TypeOf_WithData)))
|
||||
if (((constLHS->mConstType == BfConstType_TypeOf) || (constLHS->mConstType == BfConstType_TypeOf_WithData) || (constLHS->mConstType == BfConstType_TypeOf_Comptime)) &&
|
||||
((constRHS->mConstType == BfConstType_TypeOf) || (constRHS->mConstType == BfConstType_TypeOf_WithData) || (constRHS->mConstType == BfConstType_TypeOf_Comptime)))
|
||||
{
|
||||
auto typeOfLHS = (BfTypeOf_Const*)constLHS;
|
||||
auto typeOfRHS = (BfTypeOf_Const*)constRHS;
|
||||
|
@ -892,6 +897,11 @@ BfIRValue BfIRConstHolder::CreateConst(BfConstant* fromConst, BfIRConstHolder* f
|
|||
auto typeOf = (BfTypeOf_Const*)fromConst;
|
||||
return CreateTypeOf(typeOf->mType);
|
||||
}
|
||||
else if (fromConst->mConstType == BfConstType_TypeOf_Comptime)
|
||||
{
|
||||
auto typeOf = (BfTypeOf_Const*)fromConst;
|
||||
return CreateTypeOfComptime(typeOf->mType);
|
||||
}
|
||||
else if (fromConst->mConstType == BfConstType_TypeOf_WithData)
|
||||
{
|
||||
auto typeOf = (BfTypeOf_WithData_Const*)fromConst;
|
||||
|
@ -1039,6 +1049,7 @@ BfIRValue BfIRConstHolder::CreateConstAgg(BfIRType type, const BfSizedArray<BfIR
|
|||
for (auto& val : values)
|
||||
{
|
||||
BF_ASSERT(val);
|
||||
//BF_ASSERT(val.IsConst());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1137,6 +1148,18 @@ BfIRValue BfIRConstHolder::CreateConstBox(BfIRValue val, BfIRType type)
|
|||
return castedVal;
|
||||
}
|
||||
|
||||
BfIRValue BfIRConstHolder::CreateTypeOfComptime(BfType* type)
|
||||
{
|
||||
BfTypeOf_Const* typeOf = mTempAlloc.Alloc<BfTypeOf_Const>();
|
||||
typeOf->mConstType = BfConstType_TypeOf_Comptime;
|
||||
typeOf->mType = type;
|
||||
auto irValue = BfIRValue(BfIRValueFlags_Const, mTempAlloc.GetChunkedId(typeOf));
|
||||
#ifdef CHECK_CONSTHOLDER
|
||||
irValue.mHolder = this;
|
||||
#endif
|
||||
return irValue;
|
||||
}
|
||||
|
||||
BfIRValue BfIRConstHolder::CreateTypeOf(BfType* type)
|
||||
{
|
||||
BfTypeOf_Const* typeOf = mTempAlloc.Alloc<BfTypeOf_Const>();
|
||||
|
@ -2530,6 +2553,14 @@ void BfIRBuilder::Write(const BfIRValue& irValue)
|
|||
Write(MapType(typeofConst->mType, BfIRPopulateType_Identity));
|
||||
}
|
||||
break;
|
||||
case (int)BfConstType_TypeOf_Comptime:
|
||||
{
|
||||
auto typeType = mModule->ResolveTypeDef(mModule->mCompiler->mTypeTypeDef);
|
||||
auto typeofConst = (BfTypeOf_Const*)constant;
|
||||
Write(MapType(typeType, BfIRPopulateType_Identity));
|
||||
Write(typeofConst->mType->mTypeId);
|
||||
}
|
||||
break;
|
||||
case (int)BfConstType_Undef:
|
||||
{
|
||||
auto undefConst = (BfConstantUndef*)constant;
|
||||
|
|
|
@ -134,6 +134,7 @@ enum BfConstType
|
|||
BfConstType_IntToPtr,
|
||||
BfConstType_TypeOf,
|
||||
BfConstType_TypeOf_WithData,
|
||||
BfConstType_TypeOf_Comptime,
|
||||
BfConstType_AggZero,
|
||||
BfConstType_Agg,
|
||||
BfConstType_AggCE,
|
||||
|
@ -981,6 +982,7 @@ public:
|
|||
BfIRValue CreateConstBitCast(BfIRValue val, BfIRType type);
|
||||
BfIRValue CreateConstBox(BfIRValue val, BfIRType type);
|
||||
BfIRValue CreateTypeOf(BfType* type);
|
||||
BfIRValue CreateTypeOfComptime(BfType* type);
|
||||
BfIRValue CreateTypeOf(BfType* type, BfIRValue typeData);
|
||||
BfIRValue GetUndefConstValue(BfIRType type);
|
||||
BfIRValue CreateGlobalVariableConstant(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS = false);
|
||||
|
|
|
@ -5620,7 +5620,7 @@ BfIRValue BfModule::CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTy
|
|||
return globalVariable;
|
||||
}
|
||||
|
||||
BfIRValue BfModule::CreateTypeDataRef(BfType* type)
|
||||
BfIRValue BfModule::CreateTypeDataRef(BfType* type, bool forceConstant)
|
||||
{
|
||||
if (mBfIRBuilder->mIgnoreWrites)
|
||||
{
|
||||
|
@ -5629,6 +5629,9 @@ BfIRValue BfModule::CreateTypeDataRef(BfType* type)
|
|||
|
||||
if (mIsComptimeModule)
|
||||
{
|
||||
if (forceConstant)
|
||||
return mBfIRBuilder->CreateTypeOfComptime(type);
|
||||
|
||||
auto typeTypeDef = ResolveTypeDef(mCompiler->mTypeTypeDef);
|
||||
auto typeTypeInst = typeTypeDef->ToTypeInstance();
|
||||
return mBfIRBuilder->Comptime_GetReflectType(type->mTypeId, mBfIRBuilder->MapType(typeTypeInst));
|
||||
|
@ -12119,7 +12122,7 @@ BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* con
|
|||
auto constTypeOf = (BfTypeOf_Const*)constant;
|
||||
if (mCurTypeInstance != NULL)
|
||||
AddDependency(constTypeOf->mType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ExprTypeReference);
|
||||
return CreateTypeDataRef(constTypeOf->mType);
|
||||
return CreateTypeDataRef(constTypeOf->mType, true);
|
||||
}
|
||||
|
||||
if (constant->mConstType == BfConstType_PtrToInt)
|
||||
|
|
|
@ -2090,7 +2090,7 @@ public:
|
|||
BfIRValue CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* outNumElements = NULL, String* outMangledName = NULL);
|
||||
BfIRValue GetClassVDataPtr(BfTypeInstance* typeInstance);
|
||||
BfIRValue CreateClassVDataExtGlobal(BfTypeInstance* declTypeInst, BfTypeInstance* implTypeInst, int startVirtIdx);
|
||||
BfIRValue CreateTypeDataRef(BfType* type);
|
||||
BfIRValue CreateTypeDataRef(BfType* type, bool forceConstant = false);
|
||||
void EncodeAttributeData(BfTypeInstance* typeInstance, BfType* argType, BfIRValue arg, SizedArrayImpl<uint8>& data, Dictionary<int, int>& usedStringIdMap);
|
||||
BfIRValue CreateFieldData(BfFieldInstance* fieldInstance, int customAttrIdx);
|
||||
void CreateSlotOfs(BfTypeInstance* typeInstance);
|
||||
|
|
|
@ -1885,6 +1885,17 @@ CeOperand CeBuilder::GetOperand(BeValue* value, bool allowAlloca, bool allowImme
|
|||
// return GetOperand(callInst->mInlineResult);
|
||||
}
|
||||
break;
|
||||
case BeTypeOfConstant::TypeId:
|
||||
{
|
||||
auto beTypeOf = (BeTypeOfConstant*)value;
|
||||
auto ptrType = mCeMachine->GetBeContext()->GetVoidPtrType();
|
||||
CeOperand result = FrameAlloc(ptrType);
|
||||
Emit(CeOp_GetReflectType);
|
||||
EmitFrameOffset(result);
|
||||
Emit((int32)beTypeOf->mBfTypeId);
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
CeOperand* operandPtr = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue