mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-128891: add specialized opcodes to opcode.opname (#128892)
This commit is contained in:
parent
256d6d2131
commit
5eee2fe2b0
4 changed files with 15 additions and 4 deletions
|
@ -17,8 +17,9 @@ from _opcode_metadata import (_specializations, _specialized_opmap, opmap, # no
|
||||||
EXTENDED_ARG = opmap['EXTENDED_ARG']
|
EXTENDED_ARG = opmap['EXTENDED_ARG']
|
||||||
|
|
||||||
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
|
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
|
||||||
for op, i in opmap.items():
|
for m in (opmap, _specialized_opmap):
|
||||||
opname[i] = op
|
for op, i in m.items():
|
||||||
|
opname[i] = op
|
||||||
|
|
||||||
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
|
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,13 @@ class OpListTests(unittest.TestCase):
|
||||||
opcodes = [dis.opmap[opname] for opname in names]
|
opcodes = [dis.opmap[opname] for opname in names]
|
||||||
self.check_bool_function_result(_opcode.is_valid, opcodes, True)
|
self.check_bool_function_result(_opcode.is_valid, opcodes, True)
|
||||||
|
|
||||||
|
def test_opmaps(self):
|
||||||
|
def check_roundtrip(name, map):
|
||||||
|
return self.assertEqual(opcode.opname[map[name]], name)
|
||||||
|
|
||||||
|
check_roundtrip('BINARY_OP', opcode.opmap)
|
||||||
|
check_roundtrip('BINARY_OP_ADD_INT', opcode._specialized_opmap)
|
||||||
|
|
||||||
def test_oplists(self):
|
def test_oplists(self):
|
||||||
def check_function(self, func, expected):
|
def check_function(self, func, expected):
|
||||||
for op in [-10, 520]:
|
for op in [-10, 520]:
|
||||||
|
|
|
@ -999,12 +999,14 @@ class DisTests(DisTestBase):
|
||||||
def test_widths(self):
|
def test_widths(self):
|
||||||
long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT',
|
long_opcodes = set(['JUMP_BACKWARD_NO_INTERRUPT',
|
||||||
'INSTRUMENTED_CALL_FUNCTION_EX'])
|
'INSTRUMENTED_CALL_FUNCTION_EX'])
|
||||||
for opcode, opname in enumerate(dis.opname):
|
for op, opname in enumerate(dis.opname):
|
||||||
if opname in long_opcodes or opname.startswith("INSTRUMENTED"):
|
if opname in long_opcodes or opname.startswith("INSTRUMENTED"):
|
||||||
continue
|
continue
|
||||||
|
if opname in opcode._specialized_opmap:
|
||||||
|
continue
|
||||||
with self.subTest(opname=opname):
|
with self.subTest(opname=opname):
|
||||||
width = dis._OPNAME_WIDTH
|
width = dis._OPNAME_WIDTH
|
||||||
if opcode in dis.hasarg:
|
if op in dis.hasarg:
|
||||||
width += 1 + dis._OPARG_WIDTH
|
width += 1 + dis._OPARG_WIDTH
|
||||||
self.assertLessEqual(len(opname), width)
|
self.assertLessEqual(len(opname), width)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add specialized opcodes to ``opcode.opname``.
|
Loading…
Add table
Add a link
Reference in a new issue