001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2004 Navindra Umanee <navindra@cs.mcgill.ca>
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.shimple;
021:
022: import soot.*;
023: import soot.shimple.toolkits.graph.*;
024: import soot.jimple.toolkits.callgraph.*;
025: import soot.jimple.toolkits.pointer.*;
026: import soot.toolkits.graph.*;
027:
028: /**
029: * @author Navindra Umanee
030: **/
031: public class DefaultShimpleFactory implements ShimpleFactory {
032: protected Body body;
033: protected BlockGraph bg;
034: protected UnitGraph ug;
035: protected DominatorsFinder dFinder;
036: protected DominatorTree dTree;
037: protected DominanceFrontier dFrontier;
038: protected PointsToAnalysis pta;
039: protected CallGraph cg;
040: protected SideEffectAnalysis sea;
041: protected GlobalValueNumberer gvn;
042:
043: protected ReversibleGraph rbg;
044: protected DominatorTree rdTree;
045: protected DominanceFrontier rdFrontier;
046: protected DominatorsFinder rdFinder;
047:
048: public DefaultShimpleFactory() {
049: }
050:
051: public void clearCache() {
052: bg = null;
053: ug = null;
054: dFinder = null;
055: dTree = null;
056: dFrontier = null;
057: pta = null;
058: cg = null;
059: sea = null;
060: gvn = null;
061: rbg = null;
062: rdTree = null;
063: rdFinder = null;
064: rdFrontier = null;
065: }
066:
067: public void setBody(Body body) {
068: this .body = body;
069: clearCache();
070: }
071:
072: public Body getBody() {
073: if (body == null)
074: throw new RuntimeException(
075: "Assertion failed: Call setBody() first.");
076:
077: return body;
078: }
079:
080: public ReversibleGraph getReverseBlockGraph() {
081: if (rbg != null)
082: return rbg;
083:
084: BlockGraph bg = getBlockGraph();
085: rbg = new HashReversibleGraph(bg);
086: rbg.reverse();
087: return rbg;
088: }
089:
090: public DominatorsFinder getReverseDominatorsFinder() {
091: if (rdFinder != null)
092: return rdFinder;
093:
094: rdFinder = new SimpleDominatorsFinder(getReverseBlockGraph());
095: return rdFinder;
096: }
097:
098: public DominatorTree getReverseDominatorTree() {
099: if (rdTree != null)
100: return rdTree;
101:
102: rdTree = new DominatorTree(getReverseDominatorsFinder());
103: return rdTree;
104: }
105:
106: public DominanceFrontier getReverseDominanceFrontier() {
107: if (rdFrontier != null)
108: return rdFrontier;
109:
110: rdFrontier = new CytronDominanceFrontier(
111: getReverseDominatorTree());
112: return rdFrontier;
113: }
114:
115: public BlockGraph getBlockGraph() {
116: if (bg != null)
117: return bg;
118:
119: bg = new ExceptionalBlockGraph(
120: (ExceptionalUnitGraph) getUnitGraph());
121: BlockGraphConverter.addStartStopNodesTo(bg);
122: return bg;
123: }
124:
125: public UnitGraph getUnitGraph() {
126: if (ug != null)
127: return ug;
128:
129: ug = new ExceptionalUnitGraph(getBody());
130: return ug;
131: }
132:
133: public DominatorsFinder getDominatorsFinder() {
134: if (dFinder != null)
135: return dFinder;
136:
137: dFinder = new SimpleDominatorsFinder(getBlockGraph());
138: return dFinder;
139: }
140:
141: public DominatorTree getDominatorTree() {
142: if (dTree != null)
143: return dTree;
144:
145: dTree = new DominatorTree(getDominatorsFinder());
146: return dTree;
147: }
148:
149: public DominanceFrontier getDominanceFrontier() {
150: if (dFrontier != null)
151: return dFrontier;
152:
153: dFrontier = new CytronDominanceFrontier(getDominatorTree());
154: return dFrontier;
155: }
156:
157: public GlobalValueNumberer getGlobalValueNumberer() {
158: if (gvn != null)
159: return gvn;
160:
161: gvn = new SimpleGlobalValueNumberer(getBlockGraph());
162: return gvn;
163: }
164: }
|