1 salcianu 1.1.2.1 // BBConverter.java, created Wed Mar  8 15:42:33 2000 by salcianu
 2 cananian 1.1.2.3 // 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.BasicBlocks;
 5 salcianu 1.1.2.1 
 6 salcianu 1.1.2.1 import harpoon.ClassFile.HMethod;
 7 salcianu 1.1.2.1 import harpoon.ClassFile.HCodeFactory;
 8 salcianu 1.1.2.1 import harpoon.ClassFile.HCode;
 9 salcianu 1.1.2.1 import harpoon.Analysis.BasicBlock; 
10 salcianu 1.1.2.4 import harpoon.Analysis.FCFGBasicBlock; 
11 salcianu 1.1.2.4 import harpoon.Analysis.BasicBlockFactoryInterf; 
12 salcianu 1.1.2.4 
13 salcianu 1.1.2.4 import harpoon.Util.Util;
14 salcianu 1.1.2.1 
15 salcianu 1.1.2.1 /**
16 salcianu 1.1.2.1  * <code>BBConverter</code> is a convenient class that offers a function
17 salcianu 1.1.2.1  * which returns a basic block view of the code of a method.
18 salcianu 1.1.2.1  * 
19 cananian 1.1.2.3  * @author  Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu>
20 cananian 1.2      * @version $Id: BBConverter.java,v 1.2 2002/02/25 21:08:59 cananian Exp $
21 salcianu 1.1.2.1  */
22 salcianu 1.1.2.2 public class BBConverter implements java.io.Serializable{
23 salcianu 1.1.2.1     // the HCode factory used to generate the code of the methods.
24 salcianu 1.1.2.4     protected HCodeFactory hcf;
25 salcianu 1.1.2.4     // hcf is a "quad-with-try" code view
26 salcianu 1.1.2.4     protected boolean quad_with_try;
27 salcianu 1.1.2.1 
28 salcianu 1.1.2.1     /** Creates a <code>BBConverter</code>. Receives as parameter the
29 salcianu 1.1.2.1         <code>HCodeFactory</code> that will be used to generated the code
30 salcianu 1.1.2.1         of the methods passed to <code>convert2bb</code>. */
31 salcianu 1.1.2.1     public BBConverter(HCodeFactory hcf) {
32 salcianu 1.1.2.4         quad_with_try = hcf.getCodeName().equals("quad-with-try");
33 salcianu 1.1.2.1         this.hcf = hcf;
34 salcianu 1.1.2.1     }
35 salcianu 1.1.2.1 
36 salcianu 1.1.2.4     /** Converts the code of the method <code>hm</code> to basic
37 salcianu 1.1.2.4         blocks. The code of the method is obtained from the
38 salcianu 1.1.2.4         <code>HCodeFactory</code> that was passed to the constructor
39 salcianu 1.1.2.4         of <code>this</code>. */
40 salcianu 1.1.2.4     public BasicBlockFactoryInterf convert2bb(HMethod hm){
41 salcianu 1.1.2.1         HCode hcode = hcf.convert(hm);
42 salcianu 1.1.2.5         // special case: methods with no available code (e.g., native methods)
43 salcianu 1.1.2.5         if(hcode == null) return null;
44 salcianu 1.1.2.5         // normal case
45 salcianu 1.1.2.4         if(quad_with_try)
46 salcianu 1.1.2.4             return new FCFGBasicBlock.Factory(hcode);
47 salcianu 1.1.2.4         else
48 salcianu 1.1.2.4             return new BasicBlock.Factory(hcode);
49 salcianu 1.1.2.1     }
50 cananian 1.2     }