contrib: bring in the pep8 analysis framework
[nit.git] / contrib / pep8analysis / src / cfg / cfg.nit
1 import cfg_base
2 import dot_printer
3 import sanity
4
5 redef class AnalysisManager
6 var opt_cfg = new OptionBool("Print the CFG to \"cfg.dot\" (for debugging purposes)", "--cfg")
7 var opt_cfg_long = new OptionBool("Print the long format CFG", "--cfg-long")
8
9 var opt_cfg_inline = new OptionBool("Inline function calls in the CFG", "--inline")
10 #var opt_cfg_not_inline = new OptionBool("Do not inline function calls in the CFG", "--no-inline")
11
12 var cfg: nullable CFG = null
13
14 redef init
15 do
16 super
17
18 opts.add_option(opt_cfg)
19 opts.add_option(opt_cfg_long)
20 #opts.add_option(opt_cfg_not_inline)
21 opts.add_option(opt_cfg_inline)
22 end
23
24 redef fun build_cfg(model)
25 do
26 var cfg = super
27 self.cfg = cfg
28
29 if cfg.has_function_calls then
30 #if not opt_cfg_not_inline.value then
31 if opt_cfg_inline.value then
32 cfg.inline_functions
33 else
34 cfg.watchdog = 0
35 var to_link = new List[BasicBlock]
36 if not cfg.link_ret_to_calls(cfg.start, to_link, new List[BasicBlock], 0) then
37 manager.fatal_error(model.lines.first, "failed to organize function calls")
38 end
39 end
40 end
41
42 if opt_cfg.value or opt_cfg_long.value then
43 var of = new OFStream.open("cfg.dot")
44 cfg.print_dot(of, opt_cfg_long.value)
45 of.close
46 end
47
48 verify_cfg_sanity(cfg)
49
50 return cfg
51 end
52 end