KickJava   Java API By Example, From Geeks To Geeks.

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


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
33
34 /**
35  * A CFG where the nodes are {@link Block} instances, and where
36  * exception boundaries are taken into account when finding the
37  * <tt>Block</tt>s for the provided Body. Any {@link Unit} which is
38  * the first <tt>Unit</tt> to be convered by some exception handler
39  * will start a new Block, and any <ttUnit</tt> which is the last
40  * <tt>Unit</tt> to be covered a some exception handler, will end the
41  * block it is part of. These ``zones'', however, are not split up
42  * to indicate the possibility that an exception will lead to control
43  * exiting the zone before it is completed.
44  *
45  */

46
47 public class ZonedBlockGraph extends BlockGraph
48 {
49     /**
50      * <p>Constructs a <tt>ZonedBlockGraph</tt> for the <tt>Unit</tt>s
51      * comprising the passed {@link Body}.</p>
52      *
53      * <p> Note that this constructor builds a {@link
54      * BriefUnitGraph} internally when splitting <tt>body</tt>'s
55      * {@link Unit}s into {@link Block}s. Callers who need both a
56      * {@link BriefUnitGraph} and a {@link ZonedBlockGraph}
57      * can use the constructor taking the <tt>BriefUnitGraph</tt> as a
58      * parameter, as a minor optimization.</p>
59      *
60      * @param body The <tt>Body</tt> for which to produce
61      * a <tt>ZonedBlockGraph</tt>.
62      */

63     public ZonedBlockGraph(Body body)
64     {
65         this(new BriefUnitGraph(body));
66     }
67
68
69     /**
70      * Constructs a <tt>ZonedBlockGraph</tt> corresponding to the
71      * <tt>Unit</tt>-level control flow represented by the
72      * passed {@link BriefUnitGraph}.
73      *
74      * @param unitGraph The <tt>BriefUnitGraph</tt> for which to produce
75      * a <tt>ZonedBlockGraph</tt>.
76      */

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

111     protected Set computeLeaders(UnitGraph unitGraph) {
112     Body body = unitGraph.getBody();
113     if (body != mBody) {
114         throw new RuntimeException JavaDoc("ZonedBlockGraph.computeLeaders() called with a UnitGraph that doesn't match its mBody.");
115     }
116
117         Set leaders = super.computeLeaders(unitGraph);
118
119     for (Iterator it = body.getTraps().iterator(); it.hasNext(); ) {
120         Trap trap = (Trap) it.next();
121         leaders.add(trap.getBeginUnit());
122         leaders.add(trap.getEndUnit());
123     }
124     return leaders;
125     }
126 }
127
Popular Tags