예제 #1
0
    public static void Main(string [] args)
    {
        IRBlock block1 = new IRBlock(1);

        block1.AppendStatement(new IRTuple(IrOp.LABEL, "F$1"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "T", "R$2"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "A", "R$0"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "B", "R$1"));
        block1.AppendStatement(new IRTupleOneOpImm <int>(IrOp.STORE, "C", 0));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "D", "A"));

        IRBlock block2 = new IRBlock(2);

        block2.AppendStatement(new IRTuple(IrOp.LABEL, "L$1"));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.ADD, "C", "C", "B"));
        block2.AppendStatement(new IRTupleOneOpImm <int>(IrOp.STORE, "T$1", 1));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.SUB, "D", "D", "T$1"));
        block2.AppendStatement(new IRTupleOneOpImm <int>(IrOp.STORE, "T$2", 0));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.LTE, "T$3", "D", "T$2"));
        block2.AppendStatement(new IRTupleOneOpIdent(IrOp.JMPF, "L$1", "T$3"));

        IRBlock block3 = new IRBlock(3);

        block3.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "R$0", "C"));
        block3.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "R$2", "T"));

        block1.AddSuccessor(block2);
        block2.AddSuccessor(block2);
        block2.AddSuccessor(block3);

        List <IRBlock> blocks = new List <IRBlock>();

        blocks.Add(block1);
        blocks.Add(block2);
        blocks.Add(block3);

        foreach (IRBlock irb in blocks)
        {
            irb.ComputeLiveuseDef();
            irb.ComputeLiveouts();
            Console.WriteLine("B" + irb.GetIndex() + ":");
            irb.PrintStatements();
            irb.PrintSuccessors();
            irb.PrintLiveuseDef();
            irb.PrintLiveouts();
            Console.WriteLine();
        }
    }
예제 #2
0
파일: IRGraph.cs 프로젝트: ipud2/tcd-swift
 // Establish pointers between each block in the graph and its successor blocks
 private void LinkSuccessors(SortedDictionary <int, int> firsts, SortedDictionary <int, int> lasts)
 {
     foreach (KeyValuePair <int, IRBlock> pair in this.blocks)
     {
         IRBlock block = pair.Value;
         IRTuple tup   = block.GetLast(); // Get last statement in block
         if (tup.getOp() == IrOp.JMP)
         {
             foreach (KeyValuePair <int, IRBlock> pair0 in this.blocks)
             {
                 IRBlock block0 = pair0.Value;
                 IRTuple tup0   = block0.GetFirst();
                 if (tup0.getOp() == IrOp.LABEL && tup0.getDest() == tup.getDest())
                 {
                     block.AddSuccessor(block0);
                 }
             }
         }
         else if (tup.getOp() == IrOp.JMPF)
         {
             foreach (KeyValuePair <int, IRBlock> pair0 in this.blocks)
             {
                 IRBlock block0 = pair0.Value;
                 IRTuple tup0   = block0.GetFirst();
                 if (tup0.getOp() == IrOp.LABEL && tup0.getDest() == ((IRTupleOneOpIdent)tup).getDest())
                 {
                     block.AddSuccessor(block0);
                 }
                 else if (firsts[block0.GetIndex()] == lasts[block.GetIndex()] + 1)
                 {
                     block.AddSuccessor(block0);
                 }
             }
         }
         else
         {
             foreach (KeyValuePair <int, IRBlock> pair0 in this.blocks)
             {
                 IRBlock block0 = pair0.Value;
                 if (firsts[block0.GetIndex()] == lasts[block.GetIndex()] + 1)
                 {
                     block.AddSuccessor(block0);
                 }
             }
         }
     }
 }
