Exemplo n.º 1
0
        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 + ".");
            }
        }
Exemplo n.º 2
0
        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> ();
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 static void DumpFailEntry(OptimizerContext context, Method method)
 {
     context.LogMessage(MessageImportance.High, "  " + method);
     if (method.Parent != null)
     {
         DumpFailEntry(context, method.Parent);
     }
 }
Exemplo n.º 7
0
 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);
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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 + ".");
            }
        }
Exemplo n.º 13
0
 public CompareWithReportStep(OptimizerContext context)
     : base(context)
 {
     Configuration = new OptimizerConfiguration();
     context.Options.OptimizerReport.SizeComparision = Result = new SizeComparision();
 }
Exemplo n.º 14
0
 public void Process(LinkContext context)
 {
     OptimizerContext.Initialize(context, mainModule, options);
 }
Exemplo n.º 15
0
 public SizeReportStep(OptimizerContext context)
     : base(context)
 {
 }
Exemplo n.º 16
0
 public PreprocessStep(OptimizerContext context)
     : base(context)
 {
 }
Exemplo n.º 17
0
 public BlazorPreserveStep(OptimizerContext context) : base(context)
 {
 }
Exemplo n.º 18
0
 protected OptimizerBaseStep(OptimizerContext context)
 {
     Context = context;
 }
Exemplo n.º 19
0
 public InitializeOptimizerStep(OptimizerContext context)
     : base(context)
 {
 }
Exemplo n.º 20
0
 public GenerateReportStep(OptimizerContext context)
     : base(context)
 {
 }