From ef67148297fa05d0c47588c1c5972e99260ec7f4 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Mon, 4 Sep 2023 11:29:10 -0500 Subject: [PATCH] fixing issues with DDG graphs --- .../boa/functions/BoaGraphIntrinsics.java | 78 +++++++++++++++---- src/java/boa/graphs/ddg/DDG.java | 6 ++ src/java/boa/types/proto/DDGProtoTuple.java | 3 + 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/src/java/boa/functions/BoaGraphIntrinsics.java b/src/java/boa/functions/BoaGraphIntrinsics.java index 1f1a9b64e..195cd8fb0 100644 --- a/src/java/boa/functions/BoaGraphIntrinsics.java +++ b/src/java/boa/functions/BoaGraphIntrinsics.java @@ -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" }) @@ -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) { @@ -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" }) diff --git a/src/java/boa/graphs/ddg/DDG.java b/src/java/boa/graphs/ddg/DDG.java index a554652f3..d189c58ae 100644 --- a/src/java/boa/graphs/ddg/DDG.java +++ b/src/java/boa/graphs/ddg/DDG.java @@ -31,6 +31,7 @@ public class DDG { private Method md; private DDGNode entryNode; + private CFG cfg; private final HashSet nodes = new HashSet(); private final HashMap> defUseChain = new HashMap>(); //private HashMap> useDefChain; //TODO: needs reaching-def analysis @@ -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 liveVars = getLiveVariables(cfg); formDefUseChains(liveVars, cfg); @@ -81,6 +83,10 @@ public Method getMethod() { return md; } + public CFG getCfg() { + return cfg; + } + /** * Returns the entry node to the graph * diff --git a/src/java/boa/types/proto/DDGProtoTuple.java b/src/java/boa/types/proto/DDGProtoTuple.java index 7cf22ccf2..c75b0f556 100644 --- a/src/java/boa/types/proto/DDGProtoTuple.java +++ b/src/java/boa/types/proto/DDGProtoTuple.java @@ -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()))); }