diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 62f81f9e..42e5ecad 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -621,6 +621,7 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra SmallVector paramTypes; auto loadSharedLibrariesFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); auto loadSharedLibFunc = bfModule->mBfIRBuilder->CreateFunction(loadSharedLibrariesFuncType, BfIRLinkageType_External, "BfLoadSharedLibraries"); + bfModule->SetupIRMethod(NULL, loadSharedLibFunc, false); bfModule->mBfIRBuilder->SetActiveFunction(loadSharedLibFunc); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); @@ -1544,6 +1545,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) SmallVector paramTypes; auto dtorFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); dtorFunc = bfModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, "BfCallAllStaticDtors"); + bfModule->SetupIRMethod(NULL, dtorFunc, false); bfModule->mBfIRBuilder->SetActiveFunction(dtorFunc); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); @@ -1582,6 +1584,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) paramTypes.push_back(nullPtrType); mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main"); + bfModule->SetupIRMethod(NULL, mainFunc, false); } else if (project->mTargetType == BfTargetType_BeefDynLib) { @@ -1593,6 +1596,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain"); if (mSystem->mPtrSize == 4) bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); + bfModule->SetupIRMethod(NULL, mainFunc, false); } else if (project->mTargetType == BfTargetType_BeefWindowsApplication) { @@ -1605,6 +1609,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain"); if (mSystem->mPtrSize == 4) bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); + bfModule->SetupIRMethod(NULL, mainFunc, false); } else { @@ -1613,6 +1618,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) paramTypes.push_back(nullPtrType); mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain"); + bfModule->SetupIRMethod(NULL, mainFunc, false); } bfModule->mBfIRBuilder->SetActiveFunction(mainFunc); @@ -1627,6 +1633,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) auto setCmdLineFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); auto setCmdLineFunc = bfModule->mBfIRBuilder->CreateFunction(setCmdLineFuncType, BfIRLinkageType_External, "BfpSystem_SetCommandLine"); + bfModule->SetupIRMethod(NULL, setCmdLineFunc, false); SmallVector args; args.push_back(bfModule->mBfIRBuilder->GetArgument(0)); @@ -1775,6 +1782,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule) BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefMain"); + bfModule->SetupIRMethod(NULL, thunkMainFunc, false); bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc); auto thunkEntryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 7b5f9894..56aa00ef 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -9717,7 +9717,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam SetAndRestoreValue prevClosureState(mModule->mCurMethodState->mClosureState, &closureState); if (mModule->HasCompiledOutput()) - mModule->SetupLLVMMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline); + mModule->SetupIRMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline); // This keeps us from giving errors twice. ProcessMethod can give errors when we capture by value but needed to // capture by reference, so we still need to do it for resolve-only diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 072551e7..ff4ff659 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -8523,7 +8523,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetFuncCallingConv(func, callingConv); - SetupLLVMMethod(methodInstance, func, isInlined); + SetupIRMethod(methodInstance, func, isInlined); // auto srcModule = methodInstance->GetOwner()->GetModule(); // if ((srcModule != NULL) && (srcModule->mProject != mProject)) @@ -13588,24 +13588,28 @@ BfIRCallingConv BfModule::GetCallingConvention(BfMethodInstance* methodInstance) return GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef); } -void BfModule::SetupLLVMMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined) +void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined) { - auto methodDef = methodInstance->mMethodDef; + BfMethodDef* methodDef = NULL; + if (methodInstance != NULL) + methodDef = methodInstance->mMethodDef; if (!func) return; if (mCompiler->mOptions.mNoFramePointerElim) - mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim); - if (methodDef->mImportKind == BfImportKind_Export) - mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport); - + mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim); mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoUnwind); if (mSystem->mPtrSize == 8) // We need unwind info for debugging mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_UWTable); + + if (methodInstance == NULL) + return; + + if (methodDef->mImportKind == BfImportKind_Export) + mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport); if (methodDef->mNoReturn) mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn); - auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetFuncCallingConv(func, callingConv); @@ -18313,7 +18317,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man *outIsIntrinsic = isIntrinsic; if (!isIntrinsic) - SetupLLVMMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline); + SetupIRMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline); } void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& inMangledName) diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 0df72c59..dec835f7 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1678,7 +1678,7 @@ public: void CreateDllImportMethod(); BfIRCallingConv GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef); BfIRCallingConv GetCallingConvention(BfMethodInstance* methodInstance); - void SetupLLVMMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); + void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); void EmitCtorBody(bool& skipBody); void EmitDtorBody(); void EmitEnumToStringBody();