diff options
Diffstat (limited to 'vaporize/library/CFGSimp.java')
-rw-r--r-- | vaporize/library/CFGSimp.java | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/vaporize/library/CFGSimp.java b/vaporize/library/CFGSimp.java index 3a612bd..79eb4c2 100644 --- a/vaporize/library/CFGSimp.java +++ b/vaporize/library/CFGSimp.java @@ -1,5 +1,8 @@ package vaporize.library; +import java.util.logging.Logger; +import java.util.logging.ConsoleHandler; + import cs132.vapor.ast.*; import st.*; import misc.*; @@ -7,26 +10,47 @@ import java.util.*; public class CFGSimp extends VInstr.VisitorPR<String, String, RuntimeException> { - private ControlFlowGraph cfg; + private static Logger log = Logger.getLogger(CFGSimp.class.getName()); + private static ConsoleHandler consoleHandler = new ConsoleHandler(); + static { + consoleHandler.setFormatter(new MinimalSimpleFormatter()); + log.addHandler(consoleHandler); + } + + private VaporProgram vp; + private Kettle kettle; + private ArrayList<ControlFlowGraph> cfgs; + + public CFGSimp(VaporProgram vp, ArrayList<String> vapor) { + this.vp = vp; + this.kettle = new Kettle(vapor); + this.cfgs = new ArrayList<ControlFlowGraph>(); + + + for (VFunction f : this.vp.functions) { + ControlFlowGraph cfg = new ControlFlowGraph(); + CFGNode start = new CFGNode(f.body[0]); + cfg.setStart(start); - public CFGSimp(VFunction n) { - this.cfg = new ControlFlowGraph(); - CFGNode start = new CFGNode(n.body[0]); - this.cfg.setStart(start); + // nodes + this.log.info(String.format("CFGSimp is collecting nodes for %s", + this.kettle.parseFuncName(f))); + for (VInstr s : f.body) + cfg.addNode(new CFGNode(s)); - // nodes - for (VInstr s : n.body) - this.cfg.addNode(new CFGNode(s)); - // edges - for (VInstr s : n.body) - s.accept("", this); + // edges + this.log.info(String.format("CFGSimp is collecting edges for %s", + this.kettle.parseFuncName(f))); + for (VInstr s : f.body) + s.accept("", this); - System.out.println(this.cfg.getNodes().toString()); + this.cfgs.add(cfg); + } } - public ControlFlowGraph getCFG() { - return this.cfg; + public ArrayList<ControlFlowGraph> getCFGs() { + return this.cfgs; } public String visit(String p, VMemRead n) throws RuntimeException { |