git @ Cat's Eye Technologies SixtyPical / e39dbf6
Call it fall_in_map. Chris Pressey 3 years ago
2 changed file(s) with 13 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
7171 fa.analyze_program(program)
7272
7373 if options.dump_fallthru_info:
74 dump(None, fa.fallthru_map)
74 dump(None, fa.fall_in_map)
7575
7676 fa.find_cycles()
7777
8585 fa.break_cycle()
8686
8787 if options.dump_fallthru_info:
88 dump('after breaking cycle', fa.fallthru_map)
88 dump('after breaking cycle', fa.fall_in_map)
8989
9090 fa.find_cycles()
9191
1515 self.debug = debug
1616
1717 def analyze_program(self, program):
18 fallthru_map = {}
18 fall_in_map = {}
1919 for routine in program.routines:
2020 encountered_gotos = list(routine.encountered_gotos)
2121 if len(encountered_gotos) == 1 and isinstance(encountered_gotos[0].type, RoutineType):
22 fallthru_map.setdefault(encountered_gotos[0].name, set()).add(routine.name)
23 self.fallthru_map = dict([(k, sorted(v)) for k, v in fallthru_map.iteritems()])
24 return self.fallthru_map
22 fall_in_map.setdefault(encountered_gotos[0].name, set()).add(routine.name)
23 self.fall_in_map = dict([(k, sorted(v)) for k, v in fall_in_map.iteritems()])
24 return self.fall_in_map
2525
2626 def find_cycles(self):
2727 self.ancestor_map = {}
28 for key in self.fallthru_map:
28 for key in self.fall_in_map:
2929 ancestors = set()
30 make_transitive_closure(self.fallthru_map, key, ancestors)
30 make_transitive_closure(self.fall_in_map, key, ancestors)
3131 self.ancestor_map[key] = sorted(ancestors)
3232
3333 self.cycles_found = set()
4141 cycle_to_break = sorted(self.cycles_found)[0]
4242 cycles_to_break = set([cycle_to_break])
4343
44 new_fallthru_map = {}
45 for key in self.fallthru_map:
46 values = set(self.fallthru_map[key]) - cycles_to_break
44 new_fall_in_map = {}
45 for key in self.fall_in_map:
46 values = set(self.fall_in_map[key]) - cycles_to_break
4747 if values:
48 new_fallthru_map[key] = sorted(values)
49 self.fallthru_map = new_fallthru_map
48 new_fall_in_map[key] = sorted(values)
49 self.fall_in_map = new_fall_in_map
5050
5151 def serialize(self):
5252 raise NotImplementedError