git @ Cat's Eye Technologies SixtyPical / 7187fa6
Refactor: move to dedicated module. Chris Pressey 2 years ago
2 changed file(s) with 37 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
5050 sys.stdout.write("\n")
5151
5252 if options.dump_callgraph:
53 graph = {}
54
55 from sixtypical.model import RoutineType, VectorType
56
57 def find_routines_matching_vector_type(program, type_):
58 return [] # dummy
59
60 for routine in program.routines:
61 potentially_calls = []
62 for (called_routine, called_routine_type) in routine.called_routines:
63 if isinstance(called_routine_type, RoutineType):
64 potentially_calls.append(called_routine.name)
65 elif isinstance(called_routine_type, VectorType):
66 for potentially_called in find_routines_matching_vector_type(program, called_routine_type):
67 potentially_calls.append(potentially_called.name)
68 else:
69 raise NotImplementedError
70 graph[routine.name] = {
71 'potentially-calls': potentially_calls,
72 }
73
74 # Reflexive closure
75
76 for routine in program.routines:
77 potentially_called_by = []
78 for (name, node) in graph.items():
79 potential_calls = node['potentially-calls']
80 if routine.name in potential_calls:
81 potentially_called_by.append(name)
82 graph[routine.name]['potentially-called-by'] = potentially_called_by
83
53 from sixtypical.callgraph import construct_callgraph
54 graph = construct_callgraph(program)
8455 sys.stdout.write(json.dumps(graph, indent=4, sort_keys=True, separators=(',', ':')))
8556
8657 compilation_roster = None
0 from sixtypical.model import RoutineType, VectorType
1
2
3 def find_routines_matching_vector_type(program, type_):
4 return [] # dummy
5
6
7 def construct_callgraph(program):
8 graph = {}
9
10 for routine in program.routines:
11 potentially_calls = []
12 for (called_routine, called_routine_type) in routine.called_routines:
13 if isinstance(called_routine_type, RoutineType):
14 potentially_calls.append(called_routine.name)
15 elif isinstance(called_routine_type, VectorType):
16 for potentially_called in find_routines_matching_vector_type(program, called_routine_type):
17 potentially_calls.append(potentially_called.name)
18 else:
19 raise NotImplementedError
20 graph[routine.name] = {
21 'potentially-calls': potentially_calls,
22 }
23
24 # Reflexive closure
25
26 for routine in program.routines:
27 potentially_called_by = []
28 for (name, node) in graph.items():
29 potential_calls = node['potentially-calls']
30 if routine.name in potential_calls:
31 potentially_called_by.append(name)
32 graph[routine.name]['potentially-called-by'] = potentially_called_by
33
34 return graph