Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-91428: include specialized opcodes in _PyOpcode_OpName #91467

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
146 changes: 146 additions & 0 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 21 additions & 8 deletions Tools/scripts/generate_opcode_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,22 @@ def main(opcode_py, outfile='Include/opcode.h'):
hasjabs = opcode['hasjabs']
used = [ False ] * 256
next_op = 1

for name, op in opmap.items():
used[op] = True

specialized_opmap = {}
opname_including_specialized = opname.copy()
for name in opcode['_specialized_instructions']:
while used[next_op]:
next_op += 1
specialized_opmap[name] = next_op
opname_including_specialized[next_op] = name
used[next_op] = True
specialized_opmap['DO_TRACING'] = 255
opname_including_specialized[255] = 'DO_TRACING'
used[255] = True

with open(outfile, 'w') as fobj:
fobj.write(header)
for name in opname:
Expand All @@ -69,12 +83,9 @@ def main(opcode_py, outfile='Include/opcode.h'):
if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT
fobj.write(DEFINE.format("HAVE_ARGUMENT", opcode["HAVE_ARGUMENT"]))

for name in opcode['_specialized_instructions']:
while used[next_op]:
next_op += 1
fobj.write(DEFINE.format(name, next_op))
used[next_op] = True
fobj.write(DEFINE.format('DO_TRACING', 255))
for name, op in specialized_opmap.items():
fobj.write(DEFINE.format(name, op))

fobj.write("\nextern const uint8_t _PyOpcode_Caches[256];\n")
fobj.write("\nextern const uint8_t _PyOpcode_Deopt[256];\n")
fobj.write("\n#ifdef NEED_OPCODE_TABLES\n")
Expand Down Expand Up @@ -111,8 +122,10 @@ def main(opcode_py, outfile='Include/opcode.h'):
fobj.write("\n")
fobj.write("#ifdef Py_DEBUG\n")
fobj.write("static const char *const _PyOpcode_OpName[256] = {\n")
for name in opmap:
fobj.write(f''' [{name}] = "{name}",\n''')
for op, name in enumerate(opname_including_specialized):
if name[0] != "<":
op = name
fobj.write(f''' [{op}] = "{name}",\n''')
fobj.write("};\n")
fobj.write("#endif\n")

Expand Down