KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > paddle > PaddleHook


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004, 2005 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 package soot.jimple.paddle;
21 import soot.*;
22 import java.util.*;
23
24 /** Loads the Paddle plugin.
25  * @author Ondrej Lhotak
26  */

27 public class PaddleHook extends SceneTransformer
28 {
29     public PaddleHook( Singletons.Global g ) {}
30     public static PaddleHook v() { return G.v().soot_jimple_paddle_PaddleHook(); }
31
32     private IPaddleTransformer paddleTransformer;
33     public IPaddleTransformer paddleTransformer() {
34         if(paddleTransformer == null) {
35             paddleTransformer = (IPaddleTransformer)
36                 instantiate("soot.jimple.paddle.PaddleTransformer");
37         }
38         return paddleTransformer;
39     }
40
41     protected void internalTransform( String JavaDoc phaseName, Map options )
42     {
43         paddleTransformer().transform(phaseName, options);
44     }
45     public Object JavaDoc instantiate(String JavaDoc className) {
46         Object JavaDoc ret;
47         try {
48             ret = Class.forName(
49                 className ).newInstance();
50         } catch( ClassNotFoundException JavaDoc e ) {
51             throw new RuntimeException JavaDoc("Could not find "+className+". Did you include Paddle on your Java classpath?");
52         } catch( InstantiationException JavaDoc e ) {
53             throw new RuntimeException JavaDoc( "Could not instantiate "+className+": "+e );
54         } catch( IllegalAccessException JavaDoc e ) {
55             throw new RuntimeException JavaDoc( "Could not instantiate "+className+": "+e );
56         }
57         return ret;
58     }
59
60     private Object JavaDoc paddleG;
61     public Object JavaDoc paddleG() {
62         if(paddleG == null) {
63             paddleG = instantiate("soot.PaddleG");
64         }
65         return paddleG;
66     }
67     /** This is called when Soot finishes executing all interprocedural phases.
68      * Paddle uses it to stop profiling if profiling is enabled. */

69     public void finishPhases()
70     {
71         if(paddleTransformer != null) {
72             paddleTransformer().finishPhases();
73         }
74     }
75 }
76
77
78
Popular Tags