diff options
Diffstat (limited to 'vaporize/library/CFGSimp.java')
-rw-r--r-- | vaporize/library/CFGSimp.java | 148 |
1 files changed, 131 insertions, 17 deletions
diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index b7ca7bd..3e39576 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -5,35 +5,46 @@ import st.*; import misc.*; import java.util.*; -public class CFGSimp extends VInstr.VisitorPR<String, String, RuntimeException> { +public class CFGSimp extends VInstr.VisitorPR<ControlFlowGraph, String, RuntimeException> { private VaporProgram vp; private Kettle kettle; private ArrayList<ControlFlowGraph> cfgs; + private CFGNode curr; public CFGSimp(VaporProgram vp, ArrayList<String> vapor) { this.vp = vp; this.kettle = new Kettle(vapor); this.cfgs = new ArrayList<ControlFlowGraph>(); + this.curr = null; for (VFunction f : this.vp.functions) { ControlFlowGraph cfg = new ControlFlowGraph(); - CFGNode start = new CFGNode(f.body[0]); - cfg.setStart(start); + curr = new CFGNode(f.body[0]); + cfg.setStart(curr); - // nodes MinimalLogger.info(String.format("CFGSimp is collecting nodes for %s", - this.kettle.parseFuncName(f))); - for (VInstr s : f.body) + this.kettle.parseFuncName(f))); + for (VCodeLabel s : f.labels) { + MinimalLogger.info(String.format("Label %d \"%s\"", + s.sourcePos.line, + this.kettle.get(s).trim())); + cfg.addNode(new CFGNode(s)); + } + for (VInstr s : f.body) { + MinimalLogger.info(String.format(" Body %d \"%s\"", + s.sourcePos.line, + this.kettle.get(s).trim())); cfg.addNode(new CFGNode(s)); + } // edges MinimalLogger.info(String.format("CFGSimp is collecting edges for %s", - this.kettle.parseFuncName(f))); + this.kettle.parseFuncName(f))); for (VInstr s : f.body) - s.accept("", this); + s.accept(cfg, this); this.cfgs.add(cfg); } @@ -43,36 +54,139 @@ public class CFGSimp extends VInstr.VisitorPR<String, String, RuntimeException> return this.cfgs; } - public String visit(String p, VMemRead n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VMemRead n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VMemWrite n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VMemWrite n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VAssign n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VAssign n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VBranch n) throws RuntimeException { - // two edges + public String visit(ControlFlowGraph cfg, VBranch n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VGoto n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VGoto n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VCall n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VCall n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VBuiltIn n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VBuiltIn n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } - public String visit(String p, VReturn n) throws RuntimeException { + public String visit(ControlFlowGraph cfg, VReturn n) throws RuntimeException { + MinimalLogger.info(String.format("->%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); + /////////////////////////////////////////////////////////////// + CFGNode curr = cfg.getNode(n); + cfg.addEdge(this.curr, cfg.getNode(n)); + this.curr = curr; + /////////////////////////////////////////////////////////////// + MinimalLogger.info(String.format("<-%s (\"%s\":%s)", + n.getClass().getSimpleName(), + this.kettle.get(n).trim(), + n.sourcePos.toString())); return null; } |