001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: import java.util.BitSet;
023:
024: import org.apache.bcel.classfile.Method;
025:
026: import edu.umd.cs.findbugs.SystemProperties;
027:
028: /**
029: * Dataflow analysis to compute dominator sets for a CFG.
030: *
031: * @author David Hovemeyer
032: * @see CFG
033: * @see AbstractDominatorsAnalysis
034: */
035: public class DominatorsAnalysis extends AbstractDominatorsAnalysis {
036: private DepthFirstSearch dfs;
037:
038: /**
039: * Constructor.
040: *
041: * @param cfg the CFG to compute dominator relationships for
042: * @param dfs the DepthFirstSearch on the CFG
043: * @param ignoreExceptionEdges true if exception edges should be ignored
044: */
045: public DominatorsAnalysis(CFG cfg, DepthFirstSearch dfs,
046: boolean ignoreExceptionEdges) {
047: super (cfg, ignoreExceptionEdges);
048: this .dfs = dfs;
049: }
050:
051: public boolean isForwards() {
052: return true;
053: }
054:
055: public BlockOrder getBlockOrder(CFG cfg) {
056: return new ReversePostOrder(cfg, dfs);
057: }
058:
059: public static void main(String[] argv) throws Exception {
060: if (argv.length != 1) {
061: System.err.println("Usage: "
062: + DominatorsAnalysis.class.getName()
063: + " <classfile>");
064: System.exit(1);
065: }
066:
067: DataflowTestDriver<BitSet, DominatorsAnalysis> driver = new DataflowTestDriver<BitSet, DominatorsAnalysis>() {
068:
069: /* (non-Javadoc)
070: * @see edu.umd.cs.findbugs.ba.DataflowTestDriver#createDataflow(edu.umd.cs.findbugs.ba.ClassContext, org.apache.bcel.classfile.Method)
071: */
072: @Override
073: public Dataflow<BitSet, DominatorsAnalysis> createDataflow(
074: ClassContext classContext, Method method)
075: throws CFGBuilderException,
076: DataflowAnalysisException {
077: CFG cfg = classContext.getCFG(method);
078: DepthFirstSearch dfs = classContext
079: .getDepthFirstSearch(method);
080:
081: DominatorsAnalysis analysis = new DominatorsAnalysis(
082: cfg,
083: dfs,
084: SystemProperties
085: .getBoolean("dominators.ignoreexceptionedges"));
086:
087: Dataflow<BitSet, DominatorsAnalysis> dataflow = new Dataflow<BitSet, DominatorsAnalysis>(
088: cfg, analysis);
089:
090: dataflow.execute();
091:
092: return dataflow;
093: }
094:
095: };
096:
097: driver.execute(argv[0]);
098: }
099: }
100:
101: // vim:ts=4
|