KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1999 Patrice Pominville, Raja Vallee-Rai
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  * Modified by the Sable Research Group and others 1997-2003.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot.toolkits.graph;
28
29 import java.util.*;
30 import java.io.*;
31 import soot.*;
32 import soot.jimple.Stmt;
33 import soot.baf.Inst;
34
35
36 /**
37  * A CFG where the nodes are {@link Block} instances, and where
38  * {@link Unit}s which include array references start new blocks.
39  * Exceptional control flow is ignored, so
40  * the graph will be a forest where each exception handler
41  * constitutes a disjoint subgraph.
42  */

43 public class ArrayRefBlockGraph extends BlockGraph
44 {
45     /**
46      * <p>Constructs an {@link ArrayRefBlockGraph} from the given
47      * {@link Body}.</p>
48      *
49      * <p> Note that this constructor builds a {@link
50      * BriefUnitGraph} internally when splitting <tt>body</tt>'s
51      * {@link Unit}s into {@link Block}s. Callers who need both a
52      * {@link BriefUnitGraph} and an {@link ArrayRefBlockGraph}
53      * should use the constructor taking the <tt>BriefUnitGraph</tt> as a
54      * parameter, as a minor optimization.</p>
55      *
56      * @param the Body instance from which the graph is built.
57      */

58     public ArrayRefBlockGraph(Body body)
59     {
60         this(new BriefUnitGraph(body));
61     }
62
63
64     /**
65      * Constructs an <tt>ArrayRefBlockGraph</tt> corresponding to the
66      * <tt>Unit</tt>-level control flow represented by the
67      * passed {@link BriefUnitGraph}.
68      *
69      * @param unitGraph The <tt>BriefUnitGraph</tt> for which
70      * to build an <tt>ArrayRefBlockGraph</tt>.
71      */

72     public ArrayRefBlockGraph(BriefUnitGraph unitGraph)
73     {
74         super(unitGraph);
75
76     soot.util.PhaseDumper.v().dumpGraph(this, mBody);
77     }
78
79     
80     /**
81      * <p>Utility method for computing the basic block leaders for a
82      * {@link Body}, given its {@link UnitGraph} (i.e., the
83      * instructions which begin new basic blocks).</p>
84      *
85      * <p> This implementation chooses as block leaders all
86      * the <tt>Unit</tt>s that {@link BlockGraph.computerLeaders()},
87      * and adds:
88      *
89      * <ul>
90      *
91      * <li>All <tt>Unit</tt>s which contain an array reference, as
92      * defined by {@link Stmt.containsArrayRef()} and
93      * {@link Inst.containsArrayRef()}.
94      *
95      * <li>The first <tt>Unit</tt> not covered by each {@link Trap} (i.e.,
96      * the <tt>Unit</tt> returned by {@link Trap.getLastUnit()}.</li>
97      *
98      * </ul></p>
99      *
100      * @param unitGraph is the <tt>Unit</tt>-level CFG which is to be split
101      * into basic blocks.
102      *
103      * @return the {@link Set} of {@link Unit}s in <tt>unitGraph</tt> which
104      * are block leaders.
105      */

106     protected Set computeLeaders(UnitGraph unitGraph) {
107     Body body = unitGraph.getBody();
108     if (body != mBody) {
109         throw new RuntimeException JavaDoc("ArrayRefBlockGraph.computeLeaders() called with a UnitGraph that doesn't match its mBody.");
110     }
111         Set leaders = super.computeLeaders(unitGraph);
112
113     for (Iterator it = body.getUnits().iterator(); it.hasNext(); ) {
114         Unit unit = (Unit) it.next();
115         if (((unit instanceof Stmt) && ((Stmt) unit).containsArrayRef()) ||
116         ((unit instanceof Inst) && ((Inst) unit).containsArrayRef())) {
117         leaders.add(unit);
118         }
119     }
120     return leaders;
121     }
122 }
123
124
125
Popular Tags