Detect all offsets in a byte code which are jump targets. Return the list of offsets.
(code)
| 616 | yield (i, op, arg) |
| 617 | |
| 618 | def findlabels(code): |
| 619 | """Detect all offsets in a byte code which are jump targets. |
| 620 | |
| 621 | Return the list of offsets. |
| 622 | |
| 623 | """ |
| 624 | labels = [] |
| 625 | for offset, op, arg in _unpack_opargs(code): |
| 626 | if arg is not None: |
| 627 | if op in hasjrel: |
| 628 | if _is_backward_jump(op): |
| 629 | arg = -arg |
| 630 | label = offset + 2 + arg*2 |
| 631 | elif op in hasjabs: |
| 632 | label = arg*2 |
| 633 | else: |
| 634 | continue |
| 635 | if label not in labels: |
| 636 | labels.append(label) |
| 637 | return labels |
| 638 | |
| 639 | def findlinestarts(code): |
| 640 | """Find the offsets in a byte code which are start of lines in the source. |
no test coverage detected