diff options
Diffstat (limited to 'vaporize/library')
| -rw-r--r-- | vaporize/library/CFGSimp.java | 23 | ||||
| -rw-r--r-- | vaporize/library/ControlFlowGraph.java | 22 | ||||
| -rw-r--r-- | vaporize/library/SpillEverywhere.java | 63 | 
3 files changed, 68 insertions, 40 deletions
| diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index 372f926..6ab276a 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -7,10 +7,26 @@ import java.util.*;  public class CFGSimp<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> { -    ControlFlowGraph cfg; +    private ControlFlowGraph cfg; -    public CFGSimp(ControlFlowGraph cfg) { -        this.cfg = cfg; +    public CFGSimp(VFunction n) { +        this.cfg = new ControlFlowGraph(); +        CFGNode start = new CFGNode(n.body[0]); +        this.cfg.setStart(start); + +        // nodes +        for (VInstr s : n.body) +            this.cfg.addNode(new CFGNode(s)); + +        // edges +        for (VInstr s : n.body) +            s.accept("", this); + +        System.out.println(this.cfg.getNodes().toString()); +    } + +    public ControlFlowGraph getCFG() { +        return this.cfg;      }      public R visit(P p, VMemRead n) throws RuntimeException { @@ -26,6 +42,7 @@ public class CFGSimp<P, R> extends VInstr.VisitorPR<P, R, RuntimeException> {      }      public R visit(P p, VBranch n) throws RuntimeException { +        // two edges          return null;      } diff --git a/vaporize/library/ControlFlowGraph.java b/vaporize/library/ControlFlowGraph.java index f181d36..773c4cd 100644 --- a/vaporize/library/ControlFlowGraph.java +++ b/vaporize/library/ControlFlowGraph.java @@ -5,9 +5,9 @@ import java.util.ArrayList;  public class ControlFlowGraph { -    private ArrayList<Node> nodes; -    private Node start; -    private Node end; +    private ArrayList<CFGNode> nodes; +    private CFGNode start; +    private CFGNode end;      public ControlFlowGraph() {          this.nodes = new ArrayList<>(); @@ -15,13 +15,25 @@ public class ControlFlowGraph {          this.end = null;      } -    protected void addNode(Node node) { +    protected void addNode(CFGNode node) {          this.nodes.add(node);      } -    protected void addEdge(Node source, Node dest) { +    protected void addEdge(CFGNode source, CFGNode dest) {          source.addDest(dest);          dest.addSource(source);      } +    protected void setStart(CFGNode start) { +        this.start = start; +    } + +    /** +     * The following methods are for testing +     * only! +     */ +    protected ArrayList<CFGNode> getNodes() { +        return this.nodes; +    } +  } diff --git a/vaporize/library/SpillEverywhere.java b/vaporize/library/SpillEverywhere.java index aa8368f..5edbbfc 100644 --- a/vaporize/library/SpillEverywhere.java +++ b/vaporize/library/SpillEverywhere.java @@ -45,40 +45,39 @@ public class SpillEverywhere<P, R> extends VInstr.VisitorPR<P, R, RuntimeExcepti                                          n.getClass().getSimpleName(),                                          this.vapor.get(n.sourcePos.line-1),                                          n.sourcePos.toString()), true); -        System.out.println("NEXT: " + -			   return null; -			   } - -	    public R visit(P p, VGoto n) throws RuntimeException { -	    PrintFilter.print(String.format("%s (%s:%s)", -					    n.getClass().getSimpleName(), -					    this.vapor.get(n.sourcePos.line-1), -					    n.sourcePos.toString()), true); -	    return null; -	} +	return null; +    } -	public R visit(P p, VCall n) throws RuntimeException { -	    PrintFilter.print(String.format("%s (%s:%s)", -					    n.getClass().getSimpleName(), -					    this.vapor.get(n.sourcePos.line-1), -					    n.sourcePos.toString()), true); -	    return null; -	} +    public R visit(P p, VGoto n) throws RuntimeException { +	PrintFilter.print(String.format("%s (%s:%s)", +					n.getClass().getSimpleName(), +					this.vapor.get(n.sourcePos.line-1), +					n.sourcePos.toString()), true); +	return null; +    } -	public R visit(P p, VBuiltIn n) throws RuntimeException { -	    PrintFilter.print(String.format("%s (%s:%s)", -					    n.op.name, -					    this.vapor.get(n.sourcePos.line-1), -					    n.sourcePos.toString()), true); -	    return null; -	} +    public R visit(P p, VCall n) throws RuntimeException { +	PrintFilter.print(String.format("%s (%s:%s)", +					n.getClass().getSimpleName(), +					this.vapor.get(n.sourcePos.line-1), +					n.sourcePos.toString()), true); +	return null; +    } -	public R visit(P p, VReturn n) throws RuntimeException { -	    PrintFilter.print(String.format("%s (%s:%s)", -					    n.getClass().getSimpleName(), -					    this.vapor.get(n.sourcePos.line-1), -					    n.sourcePos.toString()), true); -	    return null; -	} +    public R visit(P p, VBuiltIn n) throws RuntimeException { +	PrintFilter.print(String.format("%s (%s:%s)", +					n.op.name, +					this.vapor.get(n.sourcePos.line-1), +					n.sourcePos.toString()), true); +	return null; +    } +    public R visit(P p, VReturn n) throws RuntimeException { +	PrintFilter.print(String.format("%s (%s:%s)", +					n.getClass().getSimpleName(), +					this.vapor.get(n.sourcePos.line-1), +					n.sourcePos.toString()), true); +	return null;      } + +} | 
