(reg, assignments, path, mapping)
| 42 | return check_cycle_(reg, assignments, [], mapping) |
| 43 | |
| 44 | def check_cycle_(reg, assignments, path, mapping): |
| 45 | target = assignments.get(reg) |
| 46 | if target is None: |
| 47 | real_reg = mapping.get(reg, reg) |
| 48 | reg, target = next((k, v) for k,v in assignments.items() if mapping.get(k, k) == real_reg) |
| 49 | path.append(reg) |
| 50 | |
| 51 | real_target = mapping.get(target, target) |
| 52 | |
| 53 | # No cycle, some other value (e.g. 1) |
| 54 | if all(real_target != mapping.get(k, k) for k in assignments): |
| 55 | return [] |
| 56 | |
| 57 | # Found a cycle |
| 58 | if any(real_target == mapping.get(k, k) for k in path): |
| 59 | # Does the cycle *start* with target? |
| 60 | # This determines whether the original register is |
| 61 | # in the cycle, or just depends on registers in one. |
| 62 | if real_target == mapping.get(path[0], path[0]): |
| 63 | return path |
| 64 | |
| 65 | # Just depends on one. |
| 66 | return [] |
| 67 | |
| 68 | # Recurse |
| 69 | return check_cycle_(target, assignments, path, mapping) |
| 70 | |
| 71 | def extract_dependencies(reg, assignments, mapping=None): |
| 72 | """Return a list of all registers which directly |
no test coverage detected