MCPcopy Create free account
hub / github.com/beefytech/Beef / CreateClassVDataGlobal

Method CreateClassVDataGlobal

IDEHelper/Compiler/BfModule.cpp:5604–5685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5602}
5603
5604BfIRValue BfModule::CreateClassVDataGlobal(BfTypeInstance* typeInstance, int* outNumElements, String* outMangledName)
5605{
5606 if (mBfIRBuilder->mIgnoreWrites)
5607 return mBfIRBuilder->GetFakeVal();
5608
5609 PopulateType(typeInstance, mIsComptimeModule ? BfPopulateType_Data : BfPopulateType_DataAndMethods);
5610
5611 BfType* classVDataType = ResolveTypeDef(mCompiler->mClassVDataTypeDef);
5612
5613 if (mIsComptimeModule)
5614 {
5615 auto idVal = mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, typeInstance->mTypeId);
5616 return mBfIRBuilder->CreateIntToPtr(idVal, mBfIRBuilder->MapType(CreatePointerType(classVDataType)));
5617 }
5618
5619 BfIRValue* globalVariablePtr = NULL;
5620 mClassVDataRefs.TryGetValue(typeInstance, &globalVariablePtr);
5621
5622 int numElements = 1;
5623 if (mSystem->mPtrSize == 4)
5624 numElements++;
5625
5626 if ((outNumElements != NULL) || (globalVariablePtr == NULL))
5627 {
5628 numElements += mCompiler->mMaxInterfaceSlots;
5629
5630 auto maxIFaceVirtIdx = 0;
5631
5632 if (!typeInstance->IsInterface())
5633 {
5634 int dynCastDataElems = 1 + mCompiler->mMaxInterfaceSlots;
5635 numElements += ((dynCastDataElems * 4) + mSystem->mPtrSize - 1) / mSystem->mPtrSize;
5636
5637 numElements += typeInstance->GetOrigVTableSize();
5638 int ifaceMethodLen = typeInstance->GetIFaceVMethodSize();
5639 if (typeInstance->mHotTypeData != NULL)
5640 {
5641 if (typeInstance->mHotTypeData->mOrigInterfaceMethodsLength != -1)
5642 ifaceMethodLen = typeInstance->mHotTypeData->mOrigInterfaceMethodsLength;
5643 }
5644 numElements += ifaceMethodLen;
5645 }
5646
5647 if (outNumElements != NULL)
5648 *outNumElements = numElements;
5649 }
5650
5651 StringT<128> classVDataName;
5652
5653 String memberName = "sBfClassVData";
5654 if ((typeInstance->mHotTypeData != NULL) && ((typeInstance->mHotTypeData->mHadDataChange) || (typeInstance->mHotTypeData->mPendingDataChange)))
5655 {
5656 auto curVersion = typeInstance->mHotTypeData->GetLatestVersion();
5657 memberName += "_";
5658 memberName += BfTypeUtils::HashEncode64(curVersion->mDataHash.mLow);
5659 memberName += BfTypeUtils::HashEncode64(curVersion->mDataHash.mHigh);
5660 }
5661

Callers

nothing calls this directly

Calls 15

HashEncode64Function · 0.85
BfIRValueClass · 0.85
GetFakeValMethod · 0.80
CreateIntToPtrMethod · 0.80
MapTypeMethod · 0.80
TryGetValueMethod · 0.80
GetOrigVTableSizeMethod · 0.80
GetIFaceVMethodSizeMethod · 0.80
GetLatestVersionMethod · 0.80
GetMangleKindMethod · 0.80
CreateGlobalVariableMethod · 0.80
CreateConstMethod · 0.45

Tested by

no test coverage detected