From 42452fe09c9a3ae9b480c3db95f72a8bede4179c Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 21 Dec 2019 05:44:01 -0800 Subject: [PATCH] Deferred Import dynamic/static check, fix calling convention --- BeefySysLib/platform/PlatformInterface.h | 7 ++++ BeefySysLib/util/ThreadPool.cpp | 2 +- BeefySysLib/util/WorkThread.cpp | 2 +- IDEHelper/COFF.cpp | 2 +- IDEHelper/Compiler/BfCompiler.cpp | 2 + IDEHelper/Compiler/BfCompiler.h | 5 ++- IDEHelper/Compiler/BfDefBuilder.cpp | 13 ++---- IDEHelper/Compiler/BfExprEvaluator.cpp | 13 +++--- IDEHelper/Compiler/BfMangler.cpp | 6 ++- IDEHelper/Compiler/BfModule.cpp | 46 ++++++++++++++-------- IDEHelper/Compiler/BfModule.h | 6 ++- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 19 ++++++++- IDEHelper/Compiler/BfResolvedTypeUtils.h | 4 +- IDEHelper/Compiler/BfSystem.cpp | 13 ++++++ IDEHelper/Compiler/BfSystem.h | 6 ++- 15 files changed, 102 insertions(+), 44 deletions(-) diff --git a/BeefySysLib/platform/PlatformInterface.h b/BeefySysLib/platform/PlatformInterface.h index 97cb555f..8dc00d29 100644 --- a/BeefySysLib/platform/PlatformInterface.h +++ b/BeefySysLib/platform/PlatformInterface.h @@ -4,6 +4,11 @@ #define BFP_VERSION 2 +#ifdef BFP_INTERNAL +#define BFP_EXPORT +#define BFP_CALLTYPE +#else + #ifndef BFP_EXPORT #define BFP_EXPORT BF_EXPORT #endif @@ -12,6 +17,8 @@ #define BFP_CALLTYPE BF_CALLTYPE #endif +#endif + // Windows file time (the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC)) typedef uint64 BfpTimeStamp; diff --git a/BeefySysLib/util/ThreadPool.cpp b/BeefySysLib/util/ThreadPool.cpp index 8867373b..4f029d3b 100644 --- a/BeefySysLib/util/ThreadPool.cpp +++ b/BeefySysLib/util/ThreadPool.cpp @@ -134,7 +134,7 @@ void ThreadPool::SetStackSize(int stackSize) mStackSize = stackSize; } -static void WorkerProc(void* param) +static void BFP_CALLTYPE WorkerProc(void* param) { ((ThreadPool::Thread*)param)->Proc(); } diff --git a/BeefySysLib/util/WorkThread.cpp b/BeefySysLib/util/WorkThread.cpp index 370427dd..202ad88e 100644 --- a/BeefySysLib/util/WorkThread.cpp +++ b/BeefySysLib/util/WorkThread.cpp @@ -16,7 +16,7 @@ WorkThread::~WorkThread() mThread = NULL; } -static void WorkThreadStub(void* param) +static void BFP_CALLTYPE WorkThreadStub(void* param) { ((WorkThread*)param)->Run(); } diff --git a/IDEHelper/COFF.cpp b/IDEHelper/COFF.cpp index 35081fb5..74850370 100644 --- a/IDEHelper/COFF.cpp +++ b/IDEHelper/COFF.cpp @@ -4898,7 +4898,7 @@ bool COFF::CvParseDBI(int wantAge) bool isV2 = sig == 0xf13151e4; if (isV2) { - Fail("ERROR: FastLink PDBs are not supported. Consider adding full debug info (/DEBUG:FULL)."); + Fail("FastLink PDBs are not supported. Consider adding full debug info (/DEBUG:FULL)."); mIsFastLink = true; } diff --git a/IDEHelper/Compiler/BfCompiler.cpp b/IDEHelper/Compiler/BfCompiler.cpp index 17c44a97..b40ab0fc 100644 --- a/IDEHelper/Compiler/BfCompiler.cpp +++ b/IDEHelper/Compiler/BfCompiler.cpp @@ -379,6 +379,7 @@ BfCompiler::BfCompiler(BfSystem* bfSystem, bool isResolveOnly) mBfObjectTypeDef = NULL; mClassVDataTypeDef = NULL; mCLinkAttributeTypeDef = NULL; + mImportAttributeTypeDef = NULL; mCReprAttributeTypeDef = NULL; mAlignAttributeTypeDef = NULL; mNoDiscardAttributeTypeDef = NULL; @@ -5837,6 +5838,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory) mBfObjectTypeDef = _GetRequiredType("System.Object"); mClassVDataTypeDef = _GetRequiredType("System.ClassVData"); mCLinkAttributeTypeDef = _GetRequiredType("System.CLinkAttribute"); + mImportAttributeTypeDef = _GetRequiredType("System.ImportAttribute"); mCReprAttributeTypeDef = _GetRequiredType("System.CReprAttribute"); mAlignAttributeTypeDef = _GetRequiredType("System.AlignAttribute"); mNoDiscardAttributeTypeDef = _GetRequiredType("System.NoDiscardAttribute"); diff --git a/IDEHelper/Compiler/BfCompiler.h b/IDEHelper/Compiler/BfCompiler.h index 2f83e043..949a0345 100644 --- a/IDEHelper/Compiler/BfCompiler.h +++ b/IDEHelper/Compiler/BfCompiler.h @@ -374,9 +374,10 @@ public: BfTypeDef* mAttributeTypeDef; BfTypeDef* mAttributeUsageAttributeTypeDef; BfTypeDef* mLinkNameAttributeTypeDef; - BfTypeDef* mOrderedAttributeTypeDef; - BfTypeDef* mInlineAttributeTypeDef; + BfTypeDef* mOrderedAttributeTypeDef; + BfTypeDef* mInlineAttributeTypeDef; BfTypeDef* mCLinkAttributeTypeDef; + BfTypeDef* mImportAttributeTypeDef; BfTypeDef* mCReprAttributeTypeDef; BfTypeDef* mAlignAttributeTypeDef; BfTypeDef* mNoDiscardAttributeTypeDef; diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index 4d247279..b10c26ad 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -717,7 +717,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef } else if (typeRefName == "Import") { - methodDef->mImportKind = BfImportKind_Static; + methodDef ->mImportKind = BfImportKind_Import_Unknown; if (!attributes->mArguments.IsEmpty()) { if (auto literalExpr = BfNodeDynCast(attributes->mArguments[0])) @@ -725,12 +725,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef if (literalExpr->mValue.mTypeCode == BfTypeCode_CharPtr) { String filePath = *literalExpr->mValue.mString; - String fileExt = GetFileExtension(filePath); - if ((fileExt.Equals(".DLL", StringImpl::CompareKind_OrdinalIgnoreCase)) || - (fileExt.Equals(".EXE", StringImpl::CompareKind_OrdinalIgnoreCase))) - { - methodDef->mImportKind = BfImportKind_Dynamic; - } + methodDef->mImportKind = BfMethodDef::GetImportKindFromPath(filePath); } } } @@ -752,7 +747,7 @@ void BfDefBuilder::ParseAttributes(BfAttributeDirective* attributes, BfMethodDef else { methodDef->mCommutableKind = BfCommutableKind_Forward; - } + } } } @@ -1799,7 +1794,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) } } - if (method->mImportKind == BfImportKind_Dynamic) + if ((method->mImportKind == BfImportKind_Import_Dynamic) || (method->mImportKind == BfImportKind_Import_Unknown)) needsStaticInit = true; } diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index b6fa733c..8336c4af 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -4296,7 +4296,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV firstArg = irArgs[0]; auto methodInstOwner = methodInstance->GetOwner(); - auto expectCallingConvention = mModule->GetCallingConvention(methodInstOwner, methodDef); + auto expectCallingConvention = mModule->GetIRCallingConvention(methodInstOwner, methodDef); if ((methodInstOwner->IsFunction()) && (methodInstance->GetParamCount() > 0) && (methodInstance->GetParamName(0) == "this")) { auto paramType = methodInstance->GetParamType(0); @@ -9031,7 +9031,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) auto funcType = mModule->mBfIRBuilder->CreateFunctionType(irReturnType, irParamTypes); auto funcValue = mModule->mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, methodName); - auto srcCallingConv = mModule->GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef); + auto srcCallingConv = mModule->GetIRCallingConvention(methodInstance); mModule->mBfIRBuilder->SetFuncCallingConv(funcValue, srcCallingConv); mModule->mBfIRBuilder->SetActiveFunction(funcValue); @@ -9048,7 +9048,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) if (mModule->mCompiler->mOptions.mAllowHotSwapping) bindFuncVal = mModule->mBfIRBuilder->RemapBindFunction(bindFuncVal); auto callResult = mModule->mBfIRBuilder->CreateCall(bindFuncVal, irArgs); - auto destCallingConv = mModule->GetCallingConvention(bindMethodInstance->GetOwner(), bindMethodInstance->mMethodDef); + auto destCallingConv = mModule->GetIRCallingConvention(bindMethodInstance); if (destCallingConv != BfIRCallingConv_CDecl) mModule->mBfIRBuilder->SetCallCallingConv(callResult, destCallingConv); if (methodInstance->mReturnType->IsValuelessType()) @@ -9285,7 +9285,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) auto funcType = mModule->mBfIRBuilder->CreateFunctionType(irReturnType, irParamTypes); funcValue = mModule->mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, methodName); - auto srcCallingConv = mModule->GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef); + auto srcCallingConv = mModule->GetIRCallingConvention(methodInstance); if ((!hasThis) && (methodInstance->mMethodDef->mCallingConvention == BfCallingConvention_Stdcall)) srcCallingConv = BfIRCallingConv_StdCall; mModule->mBfIRBuilder->SetFuncCallingConv(funcValue, srcCallingConv); @@ -9334,7 +9334,7 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr) if (mModule->mCompiler->mOptions.mAllowHotSwapping) bindFuncVal = mModule->mBfIRBuilder->RemapBindFunction(bindFuncVal); auto result = mModule->mBfIRBuilder->CreateCall(bindFuncVal, irArgs); - auto destCallingConv = mModule->GetCallingConvention(bindMethodInstance->GetOwner(), bindMethodInstance->mMethodDef); + auto destCallingConv = mModule->GetIRCallingConvention(bindMethodInstance); if (destCallingConv != BfIRCallingConv_CDecl) mModule->mBfIRBuilder->SetCallCallingConv(result, destCallingConv); if (methodInstance->mReturnType->IsValuelessType()) @@ -9942,6 +9942,8 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam capturedType = mModule->CreateRefType(capturedType); } + if (captureType == BfCaptureType_Reference) + capturedEntry.mExplicitlyByReference = true; capturedEntry.mType = capturedType; if (outerLocal->mName == "this") capturedEntry.mName = "__this"; @@ -10208,6 +10210,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam lambdaInstance->mClosureTypeInstance = closureTypeInst; lambdaInstance->mOuterClosure = outerClosure; lambdaInstance->mCopyOuterCaptures = copyOuterCaptures; + lambdaInstance->mDeclaringMethodIsMutating = mModule->mCurMethodInstance->mMethodDef->mIsMutating; lambdaInstance->mIsStatic = methodDef->mIsStatic; lambdaInstance->mClosureFunc = closureFunc; lambdaInstance->mMethodInstance = methodInstance; diff --git a/IDEHelper/Compiler/BfMangler.cpp b/IDEHelper/Compiler/BfMangler.cpp index b7cf0b4a..071bd59a 100644 --- a/IDEHelper/Compiler/BfMangler.cpp +++ b/IDEHelper/Compiler/BfMangler.cpp @@ -2024,10 +2024,12 @@ void BfMSMangler::Mangle(StringImpl& name, bool is64Bit, BfMethodInstance* metho name += qualifier; } + auto callingConvention = mangleContext.mModule->GetIRCallingConvention(typeInst, methodDef); + char callingConv = 'A'; - if (methodDef->mCallingConvention == BfCallingConvention_Stdcall) + if (callingConvention == BfIRCallingConv_StdCall) callingConv = 'G'; - else if ((!mangleContext.mIs64Bit) && (!methodDef->mIsStatic)) + else if (callingConvention == BfIRCallingConv_ThisCall) callingConv = 'E'; name += callingConv; diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index a84444b1..f80fb158 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -3712,7 +3712,7 @@ void BfModule::EmitEquals(BfTypedValue leftValue, BfTypedValue rightValue, BfIRB exprEvaluator.mExpectingType = mCurMethodInstance->mReturnType; exprEvaluator.PerformBinaryOperation((BfAstNode*)NULL, (BfAstNode*)NULL, BfBinaryOp_Equality, NULL, BfBinOpFlag_None, leftValue, rightValue); BfTypedValue result = exprEvaluator.GetResult(); - if (result) + if ((result) && (!result.mType->IsVar())) { auto nextBB = mBfIRBuilder->CreateBlock("next"); mBfIRBuilder->CreateCondBr(result.mValue, nextBB, exitBB); @@ -5676,6 +5676,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin MethodFlags_Virtual = 0x40, MethodFlags_StdCall = 0x1000, MethodFlags_FastCall = 0x2000, + MethodFlags_ThisCall = 0x3000, MethodFlags_Mutating = 0x4000, }; @@ -5693,6 +5694,12 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin methodFlags = (MethodFlags)(methodFlags | MethodFlags_FastCall); if (methodDef->mIsMutating) methodFlags = (MethodFlags)(methodFlags | MethodFlags_Mutating); + + auto callingConvention = GetIRCallingConvention(defaultMethod); + if (callingConvention == BfIRCallingConv_ThisCall) + methodFlags = (MethodFlags)(methodFlags | MethodFlags_ThisCall); + else if (callingConvention == BfIRCallingConv_StdCall) + methodFlags = (MethodFlags)(methodFlags | MethodFlags_StdCall); int customAttrIdx = _HandleCustomAttrs(methodCustomAttributes); @@ -8794,7 +8801,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr auto funcType = mBfIRBuilder->CreateFunctionType(returnType, paramTypes); auto func = mBfIRBuilder->CreateFunction(funcType, BfIRLinkageType_External, methodName); - auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); + auto callingConv = GetIRCallingConvention(methodInstance); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetFuncCallingConv(func, callingConv); SetupIRMethod(methodInstance, func, isInlined); @@ -13020,7 +13027,7 @@ void BfModule::CreateDelegateInvokeMethod() BfIRValue nonStaticResult; BfIRValue staticResult; - auto callingConv = GetCallingConvention(mCurTypeInstance, mCurMethodInstance->mMethodDef); + auto callingConv = GetIRCallingConvention(mCurTypeInstance, mCurMethodInstance->mMethodDef); /// Non-static invocation { @@ -13540,7 +13547,7 @@ void BfModule::EmitDtorBody() auto basePtr = mBfIRBuilder->CreateBitCast(thisVal.mValue, mBfIRBuilder->MapTypeInstPtr(mContext->mBfObjectType)); SizedArray vals = { basePtr }; result = mBfIRBuilder->CreateCall(dtorFunc.mFunc, vals); - mBfIRBuilder->SetCallCallingConv(result, GetCallingConvention(dtorFunc.mMethodInstance)); + mBfIRBuilder->SetCallCallingConv(result, GetIRCallingConvention(dtorFunc.mMethodInstance)); mBfIRBuilder->SetTailCall(result); return; @@ -13705,7 +13712,7 @@ void BfModule::EmitDtorBody() auto basePtr = mBfIRBuilder->CreateBitCast(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->MapTypeInstPtr(checkBaseType)); SizedArray vals = { basePtr }; auto callInst = mBfIRBuilder->CreateCall(dtorMethodInstance.mFunc, vals); - mBfIRBuilder->SetCallCallingConv(callInst, GetCallingConvention(dtorMethodInstance.mMethodInstance)); + mBfIRBuilder->SetCallCallingConv(callInst, GetIRCallingConvention(dtorMethodInstance.mMethodInstance)); } } else @@ -13851,7 +13858,7 @@ void BfModule::CreateDllImportMethod() mBfIRBuilder->CreateCall(loadSharedLibsFunc, SizedArray()); } - auto callingConvention = GetCallingConvention(mCurTypeInstance, mCurMethodInstance->mMethodDef); + auto callingConvention = GetIRCallingConvention(mCurTypeInstance, mCurMethodInstance->mMethodDef); BfIRType returnType; SizedArray paramTypes; @@ -13887,7 +13894,7 @@ void BfModule::CreateDllImportMethod() } } -BfIRCallingConv BfModule::GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef) +BfIRCallingConv BfModule::GetIRCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef) { if ((mCompiler->mOptions.mMachineType != BfMachineType_x86) || (mCompiler->mOptions.mPlatformType != BfPlatformType_Windows)) return BfIRCallingConv_CDecl; @@ -13899,9 +13906,15 @@ BfIRCallingConv BfModule::GetCallingConvention(BfTypeInstance* typeInst, BfMetho return BfIRCallingConv_CDecl; } -BfIRCallingConv BfModule::GetCallingConvention(BfMethodInstance* methodInstance) +BfIRCallingConv BfModule::GetIRCallingConvention(BfMethodInstance* methodInstance) { - return GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef); + auto methodDef = methodInstance->mMethodDef; + BfTypeInstance* owner = NULL; + if (!methodDef->mIsStatic) + owner = methodInstance->GetParamType(-1)->ToTypeInstance(); + if (owner == NULL) + owner = methodInstance->GetOwner(); + return GetIRCallingConvention(owner, methodInstance->mMethodDef); } void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined) @@ -13926,7 +13939,7 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport); if (methodDef->mNoReturn) mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn); - auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); + auto callingConv = GetIRCallingConvention(methodInstance); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetFuncCallingConv(func, callingConv); @@ -14401,7 +14414,7 @@ void BfModule::EmitCtorBody(bool& skipBody) } AddCallDependency(ctorBodyMethodInstance.mMethodInstance, true); auto callInst = mBfIRBuilder->CreateCall(ctorBodyMethodInstance.mFunc, args); - auto callingConv = GetCallingConvention(ctorBodyMethodInstance.mMethodInstance->GetOwner(), ctorBodyMethodInstance.mMethodInstance->mMethodDef); + auto callingConv = GetIRCallingConvention(ctorBodyMethodInstance.mMethodInstance); if (callingConv != BfIRCallingConv_CDecl) mBfIRBuilder->SetCallCallingConv(callInst, callingConv); // if (!mCurTypeInstance->mBaseType->IsValuelessType()) @@ -15288,6 +15301,7 @@ void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx) else closureState.mClosureType = lambdaInstance->mDelegateTypeInstance; closureState.mClosureInstanceInfo = lambdaInstance->mMethodInstance->mMethodInfoEx->mClosureInstanceInfo; + closureState.mDeclaringMethodIsMutating = lambdaInstance->mDeclaringMethodIsMutating; mCurMethodState->mMixinState = lambdaInstance->mDeclMixinState; _ClearState(); @@ -16255,7 +16269,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) bool isTypedPrimitiveFunc = mCurTypeInstance->IsTypedPrimitive() && (methodDef->mMethodType != BfMethodType_Ctor); int irParamCount = methodInstance->GetIRFunctionParamCount(this); - if (methodDef->mImportKind != BfImportKind_Dynamic) + if (methodInstance->GetImportKind() != BfImportKind_Import_Dynamic) { int localIdx = 0; int argIdx = 0; @@ -16823,7 +16837,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) bool skipBody = false; bool skipUpdateSrcPos = false; bool skipEndChecks = false; - bool hasExternSpecifier = (methodDeclaration != NULL) && (methodDeclaration->mExternSpecifier != NULL) && (methodDef->mImportKind != BfImportKind_Dynamic); + bool hasExternSpecifier = (methodDeclaration != NULL) && (methodDeclaration->mExternSpecifier != NULL) && (methodInstance->GetImportKind() != BfImportKind_Import_Dynamic); auto propertyDeclaration = methodDef->GetPropertyDeclaration(); if ((methodDef != NULL) && (propertyDeclaration != NULL) && (propertyDeclaration->mExternSpecifier != NULL)) @@ -16986,7 +17000,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) } bool isDllImport = false; - if (methodDef->mImportKind == BfImportKind_Static) + if (methodInstance->GetImportKind() == BfImportKind_Import_Static) { for (auto customAttr : methodInstance->GetCustomAttributes()->mAttributes) { @@ -17015,7 +17029,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) //mImportFileNames } - else if (methodDef->mImportKind == BfImportKind_Dynamic) + else if (methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) { CreateDllImportMethod(); } @@ -17534,7 +17548,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup) CreateFakeCallerMethod(mangledName); mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); } - else if ((methodDef->mImportKind == BfImportKind_Dynamic) && (!mCompiler->IsHotCompile())) + else if ((methodInstance->GetImportKind() == BfImportKind_Import_Dynamic) && (!mCompiler->IsHotCompile())) { // We only need the DLL stub when we may be hot swapping mBfIRBuilder->Func_DeleteBody(mCurMethodInstance->mIRFunction); diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index a38a468a..fb4a687f 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -813,6 +813,7 @@ public: BfIRValue mClosureFunc; BfIRValue mDtorFunc; bool mCopyOuterCaptures; + bool mDeclaringMethodIsMutating; bool mIsStatic; Array mCaptures; BfMethodInstance* mMethodInstance; @@ -829,6 +830,7 @@ public: mDeclMixinState = NULL; mOuterClosure = NULL; mCopyOuterCaptures = false; + mDeclaringMethodIsMutating = false; mIsStatic = false; mMethodInstance = NULL; mDtorMethodInstance = NULL; @@ -1722,8 +1724,8 @@ public: void CreateStaticCtor(); BfIRValue CreateDllImportGlobalVar(BfMethodInstance* methodInstance, bool define = false); void CreateDllImportMethod(); - BfIRCallingConv GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef); - BfIRCallingConv GetCallingConvention(BfMethodInstance* methodInstance); + BfIRCallingConv GetIRCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef); + BfIRCallingConv GetIRCallingConvention(BfMethodInstance* methodInstance); void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined); void EmitCtorBody(bool& skipBody); void EmitDtorBody(); diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index 519477c5..92f2337e 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -497,6 +497,23 @@ BfMethodInstance::~BfMethodInstance() delete mMethodInfoEx; } +BfImportKind BfMethodInstance::GetImportKind() +{ + if (mMethodDef->mImportKind != BfImportKind_Import_Unknown) + return mMethodDef->mImportKind; + + auto module = GetOwner()->mModule; + BfCustomAttribute* customAttribute = GetCustomAttributes()->Get(module->mCompiler->mImportAttributeTypeDef); + if (customAttribute == NULL) + return BfImportKind_Import_Static; + + BfIRConstHolder* constHolder = GetOwner()->mConstHolder; + String* filePath = module->GetStringPoolString(customAttribute->mCtorArgs[0], constHolder); + if (filePath == NULL) + return BfImportKind_Import_Static; + return BfMethodDef::GetImportKindFromPath(*filePath); +} + void BfMethodInstance::UndoDeclaration(bool keepIRFunction) { @@ -614,7 +631,7 @@ bool BfMethodInstance::AlwaysInline() BfImportCallKind BfMethodInstance::GetImportCallKind() { - if (mMethodDef->mImportKind != BfImportKind_Dynamic) + if (GetImportKind() != BfImportKind_Import_Dynamic) return BfImportCallKind_None; if ((mHotMethod != NULL) && ((mHotMethod->mFlags & BfHotDepDataFlag_IsOriginalBuild) == 0)) return BfImportCallKind_GlobalVar_Hot; diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.h b/IDEHelper/Compiler/BfResolvedTypeUtils.h index 06983809..859aceab 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.h +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.h @@ -797,14 +797,14 @@ public: return mMethodDef->mMethodType == BfMethodType_Mixin; } + BfImportKind GetImportKind(); void UndoDeclaration(bool keepIRFunction = false); BfTypeInstance* GetOwner(); BfModule* GetModule(); bool IsSpecializedGenericMethod(); bool IsSpecializedGenericMethodOrType(); bool IsSpecializedByAutoCompleteMethod(); - bool HasThis(); - bool WantsThisPointer(); + bool HasThis(); bool HasParamsArray(); bool HasStructRet(); bool HasSelf(); diff --git a/IDEHelper/Compiler/BfSystem.cpp b/IDEHelper/Compiler/BfSystem.cpp index 0e1d1ec6..02fb9188 100644 --- a/IDEHelper/Compiler/BfSystem.cpp +++ b/IDEHelper/Compiler/BfSystem.cpp @@ -453,6 +453,19 @@ BfMethodDef::~BfMethodDef() FreeMembers(); } +BfImportKind BfMethodDef::GetImportKindFromPath(const StringImpl& filePath) +{ + String fileExt = GetFileExtension(filePath); + + if ((fileExt.Equals(".DLL", StringImpl::CompareKind_OrdinalIgnoreCase)) || + (fileExt.Equals(".EXE", StringImpl::CompareKind_OrdinalIgnoreCase))) + { + return BfImportKind_Import_Dynamic; + } + + return BfImportKind_Import_Static; +} + void BfMethodDef::Reset() { FreeMembers(); diff --git a/IDEHelper/Compiler/BfSystem.h b/IDEHelper/Compiler/BfSystem.h index a5fa0e91..253bf114 100644 --- a/IDEHelper/Compiler/BfSystem.h +++ b/IDEHelper/Compiler/BfSystem.h @@ -664,8 +664,9 @@ enum BfOptimize : int8 enum BfImportKind : int8 { BfImportKind_None, - BfImportKind_Static, - BfImportKind_Dynamic, + BfImportKind_Import_Unknown, + BfImportKind_Import_Dynamic, + BfImportKind_Import_Static, BfImportKind_Export }; @@ -758,6 +759,7 @@ public: virtual ~BfMethodDef(); + static BfImportKind GetImportKindFromPath(const StringImpl& filePath); bool HasNoThisSplat() { return mIsMutating || mNoSplat; } void Reset(); void FreeMembers();