diff options
Diffstat (limited to 'vaporize/library')
| -rw-r--r-- | vaporize/library/CFGSimp.java | 20 | ||||
| -rw-r--r-- | vaporize/library/ControlFlowGraph.java | 21 | ||||
| -rw-r--r-- | vaporize/library/Kettle.java | 26 | 
3 files changed, 47 insertions, 20 deletions
diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index 0cefb5a..c261f7c 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -9,7 +9,7 @@ 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 boolean use_graphviz = true;        // if true, generates svg files of the edges in each function      private VaporProgram vp;      private Kettle kettle; @@ -27,7 +27,8 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE          for (VFunction f : this.vp.functions) {              ControlFlowGraph cfg = new ControlFlowGraph();              this.dot_format = ""; -            curr = new CFGNode(f.body[0]); +            // first visit may not find edges; cfg.addEdges will handle +            this.curr = new CFGNode(f.body[0]);              cfg.setStart(curr);              MinimalLogger.info(String.format("CFGSimp is collecting nodes for %s", @@ -138,8 +139,8 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE          ///////////////////////////////////////////////////////////////          CFGNode 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())))); +        this.dot_format += cfg.addEdge(curr, cfg.getNode(new Integer(this.kettle +                                                                     .findLabelIndex(n.target.toString()))));          this.curr = curr;          /////////////////////////////////////////////////////////////// @@ -156,11 +157,14 @@ public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeE                                           this.kettle.get(n).trim(),                                           n.sourcePos.toString()));          /////////////////////////////////////////////////////////////// -        CFGNode curr = cfg.getNode(new Integer(this.kettle -                                               .findLabelIndex(n.target.toString()))); -        this.dot_format += cfg.addEdge(this.curr, curr); +        CFGNode curr = cfg.getNode(n); +        this.dot_format += cfg.addEdge(curr, +                                       cfg.getNode(new Integer(this.kettle +                                                               .findLabelIndex(n.target.toString())))); -        this.curr = curr; +        MinimalLogger.info(String.format("curr is now %s", +                                         this.kettle.get(n).trim())); +        this.curr = cfg.getNextNode(curr);          ///////////////////////////////////////////////////////////////          MinimalLogger.info(String.format("<-%s (\"%s\":%s)",                                           n.getClass().getSimpleName(), diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index b4c995c..2a8caef 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -33,6 +33,24 @@ public class ControlFlowGraph {          return ret;      } +    protected CFGNode getNextNode(CFGNode a) { +        CFGNode ret = null; +        // we return null if the passed node is the last in the list +        for (int i = 0; i < this.nodes.size()-1; ++i) { +            if (this.nodes.get(i).equals(a)) { +                ret = this.nodes.get(i+1); +                break; +            } +        } + +        if (ret == null) +            MinimalLogger.severe(String.format("Could not find a node matching %s", +                                               a.toString())); + +        return ret; + +    } +      protected void addNode(CFGNode node) {          this.nodes.add(node);      } @@ -53,6 +71,9 @@ public class ControlFlowGraph {              source.addDest(dest);              dest.addSource(source);              ret += ";"; +        } else { +            MinimalLogger.info(String.format("Skipping duplicate edge for %d", +                                             source.getInstruction().sourcePos.line));          }          return ret; diff --git a/vaporize/library/Kettle.java b/vaporize/library/Kettle.java index d76c938..38c941a 100644 --- a/vaporize/library/Kettle.java +++ b/vaporize/library/Kettle.java @@ -71,6 +71,20 @@ class Kettle {          return String.join("\n", this.vapor);      } +    private void set(Node n, String s) { +        /** +         * Sets the position of Node n in the original +         * file to String s. +         */ +        this.vapor.set(this.indexOf(n), s); +    } + +    protected int indexOf(Node n) { +        return n.sourcePos.line-1; +    } + +    // METHODS INTENDED TO BE USED WITH CFG +      /**       * Needed because VBranch doesn't seem to       * keep track of this... @@ -99,16 +113,4 @@ class Kettle {          return index+1;      } -    protected int indexOf(Node n) { -        return n.sourcePos.line-1; -    } - -    private void set(Node n, String s) { -        /** -         * Sets the position of Node n in the original -         * file to String s. -         */ -        this.vapor.set(this.indexOf(n), s); -    } -  }  | 
