1 salcianu 1.1.2.1 // SCCLBBFactory.java, created Thu Mar 23 19:37:33 2000 by salcianu
 2 cananian 1.1.2.8 // Copyright (C) 2000 Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu>
 3 salcianu 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details.
 4 salcianu 1.1.2.1 package harpoon.Util.LightBasicBlocks;
 5 salcianu 1.1.2.1 
 6 salcianu 1.4     import java.util.Collections;
 7 salcianu 1.4     
 8 salcianu 1.1.2.1 import harpoon.ClassFile.HMethod;
 9 salcianu 1.1.2.1 import harpoon.ClassFile.HCode;
10 salcianu 1.1.2.1 import harpoon.Util.Graphs.SCComponent;
11 salcianu 1.3     import harpoon.Util.Graphs.Navigator;
12 salcianu 1.4     import harpoon.Util.Graphs.TopSortedCompDiGraph;
13 salcianu 1.1.2.1 
14 salcianu 1.1.2.1 
15 salcianu 1.1.2.1 /**
16 salcianu 1.1.2.1  * <code>SCCLBBFactory</code> computes the topologically sorted component
17 salcianu 1.1.2.1  graph of the light basic blocks containing the code of a method.
18 salcianu 1.1.2.1  * 
19 cananian 1.1.2.8  * @author  Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu>
20 salcianu 1.5      * @version $Id: SCCLBBFactory.java,v 1.5 2004/03/05 15:38:16 salcianu Exp $
21 salcianu 1.1.2.1  */
22 salcianu 1.1.2.7 public class SCCLBBFactory implements java.io.Serializable {
23 salcianu 1.1.2.1 
24 salcianu 1.1.2.1     /** The <code>LBBConverter</code> used to generate the 
25 salcianu 1.1.2.1         LightBasicBlock views of the methods */
26 salcianu 1.1.2.1     private LBBConverter lbbconv;
27 salcianu 1.1.2.1     
28 salcianu 1.1.2.1     /** Creates a <code>SCCLBBFactory</code>. */
29 salcianu 1.1.2.1     public SCCLBBFactory(LBBConverter lbbconv) {
30 salcianu 1.1.2.1         this.lbbconv = lbbconv;
31 salcianu 1.1.2.1     }
32 salcianu 1.1.2.1 
33 salcianu 1.1.2.1     /** Returns the underlying <code>LBBConverter</code>. This is the 
34 salcianu 1.1.2.1         same as the one passed to the constructor of <code>this</code>
35 salcianu 1.1.2.1         object. */
36 salcianu 1.1.2.2     public LBBConverter getLBBConverter(){
37 salcianu 1.1.2.1         return lbbconv;
38 salcianu 1.1.2.1     }
39 salcianu 1.1.2.1 
40 salcianu 1.5         private static final Navigator<LightBasicBlock> navigator = 
41 salcianu 1.5             new Navigator<LightBasicBlock>() {
42 salcianu 1.5                     public LightBasicBlock[] next(LightBasicBlock node) {
43 salcianu 1.5                         return node.getNextLBBs();
44 salcianu 1.1.2.1                 }
45 salcianu 1.5                     public LightBasicBlock[] prev(LightBasicBlock node) {
46 salcianu 1.5                         return node.getPrevLBBs();
47 salcianu 1.1.2.1                 }
48 salcianu 1.1.2.1             };
49 salcianu 1.1.2.1 
50 salcianu 1.1.2.9 
51 salcianu 1.1.2.1     /** Generates the code of the method <code>hm</code> using the 
52 salcianu 1.1.2.3         <code>HCodeFactory</code> passed to the constructor of
53 salcianu 1.1.2.3         <code>this</code> object, cut it into pieces (i.e. 
54 salcianu 1.1.2.3         <code>LightBasicBlock</code>s), build the strongly connected componnets
55 salcianu 1.1.2.3         of <code>LightBasicBlock</code>s and sort them topologically.
56 salcianu 1.1.2.3         Returns the sorted graph. */
57 salcianu 1.5         public TopSortedCompDiGraph<LightBasicBlock> computeSCCLBB(HMethod hm) {
58 salcianu 1.4             LightBasicBlock rootLBB = lbbconv.convert2lbb(hm).getRoot();
59 salcianu 1.4             return 
60 salcianu 1.5                 new TopSortedCompDiGraph<LightBasicBlock>
61 salcianu 1.4                 (Collections.singleton(rootLBB), navigator);
62 salcianu 1.1.2.1     }
63 salcianu 1.1.2.1 
64 cananian 1.2     }