5252#endif // !Py_INTERNAL_OPCODE_H
5353"""
5454
55+ intrinsic_header = f"""
56+ // Auto-generated by { SCRIPT_NAME } from { PYTHON_OPCODE }
57+
58+ """ .lstrip ()
59+
60+ intrinsic_footer = """
61+ typedef PyObject *(*instrinsic_func1)(PyThreadState* tstate, PyObject *value);
62+ typedef PyObject *(*instrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);
63+ extern const instrinsic_func1 _PyIntrinsics_UnaryFunctions[];
64+ extern const instrinsic_func2 _PyIntrinsics_BinaryFunctions[];
65+ """
66+
5567DEFINE = "#define {:<38} {:>3}\n "
5668
5769UINT32_MASK = (1 << 32 )- 1
@@ -67,7 +79,9 @@ def write_int_array_from_ops(name, ops, out):
6779 assert bits == 0
6880 out .write (f"}};\n " )
6981
70- def main (opcode_py , outfile = 'Include/opcode.h' , internaloutfile = 'Include/internal/pycore_opcode.h' ):
82+ def main (opcode_py , outfile = 'Include/opcode.h' ,
83+ internaloutfile = 'Include/internal/pycore_opcode.h' ,
84+ intrinsicoutfile = 'Include/internal/pycore_intrinsics.h' ):
7185 opcode = {}
7286 if hasattr (tokenize , 'open' ):
7387 fp = tokenize .open (opcode_py ) # Python 3.2+
@@ -107,9 +121,11 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
107121 opname_including_specialized [next_op ] = name
108122 used [next_op ] = True
109123
110- with open (outfile , 'w' ) as fobj , open (internaloutfile , 'w' ) as iobj :
124+ with open (outfile , 'w' ) as fobj , open (internaloutfile , 'w' ) as iobj , open (
125+ intrinsicoutfile , "w" ) as nobj :
111126 fobj .write (header )
112127 iobj .write (internal_header )
128+ nobj .write (intrinsic_header )
113129
114130 for name in opname :
115131 if name in opmap :
@@ -172,6 +188,22 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna
172188 for i , (op , _ ) in enumerate (opcode ["_nb_ops" ]):
173189 fobj .write (DEFINE .format (op , i ))
174190
191+ nobj .write ("/* Unary Functions: */" )
192+ nobj .write ("\n " )
193+ for i , op in enumerate (opcode ["_intrinsic_1_descs" ]):
194+ nobj .write (DEFINE .format (op , i ))
195+ nobj .write ("\n " )
196+ nobj .write (DEFINE .format ("MAX_INTRINSIC_1" , i ))
197+
198+ nobj .write ("\n \n " )
199+ nobj .write ("/* Binary Functions: */\n " )
200+ for i , op in enumerate (opcode ["_intrinsic_2_descs" ]):
201+ nobj .write (DEFINE .format (op , i ))
202+ nobj .write ("\n " )
203+ nobj .write (DEFINE .format ("MAX_INTRINSIC_2" , i ))
204+
205+ nobj .write (intrinsic_footer )
206+
175207 fobj .write ("\n " )
176208 fobj .write ("/* Defined in Lib/opcode.py */\n " )
177209 fobj .write (f"#define ENABLE_SPECIALIZATION { int (ENABLE_SPECIALIZATION )} " )
0 commit comments