1 19 20 package soot.dava.internal.SET; 21 import soot.*; 22 23 import java.util.*; 24 import soot.util.*; 25 26 public class SETBasicBlock implements Comparable 27 { 28 29 private SETNode entryNode, exitNode; 30 private IterableSet predecessors, successors, body; 31 private int priority; 32 33 34 public SETBasicBlock() 35 { 36 predecessors = new IterableSet(); 37 successors = new IterableSet(); 38 body = new IterableSet(); 39 40 entryNode = exitNode = null; 41 priority = -1; 42 } 43 44 public int compareTo( Object o) 45 { 46 if (o == this) 47 return 0; 48 49 SETBasicBlock other = (SETBasicBlock) o; 50 51 int difference = other.get_Priority() - get_Priority(); if (difference == 0) difference = 1; 55 return difference; 56 } 57 58 private int get_Priority() 59 { 60 if (priority == -1) { 61 priority = 0; 62 63 if (predecessors.size() == 1) { 64 Iterator sit = successors.iterator(); 65 66 while (sit.hasNext()) { 67 int sucScore = ((SETBasicBlock) sit.next()).get_Priority(); 68 69 if (sucScore > priority) 70 priority = sucScore; 71 } 72 73 priority++; 74 } 75 } 76 77 return priority; 78 } 79 80 81 84 85 public void add( SETNode sn) 86 { 87 if (body.isEmpty()) 88 entryNode = sn; 89 90 body.add( sn); 91 G.v().SETBasicBlock_binding.put( sn, this); 92 93 exitNode = sn; 94 } 95 96 public SETNode get_EntryNode() 97 { 98 return entryNode; 99 } 100 101 public SETNode get_ExitNode() 102 { 103 return exitNode; 104 } 105 106 public IterableSet get_Predecessors() 107 { 108 return predecessors; 109 } 110 111 public IterableSet get_Successors() 112 { 113 return successors; 114 } 115 116 public IterableSet get_Body() 117 { 118 return body; 119 } 120 121 public static SETBasicBlock get_SETBasicBlock( SETNode o) 122 { 123 return (SETBasicBlock) G.v().SETBasicBlock_binding.get( o); 124 } 125 126 127 public void printSig() 128 { 129 Iterator it = body.iterator(); 130 while (it.hasNext()) 131 ((SETNode) it.next()).dump(); 132 } 133 134 public void dump() 135 { 136 printSig(); 137 G.v().out.println( "=== preds ==="); 138 139 Iterator it = predecessors.iterator(); 140 while (it.hasNext()) 141 ((SETBasicBlock) it.next()).printSig(); 142 143 G.v().out.println( "=== succs ==="); 144 145 it = successors.iterator(); 146 while (it.hasNext()) 147 ((SETBasicBlock) it.next()).printSig(); 148 } 149 } 150 | Popular Tags |