Abstraction for dumping JSON info.
Chris Pressey
4 years ago
58 | 58 | analyzer.analyze_program(program) |
59 | 59 | |
60 | 60 | 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 | ||
62 | 68 | from sixtypical.fallthru import FallthruAnalyzer |
63 | 69 | |
64 | 70 | fa = FallthruAnalyzer(debug=options.debug) |
65 | 71 | fa.analyze_program(program) |
66 | 72 | |
67 | 73 | 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) | |
70 | 75 | |
71 | 76 | fa.find_cycles() |
72 | 77 | |
74 | 79 | if options.dump_fallthru_info: |
75 | 80 | |
76 | 81 | 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)) | |
84 | 84 | |
85 | 85 | fa.break_cycle() |
86 | 86 | |
87 | 87 | 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) | |
91 | 89 | |
92 | 90 | fa.find_cycles() |
93 | 91 |