KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > util > cfgcmd > CFGIntermediateRep


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 John Jorgensen
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.util.cfgcmd;
21
22 import soot.Body;
23 import soot.jimple.Jimple;
24 import soot.jimple.JimpleBody;
25 import soot.baf.Baf;
26 import soot.grimp.Grimp;
27 import soot.shimple.Shimple;
28
29 /**
30  * An enumeration type for representing the varieties of intermediate
31  * representation available, for use in tools that compare or display
32  * control flow graphs.
33  *
34  *
35  */

36 public abstract class CFGIntermediateRep extends CFGOptionMatcher.CFGOption {
37
38   private CFGIntermediateRep(String JavaDoc name) {
39     super(name);
40   }
41
42   /**
43    * Converts a <code>JimpleBody</code> into the
44    * corresponding <code>Body</code> in this intermediate
45    * representation.
46    *
47    * @param b The Jimple body to be represented.
48    *
49    * @return a {@link Body} in this intermediate representation which
50    * represents the same method as <code>b</code>.
51    */

52   public abstract Body getBody(JimpleBody b);
53
54
55   public static final CFGIntermediateRep JIMPLE_IR = new CFGIntermediateRep("jimple") {
56       public Body getBody(JimpleBody b) {
57     return b;
58       }
59     };
60
61   public static final CFGIntermediateRep BAF_IR = new CFGIntermediateRep("baf") {
62       public Body getBody(JimpleBody b) {
63     return Baf.v().newBody(b);
64       }
65     };
66
67   public static final CFGIntermediateRep GRIMP_IR = new CFGIntermediateRep("grimp") {
68       public Body getBody(JimpleBody b) {
69     return Grimp.v().newBody(b, "gb");
70       }
71     };
72
73   public static final CFGIntermediateRep SHIMPLE_IR = new CFGIntermediateRep("shimple") {
74       public Body getBody(JimpleBody b) {
75     return Shimple.v().newBody(b);
76       }
77     };
78
79   public static final CFGIntermediateRep VIA_SHIMPLE_JIMPLE_IR =
80     new CFGIntermediateRep("viaShimpleJimple") {
81       public Body getBody(JimpleBody b) {
82     return Shimple.v().newJimpleBody(Shimple.v().newBody(b));
83       }
84     };
85
86   private final static CFGOptionMatcher irOptions =
87     new CFGOptionMatcher(new CFGIntermediateRep[] {
88       JIMPLE_IR,
89       BAF_IR,
90       GRIMP_IR,
91       SHIMPLE_IR,
92       VIA_SHIMPLE_JIMPLE_IR,
93     });
94
95   /**
96    * Returns the <code>CFGIntermediateRep</code> identified by the
97    * passed name.
98    *
99    * @param name A {@link String} identifying the intermediate
100    * representation.
101    *
102    * @return A <code>CFGIntermediateRep</code> object whose
103    * {@link #getBody(JimpleBody)} method will create the desired intermediate
104    * representation.
105    */

106   public static CFGIntermediateRep getIR(String JavaDoc name) {
107     return (CFGIntermediateRep) irOptions.match(name);
108   }
109
110   /**
111    * Returns a string containing the names of all the
112    * available <code>CFGIntermediateRep</code>s, separated by
113    * '|' characters.
114    *
115    * @param initialIndent The number of blank spaces to insert at the
116    * beginning of the returned string. Ignored if
117    * negative.
118    *
119    * @param rightMargin If positive, newlines will be inserted to try
120    * to keep the length of each line in the
121    * returned string less than or equal to
122    * *<code>rightMargin</code>.
123    *
124    * @param hangingIndent If positive, this number of spaces will be
125    * inserted immediately after each newline
126    * inserted to respect the <code>rightMargin</code>.
127    */

128   public static String JavaDoc help(int initialIndent, int rightMargin,
129                 int hangingIndent) {
130     return irOptions.help(initialIndent, rightMargin, hangingIndent);
131   }
132
133 }
134
135
136
Popular Tags