1 19 20 25 26 27 28 package soot.jimple.toolkits.scalar; 29 import soot.options.*; 30 31 import soot.util.*; 32 import soot.*; 33 import soot.jimple.*; 34 import java.io.*; 35 import java.util.*; 36 37 38 public class ConditionalBranchFolder extends BodyTransformer 39 { 40 public ConditionalBranchFolder ( Singletons.Global g ) {} 41 public static ConditionalBranchFolder v() { return G.v().soot_jimple_toolkits_scalar_ConditionalBranchFolder (); } 42 43 protected void internalTransform(Body body, String phaseName, Map options) 44 { 45 StmtBody stmtBody = (StmtBody)body; 46 47 int numTrue = 0, numFalse = 0; 48 49 if (Options.v().verbose()) 50 G.v().out.println("[" + stmtBody.getMethod().getName() + 51 "] Folding conditional branches..."); 52 53 Chain units = stmtBody.getUnits(); 54 ArrayList unitList = new ArrayList(); unitList.addAll(units); 55 56 Iterator stmtIt = unitList.iterator(); 57 while (stmtIt.hasNext()) { 58 Stmt stmt = (Stmt)stmtIt.next(); 59 if (stmt instanceof IfStmt) { 60 Value cond = ((IfStmt) stmt).getCondition(); 62 if (Evaluator.isValueConstantValued(cond)) { 63 cond = Evaluator.getConstantValueOf(cond); 64 65 if (((IntConstant) cond).value == 1) { 66 Stmt newStmt = 68 Jimple.v().newGotoStmt(((IfStmt)stmt).getTarget()); 69 70 units.insertAfter(newStmt, stmt); 71 72 numTrue++; 73 } 74 else 75 numFalse++; 76 77 units.remove(stmt); 79 } 80 } 81 } 82 83 if (Options.v().verbose()) 84 G.v().out.println("[" + stmtBody.getMethod().getName() + 85 "] Folded " + numTrue + " true, " + numFalse + 86 " conditional branches"); 87 88 } 90 } 92 | Popular Tags |