| 18366 | } |
| 18367 | |
| 18368 | BfIRValue 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 | |
| 18419 | void BfModule::CreateDllImportMethod() |
| 18420 | { |
no test coverage detected