Skip to content

Commit a198fd9

Browse files
author
rocky
committed
Propagate needed use of python_implementation
1 parent d94bf3c commit a198fd9

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

pytest/test_disasm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def run_check_disasm(test_tuple, function_to_test):
6868
got = "\n".join(got_lines[skip_lines:])
6969

7070
if "XDIS_DONT_WRITE_DOT_GOT_FILES" not in os.environ:
71+
got_filename = filename_expected + ".got"
7172
if got != expected:
72-
got_filename = filename_expected + ".got"
7373
with open(got_filename, "w") as out:
7474
out.write(got)
7575
assert got == expected, f"see {got_filename} for diffs"

pytest/test_opcode.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import dis
22

33
import pytest
4-
from xdis import IS_PYPY, PYTHON_VERSION_TRIPLE, get_opcode
4+
from xdis import get_opcode
5+
from xdis.version_info import IS_PYPY, PYTHON_IMPLEMENTATION, PYTHON_VERSION_TRIPLE
56

67

78
@pytest.mark.skipif(
89
PYTHON_VERSION_TRIPLE >= (3, 14),
910
reason="Python >= 3.14 is not complete.",
1011
)
1112
def test_opcode() -> None:
12-
opc = get_opcode(PYTHON_VERSION_TRIPLE, IS_PYPY)
13+
opc = get_opcode(PYTHON_VERSION_TRIPLE, PYTHON_IMPLEMENTATION)
1314
opmap = dict([(k.replace("+", "_"), v) for (k, v) in dis.opmap.items()])
1415
# (2, 7),
1516
# (3, 6),

xdis/cross_dis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,10 @@ def pretty_flags(flags, python_implementation=PYTHON_IMPLEMENTATION) -> str:
273273
for i in range(32):
274274
flag = 1 << i
275275
if flags & flag:
276-
names.append(COMPILER_FLAG_NAMES.get(flag, hex(flag)))
277-
if python_implementation == PythonImplementation.PyPy:
276+
if python_implementation == PythonImplementation.PyPy and flag in PYPY_COMPILER_FLAG_NAMES:
278277
names.append(PYPY_COMPILER_FLAG_NAMES.get(flag, hex(flag)))
278+
else:
279+
names.append(COMPILER_FLAG_NAMES.get(flag, hex(flag)))
279280
flags ^= flag
280281
if not flags:
281282
break

xdis/disasm.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@
5050

5151
# FIXME we may also need to distinguish by magic_int2magic
5252
# (for 3.8.5 Graal for example.)
53-
def get_opcode(version_tuple: tuple, python_implementation, alternate_opmap=None, magic_int: int=-1):
53+
def get_opcode(
54+
version_tuple: tuple,
55+
python_implementation,
56+
alternate_opmap=None,
57+
magic_int: int = -1,
58+
):
5459
# Set up disassembler with the right opcodes
5560
lookup = ".".join((str(i) for i in version_tuple))
5661
if python_implementation == PythonImplementation.PyPy:
@@ -198,7 +203,7 @@ def disco(
198203
show_source=show_source,
199204
methods=methods,
200205
file_offsets=file_offsets,
201-
is_unusual_bytecode=magic_int in GRAAL3_MAGICS
206+
is_unusual_bytecode=magic_int in GRAAL3_MAGICS,
202207
)
203208

204209

@@ -262,9 +267,7 @@ def disco_loop(
262267

263268
if version_tuple >= (3, 11):
264269
if bytecode.exception_entries not in (None, []):
265-
exception_table = format_exception_table(
266-
bytecode, version_tuple
267-
)
270+
exception_table = format_exception_table(bytecode, version_tuple)
268271
real_out.write(exception_table + "\n")
269272

270273
for c in co.co_consts:
@@ -345,7 +348,16 @@ def disco_loop_asm_format(
345348
co = co.freeze()
346349
all_fns.add(co_name)
347350
if co.co_name != "<module>" or co.co_filename:
348-
real_out.write("\n" + format_code_info(co, version_tuple, mapped_name) + "\n")
351+
real_out.write(
352+
"\n"
353+
+ format_code_info(
354+
co,
355+
version_tuple,
356+
mapped_name,
357+
python_implementation=opc.python_implementation,
358+
)
359+
+ "\n"
360+
)
349361

350362
bytecode = Bytecode(co, opc, dup_lines=True)
351363
real_out.write(bytecode.dis(asm_format="asm") + "\n")

xdis/opcodes/opcode_311pypy.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# (C) Copyright 2025 by Rocky Bernstein
2-
"""
3-
PYPY 3.11 opcodes
2+
"""PYPY 3.11 opcodes
3+
4+
PyPy's 3.11 opcodes are more like CPython's 3.10's opcode.py than CPython 3.11 opcodes.
5+
6+
We add some classification of stack usage and information for
7+
formatting instructions.
48
5-
This is a like Python's 3.10's opcode.py with some classification
6-
of stack usage and information for formatting instructions.
79
"""
810

9-
import xdis.opcodes.opcode_310 as opcode_310
11+
import xdis.opcodes.opcode_310 as opcode_311
1012
from xdis.opcodes.base import (
1113
def_op,
1214
finalize_opcodes,
@@ -24,14 +26,14 @@
2426
python_implementation = PythonImplementation("PyPy")
2527

2628
loc = locals()
27-
init_opdata(loc, opcode_310, version_tuple, is_pypy=True)
29+
init_opdata(loc, opcode_311, version_tuple, is_pypy=True)
2830

2931

3032
# fmt: off
3133
# Changed opcodes
3234
# ----------------------
3335

34-
# Removed from Python 3.10
36+
# Removed from Python 3.11
3537
# ----------------
3638

3739
rm_op(loc, "GEN_START", 129)

0 commit comments

Comments
 (0)