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