git @ Cat's Eye Technologies SixtyPical / 182935a
First cut at finding all routines that could be assigned to vector. Chris Pressey 3 years ago
2 changed file(s) with 14 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
140140 def analyze_program(self, program):
141141 assert isinstance(program, Program)
142142 for routine in program.routines:
143 context = self.analyze_routine(routine)
143 context, type_ = self.analyze_routine(routine)
144 if type_:
145 routine.routine_type = type_
144146 routine.encountered_gotos = list(context.encountered_gotos()) if context else []
145147 routine.called_routines = list(context.called_routines) if context else []
146148
147149 def analyze_routine(self, routine):
148150 assert isinstance(routine, Routine)
151 type_ = self.get_type_for_name(routine.name)
152
149153 if routine.block is None:
150154 # it's an extern, that's fine
151 return None
155 return None, type_
152156
153157 self.current_routine = routine
154 type_ = self.get_type_for_name(routine.name)
158
155159 context = AnalysisContext(self.symtab, routine, type_.inputs, type_.outputs, type_.trashes)
156160
157161 # register any local statics as already-initialized
209213
210214 self.exit_contexts = None
211215 self.current_routine = None
212 return context
216 return context, type_
213217
214218 def analyze_block(self, block, context):
215219 assert isinstance(block, Block)
00 from sixtypical.model import RoutineType, VectorType
11
22
3 def find_routines_matching_vector_type(program, type_):
4 return [] # dummy
3 def find_routines_matching_type(program, type_):
4 """Return the subset of routines of the program whose value
5 may be assigned to a location of the given type_ (typically
6 a vector)."""
7 return [r for r in program.routines if RoutineType.executable_types_compatible(r.routine_type, type_)]
58
69
710 def construct_callgraph(program):
1316 if isinstance(called_routine_type, RoutineType):
1417 potentially_calls.append(called_routine.name)
1518 elif isinstance(called_routine_type, VectorType):
16 for potentially_called in find_routines_matching_vector_type(program, called_routine_type):
19 for potentially_called in find_routines_matching_type(program, called_routine_type):
1720 potentially_calls.append(potentially_called.name)
1821 else:
1922 raise NotImplementedError