Skip to content

Commit 5eee2fe

Browse files
authored
gh-128891: add specialized opcodes to opcode.opname (#128892)
1 parent 256d6d2 commit 5eee2fe

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

Lib/opcode.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
EXTENDED_ARG = opmap['EXTENDED_ARG']
1818

1919
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
20-
for op, i in opmap.items():
21-
opname[i] = op
20+
for m in (opmap, _specialized_opmap):
21+
for op, i in m.items():
22+
opname[i] = op
2223

2324
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2425

Lib/test/test__opcode.py

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def test_is_valid(self):
3838
opcodes = [dis.opmap[opname] for opname in names]
3939
self.check_bool_function_result(_opcode.is_valid, opcodes, True)
4040

41+
def test_opmaps(self):
42+
def check_roundtrip(name, map):
43+
return self.assertEqual(opcode.opname[map[name]], name)
44+
45+
check_roundtrip('BINARY_OP', opcode.opmap)
46+
check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)
47+
4148
def test_oplists(self):
4249
def check_function(self, func, expected):
4350
for op in [-10, 520]:

Lib/test/test_dis.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,14 @@ def test_boundaries(self):
999999
def test_widths(self):
10001000
long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT',
10011001
'INSTRUMENTED_CALL_FUNCTION_EX'])
1002-
for opcode, opname in enumerate(dis.opname):
1002+
for op, opname in enumerate(dis.opname):
10031003
if opname in long_opcodes or opname.startswith("INSTRUMENTED"):
10041004
continue
1005+
if opname in opcode._specialized_opmap:
1006+
continue
10051007
with self.subTest(opname=opname):
10061008
width = dis._OPNAME_WIDTH
1007-
if opcode in dis.hasarg:
1009+
if op in dis.hasarg:
10081010
width += 1 + dis._OPARG_WIDTH
10091011
self.assertLessEqual(len(opname), width)
10101012

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add specialized opcodes to ``opcode.opname``.

0 commit comments

Comments
 (0)