MCPcopy Index your code
hub / github.com/RustPython/RustPython / _get_instructions_bytes

Function _get_instructions_bytes

Lib/dis.py:754–807  ·  view source on GitHub ↗

Iterate over the instructions in a bytecode string. Generates a sequence of Instruction namedtuples giving the details of each opcode.

(code, linestarts=None, line_offset=0, co_positions=None,
                            original_code=None, arg_resolver=None)

Source from the content-addressed store, hash-verified

752 'END_ASYNC_FOR') # Not really a jump, but it has a "target"
753
754def _get_instructions_bytes(code, linestarts=None, line_offset=0, co_positions=None,
755 original_code=None, arg_resolver=None):
756 """Iterate over the instructions in a bytecode string.
757
758 Generates a sequence of Instruction namedtuples giving the details of each
759 opcode.
760
761 """
762 # Use the basic, unadaptive code for finding labels and actually walking the
763 # bytecode, since replacements like ENTER_EXECUTOR and INSTRUMENTED_* can
764 # mess that logic up pretty badly:
765 original_code = original_code or code
766 co_positions = co_positions or iter(())
767
768 starts_line = False
769 local_line_number = None
770 line_number = None
771 for offset, start_offset, op, arg in _unpack_opargs(original_code):
772 if linestarts is not None:
773 starts_line = offset in linestarts
774 if starts_line:
775 local_line_number = linestarts[offset]
776 if local_line_number is not None:
777 line_number = local_line_number + line_offset
778 else:
779 line_number = None
780 positions = Positions(*next(co_positions, ()))
781 deop = _deoptop(op)
782 op = code[offset]
783
784 if arg_resolver:
785 argval, argrepr = arg_resolver.get_argval_argrepr(op, arg, offset)
786 else:
787 argval, argrepr = arg, repr(arg)
788
789 caches = _get_cache_size(_all_opname[deop])
790 # Advance the co_positions iterator:
791 for _ in range(caches):
792 next(co_positions, ())
793
794 if caches:
795 cache_info = []
796 cache_offset = offset
797 for name, size in _cache_format[opname[deop]].items():
798 data = code[cache_offset + 2: cache_offset + 2 + 2 * size]
799 cache_offset += size * 2
800 cache_info.append((name, size, data))
801 else:
802 cache_info = None
803
804 label = arg_resolver.get_label_for_offset(offset) if arg_resolver else None
805 yield Instruction(_all_opname[op], op, arg, argval, argrepr,
806 offset, start_offset, starts_line, line_number,
807 label, positions, cache_info)
808
809
810def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,

Callers 3

get_instructionsFunction · 0.85
_disassemble_bytesFunction · 0.85
__iter__Method · 0.85

Calls 11

iterFunction · 0.85
_unpack_opargsFunction · 0.85
nextFunction · 0.85
_deoptopFunction · 0.85
reprFunction · 0.85
_get_cache_sizeFunction · 0.85
get_argval_argreprMethod · 0.80
InstructionClass · 0.70
itemsMethod · 0.45
appendMethod · 0.45
get_label_for_offsetMethod · 0.45

Tested by

no test coverage detected