From b7705e83c2026ff3983fc0b83f9b083d3e8be4c5 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 20 Apr 2024 01:03:23 -0600 Subject: CFG fix create edges only if nodes != (found by graphviz) --- vaporize/library/CFGNode.java | 9 ++++++--- vaporize/library/CFGSimp.java | 28 ++++++++++++++++------------ vaporize/library/ControlFlowGraph.java | 24 ++++++++++++++++-------- 3 files changed, 38 insertions(+), 23 deletions(-) (limited to 'vaporize/library') 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 { + private boolean use_graphviz = true; // if true, generates svg files of the edges in each function + private VaporProgram vp; private Kettle kettle; private ArrayList cfgs; @@ -44,13 +46,13 @@ public class CFGSimp extends VInstr.VisitorPR %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) { -- cgit v1.2.3