コード例 #1
0
        public override IMethodDefinition Rewrite(IMethodDefinition methodDefinition)
        {
            var signature = MemberHelper.GetMethodSignature(methodDefinition, NameFormattingOptions.Signature | NameFormattingOptions.ParameterName);

            System.Console.WriteLine(signature);

            var disassembler = new Disassembler(host, methodDefinition, sourceLocationProvider);
            var methodBody   = disassembler.Execute();

            //System.Console.WriteLine(methodBody);
            //System.Console.WriteLine();

            var cfg = ControlFlowGraph.GenerateNormalControlFlow(methodBody);

            ControlFlowGraph.ComputeDominators(cfg);
            ControlFlowGraph.IdentifyLoops(cfg);

            ControlFlowGraph.ComputeDominatorTree(cfg);
            ControlFlowGraph.ComputeDominanceFrontiers(cfg);

            var splitter = new WebAnalysis(cfg);

            splitter.Analyze();
            splitter.Transform();

            methodBody.UpdateVariables();

            var typeAnalysis = new TypeInferenceAnalysis(cfg);

            typeAnalysis.Analyze();

            var forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(cfg);

            forwardCopyAnalysis.Analyze();
            forwardCopyAnalysis.Transform(methodBody);

            var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(cfg);

            backwardCopyAnalysis.Analyze();
            backwardCopyAnalysis.Transform(methodBody);

            //var pointsTo = new PointsToAnalysis(cfg);
            //var result = pointsTo.Analyze();

            var ssa = new StaticSingleAssignmentAnalysis(methodBody, cfg);

            ssa.Transform();

            methodBody.UpdateVariables();

            ////var dot = DOTSerializer.Serialize(cfg);
            var dgml = DGMLSerializer.Serialize(cfg);

            return(base.Rewrite(methodDefinition));
        }
コード例 #2
0
        //string _code = String.Empty;

        /// <summary>
        /// For a given methodDefinition, create a CFG and run basic analyses such as
        /// stack removal, SSA transformation, live-variables analysis, and copy-propagation.
        /// </summary>
        /// <param name="methodDefinition"></param>
        /// <returns></returns>
        private ControlFlowGraph PrepareMethod(IMethodDefinition methodDefinition)
        {
            var disassembler = new Disassembler(mhost, methodDefinition, sourceLocationProvider);
            var methodBody   = disassembler.Execute();

            var cfg = ControlFlowGraph.GenerateNormalControlFlow(methodBody);

            ControlFlowGraph.ComputeDominators(cfg);
            ControlFlowGraph.IdentifyLoops(cfg);

            ControlFlowGraph.ComputeDominatorTree(cfg);
            ControlFlowGraph.ComputeDominanceFrontiers(cfg);

            // Uniquely rename stack variables.
            var splitter = new WebAnalysis(cfg);

            splitter.Analyze();
            splitter.Transform();

            methodBody.UpdateVariables();

            // Infer types for stack variables.
            var typeAnalysis = new TypeInferenceAnalysis(cfg);

            typeAnalysis.Analyze();

            var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(cfg);

            backwardCopyAnalysis.Analyze();
            backwardCopyAnalysis.Transform(methodBody);

            var lva = new LiveVariablesAnalysis(cfg);

            lva.Analyze();

            var ssa = new StaticSingleAssignmentAnalysis(methodBody, cfg);

            ssa.Transform();
            ssa.Prune(lva);

            methodBody.UpdateVariables();

            //_code = methodBody.ToString();
            return(cfg);
        }