diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index e6aa6df..39fc5f7 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -141,18 +141,22 @@ class Analyzer(object): def analyze_program(self, program): assert isinstance(program, Program) for routine in program.routines: - context = self.analyze_routine(routine) + context, type_ = self.analyze_routine(routine) + if type_: + routine.routine_type = type_ routine.encountered_gotos = list(context.encountered_gotos()) if context else [] routine.called_routines = list(context.called_routines) if context else [] def analyze_routine(self, routine): assert isinstance(routine, Routine) + type_ = self.get_type_for_name(routine.name) + if routine.block is None: # it's an extern, that's fine - return None + return None, type_ self.current_routine = routine - type_ = self.get_type_for_name(routine.name) + context = AnalysisContext(self.symtab, routine, type_.inputs, type_.outputs, type_.trashes) # register any local statics as already-initialized @@ -210,7 +214,7 @@ class Analyzer(object): self.exit_contexts = None self.current_routine = None - return context + return context, type_ def analyze_block(self, block, context): assert isinstance(block, Block) diff --git a/src/sixtypical/callgraph.py b/src/sixtypical/callgraph.py index d7a9773..44990d2 100644 --- a/src/sixtypical/callgraph.py +++ b/src/sixtypical/callgraph.py @@ -1,8 +1,11 @@ from sixtypical.model import RoutineType, VectorType -def find_routines_matching_vector_type(program, type_): - return [] # dummy +def find_routines_matching_type(program, type_): + """Return the subset of routines of the program whose value + may be assigned to a location of the given type_ (typically + a vector).""" + return [r for r in program.routines if RoutineType.executable_types_compatible(r.routine_type, type_)] def construct_callgraph(program): @@ -14,7 +17,7 @@ def construct_callgraph(program): if isinstance(called_routine_type, RoutineType): potentially_calls.append(called_routine.name) elif isinstance(called_routine_type, VectorType): - for potentially_called in find_routines_matching_vector_type(program, called_routine_type): + for potentially_called in find_routines_matching_type(program, called_routine_type): potentially_calls.append(potentially_called.name) else: raise NotImplementedError