Iterator for the opcodes in methods, functions or code Generates a series of Instruction named tuples giving the details of each operations in the supplied code. If *first_line* is not None, it indicates the line number that should be reported for the first source line in the disas
(x, *, first_line=None, show_caches=None, adaptive=False)
| 656 | return argval, argrepr |
| 657 | |
| 658 | def get_instructions(x, *, first_line=None, show_caches=None, adaptive=False): |
| 659 | """Iterator for the opcodes in methods, functions or code |
| 660 | |
| 661 | Generates a series of Instruction named tuples giving the details of |
| 662 | each operations in the supplied code. |
| 663 | |
| 664 | If *first_line* is not None, it indicates the line number that should |
| 665 | be reported for the first source line in the disassembled code. |
| 666 | Otherwise, the source line information (if any) is taken directly from |
| 667 | the disassembled code object. |
| 668 | """ |
| 669 | co = _get_code_object(x) |
| 670 | linestarts = dict(findlinestarts(co)) |
| 671 | if first_line is not None: |
| 672 | line_offset = first_line - co.co_firstlineno |
| 673 | else: |
| 674 | line_offset = 0 |
| 675 | |
| 676 | original_code = co.co_code |
| 677 | arg_resolver = ArgResolver(co_consts=co.co_consts, |
| 678 | names=co.co_names, |
| 679 | varname_from_oparg=co._varname_from_oparg, |
| 680 | labels_map=_make_labels_map(original_code)) |
| 681 | return _get_instructions_bytes(_get_code_array(co, adaptive), |
| 682 | linestarts=linestarts, |
| 683 | line_offset=line_offset, |
| 684 | co_positions=co.co_positions(), |
| 685 | original_code=original_code, |
| 686 | arg_resolver=arg_resolver) |
| 687 | |
| 688 | def _get_const_value(op, arg, co_consts): |
| 689 | """Helper to get the value of the const in a hasconst op. |
nothing calls this directly
no test coverage detected
searching dependent graphs…