KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > graph > ClassicCompleteBlockGraph


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 John Jorgensen
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20
21 package soot.toolkits.graph;
22
23 import java.util.*;
24 import soot.*;
25 import java.io.*;
26
27 /**
28  * <p>Represents a CFG where the nodes are {@link Block}s and the
29  * edges are derived from control flow. Control flow associated with
30  * exceptions is taken into account: when a <tt>Unit</tt> may throw
31  * an exception that is caught by a {@link Trap} within the
32  * <tt>Body</tt>, the excepting <tt>Unit</tt> starts a new basic
33  * block.</p>
34  *
35  * <p> <tt>ClassicCompleteBlockGraph</tt> approximates the results
36  * that would have been produced by Soot's {@link CompleteBlockGraph}
37  * in releases up to Soot 2.1.0. It is included solely for testing
38  * purposes, and should not be used in actual analyses. The approximation
39  * works not by duplicating the old {@link CompleteBlockGraph}'s logic,
40  * but by using {@link ClassicCompleteUnitGraph} as the basis for
41  * dividing {@link Unit}s into {@link Block}s.</p>
42  *
43  */

44
45 public class ClassicCompleteBlockGraph extends BlockGraph
46 {
47     /**
48      * <p> Constructs a <tt>ClassicCompleteBlockGraph</tt> for the blocks
49      * found by partitioning the the units of the provided
50      * {@link Body} instance into basic blocks.</p>
51      *
52      * <p> Note that this constructor builds a {@link
53      * ClassicCompleteUnitGraph} internally when splitting <tt>body</tt>'s
54      * {@link Unit}s into {@link Block}s. Callers who already have
55      * a {@link ClassicCompleteUnitGraph} to hand can use the constructor
56      * taking a <tt>ClassicCompleteUnitGraph</tt> as a parameter, as a
57      * minor optimization.
58      *
59      * @param body The underlying body we want to make a graph for.
60      */

61     public ClassicCompleteBlockGraph(Body body)
62     {
63         super(new ClassicCompleteUnitGraph(body));
64     }
65
66
67     /**
68      * Constructs a graph for the blocks found by partitioning the
69      * the units in a {@link ClassicCompleteUnitGraph}.
70      *
71      * @param unitGraph A {@link ClassicCompleteUnitGraph} built from
72      * <tt>body</tt>. The <tt>CompleteBlockGraph</tt> constructor uses
73      * the passed <tt>graph</tt> to split the body into
74      * blocks.
75      */

76     public ClassicCompleteBlockGraph(ClassicCompleteUnitGraph unitGraph)
77     {
78         super(unitGraph);
79     // Adjust the heads and tails to match the old CompleteBlockGraph.
80
Unit entryPoint = (Unit) (getBody().getUnits().getFirst());
81     List newHeads = new ArrayList(1);
82     for (Iterator blockIt = getBlocks().iterator(); blockIt.hasNext(); ) {
83         Block b = (Block) blockIt.next();
84         if (b.getHead() == entryPoint) {
85         newHeads.add(b);
86         break;
87         }
88     }
89     mHeads = Collections.unmodifiableList(newHeads);
90     mTails = Collections.EMPTY_LIST;
91
92     soot.util.PhaseDumper.v().dumpGraph(this, mBody);
93     }
94 }
95
96
97
Popular Tags