public SingleMethodCompilationModuleGroup( ReadyToRunCompilationModuleGroupConfig config, MethodDesc method) : base(config) { _method = method; }
public ReadyToRunCompilationModuleGroupBase(ReadyToRunCompilationModuleGroupConfig config) { _compilationModuleSet = new HashSet <EcmaModule>(config.CompilationModuleSet); _isCompositeBuildMode = config.IsCompositeBuildMode; _isInputBubble = config.IsInputBubble; Debug.Assert(_isCompositeBuildMode || _compilationModuleSet.Count == 1); _versionBubbleModuleSet = new HashSet <ModuleDesc>(config.VersionBubbleModuleSet); _versionBubbleModuleSet.UnionWith(_compilationModuleSet); _compileGenericDependenciesFromVersionBubbleModuleSet = config.CompileGenericDependenciesFromVersionBubbleModuleSet; _tokenResolver = new ModuleTokenResolver(this, config.Context); }
private void RunSingleCompilation(Dictionary <string, string> inFilePaths, InstructionSetSupport instructionSetSupport, string compositeRootPath, Dictionary <string, string> unrootedInputFilePaths, HashSet <ModuleDesc> versionBubbleModulesHash, CompilerTypeSystemContext typeSystemContext) { // // Initialize output filename // string inFilePath = inFilePaths.First().Value; string inputFileExtension = Path.GetExtension(inFilePath); string nearOutFilePath = inputFileExtension switch { ".dll" => Path.ChangeExtension(inFilePath, _commandLineOptions.SingleFileCompilation && _commandLineOptions.InputBubble ? ".ni.dll.tmp" : ".ni.dll"), ".exe" => Path.ChangeExtension(inFilePath, _commandLineOptions.SingleFileCompilation && _commandLineOptions.InputBubble ? ".ni.exe.tmp" : ".ni.exe"), _ => throw new CommandLineException(string.Format(SR.UnsupportedInputFileExtension, inputFileExtension)) }; string outFile = _commandLineOptions.OutNearInput ? nearOutFilePath : _commandLineOptions.OutputFilePath; using (PerfEventSource.StartStopEvents.CompilationEvents()) { ICompilation compilation; using (PerfEventSource.StartStopEvents.LoadingEvents()) { List <EcmaModule> inputModules = new List <EcmaModule>(); List <EcmaModule> rootingModules = new List <EcmaModule>(); foreach (var inputFile in inFilePaths) { EcmaModule module = typeSystemContext.GetModuleFromPath(inputFile.Value); inputModules.Add(module); rootingModules.Add(module); versionBubbleModulesHash.Add(module); if (!_commandLineOptions.CompositeOrInputBubble) { break; } } foreach (var unrootedInputFile in unrootedInputFilePaths) { EcmaModule module = typeSystemContext.GetModuleFromPath(unrootedInputFile.Value); inputModules.Add(module); versionBubbleModulesHash.Add(module); } // // Initialize compilation group and compilation roots // // Single method mode? MethodDesc singleMethod = CheckAndParseSingleMethodModeArguments(typeSystemContext); var logger = new Logger(Console.Out, _commandLineOptions.Verbose); List <string> mibcFiles = new List <string>(); foreach (var file in _commandLineOptions.MibcFilePaths) { mibcFiles.Add(file); } List <ModuleDesc> versionBubbleModules = new List <ModuleDesc>(versionBubbleModulesHash); if (!_commandLineOptions.Composite && inputModules.Count != 1) { throw new Exception(string.Format(SR.ErrorMultipleInputFilesCompositeModeOnly, string.Join("; ", inputModules))); } ReadyToRunCompilationModuleGroupBase compilationGroup; List <ICompilationRootProvider> compilationRoots = new List <ICompilationRootProvider>(); ReadyToRunCompilationModuleGroupConfig groupConfig = new ReadyToRunCompilationModuleGroupConfig(); groupConfig.Context = typeSystemContext; groupConfig.IsCompositeBuildMode = _commandLineOptions.Composite; groupConfig.IsInputBubble = _commandLineOptions.InputBubble; groupConfig.CompilationModuleSet = inputModules; groupConfig.VersionBubbleModuleSet = versionBubbleModules; groupConfig.CompileGenericDependenciesFromVersionBubbleModuleSet = _commandLineOptions.CompileBubbleGenerics; if (singleMethod != null) { // Compiling just a single method compilationGroup = new SingleMethodCompilationModuleGroup( groupConfig, singleMethod); compilationRoots.Add(new SingleMethodRootProvider(singleMethod)); } else if (_commandLineOptions.CompileNoMethods) { compilationGroup = new NoMethodsCompilationModuleGroup(groupConfig); } else { // Single assembly compilation. compilationGroup = new ReadyToRunSingleAssemblyCompilationModuleGroup(groupConfig); } // Load any profiles generated by method call chain analyis CallChainProfile jsonProfile = null; if (!string.IsNullOrEmpty(_commandLineOptions.CallChainProfileFile)) { jsonProfile = new CallChainProfile(_commandLineOptions.CallChainProfileFile, typeSystemContext, _referenceableModules); } // Examine profile guided information as appropriate ProfileDataManager profileDataManager = new ProfileDataManager(logger, _referenceableModules, inputModules, versionBubbleModules, _commandLineOptions.CompileBubbleGenerics ? inputModules[0] : null, mibcFiles, jsonProfile, typeSystemContext, compilationGroup, _commandLineOptions.EmbedPgoData); if (_commandLineOptions.Partial) { compilationGroup.ApplyProfilerGuidedCompilationRestriction(profileDataManager); } else { compilationGroup.ApplyProfilerGuidedCompilationRestriction(null); } if ((singleMethod == null) && !_commandLineOptions.CompileNoMethods) { // For normal compilations add compilation roots. foreach (var module in rootingModules) { compilationRoots.Add(new ReadyToRunRootProvider( module, profileDataManager, profileDrivenPartialNGen: _commandLineOptions.Partial)); if (!_commandLineOptions.CompositeOrInputBubble) { break; } } } // In single-file compilation mode, use the assembly's DebuggableAttribute to determine whether to optimize // or produce debuggable code if an explicit optimization level was not specified on the command line OptimizationMode optimizationMode = _optimizationMode; if (optimizationMode == OptimizationMode.None && !_commandLineOptions.OptimizeDisabled && !_commandLineOptions.Composite) { System.Diagnostics.Debug.Assert(inputModules.Count == 1); optimizationMode = ((EcmaAssembly)inputModules[0].Assembly).HasOptimizationsDisabled() ? OptimizationMode.None : OptimizationMode.Blended; } CompositeImageSettings compositeImageSettings = new CompositeImageSettings(); if (_commandLineOptions.CompositeKeyFile != null) { byte[] compositeStrongNameKey = File.ReadAllBytes(_commandLineOptions.CompositeKeyFile); if (!IsValidPublicKey(compositeStrongNameKey)) { throw new Exception(string.Format(SR.ErrorCompositeKeyFileNotPublicKey)); } compositeImageSettings.PublicKey = compositeStrongNameKey.ToImmutableArray(); } // // Compile // ReadyToRunCodegenCompilationBuilder builder = new ReadyToRunCodegenCompilationBuilder( typeSystemContext, compilationGroup, _allInputFilePaths.Values, compositeRootPath); string compilationUnitPrefix = ""; builder.UseCompilationUnitPrefix(compilationUnitPrefix); ILProvider ilProvider = new ReadyToRunILProvider(); DependencyTrackingLevel trackingLevel = _commandLineOptions.DgmlLogFileName == null ? DependencyTrackingLevel.None : (_commandLineOptions.GenerateFullDgmlLog ? DependencyTrackingLevel.All : DependencyTrackingLevel.First); builder .UseMapFile(_commandLineOptions.Map) .UseMapCsvFile(_commandLineOptions.MapCsv) .UsePdbFile(_commandLineOptions.Pdb, _commandLineOptions.PdbPath) .UsePerfMapFile(_commandLineOptions.PerfMap, _commandLineOptions.PerfMapPath, _commandLineOptions.PerfMapFormatVersion) .UseProfileFile(jsonProfile != null) .UseProfileData(profileDataManager) .FileLayoutAlgorithms(_methodLayout, _fileLayout) .UseCompositeImageSettings(compositeImageSettings) .UseJitPath(_commandLineOptions.JitPath) .UseInstructionSetSupport(instructionSetSupport) .UseCustomPESectionAlignment(_commandLineOptions.CustomPESectionAlignment) .UseVerifyTypeAndFieldLayout(_commandLineOptions.VerifyTypeAndFieldLayout) .GenerateOutputFile(outFile) .UseImageBase(_imageBase) .UseILProvider(ilProvider) .UseBackendOptions(_commandLineOptions.CodegenOptions) .UseLogger(logger) .UseParallelism(_commandLineOptions.Parallelism) .UseResilience(_commandLineOptions.Resilient) .UseDependencyTracking(trackingLevel) .UseCompilationRoots(compilationRoots) .UseOptimizationMode(optimizationMode); if (_commandLineOptions.PrintReproInstructions) { builder.UsePrintReproInstructions(CreateReproArgumentString); } compilation = builder.ToCompilation(); } compilation.Compile(outFile); if (_commandLineOptions.DgmlLogFileName != null) { compilation.WriteDependencyLog(_commandLineOptions.DgmlLogFileName); } compilation.Dispose(); } }
public ReadyToRunSingleAssemblyCompilationModuleGroup( ReadyToRunCompilationModuleGroupConfig config) : base(config) { }
public NoMethodsCompilationModuleGroup(ReadyToRunCompilationModuleGroupConfig config) : base(config) { }