KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > internal > SET > SETBasicBlock


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

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 JavaDoc
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 JavaDoc o)
45     {
46     if (o == this)
47         return 0;
48
49     SETBasicBlock other = (SETBasicBlock) o;
50
51     int difference = other.get_Priority() - get_Priority(); // major sorting order ... _descending_
52
if (difference == 0) // bogus minor order ... it isn't consistent
53
difference = 1; // but it doesn't matter.
54

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     /*
82      * adds must be done in order such that the entry node is done first and the exit is done last.
83      */

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