1 19 20 25 26 27 28 29 30 31 package soot.toolkits.scalar; 32 import soot.options.*; 33 34 import soot.*; 35 import soot.toolkits.graph.*; 36 import soot.util.*; 37 import java.util.*; 38 39 40 46 public class SimpleLocalUses implements LocalUses 47 { 48 Map unitToUses; 49 50 58 public SimpleLocalUses(UnitGraph graph, LocalDefs localDefs) 59 { 60 this(graph.getBody(), localDefs); 61 } 62 63 68 public SimpleLocalUses(Body body, LocalDefs localDefs) 69 { 70 if(Options.v().time()) 71 Timers.v().usesTimer.start(); 72 73 if(Options.v().time()) 74 Timers.v().usePhase1Timer.start(); 75 76 if(Options.v().verbose()) 77 G.v().out.println("[" + body.getMethod().getName() + 78 "] Constructing SimpleLocalUses..."); 79 80 Chain units = body.getUnits(); 81 82 unitToUses = new HashMap(units.size() * 2 + 1, 0.7f); 83 84 { 86 Iterator it = units.iterator(); 87 88 while(it.hasNext()) 89 { 90 Unit s = (Unit) it.next(); 91 unitToUses.put(s, new ArrayList()); 92 } 93 } 94 95 if(Options.v().time()) 96 Timers.v().usePhase1Timer.end(); 97 98 if(Options.v().time()) 99 Timers.v().usePhase2Timer.start(); 100 101 { 103 Iterator it = units.iterator(); 104 105 while(it.hasNext()) 106 { 107 Unit s = (Unit) it.next(); 108 109 Iterator boxIt = s.getUseBoxes().iterator(); 110 111 while(boxIt.hasNext()) 112 { 113 ValueBox useBox = (ValueBox) boxIt.next(); 114 115 if(useBox.getValue() instanceof Local) 116 { 117 119 Local l = (Local) useBox.getValue(); 120 121 List possibleDefs = localDefs.getDefsOfAt(l, s); 122 Iterator defIt = possibleDefs.iterator(); 123 124 while(defIt.hasNext()) 125 { 126 List useList = (List) unitToUses.get(defIt.next()); 127 useList.add(new UnitValueBoxPair(s, useBox)); 128 } 129 } 130 } 131 } 132 } 133 134 if(Options.v().time()) 135 Timers.v().usePhase2Timer.end(); 136 137 if(Options.v().time()) 138 Timers.v().usePhase3Timer.start(); 139 140 { 142 Iterator it = units.iterator(); 143 144 while(it.hasNext()) 145 { 146 Unit s = (Unit) it.next(); 147 148 unitToUses.put(s, Collections.unmodifiableList(((List) unitToUses.get(s)))); 149 } 150 151 } 152 153 if(Options.v().time()) 154 Timers.v().usePhase3Timer.end(); 155 156 if(Options.v().time()) 157 Timers.v().usesTimer.end(); 158 159 if(Options.v().verbose()) 160 G.v().out.println("[" + body.getMethod().getName() + 161 "] finished SimpleLocalUses..."); 162 } 163 164 171 public List getUsesOf(Unit s) 172 { 173 List l = (List) unitToUses.get(s); 174 175 return l; 176 } 177 } 178 | Popular Tags |