Skip to content

Commit

Permalink
fixing issues with DDG graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers committed Sep 4, 2023
1 parent da5d2c4 commit ef67148
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 13 deletions.
78 changes: 65 additions & 13 deletions src/java/boa/functions/BoaGraphIntrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@
public class BoaGraphIntrinsics {
@FunctionSpec(name = "getcfg", returnType = "CFG", formalParameters = { "Method" })
public static CFG getcfg(final Method method) {
return new CFG(method).get();
try {
return new CFG(method).get();
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getcfg", returnType = "CFG", formalParameters = { "Namespace" })
Expand All @@ -64,7 +68,11 @@ public static CFG getcfg(final Namespace ns) {
b.addStatements(ns.getStatements(i));
}

return new CFG(b.build(), true).get();
try {
return new CFG(b.build(), true).get();
} catch (final Exception e) {
return null;
}
}
@FunctionSpec(name = "getcfg", returnType = "CFG", formalParameters = { "Declaration" })
public static CFG getcfg(final Declaration ns) {
Expand All @@ -75,57 +83,101 @@ public static CFG getcfg(final Declaration ns) {
b.addStatements(ns.getStatements(i));
}

return new CFG(b.build(), true).get();
try {
return new CFG(b.build(), true).get();
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getpdtree", returnType = "PDTree", formalParameters = { "Method" })
public static PDTree getpdtree(final Method method) throws Exception {
return new PDTree(method);
try {
return new PDTree(method);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getcdg", returnType = "CDG", formalParameters = { "Method" })
public static CDG getcdg(final Method method) throws Exception {
return new CDG(method);
try {
return new CDG(method);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getcdg", returnType = "CDG", formalParameters = { "CFG" })
public static CDG getcdg(final CFG cfg) throws Exception {
return new CDG(cfg);
try {
return new CDG(cfg);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getddg", returnType = "DDG", formalParameters = { "Method" })
public static DDG getddg(final Method method) throws Exception {
return new DDG(method);
try {
return new DDG(method);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getddg", returnType = "DDG", formalParameters = { "CFG" })
public static DDG getddg(final CFG cfg) throws Exception {
return new DDG(cfg);
try {
return new DDG(cfg);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getpdg", returnType = "PDG", formalParameters = { "Method" })
public static PDG getpdg(final Method method) throws Exception {
return new PDG(method);
try {
return new PDG(method);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getpdg", returnType = "PDG", formalParameters = { "Method", "bool" })
public static PDG getpdg(final Method method, boolean paramAsStatement) throws Exception {
return new PDG(method, paramAsStatement);
try {
return new PDG(method, paramAsStatement);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getcfgslice", returnType = "CFGSlicer", formalParameters = { "Method", "int" })
public static CFGSlicer getcfgslice(final Method method, Long id) throws Exception {
return new CFGSlicer(method, (int)(long) id);
try {
return new CFGSlicer(method, (int)(long) id);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getpdgslice", returnType = "PDGSlicer", formalParameters = { "PDG", "int", "bool" })
public static PDGSlicer getpdgslice(final PDG pdg, Long id, boolean normalize) throws Exception {
return new PDGSlicer(pdg, (int)(long) id, normalize);
try {
return new PDGSlicer(pdg, (int)(long) id, normalize);
} catch (final Exception e) {
return null;
}
}

@FunctionSpec(name = "getpdgslice", returnType = "PDGSlicer", formalParameters = { "Method", "int", "bool" })
public static PDGSlicer getpdgslice(final Method method, Long id, boolean normalize) throws Exception {
return new PDGSlicer(method, (int)(long) id, normalize);
try {
return new PDGSlicer(method, (int)(long) id, normalize);
} catch (final Exception e) {
return null;
}
}

//@FunctionSpec(name = "get_nodes_with_definition", returnType = "set of string", formalParameters = { "Node" })
Expand Down
6 changes: 6 additions & 0 deletions src/java/boa/graphs/ddg/DDG.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class DDG {
private Method md;
private DDGNode entryNode;
private CFG cfg;
private final HashSet<DDGNode> nodes = new HashSet<DDGNode>();
private final HashMap<DDGNode, Set<DDGNode>> defUseChain = new HashMap<DDGNode, Set<DDGNode>>();
//private HashMap<DDGNode, Set<DDGNode>> useDefChain; //TODO: needs reaching-def analysis
Expand All @@ -43,6 +44,7 @@ public class DDG {
*/
public DDG(final CFG cfg) throws Exception {
if (cfg != null && cfg.getNodes().size() > 0) {
this.cfg = cfg;
this.md = cfg.getMd();
final Map<Integer, InOut> liveVars = getLiveVariables(cfg);
formDefUseChains(liveVars, cfg);
Expand Down Expand Up @@ -81,6 +83,10 @@ public Method getMethod() {
return md;
}

public CFG getCfg() {
return cfg;
}

/**
* Returns the entry node to the graph
*
Expand Down
3 changes: 3 additions & 0 deletions src/java/boa/types/proto/DDGProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class DDGProtoTuple extends BoaProtoTuple {
static {
int counter = 0;

names.put("nodes", counter++);
members.add(new BoaSet(new DDGNodeProtoTuple()));

names.put("defUseNodes", counter++);
members.add(new BoaMap(new DDGNodeProtoTuple(), new BoaSet(new DDGNodeProtoTuple())));
}
Expand Down

0 comments on commit ef67148

Please sign in to comment.