git @ Cat's Eye Technologies SixtyPical / 9c196ef
Abstraction for dumping JSON info. Chris Pressey 3 years ago
1 changed file(s) with 11 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
5858 analyzer.analyze_program(program)
5959
6060 if options.optimize_fallthru:
61 import json
61 def dump(label, data):
62 import json
63 if label:
64 sys.stdout.write("*** {}:\n".format(label))
65 sys.stdout.write(json.dumps(data, indent=4, sort_keys=True))
66 sys.stdout.write("\n")
67
6268 from sixtypical.fallthru import FallthruAnalyzer
6369
6470 fa = FallthruAnalyzer(debug=options.debug)
6571 fa.analyze_program(program)
6672
6773 if options.dump_fallthru_info:
68 sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True))
69 sys.stdout.write("\n")
74 dump(None, fa.fallthru_map)
7075
7176 fa.find_cycles()
7277
7479 if options.dump_fallthru_info:
7580
7681 if options.debug:
77 sys.stdout.write("*** ancestors:\n")
78 sys.stdout.write(json.dumps(fa.ancestor_map, indent=4, sort_keys=True))
79 sys.stdout.write("\n")
80
81 sys.stdout.write("*** cycles found:\n")
82 sys.stdout.write(json.dumps(sorted(fa.cycles_found), indent=4, sort_keys=True))
83 sys.stdout.write("\n")
82 dump('ancestors', fa.ancestor_map)
83 dump('cycles found', sorted(fa.cycles_found))
8484
8585 fa.break_cycle()
8686
8787 if options.dump_fallthru_info:
88 sys.stdout.write("*** after breaking cycle:\n")
89 sys.stdout.write(json.dumps(fa.fallthru_map, indent=4, sort_keys=True))
90 sys.stdout.write("\n")
88 dump('after breaking cycle', fa.fallthru_map)
9189
9290 fa.find_cycles()
9391