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

Method GetBuiltInFunc

IDEHelper/Compiler/BfModule.cpp:8317–8402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8315}
8316
8317BfIRFunction BfModule::GetBuiltInFunc(BfBuiltInFuncType funcTypeId)
8318{
8319 if (mBfIRBuilder->mIgnoreWrites)
8320 return mBfIRBuilder->GetFakeFunction();
8321
8322 if (!mBuiltInFuncs[(int)funcTypeId])
8323 {
8324 SizedArray<BfIRType, 4> paramTypes;
8325 auto nullPtrType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_NullPtr));
8326 auto intType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_IntPtr));
8327 auto int32Type = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_Int32));
8328 auto intPtrType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_IntPtr));
8329 auto byteType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_Int8));
8330 auto voidType = mBfIRBuilder->MapType(GetPrimitiveType(BfTypeCode_None));
8331 auto objType = mBfIRBuilder->MapType(mContext->mBfObjectType);
8332
8333 BfIRFunctionType funcType;
8334 BfIRFunction func;
8335
8336 switch (funcTypeId)
8337 {
8338 case BfBuiltInFuncType_PrintF:
8339 paramTypes.Add(nullPtrType);
8340 funcType = mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, true);
8341 func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, "PrintF");
8342 break;
8343 case BfBuiltInFuncType_Malloc:
8344 {
8345 if ((mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule))
8346 {
8347 func = GetInternalMethod("Dbg_RawAlloc", 1).mFunc;
8348 }
8349 else
8350 {
8351 String funcName = mCompiler->mOptions.mMallocLinkName;
8352 if ((funcName.IsEmpty()) || (mIsComptimeModule))
8353 funcName = "malloc";
8354 func = mBfIRBuilder->GetFunction(funcName);
8355 if (!func)
8356 {
8357 paramTypes.clear();
8358 paramTypes.push_back(intType);
8359 funcType = mBfIRBuilder->CreateFunctionType(nullPtrType, paramTypes);
8360 func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, funcName);
8361 mBfIRBuilder->Func_SetParamName(func, 1, "size");
8362 }
8363 }
8364 }
8365 break;
8366 case BfBuiltInFuncType_Free:
8367 {
8368 if ((mCompiler->mOptions.mDebugAlloc) && (!mIsComptimeModule))
8369 {
8370 func = GetInternalMethod("Dbg_RawFree").mFunc;
8371 }
8372 else
8373 {
8374 String funcName = mCompiler->mOptions.mFreeLinkName;

Callers 2

CreateCallMethod · 0.80
DoInvocationMethod · 0.80

Calls 10

GetFakeFunctionMethod · 0.80
MapTypeMethod · 0.80
Func_SetParamNameMethod · 0.80
AddMethod · 0.45
CreateFunctionTypeMethod · 0.45
CreateFunctionMethod · 0.45
IsEmptyMethod · 0.45
GetFunctionMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected