Exemplo n.º 1
0
        public static void Compile(BlockNode prog, Options opt)
        {
            var threeAddressGenerationVisitor = new ThreeAddressGenerationVisitor();

            prog.Visit(threeAddressGenerationVisitor);


            var code   = threeAddressGenerationVisitor.Data;
            var codeSz = code.Count;

            var codeBlocks = BaseBlockHelper.GenBaseBlocks(threeAddressGenerationVisitor.Data);

            foreach (var block in codeBlocks)
            {
                Console.Write(block);
            }


            codeBlocks = BaseBlockHelper.GenBaseBlocks(code);
            Optimize(codeBlocks);

            var JoindCode = BaseBlockHelper.JoinBaseBlocks(codeBlocks);

            CodeIO CP = new CodeIO(opt.OutputFile, opt.OutBinary);

            CP.Write(JoindCode);

            foreach (var block in codeBlocks)
            {
                Console.Write(block);
            }
        }
Exemplo n.º 2
0
        public override bool Optimize(List <BaseBlock> codeBlocks)
        {
            var CFG = new ControlFlowGraph(codeBlocks);

            var(InExprs, OutExpr) = CFG.GenerateInputOutputAvaliableExpr();


            var startToId = new Dictionary <int, int>();

            for (int i = 0; i < codeBlocks.Count; ++i)
            {
                startToId[codeBlocks[i].StartLabel] = i;
            }

            for (int i = 0; i < codeBlocks.Count; ++i)
            {
                if (TryOptimize(codeBlocks[i], InExprs[i], CFG.PrevBlocks(codeBlocks[i])))
                {
                    var code = BaseBlockHelper.JoinBaseBlocks(codeBlocks);
                    BaseBlockHelper.FixLabelsNumeration(code);
                    codeBlocks.Clear();
                    codeBlocks.InsertRange(0, BaseBlockHelper.GenBaseBlocks(code));

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static void Compile(BlockNode prog, Options opt)
        {
            var threeAddressGenerationVisitor = new ThreeAddressGenerationVisitor();

            prog.Visit(threeAddressGenerationVisitor);


            var code   = threeAddressGenerationVisitor.Data;
            var codeSz = code.Count;

            var codeBlocks = BaseBlockHelper.GenBaseBlocks(threeAddressGenerationVisitor.Data);

            foreach (var block in codeBlocks)
            {
                Console.Write(block);
            }


            codeBlocks = BaseBlockHelper.GenBaseBlocks(code);
            Optimize(codeBlocks);

            var JoindCode = BaseBlockHelper.JoinBaseBlocks(codeBlocks);

            CodeIO CP = new CodeIO(opt.OutputFile, opt.OutBinary);

            CP.Write(JoindCode);

            // Блоки с нумерацией
            Console.WriteLine();
            Console.WriteLine();


            // SSA


            var CFG = new ControlFlowGraph(codeBlocks);

            Console.WriteLine("Original");
            Console.Write(CFG);
            Console.Write(CFG.FindDommBlocks());



            var FOD = new FrontOnDominance(CFG); // Модифицирует CFG

            Console.Write(FOD);
            Console.Write(FOD.globalsToString());


            Console.WriteLine("Phi");
            Console.Write(CFG);
            Console.ReadLine();
        }
        public override bool Optimize(List <BaseBlock> codeBlocks)
        {
            var code = BaseBlockHelper.JoinBaseBlocks(codeBlocks);

            int startsz = code.Count;

            BaseBlockHelper.FixLabelsNumeration(code);

            var ncodeBlocks = BaseBlockHelper.GenBaseBlocks(code);
            var CFG         = new ControlFlowGraph(ncodeBlocks);

            ncodeBlocks = CFG.GetAliveBlocks();

            code = BaseBlockHelper.JoinBaseBlocks(ncodeBlocks);
            BaseBlockHelper.FixLabelsNumeration(code);
            codeBlocks.Clear();
            codeBlocks.InsertRange(0, BaseBlockHelper.GenBaseBlocks(code));
            return(startsz != code.Count);
        }