Loading pom.xml +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ <groupId>tfm</groupId> <artifactId>tfm</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <properties> Loading @@ -16,5 +17,6 @@ <modules> <module>sdg-core</module> <module>sdg-cli</module> <module>sdg-gui</module> </modules> </project> sdg-cli/META-INF/MANIFEST.MF 0 → 100644 +3 −0 Original line number Diff line number Diff line Manifest-Version: 1.0 Main-Class: tfm.cli.Slicer sdg-cli/pom.xml +2 −2 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <groupId>tfm</groupId> <artifactId>sdg-cli</artifactId> <version>1.0-SNAPSHOT</version> <version>1.0.1</version> <properties> <maven.compiler.source>11</maven.compiler.source> Loading @@ -27,7 +27,7 @@ <dependency> <groupId>tfm</groupId> <artifactId>sdg-core</artifactId> <version>1.0-SNAPSHOT</version> <version>1.1.2</version> <scope>compile</scope> </dependency> </dependencies> Loading sdg-cli/src/main/java/tfm/cli/GraphLog.java +24 −14 Original line number Diff line number Diff line package tfm.cli; import org.jgrapht.io.DOTExporter; import tfm.arcs.Arc; import tfm.graphs.Graph; import tfm.nodes.GraphNode; import tfm.utils.FileUtil; import tfm.utils.Logger; Loading @@ -21,15 +24,12 @@ public abstract class GraphLog<G extends Graph> { } } static final String CFG = "cfg"; static final String PDG = "pdg"; static final String SDG = "sdg"; G graph; protected G graph; protected String imageName; protected Format format; protected String format; protected boolean generated = false; protected File outputDir = new File("./out/"); public GraphLog() { this(null); Loading @@ -39,6 +39,10 @@ public abstract class GraphLog<G extends Graph> { this.graph = graph; } public void setDirectory(File outputDir) { this.outputDir = outputDir; } public void log() throws IOException { Logger.log( "****************************\n" + Loading @@ -52,7 +56,7 @@ public abstract class GraphLog<G extends Graph> { "****************************" ); try (StringWriter stringWriter = new StringWriter()) { graph.getDOTExporter().exportGraph(graph, stringWriter); getDOTExporter(graph).exportGraph(graph, stringWriter); stringWriter.append('\n'); Logger.log(stringWriter.toString()); } Loading @@ -63,22 +67,24 @@ public abstract class GraphLog<G extends Graph> { } public void generateImages(String imageName) throws IOException { generateImages(imageName, Format.PNG); generateImages(imageName, "pdf"); } public void generateImages(String imageName, Format format) throws IOException { this.imageName = imageName + "-" + graph.getClass().getName(); public void generateImages(String imageName, String format) throws IOException { this.imageName = imageName + "-" + graph.getClass().getSimpleName(); this.format = format; generated = true; File tmpDot = File.createTempFile("graph-source-", ".dot"); tmpDot.getParentFile().mkdirs(); getImageFile().getParentFile().mkdirs(); // Graph -> DOT -> file try (Writer w = new FileWriter(tmpDot)) { graph.getDOTExporter().exportGraph(graph, w); getDOTExporter(graph).exportGraph(graph, w); } // Execute dot ProcessBuilder pb = new ProcessBuilder("dot", tmpDot.getAbsolutePath(), "-T" + format.getExt(), tmpDot.getAbsolutePath(), "-T" + format, "-o", getImageFile().getAbsolutePath()); try { int result = pb.start().waitFor(); Loading @@ -96,7 +102,11 @@ public abstract class GraphLog<G extends Graph> { FileUtil.open(getImageFile()); } protected File getImageFile() { return new File("./out/" + imageName + "." + format.getExt()); public File getImageFile() { return new File(outputDir, imageName + "." + format); } protected DOTExporter<GraphNode<?>, Arc> getDOTExporter(G graph) { return graph.getDOTExporter(); } } sdg-cli/src/main/java/tfm/cli/PDGLog.java +3 −5 Original line number Diff line number Diff line Loading @@ -31,18 +31,16 @@ public class PDGLog extends GraphLog<PDG> { Logger.log(graph.vertexSet().stream() .sorted(Comparator.comparingLong(GraphNode::getId)) .map(node -> String.format("GraphNode { id: %s, instruction: %s, declared: %s, defined: %s, used: %s }", String.format("GraphNode { id: %s, instruction: %s, variables: %s}", node.getId(), node.getInstruction(), node.getDeclaredVariables(), node.getDefinedVariables(), node.getUsedVariables()) node.getVariableActions()) ).collect(Collectors.joining(System.lineSeparator())) ); } @Override public void generateImages(String imageName, Format format) throws IOException { public void generateImages(String imageName, String format) throws IOException { super.generateImages(imageName, format); if (cfgLog != null) cfgLog.generateImages(imageName, format); Loading Loading
pom.xml +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ <groupId>tfm</groupId> <artifactId>tfm</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <properties> Loading @@ -16,5 +17,6 @@ <modules> <module>sdg-core</module> <module>sdg-cli</module> <module>sdg-gui</module> </modules> </project>
sdg-cli/META-INF/MANIFEST.MF 0 → 100644 +3 −0 Original line number Diff line number Diff line Manifest-Version: 1.0 Main-Class: tfm.cli.Slicer
sdg-cli/pom.xml +2 −2 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ <groupId>tfm</groupId> <artifactId>sdg-cli</artifactId> <version>1.0-SNAPSHOT</version> <version>1.0.1</version> <properties> <maven.compiler.source>11</maven.compiler.source> Loading @@ -27,7 +27,7 @@ <dependency> <groupId>tfm</groupId> <artifactId>sdg-core</artifactId> <version>1.0-SNAPSHOT</version> <version>1.1.2</version> <scope>compile</scope> </dependency> </dependencies> Loading
sdg-cli/src/main/java/tfm/cli/GraphLog.java +24 −14 Original line number Diff line number Diff line package tfm.cli; import org.jgrapht.io.DOTExporter; import tfm.arcs.Arc; import tfm.graphs.Graph; import tfm.nodes.GraphNode; import tfm.utils.FileUtil; import tfm.utils.Logger; Loading @@ -21,15 +24,12 @@ public abstract class GraphLog<G extends Graph> { } } static final String CFG = "cfg"; static final String PDG = "pdg"; static final String SDG = "sdg"; G graph; protected G graph; protected String imageName; protected Format format; protected String format; protected boolean generated = false; protected File outputDir = new File("./out/"); public GraphLog() { this(null); Loading @@ -39,6 +39,10 @@ public abstract class GraphLog<G extends Graph> { this.graph = graph; } public void setDirectory(File outputDir) { this.outputDir = outputDir; } public void log() throws IOException { Logger.log( "****************************\n" + Loading @@ -52,7 +56,7 @@ public abstract class GraphLog<G extends Graph> { "****************************" ); try (StringWriter stringWriter = new StringWriter()) { graph.getDOTExporter().exportGraph(graph, stringWriter); getDOTExporter(graph).exportGraph(graph, stringWriter); stringWriter.append('\n'); Logger.log(stringWriter.toString()); } Loading @@ -63,22 +67,24 @@ public abstract class GraphLog<G extends Graph> { } public void generateImages(String imageName) throws IOException { generateImages(imageName, Format.PNG); generateImages(imageName, "pdf"); } public void generateImages(String imageName, Format format) throws IOException { this.imageName = imageName + "-" + graph.getClass().getName(); public void generateImages(String imageName, String format) throws IOException { this.imageName = imageName + "-" + graph.getClass().getSimpleName(); this.format = format; generated = true; File tmpDot = File.createTempFile("graph-source-", ".dot"); tmpDot.getParentFile().mkdirs(); getImageFile().getParentFile().mkdirs(); // Graph -> DOT -> file try (Writer w = new FileWriter(tmpDot)) { graph.getDOTExporter().exportGraph(graph, w); getDOTExporter(graph).exportGraph(graph, w); } // Execute dot ProcessBuilder pb = new ProcessBuilder("dot", tmpDot.getAbsolutePath(), "-T" + format.getExt(), tmpDot.getAbsolutePath(), "-T" + format, "-o", getImageFile().getAbsolutePath()); try { int result = pb.start().waitFor(); Loading @@ -96,7 +102,11 @@ public abstract class GraphLog<G extends Graph> { FileUtil.open(getImageFile()); } protected File getImageFile() { return new File("./out/" + imageName + "." + format.getExt()); public File getImageFile() { return new File(outputDir, imageName + "." + format); } protected DOTExporter<GraphNode<?>, Arc> getDOTExporter(G graph) { return graph.getDOTExporter(); } }
sdg-cli/src/main/java/tfm/cli/PDGLog.java +3 −5 Original line number Diff line number Diff line Loading @@ -31,18 +31,16 @@ public class PDGLog extends GraphLog<PDG> { Logger.log(graph.vertexSet().stream() .sorted(Comparator.comparingLong(GraphNode::getId)) .map(node -> String.format("GraphNode { id: %s, instruction: %s, declared: %s, defined: %s, used: %s }", String.format("GraphNode { id: %s, instruction: %s, variables: %s}", node.getId(), node.getInstruction(), node.getDeclaredVariables(), node.getDefinedVariables(), node.getUsedVariables()) node.getVariableActions()) ).collect(Collectors.joining(System.lineSeparator())) ); } @Override public void generateImages(String imageName, Format format) throws IOException { public void generateImages(String imageName, String format) throws IOException { super.generateImages(imageName, format); if (cfgLog != null) cfgLog.generateImages(imageName, format); Loading