Skip to content

Commit

Permalink
Merge pull request #17 from sinha108/main
Browse files Browse the repository at this point in the history
SDG with call-dep edges only
  • Loading branch information
sinha108 authored May 12, 2024
2 parents 1794971 + 64ee7e6 commit 248dae1
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/main/java/com/ibm/northstar/SystemDependencyGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,58 +104,58 @@ private static org.jgrapht.Graph<Pair<String, Callable>, AbstractGraphEdge> buil
// We'll use forward and backward search on the DFS to identify which CFG nodes
// are dominant
// This is a forward DFS search (or exit time first search)
int dfsNumber = 0;
Map<Statement, Integer> dfsFinish = HashMapFactory.make();
Iterator<Statement> search = DFS.iterateFinishTime(sdg, entryPoints.get());

while (search.hasNext()) {
dfsFinish.put(search.next(), dfsNumber++);
}

// This is a reverse DFS search (or entry time first search)
int reverseDfsNumber = 0;
Map<Statement, Integer> dfsStart = HashMapFactory.make();
Iterator<Statement> reverseSearch = DFS.iterateDiscoverTime(sdg, entryPoints.get());

while (reverseSearch.hasNext()) {
dfsStart.put(reverseSearch.next(), reverseDfsNumber++);
}
// int dfsNumber = 0;
// Map<Statement, Integer> dfsFinish = HashMapFactory.make();
// Iterator<Statement> search = DFS.iterateFinishTime(sdg, entryPoints.get());
//
// while (search.hasNext()) {
// dfsFinish.put(search.next(), dfsNumber++);
// }
//
// // This is a reverse DFS search (or entry time first search)
// int reverseDfsNumber = 0;
// Map<Statement, Integer> dfsStart = HashMapFactory.make();
// Iterator<Statement> reverseSearch = DFS.iterateDiscoverTime(sdg, entryPoints.get());
//
// while (reverseSearch.hasNext()) {
// dfsStart.put(reverseSearch.next(), reverseDfsNumber++);
// }

// Populate graph
sdg.stream()
.filter(dfsFinish::containsKey)
.sorted(Comparator.comparingInt(dfsFinish::get))
.forEach(p -> sdg.getSuccNodes(p).forEachRemaining(s -> {
if (dfsFinish.containsKey(s)
&& dfsStart.get(p) != null && dfsStart.get(s) != null
&& !((dfsStart.get(p) >= dfsStart.get(s))
&& (dfsFinish.get(p) <= dfsFinish.get(s)))
&& !p.getNode().getMethod().equals(s.getNode().getMethod())) {

// Add the source nodes to the graph as vertices
Pair<String, Callable> source = Optional.ofNullable(getCallableFromSymbolTable(p.getNode().getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(p.getNode().getMethod()));
graph.addVertex(source);

// Add the target nodes to the graph as vertices
Pair<String, Callable> target = Optional.ofNullable(getCallableFromSymbolTable(s.getNode().getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(s.getNode().getMethod()));
graph.addVertex(target);


String edgeType = edgeLabels.apply(p, s);
SystemDepEdge graphEdge = new SystemDepEdge(p, s, edgeType);
SystemDepEdge cgEdge = (SystemDepEdge) graph.getEdge(source, target);
if (source.getRight() != null && target.getRight() != null) {
if (cgEdge == null || !cgEdge.equals(graphEdge)) {
graph.addEdge(
source,
target,
graphEdge);
} else {
graphEdge.incrementWeight();
}
}
}
}));
// sdg.stream()
// .filter(dfsFinish::containsKey)
// .sorted(Comparator.comparingInt(dfsFinish::get))
// .forEach(p -> sdg.getSuccNodes(p).forEachRemaining(s -> {
// if (dfsFinish.containsKey(s)
// && dfsStart.get(p) != null && dfsStart.get(s) != null
// && !((dfsStart.get(p) >= dfsStart.get(s))
// && (dfsFinish.get(p) <= dfsFinish.get(s)))
// && !p.getNode().getMethod().equals(s.getNode().getMethod())) {
//
// // Add the source nodes to the graph as vertices
// Pair<String, Callable> source = Optional.ofNullable(getCallableFromSymbolTable(p.getNode().getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(p.getNode().getMethod()));
// graph.addVertex(source);
//
// // Add the target nodes to the graph as vertices
// Pair<String, Callable> target = Optional.ofNullable(getCallableFromSymbolTable(s.getNode().getMethod())).orElseGet(() -> createAndPutNewCallableInSymbolTable(s.getNode().getMethod()));
// graph.addVertex(target);
//
//
// String edgeType = edgeLabels.apply(p, s);
// SystemDepEdge graphEdge = new SystemDepEdge(p, s, edgeType);
// SystemDepEdge cgEdge = (SystemDepEdge) graph.getEdge(source, target);
// if (source.getRight() != null && target.getRight() != null) {
// if (cgEdge == null || !cgEdge.equals(graphEdge)) {
// graph.addEdge(
// source,
// target,
// graphEdge);
// } else {
// graphEdge.incrementWeight();
// }
// }
// }
// }));

callGraph.getEntrypointNodes()
.forEach(p -> {
Expand Down

0 comments on commit 248dae1

Please sign in to comment.