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
(x, *, first_line=None, show_caches=False, adaptive=False)
| 328 | |
| 329 | |
| 330 | def get_instructions(x, *, first_line=None, show_caches=False, adaptive=False): |
| 331 | """Iterator for the opcodes in methods, functions or code |
| 332 | |
| 333 | Generates a series of Instruction named tuples giving the details of |
| 334 | each operations in the supplied code. |
| 335 | |
| 336 | If *first_line* is not None, it indicates the line number that should |
| 337 | be reported for the first source line in the disassembled code. |
| 338 | Otherwise, the source line information (if any) is taken directly from |
| 339 | the disassembled code object. |
| 340 | """ |
| 341 | co = _get_code_object(x) |
| 342 | linestarts = dict(findlinestarts(co)) |
| 343 | if first_line is not None: |
| 344 | line_offset = first_line - co.co_firstlineno |
| 345 | else: |
| 346 | line_offset = 0 |
| 347 | return _get_instructions_bytes(_get_code_array(co, adaptive), |
| 348 | co._varname_from_oparg, |
| 349 | co.co_names, co.co_consts, |
| 350 | linestarts, line_offset, |
| 351 | co_positions=co.co_positions(), |
| 352 | show_caches=show_caches) |
| 353 | |
| 354 | def _get_const_value(op, arg, co_consts): |
| 355 | """Helper to get the value of the const in a hasconst op. |
nothing calls this directly
no test coverage detected