summaryrefslogtreecommitdiff
path: root/vaporize/library/ControlFlowGraph.java
diff options
context:
space:
mode:
Diffstat (limited to 'vaporize/library/ControlFlowGraph.java')
-rw-r--r--vaporize/library/ControlFlowGraph.java97
1 files changed, 0 insertions, 97 deletions
diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java
deleted file mode 100644
index 5d589fb..0000000
--- a/vaporize/library/ControlFlowGraph.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package vaporize.library;
-
-import cs132.vapor.ast.*;
-import misc.*;
-
-import java.util.ArrayList;
-
-public class ControlFlowGraph {
-
- private ArrayList<CFGNode> nodes;
- private CFGNode start;
-
- protected ControlFlowGraph() {
- this.nodes = new ArrayList<>();
- this.start = null;
- }
-
- protected CFGNode getNode(Object a) {
- CFGNode ret = null;
- for (CFGNode n : this.nodes) {
- if (n.equals(a)) {
- ret = n;
- break;
- }
- }
-
- if (ret == null) {
- String str = (a instanceof Node) ? ((Node) a).sourcePos.toString() :
- a.toString();
- MinimalLogger.severe(String.format("Could not find a node matching %s",
- str));
- }
- 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 the next node for %s",
- a.toString()));
-
- return ret;
-
- }
-
- protected void addNode(CFGNode node) {
- this.nodes.add(node);
- }
-
- protected String addEdge(CFGNode source, CFGNode dest) {
- /**
- * Iff the CFGNodes are different, construct an edge between them.
- * All variables reaching the parent also reach the children.
- *
- * 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);
-
- ret += ";";
- } else {
- MinimalLogger.info(String.format("Skipping duplicate edge for %d",
- source.getInstruction().sourcePos.line));
- }
-
- MinimalLogger.info(String.format("Spilling variables: %s",
- source.getReaching().toString()));
- dest.getReaching().addAll(source.getReaching());
-
- return ret;
- }
-
- protected void setStart(CFGNode start) {
- this.start = start;
- }
-
- protected ArrayList<CFGNode> getNodes() {
- return this.nodes;
- }
-
-}