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)); }
//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); }
public static void TransformToTac(MethodDefinition method) { Disassembler disassembler = new Disassembler(method); MethodBody methodBody = disassembler.Execute(); method.Body = methodBody; ControlFlowAnalysis cfAnalysis = new ControlFlowAnalysis(method.Body); //var cfg = cfAnalysis.GenerateNormalControlFlow(); Backend.Model.ControlFlowGraph cfg = cfAnalysis.GenerateExceptionalControlFlow(); WebAnalysis splitter = new WebAnalysis(cfg); splitter.Analyze(); splitter.Transform(); methodBody.UpdateVariables(); TypeInferenceAnalysis typeAnalysis = new TypeInferenceAnalysis(cfg, method.ReturnType); typeAnalysis.Analyze(); // Copy Propagation ForwardCopyPropagationAnalysis forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(cfg); forwardCopyAnalysis.Analyze(); forwardCopyAnalysis.Transform(methodBody); BackwardCopyPropagationAnalysis backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(cfg); backwardCopyAnalysis.Analyze(); backwardCopyAnalysis.Transform(methodBody); methodBody.UpdateVariables(); }
//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 sw2 = new Stopwatch(); sw2.Start(); var disassembler = new Disassembler(mhost, methodDefinition, sourceLocationProvider); var methodBody = disassembler.Execute(); var cfAnalysis = new ControlFlowAnalysis(methodBody); var cfg = cfAnalysis.GenerateNormalControlFlow(); var domAnalysis = new DominanceAnalysis(cfg); domAnalysis.Analyze(); domAnalysis.GenerateDominanceTree(); var loopAnalysis = new NaturalLoopAnalysis(cfg); loopAnalysis.Analyze(); var domFrontierAnalysis = new DominanceFrontierAnalysis(cfg); domFrontierAnalysis.Analyze(); var splitter = new WebAnalysis(cfg, methodDefinition); splitter.Analyze(); splitter.Transform(); methodBody.UpdateVariables(); var analysis = new TypeInferenceAnalysis(cfg, methodBody.MethodDefinition.Type); analysis.Analyze(); var copyProgapagtion = new ForwardCopyPropagationAnalysis(cfg); copyProgapagtion.Analyze(); copyProgapagtion.Transform(methodBody); var backwardCopyProgapagtion = new BackwardCopyPropagationAnalysis(cfg); backwardCopyProgapagtion.Analyze(); backwardCopyProgapagtion.Transform(methodBody); var liveVariables = new LiveVariablesAnalysis(cfg); var resultLiveVar = liveVariables.Analyze(); var ssa = new StaticSingleAssignment(methodBody, cfg); ssa.Transform(); ssa.Prune(liveVariables); methodBody.UpdateVariables(); sw2.Stop(); this.nonAnalysisOverhead = sw2.Elapsed; return(cfg); //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; }