Simplify, fixing an apparent bug in the process.
Chris Pressey
3 years ago
140 | 140 | def analyze_program(self, program): |
141 | 141 | assert isinstance(program, Program) |
142 | 142 | for routine in program.routines: |
143 | routine.called_routines = set() | |
143 | 144 | context, type_ = self.analyze_routine(routine) |
144 | 145 | if type_: |
145 | 146 | routine.routine_type = type_ |
146 | 147 | routine.encountered_gotos = list(context.encountered_gotos()) if context else [] |
147 | routine.called_routines = list(context.called_routines) if context else [] | |
148 | routine.called_routines = list(routine.called_routines) | |
148 | 149 | |
149 | 150 | def analyze_routine(self, routine): |
150 | 151 | assert isinstance(routine, Routine) |
519 | 520 | type_ = self.get_type(instr.location) |
520 | 521 | if not isinstance(type_, (RoutineType, VectorType)): |
521 | 522 | raise TypeMismatchError(instr, instr.location.name) |
522 | context.mark_as_called(instr.location, type_) | |
523 | ||
524 | self.current_routine.called_routines.add((instr.location, type_)) | |
525 | ||
523 | 526 | if isinstance(type_, VectorType): |
524 | 527 | type_ = type_.of_type |
525 | 528 | for ref in type_.inputs: |
537 | 540 | |
538 | 541 | if not isinstance(type_, (RoutineType, VectorType)): |
539 | 542 | raise TypeMismatchError(instr, location.name) |
540 | context.mark_as_called(instr.location, type_) | |
543 | ||
544 | self.current_routine.called_routines.add((instr.location, type_)) | |
541 | 545 | |
542 | 546 | # assert that the dest routine's inputs are all initialized |
543 | 547 | if isinstance(type_, VectorType): |