tabulation and visualization cleanps
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1887 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
96ba7cee90
commit
dc0185e8bf
|
@ -18,6 +18,7 @@ import com.ibm.wala.util.collections.Iterator2Collection;
|
|||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.debug.UnimplementedError;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +30,7 @@ import com.ibm.wala.util.intset.IntSet;
|
|||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
||||
public class BackwardsSupergraph<T, P> implements ISupergraph<T, P> {
|
||||
|
||||
/**
|
||||
* DEBUG_LEVEL:
|
||||
|
@ -40,26 +41,37 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
* </ul>
|
||||
*/
|
||||
static final int DEBUG_LEVEL = 0;
|
||||
private final ISupergraph<T,P> delegate;
|
||||
|
||||
private final ISupergraph<T, P> delegate;
|
||||
|
||||
private final ExitFilter exitFilter = new ExitFilter();
|
||||
|
||||
/**
|
||||
* @param forwardGraph
|
||||
* the graph to ``reverse''
|
||||
* the graph to ``reverse''
|
||||
*/
|
||||
private BackwardsSupergraph(ISupergraph<T,P> forwardGraph) {
|
||||
private BackwardsSupergraph(ISupergraph<T, P> forwardGraph) {
|
||||
this.delegate = forwardGraph;
|
||||
}
|
||||
|
||||
public static <T,P> BackwardsSupergraph<T, P> make(ISupergraph<T, P> forwardGraph) {
|
||||
|
||||
public static <T, P> BackwardsSupergraph<T, P> make(ISupergraph<T, P> forwardGraph) {
|
||||
return new BackwardsSupergraph<T, P>(forwardGraph);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: for now, this is not inverted.
|
||||
*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getProcedureGraph()
|
||||
*/
|
||||
public Graph<P> getProcedureGraph() {
|
||||
return delegate.getProcedureGraph();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getMain()
|
||||
*/
|
||||
public P getMain() throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
return delegate.getMain();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -91,14 +103,15 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
public Iterator<T> getCalledNodes(T ret) {
|
||||
if (DEBUG_LEVEL > 1) {
|
||||
Trace.println(getClass() + " getCalledNodes " + ret);
|
||||
Trace.printCollection("called nodes ", Iterator2Collection.toCollection(new FilterIterator<Object>(getSuccNodes(ret), exitFilter)));
|
||||
Trace.printCollection("called nodes ", Iterator2Collection.toCollection(new FilterIterator<Object>(getSuccNodes(ret),
|
||||
exitFilter)));
|
||||
}
|
||||
return new FilterIterator<T>(getSuccNodes(ret), exitFilter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the "normal" successors (sic) for a return site; i.e., the "normal" CFG predecessors
|
||||
* that are not call nodes.
|
||||
* get the "normal" successors (sic) for a return site; i.e., the "normal" CFG
|
||||
* predecessors that are not call nodes.
|
||||
*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getCalledNodes(java.lang.Object)
|
||||
*/
|
||||
|
@ -110,14 +123,14 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
return getProcOf(ret).equals(getProcOf((T) o));
|
||||
}
|
||||
};
|
||||
Iterator<Object> sameProcPreds = new FilterIterator<Object>(allPreds,sameProc);
|
||||
Iterator<Object> sameProcPreds = new FilterIterator<Object>(allPreds, sameProc);
|
||||
Filter notCall = new Filter() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean accepts(Object o) {
|
||||
return !delegate.isCall((T) o);
|
||||
}
|
||||
};
|
||||
return new FilterIterator<T>(sameProcPreds,notCall);
|
||||
return new FilterIterator<T>(sameProcPreds, notCall);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -202,10 +215,9 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
public Iterator<? extends T> getSuccNodes(T N) {
|
||||
return delegate.getPredNodes(N);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean hasEdge(T src, T dst) {
|
||||
return delegate.hasEdge(dst,src);
|
||||
return delegate.hasEdge(dst, src);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -222,7 +234,7 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
public void addEdge(Object src, Object dst) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
public void removeEdge(Object src, Object dst) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -240,7 +252,7 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
public T[] getEntriesForProcedure(P object) {
|
||||
return delegate.getExitsForProcedure(object);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getEntriesForProcedure(java.lang.Object)
|
||||
*/
|
||||
|
@ -312,32 +324,33 @@ public class BackwardsSupergraph<T,P> implements ISupergraph<T,P> {
|
|||
|
||||
public void removeIncomingEdges(Object node) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void removeOutgoingEdges(T node) throws UnsupportedOperationException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getNumberOfBlocks(java.lang.Object)
|
||||
*/
|
||||
public int getNumberOfBlocks(P procedure) {
|
||||
return delegate.getNumberOfBlocks(procedure);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlockNumber(java.lang.Object)
|
||||
*/
|
||||
public int getLocalBlockNumber(T n) {
|
||||
return delegate.getLocalBlockNumber(n);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlock(java.lang.Object, int)
|
||||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.ISupergraph#getLocalBlock(java.lang.Object,
|
||||
* int)
|
||||
*/
|
||||
public T getLocalBlock(P procedure, int i) {
|
||||
return delegate.getLocalBlock(procedure,i);
|
||||
return delegate.getLocalBlock(procedure, i);
|
||||
}
|
||||
|
||||
public int getNumber(T N) {
|
||||
|
|
|
@ -12,6 +12,7 @@ package com.ibm.wala.dataflow.IFDS;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.NumberedGraph;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +46,11 @@ public interface ISupergraph<T,P> extends NumberedGraph<T> {
|
|||
* @return an identifier for the main procedure for this supergraph
|
||||
*/
|
||||
P getMain();
|
||||
|
||||
/**
|
||||
* @return the graph of procedures (e.g. a call graph) over which this supergraph is induced.
|
||||
*/
|
||||
Graph<P> getProcedureGraph();
|
||||
|
||||
/**
|
||||
* @param n
|
||||
|
|
|
@ -40,6 +40,7 @@ import com.ibm.wala.util.debug.Assertions;
|
|||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.debug.UnimplementedError;
|
||||
import com.ibm.wala.util.graph.AbstractGraph;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.GraphIntegrity;
|
||||
import com.ibm.wala.util.graph.NumberedEdgeManager;
|
||||
import com.ibm.wala.util.graph.NumberedNodeManager;
|
||||
|
@ -94,6 +95,10 @@ public class PartiallyCollapsedSupergraph extends AbstractGraph<Object> implemen
|
|||
return isEntry(o);
|
||||
}
|
||||
};
|
||||
|
||||
public Graph<CGNode> getProcedureGraph() {
|
||||
return cg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cg
|
||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.util.intset.SparseIntSet;
|
|||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public interface TabulationResult<T> {
|
||||
public interface TabulationResult<T, P> {
|
||||
/**
|
||||
* get the bitvector of facts that hold at the entry to a given node
|
||||
*
|
||||
|
@ -33,7 +33,7 @@ public interface TabulationResult<T> {
|
|||
/**
|
||||
* @return the governing IFDS problem
|
||||
*/
|
||||
public TabulationProblem getProblem();
|
||||
public TabulationProblem<T, P> getProblem();
|
||||
|
||||
/**
|
||||
* @return the set of supergraph nodes for which any fact is reached
|
||||
|
|
|
@ -67,7 +67,7 @@ public class TabulationSolver<T, P> {
|
|||
* <li>2 Detailed debugging
|
||||
* </ul>
|
||||
*/
|
||||
protected static final int DEBUG_LEVEL = 0;
|
||||
protected static final int DEBUG_LEVEL = 2;
|
||||
|
||||
static protected final boolean verbose = true && ("true".equals(System.getProperty("com.ibm.wala.util.fixedpoint.impl.verbose")) ? true
|
||||
: false);
|
||||
|
@ -208,7 +208,7 @@ public class TabulationSolver<T, P> {
|
|||
* @return a representation of the result
|
||||
* @throws SolverInterruptedException
|
||||
*/
|
||||
public TabulationResult<T> solve() throws SolverInterruptedException {
|
||||
public TabulationResult<T, P> solve() throws SolverInterruptedException {
|
||||
EngineTimings.startVirtual("TabulationSolver.solve()");
|
||||
|
||||
EngineTimings.startVirtual("TabulationSolver.initialize");
|
||||
|
@ -604,12 +604,13 @@ public class TabulationSolver<T, P> {
|
|||
|
||||
reached.foreach(new IntSetAction() {
|
||||
public void act(int d1) {
|
||||
// eagerly propagate 0 into the callee for fact d1. this is a
|
||||
// heuristic intended
|
||||
// to realize better order for merges
|
||||
if (d1 != 0) {
|
||||
propagate(callee, d1, callee, 0);
|
||||
}
|
||||
// This is buggy. Who says 0 always propagates?
|
||||
// // eagerly propagate 0 into the callee for fact d1. this is a
|
||||
// // heuristic intended
|
||||
// // to realize better order for merges
|
||||
// if (d1 != 0) {
|
||||
// propagate(callee, d1, callee, 0);
|
||||
// }
|
||||
propagate(callee, d1, callee, d1);
|
||||
// cache the fact that we've flowed <c, d2> -> <callee, d1> by a
|
||||
// call flow
|
||||
|
@ -970,7 +971,7 @@ public class TabulationSolver<T, P> {
|
|||
/**
|
||||
* @author sfink
|
||||
*/
|
||||
public class Result implements TabulationResult<T> {
|
||||
public class Result implements TabulationResult<T, P> {
|
||||
|
||||
/**
|
||||
* get the bitvector of facts that hold at the entry to a given node
|
||||
|
@ -1050,7 +1051,7 @@ public class TabulationSolver<T, P> {
|
|||
/*
|
||||
* @see com.ibm.wala.dataflow.IFDS.TabulationResult#getProblem()
|
||||
*/
|
||||
public TabulationProblem getProblem() {
|
||||
public TabulationProblem<T,P> getProblem() {
|
||||
return problem;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public final class BasicBlockInContext<T extends ISSABasicBlock> extends NodeWit
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString() + "(node:" + node.getGraphNodeId() + ")";
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.ibm.wala.util.collections.Filter;
|
|||
import com.ibm.wala.util.collections.FilterIterator;
|
||||
import com.ibm.wala.util.collections.IteratorUtil;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.util.intset.SparseIntSet;
|
||||
|
||||
|
@ -50,6 +51,11 @@ class SDGSupergraph implements ISupergraph<Statement, PDG> {
|
|||
this.srcStatement = src;
|
||||
this.backward = backward;
|
||||
}
|
||||
|
||||
public Graph<PDG> getProcedureGraph() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] getEntry(Statement n) {
|
||||
Assertions.UNREACHABLE();
|
||||
|
|
|
@ -227,7 +227,7 @@ public class Slicer {
|
|||
}
|
||||
|
||||
TabulationSolver<Statement, PDG> solver = TabulationSolver.make(p);
|
||||
TabulationResult<Statement> tr = null;
|
||||
TabulationResult<Statement, PDG> tr = null;
|
||||
try {
|
||||
tr = solver.solve();
|
||||
} catch (SolverInterruptedException e) {
|
||||
|
@ -371,7 +371,7 @@ public class Slicer {
|
|||
* Convert the results of the tabulation to a slice, represented as a
|
||||
* Collection<Statement>
|
||||
*/
|
||||
private static Collection<Statement> result2Slice(final TabulationResult<Statement> result) {
|
||||
private static Collection<Statement> result2Slice(final TabulationResult<Statement, PDG> result) {
|
||||
return result.getSupergraphNodesReached();
|
||||
// final Collection<Statement> nodes = new
|
||||
// Iterator2Collection<Statement>(sdg.iterateLazyNodes());
|
||||
|
|
|
@ -30,12 +30,13 @@ import com.ibm.wala.util.warnings.WalaException;
|
|||
*
|
||||
*/
|
||||
public class DotUtil {
|
||||
|
||||
/**
|
||||
* Recent versions of dot appear to croak on long labels. Sigh.
|
||||
*/
|
||||
private final static int MAX_LABEL_LENGTH = 75;
|
||||
|
||||
/**
|
||||
* @param g
|
||||
* @param labels
|
||||
* @throws WalaException
|
||||
* @throws IllegalArgumentException if g is null
|
||||
*/
|
||||
public static <T> void dotify(Graph<T> g, NodeDecorator labels, String dotFile, String psFile, String dotExe) throws WalaException {
|
||||
if (g == null) {
|
||||
|
@ -283,12 +284,17 @@ public class DotUtil {
|
|||
// }
|
||||
//
|
||||
private static String getLabel(Object o, NodeDecorator d) throws WalaException {
|
||||
String result = null;
|
||||
if (d == null) {
|
||||
return o.toString();
|
||||
result = o.toString();
|
||||
} else {
|
||||
String result = d.getLabel(o);
|
||||
return result == null ? o.toString() : result;
|
||||
result = d.getLabel(o);
|
||||
result = result == null ? o.toString() : result;
|
||||
}
|
||||
if (result.length() >= MAX_LABEL_LENGTH) {
|
||||
result = result.substring(0, MAX_LABEL_LENGTH - 3) + "...";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getPort(Object o, NodeDecorator d) throws WalaException {
|
||||
|
|
|
@ -92,8 +92,6 @@ public class GhostviewUtil {
|
|||
}
|
||||
|
||||
/**
|
||||
* @author sfink
|
||||
*
|
||||
* A node decorator which concatenates the labels from two other node
|
||||
* decorators
|
||||
*/
|
||||
|
|
|
@ -15,31 +15,25 @@ import java.util.Collection;
|
|||
import java.util.Properties;
|
||||
|
||||
import com.ibm.wala.dataflow.IFDS.TabulationResult;
|
||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||
import com.ibm.wala.ipa.cfg.BasicBlockInContext;
|
||||
import com.ibm.wala.properties.WalaProperties;
|
||||
import com.ibm.wala.ssa.ISSABasicBlock;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.graph.Graph;
|
||||
import com.ibm.wala.util.graph.InferGraphRoots;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
/**
|
||||
* Explore the result of an IFDS problem with an SWT viewer and
|
||||
* ghostview.
|
||||
* Explore the result of an IFDS problem with an SWT viewer and ghostview.
|
||||
*
|
||||
* @author Stephen Fink
|
||||
*/
|
||||
public class IFDSExplorer {
|
||||
public class IFDSExplorer {
|
||||
|
||||
/**
|
||||
* absolute path name to invoke dot
|
||||
*/
|
||||
protected static String dotExe = null;
|
||||
|
||||
|
||||
/**
|
||||
* Absolute path name to invoke ghostview
|
||||
*/
|
||||
|
@ -53,19 +47,23 @@ public class IFDSExplorer {
|
|||
gvExe = newGvExe;
|
||||
}
|
||||
|
||||
public static void viewIFDS(CallGraph cg, TabulationResult r) throws WalaException {
|
||||
|
||||
/**
|
||||
* We pass in the supergraph to allow viewing of a forward supergraph with the results of a backwards problem.
|
||||
*/
|
||||
public static <T,P> void viewIFDS(TabulationResult<T, P> r) throws WalaException {
|
||||
|
||||
if (r == null) {
|
||||
throw new IllegalArgumentException("r is null");
|
||||
}
|
||||
assert gvExe != null;
|
||||
assert dotExe != null;
|
||||
|
||||
|
||||
// dump the domain to stderr
|
||||
System.err.println("Domain:\n" + r.getProblem().getDomain().toString());
|
||||
Trace.println("Domain:\n" + r.getProblem().getDomain().toString());
|
||||
|
||||
Properties p = null;;
|
||||
|
||||
Properties p = null;
|
||||
;
|
||||
try {
|
||||
p = WalaProperties.loadProperties();
|
||||
} catch (WalaException e) {
|
||||
|
@ -76,29 +74,14 @@ public class IFDSExplorer {
|
|||
String dotFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + "ir.dt";
|
||||
|
||||
final SWTTreeViewer v = new SWTTreeViewer();
|
||||
v.setGraphInput(cg);
|
||||
Graph<P> g = r.getProblem().getSupergraph().getProcedureGraph();
|
||||
v.setGraphInput(g);
|
||||
v.setBlockInput(true);
|
||||
Collection<CGNode> roots = InferGraphRoots.inferRoots(cg);
|
||||
Collection<P> roots = InferGraphRoots.inferRoots(g);
|
||||
v.setRootsInput(roots);
|
||||
v.getPopUpActions().add(new ViewAnnotatedIRAction(v,cg,psFile,dotFile,dotExe,gvExe, new IFDSAnnotator(r)));
|
||||
v.getPopUpActions().add(new ViewIFDSLocalAction<T, P>(v, r, psFile, dotFile, dotExe, gvExe));
|
||||
v.run();
|
||||
}
|
||||
|
||||
private final static class IFDSAnnotator extends BasicBlockDecorator {
|
||||
final private TabulationResult r;
|
||||
public IFDSAnnotator(TabulationResult r) {
|
||||
this.r = r;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getLabel(Object o) throws WalaException {
|
||||
ISSABasicBlock bb = (ISSABasicBlock)o;
|
||||
Object b = new BasicBlockInContext(getCurrentNode(),bb);
|
||||
IntSet result = r.getResult(b);
|
||||
String label = result == null ? "no result" : result.toString();
|
||||
return label + "\\n-----\\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getDotExe() {
|
||||
return dotExe;
|
||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Iterator;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
|
@ -70,7 +71,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner {
|
|||
* @generated
|
||||
* @ordered
|
||||
*/
|
||||
final protected List<ViewIRAction> popUpActions = new LinkedList<ViewIRAction>();
|
||||
final protected List<IAction> popUpActions = new LinkedList<IAction>();
|
||||
|
||||
/**
|
||||
* <!-- begin-user-doc --> <!-- end-user-doc -->
|
||||
|
@ -132,7 +133,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner {
|
|||
* <!-- begin-user-doc --> <!-- end-user-doc -->
|
||||
* @generated
|
||||
*/
|
||||
public List<ViewIRAction> getPopUpActions() {
|
||||
public List<IAction> getPopUpActions() {
|
||||
return popUpActions;
|
||||
}
|
||||
|
||||
|
@ -236,7 +237,7 @@ public class SWTTreeViewer extends EJfaceApplicationRunner {
|
|||
if (getPopUpActions().size() > 0) {
|
||||
MenuManager mm = new MenuManager();
|
||||
treeViewer.getTree().setMenu(mm.createContextMenu(treeViewer.getTree()));
|
||||
for (Iterator<ViewIRAction> it = getPopUpActions().iterator(); it.hasNext(); ) {
|
||||
for (Iterator<IAction> it = getPopUpActions().iterator(); it.hasNext(); ) {
|
||||
mm.add(it.next());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue