| 17854 | } |
| 17855 | |
| 17856 | void BfModule::CreateStaticCtor() |
| 17857 | { |
| 17858 | auto typeDef = mCurTypeInstance->mTypeDef; |
| 17859 | auto methodDef = mCurMethodInstance->mMethodDef; |
| 17860 | |
| 17861 | BfIRBlock exitBB; |
| 17862 | if ((HasCompiledOutput()) && (!mCurMethodInstance->mIsUnspecialized) && (mCurMethodInstance->mChainType != BfMethodChainType_ChainMember)) |
| 17863 | { |
| 17864 | auto boolType = GetPrimitiveType(BfTypeCode_Boolean); |
| 17865 | auto didStaticInitVarAddr = mBfIRBuilder->CreateGlobalVariable( |
| 17866 | mBfIRBuilder->MapType(boolType), |
| 17867 | false, |
| 17868 | BfIRLinkageType_Internal, |
| 17869 | GetDefaultValue(boolType), |
| 17870 | "didStaticInit"); |
| 17871 | |
| 17872 | auto initBB = mBfIRBuilder->CreateBlock("init", true); |
| 17873 | mCurMethodState->mIRExitBlock = mBfIRBuilder->CreateBlock("exit", true); |
| 17874 | |
| 17875 | auto didStaticInitVar = mBfIRBuilder->CreateLoad(didStaticInitVarAddr); |
| 17876 | mBfIRBuilder->CreateCondBr(didStaticInitVar, mCurMethodState->mIRExitBlock, initBB); |
| 17877 | |
| 17878 | mBfIRBuilder->SetInsertPoint(initBB); |
| 17879 | mBfIRBuilder->CreateStore(GetConstValue(1, boolType), didStaticInitVarAddr); |
| 17880 | } |
| 17881 | |
| 17882 | // Do DLL imports |
| 17883 | if (!mDllImportEntries.empty()) |
| 17884 | { |
| 17885 | auto internalType = ResolveTypeDef(mCompiler->mInternalTypeDef); |
| 17886 | PopulateType(internalType); |
| 17887 | auto getSharedProcAddressInstance = GetMethodByName(internalType->ToTypeInstance(), "GetSharedProcAddress"); |
| 17888 | if (!getSharedProcAddressInstance) |
| 17889 | { |
| 17890 | if (!mCompiler->mPassInstance->HasFailed()) |
| 17891 | Fail("Internal error: System.Internal doesn't contain LoadSharedLibrary method"); |
| 17892 | } |
| 17893 | } |
| 17894 | |
| 17895 | // Fill in initializer values |
| 17896 | if ((!mCompiler->mIsResolveOnly) || (mCompiler->mResolvePassData->mAutoComplete == NULL)) |
| 17897 | { |
| 17898 | for (auto fieldDef : typeDef->mFields) |
| 17899 | { |
| 17900 | if ((!fieldDef->mIsConst) && (fieldDef->mIsStatic)) |
| 17901 | { |
| 17902 | // For extensions, only handle these fields in the appropriate extension |
| 17903 | if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) |
| 17904 | continue; |
| 17905 | |
| 17906 | auto initializer = fieldDef->GetInitializer(); |
| 17907 | auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; |
| 17908 | if (!fieldInst->mFieldIncluded) |
| 17909 | continue; |
| 17910 | if (fieldInst->mResolvedType->IsVar()) |
| 17911 | { |
| 17912 | continue; |
| 17913 | } |
nothing calls this directly
no test coverage detected