diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-20 01:03:23 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-20 01:03:23 -0600 |
commit | b7705e83c2026ff3983fc0b83f9b083d3e8be4c5 (patch) | |
tree | 9795143d8c2c9cb9fa7bac25a339533eb704cc32 | |
parent | 63551aff281f1d289605fe2c9975a15124dbe643 (diff) |
CFG fix create edges only if nodes != (found by graphviz)
-rw-r--r-- | V2VM.java | 4 | ||||
-rw-r--r-- | graphviz/config.properties | 18 | ||||
-rw-r--r-- | vaporize/library/CFGNode.java | 9 | ||||
-rw-r--r-- | vaporize/library/CFGSimp.java | 28 | ||||
-rw-r--r-- | vaporize/library/ControlFlowGraph.java | 24 |
5 files changed, 43 insertions, 40 deletions
@@ -33,8 +33,8 @@ public class V2VM { MinimalLogger.info(String.format("Generating CFGs...")); CFGSimp cfv = new CFGSimp(prog, strProg); ArrayList<ControlFlowGraph> cfgs = cfv.getCFGs(); - MinimalLogger.info(String.format("Spilling Everywhere...")); - SpillEverywhere spill = new SpillEverywhere(prog, strProg); + // MinimalLogger.info(String.format("Spilling Everywhere...")); + // SpillEverywhere spill = new SpillEverywhere(prog, strProg); } catch (IOException e) { System.out.println(e.toString()); diff --git a/graphviz/config.properties b/graphviz/config.properties index 60901d5..786f977 100644 --- a/graphviz/config.properties +++ b/graphviz/config.properties @@ -1,23 +1,11 @@ -############################################################## -# Linux Configurations # -############################################################## -# The dir. where temporary files will be created. +# Linux Configurations tempDirForLinux = /tmp -# Where is your dot program located? It will be called externally. dotForLinux = /home/bdunahu/.guix-home/profile/bin/dot -############################################################## -# Windows Configurations # -############################################################## -# The dir. where temporary files will be created. +# Windows Configurations tempDirForWindows = c:/temp -# Where is your dot program located? It will be called externally. dotForWindows = "c:/Program Files (x86)/Graphviz 2.28/bin/dot.exe" -############################################################## -# Mac Configurations # -############################################################## -# The dir. where temporary files will be created. +# Mac Configurations tempDirForMacOSX = /tmp -# Where is your dot program located? It will be called externally. dotForMacOSX = /usr/local/bin/dot
\ No newline at end of file diff --git a/vaporize/library/CFGNode.java b/vaporize/library/CFGNode.java index 0afce60..b79ee6b 100644 --- a/vaporize/library/CFGNode.java +++ b/vaporize/library/CFGNode.java @@ -33,9 +33,12 @@ class CFGNode { */ // FIXME public boolean equals(Object other) { - return (other instanceof Node && - (((Node) other).sourcePos == - this.instruction.sourcePos)) || + return (other instanceof CFGNode && + (((CFGNode) other).instruction == + this.instruction)) || + (other instanceof Node && + (((Node) other).sourcePos == + this.instruction.sourcePos)) || (other instanceof Integer && (((Integer) other) .equals(this.instruction.sourcePos.line))); diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index f4d63cf..0cefb5a 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -9,6 +9,8 @@ import java.util.*; public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeException> { + private boolean use_graphviz = true; // if true, generates svg files of the edges in each function + private VaporProgram vp; private Kettle kettle; private ArrayList<ControlFlowGraph> cfgs; @@ -44,13 +46,13 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE } - // edges MinimalLogger.info(String.format("CFGSimp is collecting edges for %s", this.kettle.parseFuncName(f))); for (VInstr s : f.body) s.accept(cfg, this); - this.createDotGraph(this.kettle.parseFuncName(f)); + if (this.use_graphviz) + this.createDotGraph(this.kettle.parseFuncName(f)); this.cfgs.add(cfg); } @@ -71,6 +73,8 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE String type = "svg"; gv.decreaseDpi(); gv.decreaseDpi(); + gv.decreaseDpi(); + gv.decreaseDpi(); File out = new File(file_name+"."+ type); gv.writeGraphToFile( gv.getGraph( gv.getDotSource(), type ), out ); } @@ -82,7 +86,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", @@ -99,7 +103,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", @@ -116,7 +120,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", @@ -133,7 +137,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.dot_format += cfg.addEdge(this.curr, cfg.getNode(new Integer(this.kettle .findLabelIndex(n.target.toString())))); @@ -152,9 +156,9 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE this.kettle.get(n).trim(), n.sourcePos.toString())); /////////////////////////////////////////////////////////////// - CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(new Integer(this.kettle - .findLabelIndex(n.target.toString())))); + CFGNode curr = cfg.getNode(new Integer(this.kettle + .findLabelIndex(n.target.toString()))); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// @@ -172,7 +176,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", @@ -189,7 +193,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", @@ -206,7 +210,7 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE n.sourcePos.toString())); /////////////////////////////////////////////////////////////// CFGNode curr = cfg.getNode(n); - this.dot_format += cfg.addEdge(this.curr, cfg.getNode(n)); + this.dot_format += cfg.addEdge(this.curr, curr); this.curr = curr; /////////////////////////////////////////////////////////////// MinimalLogger.info(String.format("<-%s (\"%s\":%s)", diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index 364cec1..b4c995c 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -38,16 +38,24 @@ public class ControlFlowGraph { } protected String addEdge(CFGNode source, CFGNode dest) { - String ret = String.format("%d -> %d", - source.getInstruction().sourcePos.line, - dest.getInstruction().sourcePos.line); - MinimalLogger.info(String.format("Edge %s", - ret)); + /** + * Iff the CFGNodes are different, construct an edge between them. + * Returns a string capable of being manipulated by graphviz. + */ + String ret = ""; + if (!source.equals(dest)) { + ret = String.format("%d -> %d", + source.getInstruction().sourcePos.line, + dest.getInstruction().sourcePos.line); + MinimalLogger.info(String.format("Edge %s", + ret)); - source.addDest(dest); - dest.addSource(source); + source.addDest(dest); + dest.addSource(source); + ret += ";"; + } - return ret +";"; + return ret; } protected void setStart(CFGNode start) { |