MCPcopy Index your code
hub / github.com/python/cpython / get_instructions

Function get_instructions

Lib/dis.py:658–686  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

656 return argval, argrepr
657
658def 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
688def _get_const_value(op, arg, co_consts):
689 """Helper to get the value of the const in a hasconst op.

Callers

nothing calls this directly

Calls 6

_get_code_objectFunction · 0.85
findlinestartsFunction · 0.85
ArgResolverClass · 0.85
_make_labels_mapFunction · 0.85
_get_instructions_bytesFunction · 0.85
_get_code_arrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…