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

Method AllocBytes

IDEHelper/Compiler/BfModule.cpp:9642–9767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9640}
9641
9642BfIRValue BfModule::AllocBytes(BfAstNode* refNode, const BfAllocTarget& allocTarget, BfType* type, BfIRValue sizeValue, BfIRValue alignValue, BfAllocFlags allocFlags/*, bool zeroMemory, bool defaultToMalloc*/)
9643{
9644 BfIRValue result;
9645
9646 BfType* ptrType;
9647 if ((type->IsObject()) && ((allocFlags & BfAllocFlags_RawArray) == 0))
9648 ptrType = type;
9649 else
9650 ptrType = CreatePointerType(type);
9651
9652 if ((allocTarget.mScopedInvocationTarget != NULL) || (allocTarget.mCustomAllocator))
9653 {
9654 auto intType = GetPrimitiveType(BfTypeCode_IntPtr);
9655 SizedArray<BfExpression*, 2> argExprs;
9656
9657 BfTypedValueExpression typedValueExpr;
9658 typedValueExpr.Init(BfTypedValue(sizeValue, intType));
9659 typedValueExpr.mRefNode = refNode;
9660 argExprs.push_back(&typedValueExpr);
9661
9662 BfTypedValueExpression appendSizeValueExpr;
9663 appendSizeValueExpr.Init(BfTypedValue(alignValue, intType));
9664 appendSizeValueExpr.mRefNode = refNode;
9665 argExprs.push_back(&appendSizeValueExpr);
9666
9667 BfExprEvaluator exprEvaluator(this);
9668 BfTypedValue allocResult;
9669
9670 if (allocTarget.mScopedInvocationTarget != NULL)
9671 {
9672 SizedArray<BfTypeReference*, 2> genericArgs;
9673 exprEvaluator.DoInvocation(allocTarget.mScopedInvocationTarget, NULL, argExprs, BfMethodGenericArguments());
9674 allocResult = LoadValue(exprEvaluator.mResult);
9675 }
9676 else if (allocTarget.mCustomAllocator)
9677 {
9678 auto customTypeInst = allocTarget.mCustomAllocator.mType->ToTypeInstance();
9679 if (customTypeInst == NULL)
9680 {
9681 if (allocTarget.mCustomAllocator.mType->IsStructPtr())
9682 customTypeInst = allocTarget.mCustomAllocator.mType->GetUnderlyingType()->ToTypeInstance();
9683 }
9684
9685 if (customTypeInst == NULL)
9686 {
9687 Fail(StrFormat("Type '%s' cannot be used as a custom allocator", TypeToString(allocTarget.mCustomAllocator.mType).c_str()), refNode);
9688 }
9689 else
9690 {
9691 BfTypedValueExpression typeValueExpr;
9692 String allocMethodName = "Alloc";
9693 if (GetRawMethodByName(customTypeInst, "AllocTyped", -1, true, true))
9694 {
9695 allocMethodName = "AllocTyped";
9696 auto typeType = ResolveTypeDef(mCompiler->mTypeTypeDef);
9697 auto typeRefVal = CreateTypeDataRef(type);
9698
9699 typeValueExpr.Init(BfTypedValue(typeRefVal, typeType));

Callers 15

InsertUniqueFunction · 0.45
DbgDupStringMethod · 0.45
ParseDWARFMethod · 0.45
ReadCOFFMethod · 0.45
GetPermanentPtrMethod · 0.45
CvParseAndDupStringMethod · 0.45
CvDupStringMethod · 0.45
FixupInlineeMethod · 0.45
LocateSymbolMethod · 0.45
ParseFrameDescriptorsMethod · 0.45
AddToSetMethod · 0.45

Calls 15

BfTypedValueClass · 0.85
FailFunction · 0.85
TypeToStringFunction · 0.85
InjectMixinMethod · 0.80
MapTypeMethod · 0.80
IsObjectMethod · 0.45
InitMethod · 0.45
push_backMethod · 0.45
DoInvocationMethod · 0.45
ToTypeInstanceMethod · 0.45
IsStructPtrMethod · 0.45

Tested by

no test coverage detected