KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > JavaToJimpleBodyPack


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
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 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27 package soot;
28 import soot.options.*;
29
30 import soot.jimple.*;
31 import java.util.*;
32 import soot.toolkits.scalar.*;
33 import soot.jimple.toolkits.scalar.*;
34 import soot.jimple.toolkits.typing.*;
35 import soot.jimple.toolkits.base.*;
36 import soot.options.JBOptions;
37
38
39 /** A wrapper object for a pack of optimizations.
40  * Provides chain-like operations, except that the key is the phase name.
41  * This is a specific one for the very messy jb phase. */

42 public class JavaToJimpleBodyPack extends BodyPack
43 {
44     public JavaToJimpleBodyPack() {
45         super("jj");
46     }
47
48
49     /** Applies the transformations corresponding to the given options. */
50     private void applyPhaseOptions(JimpleBody b, Map opts)
51     {
52         JJOptions options = new JJOptions( opts );
53         
54         if(options.use_original_names())
55             PhaseOptions.v().setPhaseOptionIfUnset( "jj.lns", "only-stack-locals");
56         
57         if(Options.v().time()) Timers.v().splitTimer.start();
58
59         PackManager.v().getTransform( "jj.ls" ).apply( b );
60
61         if(Options.v().time()) Timers.v().splitTimer.end();
62
63         PackManager.v().getTransform( "jj.a" ).apply( b );
64         PackManager.v().getTransform( "jj.ule" ).apply( b );
65         PackManager.v().getTransform( "jj.ne" ).apply( b );
66
67         if(Options.v().time()) Timers.v().assignTimer.start();
68
69         PackManager.v().getTransform( "jj.tr" ).apply( b );
70         
71         if(Options.v().time()) Timers.v().assignTimer.end();
72
73         if(options.use_original_names())
74         {
75             PackManager.v().getTransform( "jj.ulp" ).apply( b );
76         }
77         PackManager.v().getTransform( "jj.lns" ).apply( b );
78         PackManager.v().getTransform( "jj.cp" ).apply( b );
79         PackManager.v().getTransform( "jj.dae" ).apply( b );
80         PackManager.v().getTransform( "jj.cp-ule" ).apply( b );
81         PackManager.v().getTransform( "jj.lp" ).apply( b );
82         //PackManager.v().getTransform( "jj.ct" ).apply( b );
83
PackManager.v().getTransform( "jj.uce" ).apply( b );
84                     
85         if(Options.v().time())
86             Timers.v().stmtCount += b.getUnits().size();
87     }
88
89
90     protected void internalApply(Body b)
91     {
92         applyPhaseOptions( (JimpleBody) b,
93                 PhaseOptions.v().getPhaseOptions( getPhaseName() ) );
94     }
95 }
96
Popular Tags