public void GenerateCFG(MethodDefinition method) { var methodInfo = programInfo.GetOrAdd(method); //GenerateIL(method); GenerateTAC(method); if (!methodInfo.Contains("CFG")) { // Control-flow var cfAnalysis = new ControlFlowAnalysis(method.Body); var cfg = cfAnalysis.GenerateNormalControlFlow(); //var cfg = cfAnalysis.GenerateExceptionalControlFlow(); var domAnalysis = new DominanceAnalysis(cfg); domAnalysis.Analyze(); domAnalysis.GenerateDominanceTree(); //// Optional //var loopAnalysis = new NaturalLoopAnalysis(cfg); //loopAnalysis.Analyze(); var domFrontierAnalysis = new DominanceFrontierAnalysis(cfg); domFrontierAnalysis.Analyze(); var pdomAnalysis = new PostDominanceAnalysis(cfg); pdomAnalysis.Analyze(); pdomAnalysis.GeneratePostDominanceTree(); var pdomFrontierAnalysis = new PostDominanceFrontierAnalysis(cfg); pdomFrontierAnalysis.Analyze(); var controlDependenceAnalysis = new ControlDependenceAnalysis(cfg); controlDependenceAnalysis.Analyze(); var text = DGMLSerializer.Serialize(cfg); methodInfo.Add("CFG", cfg); methodInfo.Add("CFG_TEXT", text); text = DGMLSerializer.SerializeDominanceTree(cfg); methodInfo.Add("DT_TEXT", text); text = DGMLSerializer.SerializePostDominanceTree(cfg); methodInfo.Add("PDT_TEXT", text); text = DGMLSerializer.SerializeControlDependenceGraph(cfg); methodInfo.Add("CDG_TEXT", text); } }
public void GenerateWebs(MethodDefinition method) { var methodInfo = programInfo.GetOrAdd(method); //GenerateIL(method); //GenerateTAC(method); GenerateCFG(method); if (!methodInfo.Contains("WEBS_TEXT")) { var cfg = methodInfo.Get <ControlFlowGraph>("CFG"); // Webs var splitter = new WebAnalysis(cfg); splitter.Analyze(); splitter.Transform(); method.Body.UpdateVariables(); var typeAnalysis = new TypeInferenceAnalysis(cfg, method.ReturnType); typeAnalysis.Analyze(); //// Optional //var forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(cfg); //forwardCopyAnalysis.Analyze(); //forwardCopyAnalysis.Transform(method.Body); //// Optional //var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(cfg); //backwardCopyAnalysis.Analyze(); //backwardCopyAnalysis.Transform(method.Body); var text = method.Body.ToString(); methodInfo.Add("WEBS_TEXT", text); text = DGMLSerializer.Serialize(cfg); methodInfo.Set("CFG_TEXT", text); text = DGMLSerializer.SerializeDominanceTree(cfg); methodInfo.Set("DT_TEXT", text); text = DGMLSerializer.SerializePostDominanceTree(cfg); methodInfo.Set("PDT_TEXT", text); text = DGMLSerializer.SerializeControlDependenceGraph(cfg); methodInfo.Set("CDG_TEXT", text); } }
public void GenerateSSA(MethodDefinition method) { var methodInfo = programInfo.GetOrAdd(method); //GenerateIL(method); //GenerateTAC(method); //GenerateCFG(method); GenerateWebs(method); if (!methodInfo.Contains("SSA_TEXT")) { var cfg = methodInfo.Get <ControlFlowGraph>("CFG"); // Live Variables var liveVariables = new LiveVariablesAnalysis(cfg); var livenessInfo = liveVariables.Analyze(); // SSA var ssa = new StaticSingleAssignment(method.Body, cfg); ssa.Transform(); ssa.Prune(livenessInfo); method.Body.UpdateVariables(); var text = method.Body.ToString(); methodInfo.Add("SSA_TEXT", text); text = DGMLSerializer.Serialize(cfg); methodInfo.Set("CFG_TEXT", text); text = DGMLSerializer.SerializeDominanceTree(cfg); methodInfo.Set("DT_TEXT", text); text = DGMLSerializer.SerializePostDominanceTree(cfg); methodInfo.Set("PDT_TEXT", text); text = DGMLSerializer.SerializeControlDependenceGraph(cfg); methodInfo.Set("CDG_TEXT", text); } }