Ejemplo 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);
            }
        }
Ejemplo n.º 2
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();
        }