Ejemplo n.º 1
0
        public ILCompilationUnit BuildAst(
            ControlFlowGraph graph,
            IFrameLayout frameLayout,
            VMConstants constants)
        {
            var result = BuildBasicAst(graph, frameLayout);

            OnInitialAstBuilt(result);
            ApplyTransformations(result, constants);
            return(result);
        }
Ejemplo n.º 2
0
        public ILCompilationUnit(ControlFlowGraph controlFlowGraph, IFrameLayout frameLayout)
        {
            ControlFlowGraph = controlFlowGraph ?? throw new ArgumentNullException(nameof(controlFlowGraph));
            FrameLayout      = frameLayout;
            DominatorInfo    = new DominatorInfo(controlFlowGraph.Entrypoint);
            DominatorTree    = DominatorInfo.ToDominatorTree();

            for (int i = 0; i < frameLayout.Parameters.Count; i++)
            {
                var parameter = new ILParameter("arg_" + i, i);
                Parameters.Add(parameter);
                _variables.Add(parameter.Name, parameter);
            }
        }
Ejemplo n.º 3
0
        public ILCompilationUnit BuildAst(
            ControlFlowGraph graph,
            IFrameLayout frameLayout,
            VMConstants constants)
        {
            Logger.Debug(Tag, "Building initial IL-AST...");
            var result = BuildBasicAst(graph, frameLayout);

            OnInitialAstBuilt(result);

            Logger.Debug(Tag, "Applying IL-AST transforms...");
            ApplyTransformations(result, constants);

            return(result);
        }
Ejemplo n.º 4
0
        private ILCompilationUnit BuildBasicAst(ControlFlowGraph graph, IFrameLayout frameLayout)
        {
            var result = new ILCompilationUnit(graph, frameLayout);

            // Introduce variables:
            Logger.Debug2(Tag, "Determining variables...");
            var resultVariables = DetermineVariables(result);

            // Build AST blocks.
            Logger.Debug2(Tag, "Building AST blocks...");
            BuildAstBlocks(result, resultVariables);

            Logger.Debug2(Tag, "Marking expressions affecting flags...");
            var marker = new FlagDataSourceMarker();

            result.AcceptVisitor(marker);

            return(result);
        }
Ejemplo n.º 5
0
        private static MethodSignature CreateMethodSignature(DevirtualisationContext context, IFrameLayout layout)
        {
            var methodSignature = new MethodSignature(layout.ReturnType ?? context.TargetImage.TypeSystem.Object);

            // Add parameters.
            for (int i = 0; i < layout.Parameters.Count; i++)
            {
                methodSignature.Parameters.Add(
                    new ParameterSignature(layout.Parameters[i].Type ?? context.TargetImage.TypeSystem.Object));
            }

            methodSignature.HasThis = layout.HasThis;

            return(methodSignature);
        }
Ejemplo n.º 6
0
        private static MethodSignature CreateMethodSignature(DevirtualisationContext context, IFrameLayout layout)
        {
            var flags          = layout.HasThis ? CallingConventionAttributes.HasThis : 0;
            var returnType     = layout.ReturnType ?? context.TargetModule.CorLibTypeFactory.Object;
            var parameterTypes = new List <TypeSignature>();

            // Add parameters.
            for (int i = 0; i < layout.Parameters.Count; i++)
            {
                parameterTypes.Add(layout.Parameters[i].Type ?? context.TargetModule.CorLibTypeFactory.Object);
            }

            return(new MethodSignature(flags, returnType, parameterTypes));
        }