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

Method CreateDllImportGlobalVar

IDEHelper/Compiler/BfModule.cpp:18368–18417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18366}
18367
18368BfIRValue BfModule::CreateDllImportGlobalVar(BfMethodInstance* methodInstance, bool define)
18369{
18370 BF_ASSERT(methodInstance->mIsReified);
18371
18372 auto typeInstance = methodInstance->GetOwner();
18373
18374 bool foundDllImportAttr = false;
18375 BfCallingConvention callingConvention = methodInstance->mCallingConvention;
18376 for (auto customAttr : methodInstance->GetCustomAttributes()->mAttributes)
18377 {
18378 if (customAttr.mType->mTypeDef->mFullName.ToString() == "System.ImportAttribute")
18379 {
18380 foundDllImportAttr = true;
18381 }
18382 }
18383 if (!foundDllImportAttr)
18384 {
18385 AssertErrorState();
18386 return BfIRValue();
18387 }
18388
18389 StringT<512> name = "bf_hs_preserve@";
18390 BfMangler::Mangle(name, mCompiler->GetMangleKind(), methodInstance);
18391 name += "__imp";
18392
18393 BfIRType returnType;
18394 SizedArray<BfIRType, 8> paramTypes;
18395 methodInstance->GetIRFunctionInfo(this, returnType, paramTypes);
18396
18397 BfIRFunctionType externFunctionType = mBfIRBuilder->CreateFunctionType(returnType, paramTypes, methodInstance->IsVarArgs());
18398 auto ptrType = mBfIRBuilder->GetPointerTo(externFunctionType);
18399
18400 BfIRValue initVal;
18401 if (define)
18402 {
18403 if (methodInstance->GetImportCallKind() != BfImportCallKind_None)
18404 initVal = mBfIRBuilder->CreateConstNull(ptrType);
18405 }
18406
18407 auto globalVar = mBfIRBuilder->CreateGlobalVariable(ptrType, false, BfIRLinkageType_External, initVal, name);
18408
18409 if ((define) && (mBfIRBuilder->DbgHasInfo()))
18410 {
18411 auto voidType = GetPrimitiveType(BfTypeCode_None);
18412 auto ptrType = CreatePointerType(voidType);
18413 mBfIRBuilder->DbgCreateGlobalVariable(mDICompileUnit, name, name, BfIRMDNode(), 0, mBfIRBuilder->DbgGetType(ptrType), false, globalVar);
18414 }
18415
18416 return globalVar;
18417}
18418
18419void BfModule::CreateDllImportMethod()
18420{

Callers 2

GetMethodInstanceMethod · 0.80

Calls 15

BfIRValueClass · 0.85
BfIRMDNodeClass · 0.85
GetMangleKindMethod · 0.80
GetIRFunctionInfoMethod · 0.80
IsVarArgsMethod · 0.80
GetImportCallKindMethod · 0.80
CreateConstNullMethod · 0.80
CreateGlobalVariableMethod · 0.80
DbgHasInfoMethod · 0.80
DbgGetTypeMethod · 0.80
GetOwnerMethod · 0.45

Tested by

no test coverage detected