KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olhotak > liveness > LiveVariablesAnalysis


1 package olhotak.liveness;
2
3 import soot.*;
4 import soot.util.*;
5 import java.util.*;
6 import soot.jimple.*;
7 import soot.toolkits.graph.*;
8 import soot.toolkits.scalar.*;
9
10 class LiveVariablesAnalysis extends BackwardFlowAnalysis
11 {
12     protected void copy(Object JavaDoc src, Object JavaDoc dest)
13     {
14         FlowSet srcSet = (FlowSet) src;
15         FlowSet destSet = (FlowSet) dest;
16             
17         srcSet.copy(destSet);
18     }
19
20     protected void merge(Object JavaDoc src1, Object JavaDoc src2, Object JavaDoc dest)
21     {
22         FlowSet srcSet1 = (FlowSet) src1;
23         FlowSet srcSet2 = (FlowSet) src2;
24         FlowSet destSet = (FlowSet) dest;
25
26         srcSet1.union(srcSet2, destSet);
27     }
28
29     protected void flowThrough(Object JavaDoc srcValue, Object JavaDoc unit,
30             Object JavaDoc destValue)
31     {
32         FlowSet dest = (FlowSet) destValue;
33         FlowSet src = (FlowSet) srcValue;
34         Unit s = (Unit) unit;
35         src.copy (dest);
36
37         // Take out kill set
38
Iterator boxIt = s.getDefBoxes().iterator();
39         while (boxIt.hasNext()) {
40             ValueBox box = (ValueBox) boxIt.next();
41             Value value = box.getValue();
42             if (value instanceof Local)
43                 dest.remove(value);
44         }
45
46         // Add gen set
47
boxIt = s.getUseBoxes().iterator();
48         while (boxIt.hasNext()) {
49             ValueBox box = (ValueBox) boxIt.next();
50             Value value = box.getValue();
51             if (value instanceof Local)
52                 dest.add(value);
53         }
54     }
55
56     protected Object JavaDoc entryInitialFlow()
57     {
58         return new ArraySparseSet();
59     }
60         
61     protected Object JavaDoc newInitialFlow()
62     {
63         return new ArraySparseSet();
64     }
65
66     LiveVariablesAnalysis(DirectedGraph g)
67     {
68         super(g);
69
70         doAnalysis();
71     }
72 }
73
Popular Tags