// this function applies analysis-net analyses on the method defined in our assembly (methodDefinition) // the result is a typed stackless three address code representation of the orignal method definition body // you can 'out' the control flow graph because it can be reused for another analysis public static MethodBody ThreeAddressCode(IMethodDefinition methodDefinition, MetadataReaderHost host, out ControlFlowGraph cfg) { if (methodDefinition.IsAbstract || methodDefinition.IsExternal) { cfg = null; return(null); } var disassembler = new Disassembler(host, methodDefinition, null); var methodBody = disassembler.Execute(); var cfAnalysis = new ControlFlowAnalysis(methodBody); //var cfg = cfAnalysis.GenerateNormalControlFlow(); cfg = cfAnalysis.GenerateExceptionalControlFlow(); var splitter = new WebAnalysis(cfg, methodDefinition); splitter.Analyze(); splitter.Transform(); methodBody.UpdateVariables(); var typeAnalysis = new TypeInferenceAnalysis(cfg, methodDefinition.Type); typeAnalysis.Analyze(); methodBody.UpdateVariables(); return(methodBody); }
public void Execute() { var disassembler = new Backend.Transformations.Disassembler(host, methodDefinition, sourceLocationProvider); var methodBody = disassembler.Execute(); MethodBody = methodBody; var cfAnalysis = new ControlFlowAnalysis(methodBody); ControlFlowGraph = cfAnalysis.GenerateExceptionalControlFlow(); var splitter = new WebAnalysis(ControlFlowGraph, methodBody.MethodDefinition); splitter.Analyze(); splitter.Transform(); methodBody.UpdateVariables(); var typeAnalysis = new TypeInferenceAnalysis(ControlFlowGraph, methodBody.MethodDefinition.Type); typeAnalysis.Analyze(); //var forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(Traverser.CFG); //forwardCopyAnalysis.Analyze(); //forwardCopyAnalysis.Transform(methodBody); //var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(Traverser.CFG); //backwardCopyAnalysis.Analyze(); //backwardCopyAnalysis.Transform(methodBody); // TinyBCT transformations var fieldInitialization = new FieldInitialization(methodBody); fieldInitialization.Transform(); if (!Settings.AddressesEnabled()) { var refAlias = new RefAlias(methodBody); refAlias.Transform(); } // execute this after RefAlias! var immutableArguments = new ImmutableArguments(methodBody); immutableArguments.Transform(); methodBody.RemoveUnusedLabels(); }
public static void transformBody(MethodBody methodBody) { var cfAnalysis = new ControlFlowAnalysis(methodBody); //var cfg = cfAnalysis.GenerateNormalControlFlow(); Traverser.CFG = cfAnalysis.GenerateExceptionalControlFlow(); var splitter = new WebAnalysis(Traverser.CFG, methodBody.MethodDefinition); splitter.Analyze(); splitter.Transform(); methodBody.UpdateVariables(); var typeAnalysis = new TypeInferenceAnalysis(Traverser.CFG, methodBody.MethodDefinition.Type); typeAnalysis.Analyze(); //var forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(Traverser.CFG); //forwardCopyAnalysis.Analyze(); //forwardCopyAnalysis.Transform(methodBody); //var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(Traverser.CFG); //backwardCopyAnalysis.Analyze(); //backwardCopyAnalysis.Transform(methodBody); // TinyBCT transformations if (!Settings.NewAddrModelling) { var refAlias = new RefAlias(methodBody); refAlias.Transform(); var immutableArguments = new ImmutableArguments(methodBody); immutableArguments.Transform(); var fieldInitialization = new FieldInitialization(methodBody); fieldInitialization.Transform(); } methodBody.RemoveUnusedLabels(); }
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(); }
public MethodCfgAndTac AnalyzeIntraProcedural(IMethodDefinition methodDefinition) { // System.Console.WriteLine("Traversing: {0}", methodDefinition.GetName()); if (Stubber.SuppressM(methodDefinition)) { return(null); } if (methodDefinition.IsExternal) { return(null); } if (methodDefinition.IsAbstract) { return(null); } ITypeDefinition containingDefn = methodDefinition.ContainingTypeDefinition; ISourceLocationProvider sourceLocationProvider = null; if (containingDefn != null) { IModule mod = TypeHelper.GetDefiningUnit(containingDefn) as IModule; if (moduleToPdbMap.ContainsKey(mod)) { sourceLocationProvider = moduleToPdbMap[mod]; } else { if (!(mod == null || mod == Dummy.Module || mod == Dummy.Assembly)) { sourceLocationProvider = GetPdbReader(mod.Location); moduleToPdbMap[mod] = sourceLocationProvider; } } } var disassembler = new Disassembler(host, methodDefinition, sourceLocationProvider); var methodBody = disassembler.Execute(); var cfAnalysis = new ControlFlowAnalysis(methodBody); // var cfg = cfAnalysis.GenerateNormalControlFlow(); var cfg = cfAnalysis.GenerateExceptionalControlFlow(); 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 typeAnalysis = new TypeInferenceAnalysis(cfg, methodDefinition.Type); typeAnalysis.Analyze(); var forwardCopyAnalysis = new ForwardCopyPropagationAnalysis(cfg); forwardCopyAnalysis.Analyze(); forwardCopyAnalysis.Transform(methodBody); // backwardCopyAnalysis is buggy - it says so in the source file - see notes in src/test // var backwardCopyAnalysis = new BackwardCopyPropagationAnalysis(cfg); // backwardCopyAnalysis.Analyze(); // backwardCopyAnalysis.Transform(methodBody); var liveVariables = new LiveVariablesAnalysis(cfg); liveVariables.Analyze(); var ssa = new StaticSingleAssignment(methodBody, cfg); ssa.Transform(); ssa.Prune(liveVariables); methodBody.UpdateVariables(); MethodCfgAndTac mct = new MethodCfgAndTac(cfg, methodBody); foreach (IExceptionHandlerBlock ehInfo in disassembler.GetExceptionHandlers()) { if (ehInfo is CatchExceptionHandler) { mct.ehInfoList.Add(ehInfo as CatchExceptionHandler); } } return(mct); }