Exemple #1
0
        public IEnumerable <string> TestReachingDefinitionsOptimization(string sourceCode, bool preOptimize = false)
        {
            var graph = preOptimize ? BuildTACOptimizeCFG(sourceCode) : GenCFG(sourceCode);

            ReachingDefinitionsOptimization.DeleteDeadCode(graph);
            return(graph.GetInstructions().Select(i => i.ToString()));
        }
Exemple #2
0
        internal static (string, string) ApplyIterativeAlgorithm(ControlFlowGraph cfg, List <string> opts)
        {
            var strReturn = new StringBuilder();
            var strBefore = new StringBuilder();


            foreach (var b in cfg.GetCurrentBasicBlocks())
            {
                foreach (var inst in b.GetInstructions())
                {
                    strBefore.AppendLine(inst.ToString());
                }
                strBefore.AppendLine("----------");
            }

            foreach (var opt in opts)
            {
                switch (opt)
                {
                case "Доступные выражения":
                    var inout = new AvailableExpressions().Execute(cfg);
                    AvailableExpressionsOptimization.Execute(cfg, inout);
                    break;

                case "Активные переменные":
                    LiveVariablesOptimization.DeleteDeadCode(cfg);
                    break;

                case "Достигающие определения":
                    var reachDef = new ReachingDefinitionsOptimization();
                    reachDef.DeleteDeadCode(cfg);
                    break;
                }
            }


            foreach (var b in cfg.GetCurrentBasicBlocks())
            {
                foreach (var inst in b.GetInstructions())
                {
                    strReturn.AppendLine(inst.ToString());
                }
                strReturn.AppendLine("----------");
            }

            return(strBefore.ToString(), strReturn.ToString());
        }