add ability to output SVG
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2584 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
314927349f
commit
bc6648e771
|
@ -19,6 +19,7 @@ import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.ibm.wala.util.collections.Iterator2Collection;
|
import com.ibm.wala.util.collections.Iterator2Collection;
|
||||||
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
import com.ibm.wala.util.graph.Graph;
|
import com.ibm.wala.util.graph.Graph;
|
||||||
import com.ibm.wala.util.warnings.WalaException;
|
import com.ibm.wala.util.warnings.WalaException;
|
||||||
|
|
||||||
|
@ -30,6 +31,35 @@ import com.ibm.wala.util.warnings.WalaException;
|
||||||
*/
|
*/
|
||||||
public class DotUtil {
|
public class DotUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* possible output formats for dot
|
||||||
|
* @author manu
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static enum DotOutputType { PS,SVG }
|
||||||
|
|
||||||
|
private static DotOutputType outputType = DotOutputType.PS;
|
||||||
|
|
||||||
|
public static void setOutputType(DotOutputType outType) {
|
||||||
|
outputType = outType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DotOutputType getOutputType() {
|
||||||
|
return outputType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String outputTypeCmdLineParam() {
|
||||||
|
switch (outputType) {
|
||||||
|
case PS:
|
||||||
|
return "-Tps";
|
||||||
|
case SVG:
|
||||||
|
return "-Tsvg";
|
||||||
|
default:
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recent versions of dot appear to croak on long labels. Sigh.
|
* Recent versions of dot appear to croak on long labels. Sigh.
|
||||||
*/
|
*/
|
||||||
|
@ -37,19 +67,19 @@ public class DotUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public static <T> void dotify(Graph<T> g, NodeDecorator labels, String dotFile, String psFile, String dotExe) throws WalaException {
|
public static <T> void dotify(Graph<T> g, NodeDecorator labels, String dotFile, String outputFile, String dotExe) throws WalaException {
|
||||||
if (g == null) {
|
if (g == null) {
|
||||||
throw new IllegalArgumentException("g is null");
|
throw new IllegalArgumentException("g is null");
|
||||||
}
|
}
|
||||||
File f = DotUtil.writeDotFile(g, labels, dotFile);
|
File f = DotUtil.writeDotFile(g, labels, dotFile);
|
||||||
spawnDot(dotExe, psFile, f);
|
spawnDot(dotExe, outputFile, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spawnDot(String dotExe, String psFile, File dotFile) throws WalaException {
|
public static void spawnDot(String dotExe, String outputFile, File dotFile) throws WalaException {
|
||||||
if (dotFile == null) {
|
if (dotFile == null) {
|
||||||
throw new IllegalArgumentException("dotFile is null");
|
throw new IllegalArgumentException("dotFile is null");
|
||||||
}
|
}
|
||||||
String[] cmdarray = { dotExe, "-Tps", "-o", psFile, "-v", dotFile.getAbsolutePath() };
|
String[] cmdarray = { dotExe, outputTypeCmdLineParam(), "-o", outputFile, "-v", dotFile.getAbsolutePath() };
|
||||||
System.out.println("spawning process " + Arrays.toString(cmdarray));
|
System.out.println("spawning process " + Arrays.toString(cmdarray));
|
||||||
try {
|
try {
|
||||||
Process p = Runtime.getRuntime().exec(cmdarray);
|
Process p = Runtime.getRuntime().exec(cmdarray);
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.ibm.wala.util.debug.Trace;
|
||||||
import com.ibm.wala.util.graph.Graph;
|
import com.ibm.wala.util.graph.Graph;
|
||||||
import com.ibm.wala.util.graph.InferGraphRoots;
|
import com.ibm.wala.util.graph.InferGraphRoots;
|
||||||
import com.ibm.wala.util.warnings.WalaException;
|
import com.ibm.wala.util.warnings.WalaException;
|
||||||
|
import com.ibm.wala.viz.DotUtil.DotOutputType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@ -69,7 +70,7 @@ public class IFDSExplorer {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Assertions.UNREACHABLE();
|
Assertions.UNREACHABLE();
|
||||||
}
|
}
|
||||||
String psFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + "ir.ps";
|
String outputFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + (DotUtil.getOutputType() == DotOutputType.PS ? "ir.ps" : "ir.svg");
|
||||||
String dotFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + "ir.dt";
|
String dotFile = p.getProperty(WalaProperties.OUTPUT_DIR) + File.separatorChar + "ir.dt";
|
||||||
|
|
||||||
final SWTTreeViewer v = new SWTTreeViewer();
|
final SWTTreeViewer v = new SWTTreeViewer();
|
||||||
|
@ -78,7 +79,7 @@ public class IFDSExplorer {
|
||||||
v.setBlockInput(true);
|
v.setBlockInput(true);
|
||||||
Collection<? extends P> roots = InferGraphRoots.inferRoots(r.getProblem().getSupergraph().getProcedureGraph());
|
Collection<? extends P> roots = InferGraphRoots.inferRoots(r.getProblem().getSupergraph().getProcedureGraph());
|
||||||
v.setRootsInput(roots);
|
v.setRootsInput(roots);
|
||||||
v.getPopUpActions().add(new ViewIFDSLocalAction<T, P>(v, r, psFile, dotFile, dotExe, gvExe));
|
v.getPopUpActions().add(new ViewIFDSLocalAction<T, P>(v, r, outputFile, dotFile, dotExe, gvExe));
|
||||||
v.run();
|
v.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue