1 19 20 package soot.jimple.toolkits.annotation.parity; 21 import soot.*; 22 import java.util.*; 23 import soot.toolkits.graph.*; 24 import soot.toolkits.scalar.*; 25 import soot.tagkit.*; 26 import soot.jimple.*; 27 import soot.options.*; 28 29 31 public class ParityTagger extends BodyTransformer 32 { 33 public ParityTagger( Singletons.Global g ) {} 34 public static ParityTagger v() { return G.v().soot_jimple_toolkits_annotation_parity_ParityTagger(); } 35 36 protected void internalTransform( 37 Body b, String phaseName, Map options) 38 { 39 40 boolean isInteractive = Options.v().interactive_mode(); 42 Options.v().set_interactive_mode(false); 43 ParityAnalysis a; 44 45 if (isInteractive){ 46 LiveLocals sll = new SimpleLiveLocals(new BriefUnitGraph(b)); 47 Options.v().set_interactive_mode(isInteractive); 48 49 a = new ParityAnalysis( 50 new BriefUnitGraph( b ) , sll); 51 } 52 else { 53 a = new ParityAnalysis(new BriefUnitGraph(b)); 54 } 55 56 Iterator sIt = b.getUnits().iterator(); 57 while( sIt.hasNext() ) { 58 59 Stmt s = (Stmt) sIt.next(); 60 61 HashMap parityVars = (HashMap) a.getFlowAfter( s ); 62 63 Iterator it = parityVars.keySet().iterator(); 64 while( it.hasNext() ) { 65 66 final Value variable = (Value) it.next(); 67 if ((variable instanceof IntConstant) || (variable instanceof LongConstant)){ 68 } 70 else{ 71 StringTag t = new StringTag( 72 "Parity variable: "+variable+" "+ 73 parityVars.get(variable) , "Parity Analysis"); 74 s.addTag( t ); 75 } 76 } 77 78 HashMap parityVarsUses = (HashMap) a.getFlowBefore( s ); 79 HashMap parityVarsDefs = (HashMap) a.getFlowAfter( s ); 80 81 82 84 Iterator valBoxIt = s.getUseBoxes().iterator(); 85 86 while (valBoxIt.hasNext()){ 87 ValueBox vb = (ValueBox)valBoxIt.next(); 88 if (parityVarsUses.containsKey(vb.getValue())){ 89 String type = (String )parityVarsUses.get(vb.getValue()); 91 addColorTag(vb, type); 92 } 93 } 94 95 97 valBoxIt = s.getDefBoxes().iterator(); 98 99 while (valBoxIt.hasNext()){ 100 ValueBox vb = (ValueBox)valBoxIt.next(); 101 if (parityVarsDefs.containsKey(vb.getValue())){ 102 String type = (String )parityVarsDefs.get(vb.getValue()); 104 addColorTag(vb, type); 105 } 106 } 107 } 108 109 Iterator keyIt = b.getMethod().getDeclaringClass().getTags().iterator(); 111 boolean keysAdded = false; 112 while (keyIt.hasNext()){ 113 Object next = keyIt.next(); 114 if (next instanceof KeyTag){ 115 if (((KeyTag)next).analysisType().equals("Parity Analysis")){ 116 keysAdded = true; 117 } 118 } 119 } 120 if (!keysAdded){ 121 b.getMethod().getDeclaringClass().addTag(new KeyTag(255,0,0, "Parity: Top", "Parity Analysis")); 122 b.getMethod().getDeclaringClass().addTag(new KeyTag(45,255,84, "Parity: Bottom", "Parity Analysis")); 123 b.getMethod().getDeclaringClass().addTag(new KeyTag(255,248,35, "Parity: Even", "Parity Analysis")); 124 b.getMethod().getDeclaringClass().addTag(new KeyTag(174,210,255, "Parity: Odd", "Parity Analysis")); 125 } 126 } 127 128 private void addColorTag(ValueBox vb, String type) { 129 if (type.equals("bottom")){ 130 vb.addTag(new ColorTag(ColorTag.GREEN, "Parity Analysis")); 132 } 133 else if (type.equals("top")){ 134 vb.addTag(new ColorTag(ColorTag.RED, "Parity Analysis")); 136 } 137 else if (type.equals("even")){ 138 vb.addTag(new ColorTag(ColorTag.YELLOW, "Parity Analysis")); 140 } 141 else if (type.equals("odd")){ 142 vb.addTag(new ColorTag(ColorTag.BLUE, "Parity Analysis")); 144 } 145 } 146 } 147 148 149 | Popular Tags |