1 19 20 25 26 27 28 29 30 package soot.baf; 31 import soot.options.*; 32 33 import soot.*; 34 import soot.jimple.*; 35 import soot.baf.toolkits.base.*; 36 import soot.toolkits.scalar.*; 37 38 import soot.util.*; 39 import java.util.*; 40 import java.io.*; 41 42 public class BafBody extends Body 43 { 44 public Object clone() 45 { 46 Body b = new BafBody(getMethod()); 47 b.importBodyContentsFrom(this); 48 return b; 49 } 50 51 BafBody(SootMethod m) 52 { 53 super(m); 54 } 55 56 public BafBody(Body body, Map options) 57 { 58 super(body.getMethod()); 59 60 if(Options.v().verbose()) 61 G.v().out.println("[" + getMethod().getName() + "] Constructing BafBody..."); 62 63 JimpleBody jimpleBody; 64 65 if(body instanceof JimpleBody) 66 jimpleBody = (JimpleBody) body; 67 else 68 throw new RuntimeException ("Can only construct BafBody's directly" 69 + " from JimpleBody's."); 70 71 jimpleBody.validate(); 72 73 JimpleToBafContext context = new JimpleToBafContext(jimpleBody.getLocalCount()); 74 75 { 77 Iterator localIt = jimpleBody.getLocals().iterator(); 78 79 while(localIt.hasNext()) 80 { 81 Local l = (Local) localIt.next(); 82 Type t = l.getType(); 83 Local newLocal; 84 85 newLocal = Baf.v().newLocal(l.getName(), UnknownType.v()); 86 87 if(t.equals(DoubleType.v()) || t.equals(LongType.v())) 88 newLocal.setType(DoubleWordType.v()); 89 else 90 newLocal.setType(WordType.v()); 91 92 context.setBafLocalOfJimpleLocal(l, newLocal); 93 getLocals().add(newLocal); 94 } 95 } 96 97 Map stmtToFirstInstruction = new HashMap(); 98 99 { 101 Iterator stmtIt = jimpleBody.getUnits().iterator(); 102 103 while(stmtIt.hasNext()) 104 { 105 Stmt s = (Stmt) stmtIt.next(); 106 List conversionList = new ArrayList(); 107 108 context.setCurrentUnit(s); 109 ((ConvertToBaf) s).convertToBaf(context, conversionList); 110 111 stmtToFirstInstruction.put(s, conversionList.get(0)); 112 getUnits().addAll(conversionList); 113 } 114 } 115 116 { 118 Iterator boxIt = getAllUnitBoxes().iterator(); 119 120 while(boxIt.hasNext()) 121 { 122 UnitBox box = (UnitBox) boxIt.next(); 123 124 if(box.getUnit() instanceof PlaceholderInst) 125 { 126 Unit source = ((PlaceholderInst) box.getUnit()).getSource(); 127 box.setUnit((Unit) stmtToFirstInstruction.get(source)); 128 } 129 } 130 } 131 132 { 134 Iterator trapIt = jimpleBody.getTraps().iterator(); 135 while (trapIt.hasNext()) 136 { 137 Trap trap = (Trap) trapIt.next(); 138 139 getTraps().add(Baf.v().newTrap(trap.getException(), 140 (Unit)stmtToFirstInstruction.get(trap.getBeginUnit()), 141 (Unit)stmtToFirstInstruction.get(trap.getEndUnit()), 142 (Unit)stmtToFirstInstruction.get(trap.getHandlerUnit()))); 143 } 144 } 145 146 PackManager.v().getPack( "bb" ).apply( this ); 147 } 148 } 149 | Popular Tags |