KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > scalar > BranchedFlowAnalysis


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-2000 Patrick Lam
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-2000.
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
28 /*
29     2000, March 20 - Updated code provided by
30                                     Patrick Lam <plam@sable.mcgill.ca>
31                      from 1.beta.4.dev.60
32                      to 1.beta.6.dev.34
33                      -- Janus (Richard Godard)
34 */

35
36 package soot.toolkits.scalar;
37
38 import soot.*;
39 import soot.toolkits.graph.*;
40 import soot.util.*;
41 import java.util.*;
42
43 /** Abstract class providing functionality for branched flow analysis.
44  *
45  * A branched flow analysis is one which can propagate different
46  * information to the successors of a node. This is useful for
47  * propagating information past a statement like <code>if(x &gt;
48  * 0)</code>: one successor has <code>x &gt; 0</code> while the other
49  * successor has <code>x &le; 0</code>. */

50 public abstract class BranchedFlowAnalysis extends AbstractFlowAnalysis
51 {
52     /** Maps graph nodes to OUT sets. */
53     protected Map unitToAfterFallFlow;
54     protected Map unitToAfterBranchFlow;
55
56     public BranchedFlowAnalysis(UnitGraph graph)
57     {
58         super(graph);
59
60         unitToAfterFallFlow = new HashMap(graph.size() * 2 + 1, 0.7f);
61         unitToAfterBranchFlow = new HashMap(graph.size() * 2 + 1, 0.7f);
62     }
63
64     /** Given the merge of the <code>in</code> sets,
65      * compute the <code>fallOut</code> and <code>branchOuts</code>
66      * set for <code>s</code>. */

67     protected abstract void flowThrough(Object JavaDoc in, Unit s,
68                                         List fallOut, List branchOuts);
69
70     public Object JavaDoc getFallFlowAfter(Unit s)
71     {
72         List fl = (List) unitToAfterFallFlow.get(s);
73
74         if (fl.isEmpty())
75             return newInitialFlow();
76         else
77             return fl.get(0);
78     }
79
80
81     public List getBranchFlowAfter(Unit s)
82     {
83         return (List) (unitToAfterBranchFlow.get(s));
84     }
85
86     public Object JavaDoc getFlowBefore(Unit s)
87     {
88         return unitToBeforeFlow.get(s);
89     }
90 } // end class BranchedFlowAnalysis
91

92
Popular Tags