Exemple #1
0
            public BuildBlocks(List <TExp> instList)
            {
                Dictionary <Temp.Label, BasicBlock> LabelToBlock = new Dictionary <Temp.Label, BasicBlock>();

                foreach (TExp e in instList)
                {
                    if (e is Label)
                    {
                        BasicBlock b = new BasicBlock();
                        Blocks.Add(b);
                        LabelToBlock[(e as Label).Lab] = b;
                    }
                    Blocks[Blocks.Count - 1].List.Add(e);
                }
                for (int i = 0; i < Blocks.Count; ++i)
                {
                    BasicBlock b = Blocks[i];
                    if (b.List[b.List.Count - 1] is Jump)
                    {
                        b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as Jump).Label.Lab]);
                    }
                    else
                    {
                        if (i + 1 < Blocks.Count)
                        {
                            b.AddEdge(Blocks[i + 1]);
                        }
                        if (b.List[b.List.Count - 1] is CJump)
                        {
                            b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as CJump).Label.Lab]);
                        }
                        else if (b.List[b.List.Count - 1] is CJumpInt)
                        {
                            b.AddEdge(LabelToBlock[(b.List[b.List.Count - 1] as CJumpInt).Label.Lab]);
                        }
                    }
                }
            }