GH-103963: Make dis display names of args for intrinsics opcodes (#104029)

This commit is contained in:
Juhi Chandalia 2023-05-02 19:00:17 -07:00 committed by GitHub
parent 65a49c6553
commit 872cbc6132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 17 deletions

View file

@ -52,6 +52,18 @@ internal_footer = """
#endif // !Py_INTERNAL_OPCODE_H
"""
intrinsic_header = f"""
// Auto-generated by {SCRIPT_NAME} from {PYTHON_OPCODE}
""".lstrip()
intrinsic_footer = """
typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);
typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);
extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];
"""
DEFINE = "#define {:<38} {:>3}\n"
UINT32_MASK = (1<<32)-1
@ -67,7 +79,9 @@ def write_int_array_from_ops(name, ops, out):
assert bits == 0
out.write(f"}};\n")
def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h'):
def main(opcode_py, outfile='Include/opcode.h',
internaloutfile='Include/internal/pycore_opcode.h',
intrinsicoutfile='Include/internal/pycore_intrinsics.h'):
opcode = {}
if hasattr(tokenize, 'open'):
fp = tokenize.open(opcode_py) # Python 3.2+
@ -107,9 +121,11 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
opname_including_specialized[next_op] = name
used[next_op] = True
with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj:
with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj, open(
intrinsicoutfile, "w") as nobj:
fobj.write(header)
iobj.write(internal_header)
nobj.write(intrinsic_header)
for name in opname:
if name in opmap:
@ -172,6 +188,22 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
for i, (op, _) in enumerate(opcode["_nb_ops"]):
fobj.write(DEFINE.format(op, i))
nobj.write("/* Unary Functions: */")
nobj.write("\n")
for i, op in enumerate(opcode["_intrinsic_1_descs"]):
nobj.write(DEFINE.format(op, i))
nobj.write("\n")
nobj.write(DEFINE.format("MAX_INTRINSIC_1", i))
nobj.write("\n\n")
nobj.write("/* Binary Functions: */\n")
for i, op in enumerate(opcode["_intrinsic_2_descs"]):
nobj.write(DEFINE.format(op, i))
nobj.write("\n")
nobj.write(DEFINE.format("MAX_INTRINSIC_2", i))
nobj.write(intrinsic_footer)
fobj.write("\n")
fobj.write("/* Defined in Lib/opcode.py */\n")
fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}")