001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 John Jorgensen
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package soot.util.cfgcmd;
021:
022: import soot.Body;
023: import soot.jimple.JimpleBody;
024: import soot.baf.Baf;
025: import soot.grimp.Grimp;
026: import soot.shimple.Shimple;
027:
028: /**
029: * An enumeration type for representing the varieties of intermediate
030: * representation available, for use in tools that compare or display
031: * control flow graphs.
032: *
033: *
034: */
035: public abstract class CFGIntermediateRep extends
036: CFGOptionMatcher.CFGOption {
037:
038: private CFGIntermediateRep(String name) {
039: super (name);
040: }
041:
042: /**
043: * Converts a <code>JimpleBody</code> into the
044: * corresponding <code>Body</code> in this intermediate
045: * representation.
046: *
047: * @param b The Jimple body to be represented.
048: *
049: * @return a {@link Body} in this intermediate representation which
050: * represents the same method as <code>b</code>.
051: */
052: public abstract Body getBody(JimpleBody b);
053:
054: public static final CFGIntermediateRep JIMPLE_IR = new CFGIntermediateRep(
055: "jimple") {
056: public Body getBody(JimpleBody b) {
057: return b;
058: }
059: };
060:
061: public static final CFGIntermediateRep BAF_IR = new CFGIntermediateRep(
062: "baf") {
063: public Body getBody(JimpleBody b) {
064: return Baf.v().newBody(b);
065: }
066: };
067:
068: public static final CFGIntermediateRep GRIMP_IR = new CFGIntermediateRep(
069: "grimp") {
070: public Body getBody(JimpleBody b) {
071: return Grimp.v().newBody(b, "gb");
072: }
073: };
074:
075: public static final CFGIntermediateRep SHIMPLE_IR = new CFGIntermediateRep(
076: "shimple") {
077: public Body getBody(JimpleBody b) {
078: return Shimple.v().newBody(b);
079: }
080: };
081:
082: public static final CFGIntermediateRep VIA_SHIMPLE_JIMPLE_IR = new CFGIntermediateRep(
083: "viaShimpleJimple") {
084: public Body getBody(JimpleBody b) {
085: return Shimple.v().newJimpleBody(Shimple.v().newBody(b));
086: }
087: };
088:
089: private final static CFGOptionMatcher irOptions = new CFGOptionMatcher(
090: new CFGIntermediateRep[] { JIMPLE_IR, BAF_IR, GRIMP_IR,
091: SHIMPLE_IR, VIA_SHIMPLE_JIMPLE_IR, });
092:
093: /**
094: * Returns the <code>CFGIntermediateRep</code> identified by the
095: * passed name.
096: *
097: * @param name A {@link String} identifying the intermediate
098: * representation.
099: *
100: * @return A <code>CFGIntermediateRep</code> object whose
101: * {@link #getBody(JimpleBody)} method will create the desired intermediate
102: * representation.
103: */
104: public static CFGIntermediateRep getIR(String name) {
105: return (CFGIntermediateRep) irOptions.match(name);
106: }
107:
108: /**
109: * Returns a string containing the names of all the
110: * available <code>CFGIntermediateRep</code>s, separated by
111: * '|' characters.
112: *
113: * @param initialIndent The number of blank spaces to insert at the
114: * beginning of the returned string. Ignored if
115: * negative.
116: *
117: * @param rightMargin If positive, newlines will be inserted to try
118: * to keep the length of each line in the
119: * returned string less than or equal to
120: * *<code>rightMargin</code>.
121: *
122: * @param hangingIndent If positive, this number of spaces will be
123: * inserted immediately after each newline
124: * inserted to respect the <code>rightMargin</code>.
125: */
126: public static String help(int initialIndent, int rightMargin,
127: int hangingIndent) {
128: return irOptions
129: .help(initialIndent, rightMargin, hangingIndent);
130: }
131:
132: }
|