| 1 19 20 package soot.shimple.toolkits.scalar; 21 22 import soot.*; 23 import soot.util.*; 24 import soot.jimple.*; 25 import soot.shimple.*; 26 import soot.toolkits.scalar.*; 27 import java.util.*; 28 29 45 public class ShimpleLocalUses implements LocalUses 46 { 47 protected Map localToUses; 48 49 54 public ShimpleLocalUses(ShimpleBody sb) 55 { 56 if(!sb.isSSA()) 59 throw new RuntimeException ("ShimpleBody is not in proper SSA form as required by ShimpleLocalUses. You may need to rebuild it or use SimpleLocalUses instead."); 60 61 localToUses = new HashMap(); 63 Iterator localsIt = sb.getLocals().iterator(); 64 while(localsIt.hasNext()){ 65 Local local = (Local) localsIt.next(); 66 localToUses.put(local, new ArrayList()); 67 } 68 69 Iterator unitsIt = sb.getUnits().iterator(); 73 while(unitsIt.hasNext()){ 74 Unit unit = (Unit) unitsIt.next(); 75 Iterator boxIt = unit.getUseBoxes().iterator(); 76 77 while(boxIt.hasNext()){ 78 ValueBox box = (ValueBox)boxIt.next(); 79 Value value = box.getValue(); 80 81 if(!(value instanceof Local)) 82 continue; 83 84 List useList = (List) localToUses.get(value); 85 useList.add(new UnitValueBoxPair(unit, box)); 86 } 87 } 88 } 89 90 98 public List getUsesOf(Local local) 99 { 100 List uses = (List) localToUses.get(local); 101 if(uses == null) 102 return Collections.EMPTY_LIST; 103 return uses; 104 } 105 106 112 public List getUsesOf(Unit unit) 113 { 114 List defBoxes = unit.getDefBoxes(); 115 116 switch(defBoxes.size()){ 117 case 0: 118 return Collections.EMPTY_LIST; 119 case 1: 120 Value local = ((ValueBox)defBoxes.get(0)).getValue(); 121 if(!(local instanceof Local)) 122 return Collections.EMPTY_LIST; 123 return getUsesOf((Local) local); 124 default: 125 G.v().out.println("Warning: Unit has multiple definition boxes?"); 126 List usesList = new ArrayList(); 127 Iterator defBoxesIt = defBoxes.iterator(); 128 while(defBoxesIt.hasNext()){ 129 Value def = ((ValueBox)defBoxesIt.next()).getValue(); 130 if(def instanceof Local) 131 usesList.addAll(getUsesOf((Local) def)); 132 } 133 return usesList; 134 } 135 } 136 } 137 | Popular Tags |