KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > Transform


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai and Patrick Lam
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-2003.
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
29 import java.util.*;
30 import soot.util.*;
31 import soot.options.Options;
32
33 /** Maintains the pair (phaseName, singleton) needed for a
34  * transformation. */

35 public class Transform implements HasPhaseOptions
36 {
37     final private boolean DEBUG = true;
38     String JavaDoc phaseName;
39     Transformer t;
40     
41     public Transform(String JavaDoc phaseName, Transformer t)
42     {
43         this.phaseName = phaseName;
44         this.t = t;
45     }
46
47     public String JavaDoc getPhaseName() { return phaseName; }
48     public Transformer getTransformer() { return t; }
49
50     private String JavaDoc declaredOpts;
51     private String JavaDoc defaultOpts;
52     public String JavaDoc getDeclaredOptions() {
53         if( declaredOpts != null ) return declaredOpts;
54         return Options.getDeclaredOptionsForPhase( phaseName );
55     }
56     public String JavaDoc getDefaultOptions() {
57         if( defaultOpts != null ) return defaultOpts;
58         return Options.getDefaultOptionsForPhase( phaseName );
59     }
60
61     /** Allows user-defined phases to have options other than just enabled
62      * without having to mess with the XML.
63      * Call this method with a space-separated list of options declared
64      * for this Transform. Only declared options may be passed to this
65      * transform as a phase option. */

66     public void setDeclaredOptions( String JavaDoc options ) {
67         declaredOpts = options;
68     }
69
70     /** Allows user-defined phases to have options other than just
71      * enabled without having to mess with the XML. Call this method
72      * with a space-separated list of option:value pairs that this
73      * Transform is to use as default parameters (eg
74      * `enabled:off'). */

75     public void setDefaultOptions( String JavaDoc options ) {
76         defaultOpts = options;
77     }
78
79     public void apply() {
80         Map options = PhaseOptions.v().getPhaseOptions( phaseName );
81         if( PhaseOptions.getBoolean( options, "enabled" ) ) {
82             if( Options.v().verbose() ) {
83                 G.v().out.println( "Applying phase "+phaseName+" to the scene." );
84             }
85         }
86     if (DEBUG)
87         PhaseDumper.v().dumpBefore(getPhaseName());
88
89         ((SceneTransformer) t).transform( phaseName, options );
90
91     if (DEBUG)
92         PhaseDumper.v().dumpAfter(getPhaseName());
93     }
94     public void apply(Body b) {
95         Map options = PhaseOptions.v().getPhaseOptions( phaseName );
96         if( PhaseOptions.getBoolean( options, "enabled" ) ) {
97             if( Options.v().verbose() ) {
98                 G.v().out.println( "Applying phase "+phaseName+" to "+b.getMethod()+"." );
99             }
100         }
101     if (DEBUG)
102         PhaseDumper.v().dumpBefore(b, getPhaseName());
103
104         ((BodyTransformer) t).transform( b, phaseName, options );
105
106     if (DEBUG)
107         PhaseDumper.v().dumpAfter(b, getPhaseName());
108     }
109 }
110
Popular Tags