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 src, Object dest) 13 { 14 FlowSet srcSet = (FlowSet) src; 15 FlowSet destSet = (FlowSet) dest; 16 17 srcSet.copy(destSet); 18 } 19 20 protected void merge(Object src1, Object src2, Object 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 srcValue, Object unit, 30 Object destValue) 31 { 32 FlowSet dest = (FlowSet) destValue; 33 FlowSet src = (FlowSet) srcValue; 34 Unit s = (Unit) unit; 35 src.copy (dest); 36 37 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 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 entryInitialFlow() 57 { 58 return new ArraySparseSet(); 59 } 60 61 protected Object newInitialFlow() 62 { 63 return new ArraySparseSet(); 64 } 65 66 LiveVariablesAnalysis(DirectedGraph g) 67 { 68 super(g); 69 70 doAnalysis(); 71 } 72 } 73 | Popular Tags |