Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package tfm.exec;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.utils.Logger;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
public class Main {
public static final String PROGRAM = "src/main/java/tfm/programs/pdg/Example1.java";
public static final String METHOD = "";
public static final String GRAPH = GraphLog.PDG;
public static void main(String[] args) throws IOException {
JavaParser.getStaticConfiguration().setAttributeComments(false);
// File
File file = new File(PROGRAM);
Node root = JavaParser.parse(file);
// GraphLog
GraphLog<?, ?> graphLog = getGraphLog(args.length == 1 ? args[0] : GRAPH);
if (!METHOD.isEmpty()) {
Optional<MethodDeclaration> methodDeclarationOptional = root.findFirst(MethodDeclaration.class,
methodDeclaration -> Objects.equals(methodDeclaration.getNameAsString(), METHOD));
if (!methodDeclarationOptional.isPresent()) {
Logger.format("Method '%s' not found in '%s'. Exiting...", METHOD, PROGRAM);
return;
}
root = methodDeclarationOptional.get();
}
// Generate Graph and measure time
long t0 = System.nanoTime();
graphLog.visit(root);
long tf = System.nanoTime();
long tt = tf - t0;
graphLog.log();
graphLog.generatePNGs();
graphLog.openVisualRepresentation();
Logger.log();
Logger.format("Graph generated in %.2f ms", tt / 10e6);
}
private static GraphLog<?, ?> getGraphLog(String graph) throws IOException {
GraphLog<?, ?> graphLog = null;
switch (graph) {
case GraphLog.CFG:
graphLog = new CFGLog();
break;
case GraphLog.PDG:
// main(new String[]{GraphLog.CFG});
graphLog = new PDGLog();
break;
default:
Logger.log("Unkown graph type");
System.exit(1);
}
return graphLog;
}
}