예제 #3
0
    public static void Main(string [] args)
    {
        IRBlock block1 = new IRBlock(1);
        block1.AppendStatement(new IRTuple(IrOp.LABEL, "F$1"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "T", "R$2"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "A", "R$0"));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "B", "R$1"));
        block1.AppendStatement(new IRTupleOneOpImm<int>(IrOp.STORE, "C", 0));
        block1.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "D", "A"));

        IRBlock block2 = new IRBlock(2);
        block2.AppendStatement(new IRTuple(IrOp.LABEL, "L$1"));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.ADD, "C", "C", "B"));
        block2.AppendStatement(new IRTupleOneOpImm<int>(IrOp.STORE, "T$1", 1));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.SUB, "D", "D", "T$1"));
        block2.AppendStatement(new IRTupleOneOpImm<int>(IrOp.STORE, "T$2", 0));
        block2.AppendStatement(new IRTupleTwoOp(IrOp.LTE, "T$3", "D", "T$2"));
        block2.AppendStatement(new IRTupleOneOpIdent(IrOp.JMPF, "L$1", "T$3"));

        IRBlock block3 = new IRBlock(3);
        block3.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "R$0", "C"));
        block3.AppendStatement(new IRTupleOneOpIdent(IrOp.STORE, "R$2", "T"));

        block1.AddSuccessor(block2);
        block2.AddSuccessor(block2);
        block2.AddSuccessor(block3);

        List<IRBlock> blocks = new List<IRBlock>();
        blocks.Add(block1);
        blocks.Add(block2);
        blocks.Add(block3);

        foreach (IRBlock irb in blocks)
        {
          irb.ComputeLiveuseDef();
          irb.ComputeLiveouts();
          Console.WriteLine("B" + irb.GetIndex() + ":");
          irb.PrintStatements();
          irb.PrintSuccessors();
          irb.PrintLiveuseDef();
          irb.PrintLiveouts();
          Console.WriteLine();
        }
    }
예제 #4
0
    /*
     * Helper Methods
     */
    private static IRGraph BuildSampleCFG()
    {
        IRBlock block1 = new IRBlock(1);
        IRBlock block2 = new IRBlock(2);
        IRBlock block3 = new IRBlock(3);
        IRBlock block4 = new IRBlock(4);
        IRBlock block5 = new IRBlock(5);
        IRBlock block6 = new IRBlock(6);
        IRBlock block7 = new IRBlock(7);
        IRBlock block8 = new IRBlock(8);
        IRBlock block9 = new IRBlock(9);

        block1.AddSuccessor(block2);
        block2.AddSuccessor(block3);
        block3.AddSuccessor(block4);
        block3.AddSuccessor(block5);
        block4.AddSuccessor(block6);
        block4.AddSuccessor(block7);
        block5.AddSuccessor(block8);
        block6.AddSuccessor(block9);
        block7.AddSuccessor(block9);
        block9.AddSuccessor(block3);

        List <IRBlock> blocks = new List <IRBlock>();

        blocks.Add(block1);
        blocks.Add(block2);
        blocks.Add(block3);
        blocks.Add(block4);
        blocks.Add(block5);
        blocks.Add(block6);
        blocks.Add(block7);
        blocks.Add(block8);
        blocks.Add(block9);

        IRGraph cfg = new IRGraph(blocks);

        return(cfg);
    }
예제 #5
0
    /*
       * Helper Methods
       */
    private static IRGraph BuildSampleCFG()
    {
        IRBlock block1 = new IRBlock(1);
        IRBlock block2 = new IRBlock(2);
        IRBlock block3 = new IRBlock(3);
        IRBlock block4 = new IRBlock(4);
        IRBlock block5 = new IRBlock(5);
        IRBlock block6 = new IRBlock(6);
        IRBlock block7 = new IRBlock(7);
        IRBlock block8 = new IRBlock(8);
        IRBlock block9 = new IRBlock(9);

        block1.AddSuccessor(block2);
        block2.AddSuccessor(block3);
        block3.AddSuccessor(block4);
        block3.AddSuccessor(block5);
        block4.AddSuccessor(block6);
        block4.AddSuccessor(block7);
        block5.AddSuccessor(block8);
        block6.AddSuccessor(block9);
        block7.AddSuccessor(block9);
        block9.AddSuccessor(block3);

        List<IRBlock> blocks = new List<IRBlock>();
        blocks.Add(block1);
        blocks.Add(block2);
        blocks.Add(block3);
        blocks.Add(block4);
        blocks.Add(block5);
        blocks.Add(block6);
        blocks.Add(block7);
        blocks.Add(block8);
        blocks.Add(block9);

        IRGraph cfg = new IRGraph(blocks);
        return cfg;
    }