From 66ffeaf968bd332f1e18cb27aad11b50e4dd0eab Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 19 Apr 2024 19:04:01 -0600 Subject: Switched to use of Logger Module --- vaporize/library/CFGSimp.java | 52 +++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'vaporize/library/CFGSimp.java') 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 { - 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 cfgs; + + public CFGSimp(VaporProgram vp, ArrayList vapor) { + this.vp = vp; + this.kettle = new Kettle(vapor); + this.cfgs = new ArrayList(); + + + 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 getCFGs() { + return this.cfgs; } public String visit(String p, VMemRead n) throws RuntimeException { -- cgit v1.2.3