gh-102676: Add more convenience properties to dis.Instruction (#103969)

Adds start_offset, cache_offset, end_offset, baseopcode,
baseopname, jump_target and oparg to dis.Instruction.

Also slightly improves the disassembly output by allowing
opnames to overflow into the space reserved for opargs.
This commit is contained in:
Tomas R 2023-06-11 17:50:34 +02:00 committed by GitHub
parent 845e593c4e
commit 18d16e93b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 435 additions and 196 deletions

View file

@ -342,10 +342,25 @@ details of bytecode instructions as :class:`Instruction` instances:
human readable name for operation
.. data:: baseopcode
numeric code for the base operation if operation is specialized;
otherwise equal to :data:`opcode`
.. data:: baseopname
human readable name for the base operation if operation is specialized;
otherwise equal to :data:`opname`
.. data:: arg
numeric argument to operation (if any), otherwise ``None``
.. data:: oparg
alias for :data:`arg`
.. data:: argval
@ -363,6 +378,22 @@ details of bytecode instructions as :class:`Instruction` instances:
start index of operation within bytecode sequence
.. data:: start_offset
start index of operation within bytecode sequence, including prefixed
``EXTENDED_ARG`` operations if present; otherwise equal to :data:`offset`
.. data:: cache_offset
start index of the cache entries following the operation
.. data:: end_offset
end index of the cache entries following the operation
.. data:: starts_line
line started by this opcode (if any), otherwise ``None``
@ -373,6 +404,12 @@ details of bytecode instructions as :class:`Instruction` instances:
``True`` if other code jumps to here, otherwise ``False``
.. data:: jump_target
bytecode index of the jump target if this is a jump operation,
otherwise ``None``
.. data:: positions
:class:`dis.Positions` object holding the
@ -384,6 +421,11 @@ details of bytecode instructions as :class:`Instruction` instances:
Field ``positions`` is added.
.. versionchanged:: 3.13
Added fields ``start_offset``, ``cache_offset``, ``end_offset``,
``baseopname``, ``baseopcode``, ``jump_target`` and ``oparg``.
.. class:: Positions