Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-112137: change dis output to display labels instead of offsets#112138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iritkatriel merged 25 commits intopython:mainfromiritkatriel:dis_labels
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
5470f75
Instruction gets the label
iritkatrielNov 15, 2023
54cb8ca
replace offsets by labels
iritkatrielNov 16, 2023
c363ee8
📜🤖 Added by blurb_it.
blurb-it[bot]Nov 16, 2023
6ac23fd
Merge branch 'main' into dis_labels
iritkatrielNov 16, 2023
852c5c4
distinguish between jump targets (J) and exception handlers (H)
iritkatrielNov 16, 2023
af97cee
nice exception ranges
iritkatrielNov 16, 2023
d2884ed
labels in exception table, and on separate line in the code
iritkatrielNov 17, 2023
c527ded
fix tests
iritkatrielNov 17, 2023
b3914e6
do not collapse excaption table in tests
iritkatrielNov 17, 2023
efd5906
update dis.rst doctest
iritkatrielNov 17, 2023
83ae74e
whitespace
iritkatrielNov 17, 2023
bac6628
whitespace
iritkatrielNov 20, 2023
390c7a2
add option to include offset and labels on same line as instruction
iritkatrielNov 21, 2023
020c742
fix doctest
iritkatrielNov 21, 2023
965a3cd
linenumber, then labels, then (optionally) offsets
iritkatrielNov 22, 2023
7d00ddb
update tests
iritkatrielNov 22, 2023
a7de18c
fix doctest
iritkatrielNov 22, 2023
cc24af8
whitespace
iritkatrielNov 22, 2023
6542b06
whitespace
iritkatrielNov 22, 2023
823b0e1
add test with offsets
iritkatrielNov 22, 2023
2219a96
add doc
iritkatrielNov 22, 2023
f52d698
whitespace
iritkatrielNov 22, 2023
278aae3
whitespace
iritkatrielNov 22, 2023
5420f6b
tweak doc
iritkatrielNov 22, 2023
d741666
remove extra line
iritkatrielNov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
replace offsets by labels
  • Loading branch information
@iritkatriel
iritkatriel committedNov 16, 2023
commit54cb8ca3dff4e6b3f465a5b31e3429cc9e8babb2
47 changes: 30 additions & 17 deletionsLib/dis.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -311,6 +311,15 @@ def _get_jump_target(op, arg, offset):
target = None
return target

def _label_string(label, width=None, suffix=''):
if label is not None:
lbl = f'{label}'
padding = width - len(lbl) if width is not None else 0
assert padding >= 0
return f"L{lbl}{suffix}{'':<{padding}}"
else:
return ' ' * (width + 1 + len(suffix))

class Instruction(_Instruction):
"""Details for a bytecode operation.

Expand All@@ -331,7 +340,8 @@ class Instruction(_Instruction):
"""

@staticmethod
def _get_argval_argrepr(op, arg, offset, co_consts, names, varname_from_oparg):
def _get_argval_argrepr(op, arg, offset, co_consts, names, varname_from_oparg,
labels_map, label_width):
get_name = None if names is None else names.__getitem__
argval = None
argrepr = ''
Expand DownExpand Up@@ -361,13 +371,13 @@ def _get_argval_argrepr(op, arg, offset, co_consts, names, varname_from_oparg):
argval, argrepr = _get_name_info(arg, get_name)
elif deop in hasjabs:
argval = arg*2
argrepr = "to" + repr(argval)
argrepr =f"to{_label_string(labels_map[argval])}"
elif deop in hasjrel:
signed_arg = -arg if _is_backward_jump(deop) else arg
argval = offset + 2 + signed_arg*2
caches = _get_cache_size(_all_opname[deop])
argval += 2 * caches
argrepr = "to" + repr(argval)
argrepr =f"to{_label_string(labels_map[argval])}"
elif deop in (LOAD_FAST_LOAD_FAST, STORE_FAST_LOAD_FAST, STORE_FAST_STORE_FAST):
arg1 = arg >> 4
arg2 = arg & 15
Expand DownExpand Up@@ -399,14 +409,21 @@ def _get_argval_argrepr(op, arg, offset, co_consts, names, varname_from_oparg):

@classmethod
def _create(cls, op, arg, offset, start_offset, starts_line, line_number,
label, positions,
co_consts=None, varname_from_oparg=None, names=None):
positions,
co_consts=None, varname_from_oparg=None, names=None,
labels_map=None):

label_width = len(str(len(labels_map)))
argval, argrepr = cls._get_argval_argrepr(
op, arg, offset,
co_consts, names, varname_from_oparg)
return Instruction(_all_opname[op], op, arg, argval, argrepr,
offset, start_offset, starts_line, line_number,
label, positions)
co_consts, names, varname_from_oparg, labels_map,
label_width)
label = labels_map.get(offset, None)
instr = Instruction(_all_opname[op], op, arg, argval, argrepr,
offset, start_offset, starts_line, line_number,
label, positions)
instr.label_width = label_width
return instr

@property
def oparg(self):
Expand DownExpand Up@@ -474,12 +491,7 @@ def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=4):
else:
fields.append(' ')
# Column: Jump target marker
if self.is_jump_target:
fields.append('>>')
else:
fields.append(' ')
# Column: Instruction offset from start of code sequence
fields.append(repr(self.offset).rjust(offset_width))
fields.append(_label_string(self.label, width=self.label_width, suffix=': '))
# Column: Opcode name
fields.append(self.opname.ljust(_OPNAME_WIDTH))
# Column: Opcode argument
Expand DownExpand Up@@ -637,8 +649,9 @@ def make_labels_map(original_code, exception_entries):
op = code[offset]

yield Instruction._create(op, arg, offset, start_offset, starts_line, line_number,
labels_map.get(offset, None), positions, co_consts=co_consts,
varname_from_oparg=varname_from_oparg, names=names)
positions, co_consts=co_consts,
varname_from_oparg=varname_from_oparg, names=names,
labels_map=labels_map)

caches = _get_cache_size(_all_opname[deop])
if not caches:
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp