Refine the callgraph algorithm. Still incomplete though.
Chris Pressey
3 years ago
50 | 50 | sys.stdout.write("\n") |
51 | 51 | |
52 | 52 | if options.dump_callgraph: |
53 | graph = {} | |
54 | ||
53 | 55 | for routine in program.routines: |
54 | sys.stdout.write('-----------\n') | |
55 | sys.stdout.write('{}\n'.format(routine.name)) | |
56 | potentially_calls = [] | |
56 | 57 | for called_routine in routine.called_routines: |
57 | sys.stdout.write(' {}\n'.format(called_routine.name)) | |
58 | # TODO if called_routine is a vector, this should be all routines which can be assigned to this vector | |
59 | potentially_calls.append(called_routine.name) | |
60 | graph[routine.name] = { | |
61 | 'potentially-calls': potentially_calls, | |
62 | } | |
63 | ||
64 | # Reflexive closure | |
65 | ||
66 | for routine in program.routines: | |
67 | potentially_called_by = [] | |
68 | for (name, node) in graph.items(): | |
69 | potential_calls = node['potentially-calls'] | |
70 | if routine.name in potential_calls: | |
71 | potentially_called_by.append(name) | |
72 | graph[routine.name]['potentially-called-by'] = potentially_called_by | |
73 | ||
74 | sys.stdout.write(json.dumps(graph, indent=4, sort_keys=True, separators=(',', ':'))) | |
58 | 75 | |
59 | 76 | compilation_roster = None |
60 | 77 | if options.optimize_fallthru: |