git @ Cat's Eye Technologies SixtyPical / efe8859
Find the longest chain of routines in R and remove it. Chris Pressey 4 years ago
1 changed file(s) with 25 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
99 if sub not in s:
1010 s.add(sub)
1111 make_transitive_closure(d, sub, s)
12
13
14 def find_chains(d, key, pred):
15 chains = []
16 for sub in d.get(key, []):
17 if pred(sub):
18 subchains = find_chains(d, sub, pred)
19 for subchain in subchains:
20 chains.append([key] + subchain)
21 chains.append([key])
22 return chains
1223
1324
1425 class FallthruAnalyzer(object):
6273 self.fall_out_map[routine.name] = None
6374
6475 routine_list = []
65 fall_out_map = copy(self.fall_out_map)
66 while fall_out_map:
67 key = fall_out_map.keys()[0]
76 pending_routines = copy(self.fall_out_map)
77 while pending_routines:
78 # Pick a routine that is still pending to be serialized.
79 key = pending_routines.keys()[0]
80
6881 in_set = self.fall_in_map.get(key, [])
69 # Find the longest chain of routines r1,r2,...rn in R where out(r1) = {r2}, out(r2} = {r3}, ... out(rn-1) = {rn}, and rn = r.
70 # TODO implement this
71 routines = [key]
7282
73 # Remove (r1,r2,...,rn) from R and append them to L in that order. Mark (r1,r2,...rn-1) as "will have their final goto removed."
83 # Find the longest chain of routines r1,r2,...rn in R
84 # where out(r1) = {r2}, out(r2} = {r3}, ... out(rn-1) = {rn}, and rn = r.
85 chains = find_chains(self.fall_in_map, key, lambda k: k in pending_routines)
86 chains.sort(key=len, reverse=True)
87 routines = chains[0]
88
89 # Remove (r1,r2,...,rn) from R and append them to L in that order.
90 # Mark (r1,r2,...rn-1) as "will have their final goto removed."
7491 for r in routines:
75 del fall_out_map[r]
92 del pending_routines[r]
7693 if r == routines[-1]:
7794 routine_list.append(['retain', r])
7895 else: