+ /** This method assigns labels to flatnodes */
+
+ private Hashtable<FlatNode, Integer> assignLabels(FlatMethod fm) {
+ HashSet tovisit=new HashSet();
+ HashSet visited=new HashSet();
+ int labelindex=0;
+ Hashtable<FlatNode, Integer> nodetolabel=new Hashtable<FlatNode, Integer>();
+ tovisit.add(fm.getNext(0));
+
+ /*Assign labels first. A node needs a label if the previous
+ * node has two exits or this node is a join point. */
+
+ while(!tovisit.isEmpty()) {
+ FlatNode fn=(FlatNode)tovisit.iterator().next();
+ tovisit.remove(fn);
+ visited.add(fn);
+ for(int i=0;i<fn.numNext();i++) {
+ FlatNode nn=fn.getNext(i);
+ if(i>0) {
+ //1) Edge >1 of node
+ nodetolabel.put(nn,new Integer(labelindex++));
+ }
+ if (!visited.contains(nn)&&!tovisit.contains(nn)) {
+ tovisit.add(nn);
+ } else {
+ //2) Join point
+ nodetolabel.put(nn,new Integer(labelindex++));
+ }
+ }
+ }
+ return nodetolabel;
+ }
+
+