public void CheckFailList(OptimizerContext context, MethodDefinition method) { CheckFailList(context, method.DeclaringType, method.FullName); var entry = context.GetMethodEntries(method)?.FirstOrDefault(m => m.Action == MethodAction.Warn || m.Action == MethodAction.Fail); if (entry == null) { return; } var message = $"Found fail-listed method `{method.FullName}`"; context.LogMessage(MessageImportance.High, Environment.NewLine); context.LogMessage(MessageImportance.High, message + ":"); DumpFailEntry(context, entry); var stack = context.DumpTracerStack(); OptimizerReport.FailList.Add(new FailListEntry(method, entry, stack)); context.LogMessage(MessageImportance.High, Environment.NewLine); if (entry.Action == MethodAction.Fail) { throw new OptimizerException(message + "."); } }
public bool EnableDebugging(OptimizerContext context, TypeDefinition type) { if (type.DeclaringType != null) { return(EnableDebugging(context, type.DeclaringType)); } if (DontDebugThis(type)) { return(false); } if (AutoDebugMain) { if (type.Namespace == "Martin.LinkerTest") { return(true); } if (type.Module.Assembly.Name.Name.ToLowerInvariant().Contains("martin")) { return(true); } } return(context.GetTypeEntries(type)?.Any(t => t.Action == TypeAction.Debug) ?? false); }
protected override void DoAdditionalProcessing() { if (_methods.Count > 0) { return; } ProcessingConditionals = true; while (_conditional_methods.Count > 0) { var conditional = _conditional_methods.Dequeue(); Tracer.Push(conditional); var scanner = _block_scanner_by_method [conditional]; if (scanner.DebugLevel > 0) { OptimizerContext.LogMessage(MessageImportance.Normal, $"CONDITIONAL METHOD: {conditional}"); OptimizerContext.Debug(); } scanner.RewriteConditionals(); base.MarkMethodBody(conditional.Body); Tracer.Pop(); } }
public ConditionalMarkStep(OptimizerContext context) { OptimizerContext = context; _conditional_methods = new Queue <MethodDefinition> (); _block_scanner_by_method = new Dictionary <MethodDefinition, BasicBlockScanner> (); }
public bool EnableDebugging(OptimizerContext context, MethodDefinition method) { if (DontDebugThis(method.DeclaringType)) { return(false); } if (EnableDebugging(context, method.DeclaringType)) { return(true); } if (AutoDebugMain) { if (method.Name == "Main") { return(true); } if (method.FullName.Contains("Martin")) { return(true); } } return(context.GetMethodEntries(method)?.Any(m => m.Action == MethodAction.Debug) ?? false); }
static void DumpFailEntry(OptimizerContext context, Method method) { context.LogMessage(MessageImportance.High, " " + method); if (method.Parent != null) { DumpFailEntry(context, method.Parent); } }
static void DumpFailEntry(OptimizerContext context, Type type) { context.LogMessage(MessageImportance.High, " " + type); if (type.Parent != null) { DumpFailEntry(context, type.Parent); } }
protected override TypeDefinition MarkType(TypeReference reference) { if (reference == null) { return(null); } reference = GetOriginalType(reference); if (reference is FunctionPointerType) { return(null); } if (reference is GenericParameter) { return(null); } var type = ResolveTypeDefinition(reference); if (type == null) { HandleUnresolvedType(reference); return(null); } if (Annotations.IsProcessed(type)) { return(null); } if (OptimizerContext.Options.EnableDebugging(OptimizerContext, type)) { OptimizerContext.LogMessage(MessageImportance.Normal, $"MARK TYPE: {type}"); OptimizerContext.Debug(); } OptimizerContext.Options.CheckFailList(OptimizerContext, type); if (ProcessingConditionals && OptimizerContext.IsConditionalTypeMarked(type)) { OptimizerContext.AttemptingToRedefineConditional(type); } return(base.MarkType(reference)); }
protected override void EnqueueMethod(MethodDefinition method) { if (OptimizerContext.Options.EnableDebugging(OptimizerContext, method)) { OptimizerContext.LogMessage(MessageImportance.Normal, $"ENQUEUE METHOD: {method}"); OptimizerContext.Debug(); } OptimizerContext.Options.CheckFailList(OptimizerContext, method); if (_conditional_methods.Contains(method)) { return; } base.EnqueueMethod(method); }
public static void Initialize(LinkContext linkContext, string mainModule, OptimizerOptions options) { if (initialized) { return; } initialized = true; var context = new OptimizerContext(linkContext, options, mainModule); if (options.CheckSize) { options.ReportMode |= ReportMode.Size; } if (options.OptimizerReport.IsEnabled(ReportMode.Detailed) || options.OptimizerReport.IsEnabled(ReportMode.Size)) { options.AnalyzeAll = options.ScanAllModules = true; if (options.Preprocessor == OptimizerOptions.PreprocessorMode.None) { options.Preprocessor = OptimizerOptions.PreprocessorMode.Automatic; } } linkContext.Pipeline.AddStepAfter(typeof(TypeMapStep), new InitializeOptimizerStep(context)); if (options.EnableBlazor) { linkContext.Pipeline.AddStepBefore(typeof(MarkStep), new BlazorPreserveStep(context)); } linkContext.Pipeline.AddStepBefore(typeof(MarkStep), new PreprocessStep(context)); linkContext.Pipeline.ReplaceStep(typeof(MarkStep), new ConditionalMarkStep(context)); linkContext.Pipeline.AppendStep(new SizeReportStep(context)); if (options.CompareWith != null) { linkContext.Pipeline.AppendStep(new CompareWithReportStep(context)); } linkContext.Pipeline.AppendStep(new GenerateReportStep(context)); linkContext.Pipeline.AppendStep(new FinalCheckStep(context)); context.ResolveAssemblies(); }
protected override void MarkMethodBody(MethodBody body) { if (!OptimizerContext.IsEnabled(body.Method)) { base.MarkMethodBody(body); return; } var debug = OptimizerContext.GetDebugLevel(body.Method); if (debug > 0) { OptimizerContext.LogMessage(MessageImportance.Normal, $"MARK BODY: {body.Method}"); OptimizerContext.Debug(); } var scanner = BasicBlockScanner.Scan(OptimizerContext, body.Method); if (scanner == null) { OptimizerContext.LogDebug($"BB SCAN FAILED: {body.Method}"); base.MarkMethodBody(body); return; } if (scanner == null || !scanner.FoundConditionals) { base.MarkMethodBody(body); return; } if (debug > 0) { OptimizerContext.LogDebug($"MARK BODY - CONDITIONAL: {body.Method}"); } scanner.RewriteConditionals(); base.MarkMethodBody(body); }
public void CheckFailList(OptimizerContext context, TypeDefinition type, string original = null) { var entry = context.GetTypeEntries(type)?.FirstOrDefault(t => t.Action == TypeAction.Warn || t.Action == TypeAction.Fail); if (entry == null) { return; } var original_message = original != null ? $" while parsing `{original}`" : string.Empty; var message = $"Found fail-listed type `{type.FullName}`"; context.LogMessage(MessageImportance.High, Environment.NewLine); context.LogMessage(MessageImportance.High, message + ":"); DumpFailEntry(context, entry); var stack = context.DumpTracerStack(); OptimizerReport.FailList.Add(new FailListEntry(type, entry, original, stack)); context.LogMessage(MessageImportance.High, Environment.NewLine); if (entry.Action == TypeAction.Fail) { throw new OptimizerException(message + original_message + "."); } }
public CompareWithReportStep(OptimizerContext context) : base(context) { Configuration = new OptimizerConfiguration(); context.Options.OptimizerReport.SizeComparision = Result = new SizeComparision(); }
public void Process(LinkContext context) { OptimizerContext.Initialize(context, mainModule, options); }
public SizeReportStep(OptimizerContext context) : base(context) { }
public PreprocessStep(OptimizerContext context) : base(context) { }
public BlazorPreserveStep(OptimizerContext context) : base(context) { }
protected OptimizerBaseStep(OptimizerContext context) { Context = context; }
public InitializeOptimizerStep(OptimizerContext context) : base(context) { }
public GenerateReportStep(OptimizerContext context) : base(context) { }