| 694 | } |
| 695 | |
| 696 | BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Array<BfMethodInstance*>& dllMethods) |
| 697 | { |
| 698 | BfIRType nullPtrType = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_NullPtr)); |
| 699 | BfIRType nullPtrPtrType = bfModule->mBfIRBuilder->MapType(bfModule->CreatePointerType(bfModule->GetPrimitiveType(BfTypeCode_NullPtr))); |
| 700 | BfIRType voidType = bfModule->mBfIRBuilder->MapType(bfModule->GetPrimitiveType(BfTypeCode_None)); |
| 701 | |
| 702 | SmallVector<BfIRType, 2> paramTypes; |
| 703 | auto loadSharedLibrariesFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); |
| 704 | auto loadSharedLibFunc = bfModule->mBfIRBuilder->CreateFunction(loadSharedLibrariesFuncType, BfIRLinkageType_External, "BfLoadSharedLibraries"); |
| 705 | bfModule->SetupIRMethod(NULL, loadSharedLibFunc, false); |
| 706 | |
| 707 | bfModule->mBfIRBuilder->SetActiveFunction(loadSharedLibFunc); |
| 708 | auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); |
| 709 | bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); |
| 710 | |
| 711 | HashSet<int> dllNameSet; |
| 712 | |
| 713 | auto internalType = bfModule->ResolveTypeDef(mInternalTypeDef); |
| 714 | bfModule->PopulateType(internalType); |
| 715 | auto getSharedProcAddressInstance = bfModule->GetMethodByName(internalType->ToTypeInstance(), "GetSharedProcAddressInto"); |
| 716 | auto loadSharedLibraryProc = bfModule->GetMethodByName(internalType->ToTypeInstance(), "LoadSharedLibraryInto"); |
| 717 | BF_ASSERT(getSharedProcAddressInstance); |
| 718 | BF_ASSERT(loadSharedLibraryProc); |
| 719 | |
| 720 | if (!getSharedProcAddressInstance) |
| 721 | { |
| 722 | bfModule->Fail("Missing Internal.GetSharedProcAddressInto"); |
| 723 | return loadSharedLibFunc; |
| 724 | } |
| 725 | |
| 726 | if (!loadSharedLibraryProc) |
| 727 | { |
| 728 | bfModule->Fail("Missing Internal.LoadSharedLibraryInto"); |
| 729 | return loadSharedLibFunc; |
| 730 | } |
| 731 | |
| 732 | Dictionary<int, BfIRValue> dllHandleMap; |
| 733 | for (auto methodInstance : dllMethods) |
| 734 | { |
| 735 | auto typeInstance = methodInstance->GetOwner(); |
| 736 | auto methodDef = methodInstance->mMethodDef; |
| 737 | BF_ASSERT(methodInstance->GetCustomAttributes() != NULL); |
| 738 | for (auto customAttr : methodInstance->GetCustomAttributes()->mAttributes) |
| 739 | { |
| 740 | if (customAttr.mType->mTypeDef->mFullName.ToString() == "System.ImportAttribute") |
| 741 | { |
| 742 | bool doCLink = false; |
| 743 | bool undecorated = false; |
| 744 | BfCallingConvention callingConvention = methodDef->mCallingConvention; |
| 745 | for (auto fieldSet : customAttr.mSetField) |
| 746 | { |
| 747 | BfFieldDef* fieldDef = fieldSet.mFieldRef; |
| 748 | |
| 749 | if (fieldDef->mName == "CLink") |
| 750 | { |
| 751 | auto constant = typeInstance->mConstHolder->GetConstant(fieldSet.mParam.mValue); |
| 752 | if (constant != NULL) |
| 753 | doCLink = constant->mBool; |
nothing calls this directly
no test coverage detected