1 19 20 package soot.shimple; 21 22 import soot.*; 23 import soot.options.*; 24 import soot.jimple.*; 25 import soot.jimple.internal.*; 26 import soot.jimple.toolkits.scalar.*; 27 import soot.shimple.internal.*; 28 import soot.shimple.toolkits.scalar.*; 29 import soot.toolkits.scalar.*; 30 import soot.util.*; 31 import java.util.*; 32 33 49 public class ShimpleBody extends StmtBody 50 { 51 54 protected ShimpleOptions options; 55 56 protected ShimpleBodyBuilder sbb; 57 58 protected boolean isExtendedSSA = false; 59 60 63 ShimpleBody(SootMethod m, Map options) 64 { 65 super(m); 66 67 this.options = new ShimpleOptions(options); 69 setSSA(true); 70 isExtendedSSA = this.options.extended(); 71 72 unitChain = new SPatchingChain(this, new HashChain()); 73 sbb = new ShimpleBodyBuilder(this); 74 } 75 76 84 ShimpleBody(Body body, Map options) 85 { 86 super(body.getMethod()); 87 88 if (!(body instanceof JimpleBody || body instanceof ShimpleBody)) 89 throw new RuntimeException ("Cannot construct ShimpleBody from given Body type."); 90 91 if(Options.v().verbose()) 92 G.v().out.println("[" + getMethod().getName() + "] Constructing ShimpleBody..."); 93 94 this.options = new ShimpleOptions(options); 96 97 unitChain = new SPatchingChain(this, new HashChain()); 98 importBodyContentsFrom(body); 99 100 101 sbb = new ShimpleBodyBuilder(this); 102 103 if(body instanceof ShimpleBody) 104 rebuild(true); 105 else 106 rebuild(false); 107 } 108 109 117 public void rebuild() 118 { 119 rebuild(true); 120 } 121 122 134 public void rebuild(boolean hasPhiNodes) 135 { 136 isExtendedSSA = options.extended(); 137 sbb.transform(); 138 setSSA(true); 139 } 140 141 156 public JimpleBody toJimpleBody() 157 { 158 ShimpleBody sBody = (ShimpleBody) this.clone(); 159 160 sBody.eliminateNodes(); 161 JimpleBody jBody = Jimple.v().newBody(sBody.getMethod()); 162 jBody.importBodyContentsFrom(sBody); 163 return jBody; 164 } 165 166 178 public void eliminatePhiNodes() 179 { 180 sbb.preElimOpt(); 181 sbb.eliminatePhiNodes(); 182 sbb.postElimOpt(); 183 setSSA(false); 184 } 185 186 public void eliminatePiNodes() 187 { 188 sbb.eliminatePiNodes(); 189 } 190 191 public void eliminateNodes() 192 { 193 sbb.preElimOpt(); 194 sbb.eliminatePhiNodes(); 195 if(isExtendedSSA) 196 sbb.eliminatePiNodes(); 197 sbb.postElimOpt(); 198 setSSA(false); 199 } 200 201 202 205 public Object clone() 206 { 207 Body b = Shimple.v().newBody(getMethod()); 208 b.importBodyContentsFrom(this); 209 return b; 210 } 211 212 216 protected boolean isSSA = false; 217 218 223 public void setSSA(boolean isSSA) 224 { 225 this.isSSA = isSSA; 226 } 227 228 233 public boolean isSSA() 234 { 235 return isSSA; 236 } 237 238 public boolean isExtendedSSA() 239 { 240 return isExtendedSSA; 241 } 242 243 246 public ShimpleOptions getOptions() 247 { 248 return options; 249 } 250 251 261 public void makeUniqueLocalNames() 262 { 263 sbb.makeUniqueLocalNames(); 264 } 265 } 266 | Popular Tags |