| 18417 | } |
| 18418 | |
| 18419 | void BfModule::CreateDllImportMethod() |
| 18420 | { |
| 18421 | if (mBfIRBuilder->mIgnoreWrites) |
| 18422 | return; |
| 18423 | |
| 18424 | auto globalVar = mFuncReferences[mCurMethodInstance]; |
| 18425 | if (!globalVar) |
| 18426 | return; |
| 18427 | |
| 18428 | bool allowTailCall = true; |
| 18429 | |
| 18430 | mBfIRBuilder->ClearDebugLocation(); |
| 18431 | |
| 18432 | bool isHotCompile = mCompiler->IsHotCompile(); |
| 18433 | |
| 18434 | // If we are hot swapping, we need to have this stub because we may need to call the LoadSharedLibraries on demand |
| 18435 | if (isHotCompile) |
| 18436 | { |
| 18437 | auto loadSharedLibsFunc = GetBuiltInFunc(BfBuiltInFuncType_LoadSharedLibraries); |
| 18438 | mBfIRBuilder->CreateCall(loadSharedLibsFunc, SizedArray<BfIRValue, 0>()); |
| 18439 | } |
| 18440 | |
| 18441 | auto callingConvention = GetIRCallingConvention(mCurMethodInstance); |
| 18442 | |
| 18443 | BfIRType returnType; |
| 18444 | SizedArray<BfIRType, 8> paramTypes; |
| 18445 | mCurMethodInstance->GetIRFunctionInfo(this, returnType, paramTypes, mCurMethodInstance->IsVarArgs()); |
| 18446 | |
| 18447 | SizedArray<BfIRValue, 8> args; |
| 18448 | |
| 18449 | for (int i = 0; i < (int)paramTypes.size(); i++) |
| 18450 | args.push_back(mBfIRBuilder->GetArgument(i)); |
| 18451 | |
| 18452 | BfIRFunctionType externFunctionType = mBfIRBuilder->CreateFunctionType(returnType, paramTypes, mCurMethodInstance->IsVarArgs()); |
| 18453 | |
| 18454 | if (isHotCompile) |
| 18455 | { |
| 18456 | BfIRValue funcVal = mBfIRBuilder->CreateLoad(globalVar); |
| 18457 | auto result = mBfIRBuilder->CreateCall(funcVal, args); |
| 18458 | if (callingConvention == BfIRCallingConv_StdCall) |
| 18459 | mBfIRBuilder->SetCallCallingConv(result, BfIRCallingConv_StdCall); |
| 18460 | else if (callingConvention == BfIRCallingConv_FastCall) |
| 18461 | mBfIRBuilder->SetCallCallingConv(result, BfIRCallingConv_FastCall); |
| 18462 | else |
| 18463 | mBfIRBuilder->SetCallCallingConv(result, BfIRCallingConv_CDecl); |
| 18464 | if (allowTailCall) |
| 18465 | mBfIRBuilder->SetTailCall(result); |
| 18466 | CreateReturn(result); |
| 18467 | mCurMethodState->mHadReturn = true; |
| 18468 | } |
| 18469 | |
| 18470 | if (HasCompiledOutput()) |
| 18471 | { |
| 18472 | BfDllImportEntry dllImportEntry; |
| 18473 | dllImportEntry.mFuncVar = globalVar; |
| 18474 | dllImportEntry.mMethodInstance = mCurMethodInstance; |
| 18475 | mDllImportEntries.push_back(dllImportEntry); |
| 18476 | } |
nothing calls this directly
no test coverage detected