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);

            // Блоки с нумерацией
            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();
        }
Exemplo n.º 2
0
        public void initCountersAndStacks(FrontOnDominance Fod, ControlFlowGraph CFG)
        {
            counters = new Dictionary <string, int>();
            stacks   = new Dictionary <string, Stack <string> >();
            foreach (string i in Fod.globals)
            {
                counters.Add(i, 0);
                stacks.Add(i, new Stack <string>());
            }

            CFG_ins = CFG;

            Idom = CFG_ins.CalcDommTree();

            succesor_list_cfg = CFG_ins.Next;
            Dom        = CFG_ins.FindDommBlocks();
            countNodes = CFG_ins.getCountNodes();
            var nodes = Enumerable.Range(0, countNodes);

            succesor_list_dom = new Dictionary <int, List <int> >();
            foreach (var n in nodes)
            {
                var tmp_list = new List <int>();
                for (int boxIndex = 0; boxIndex < CFG_ins.getCountNodes(); boxIndex++) //построение списка Succ дерева доминаторов
                {
                    if (boxIndex == n)
                    {
                        continue;
                    }
                    if (Idom[boxIndex] == n)
                    {
                        tmp_list.Add(boxIndex);
                    }
                }
                succesor_list_dom.Add(n, tmp_list);
            }
        }