GH-103963: Make dis display names of args for intrinsics opcodes (#10… · python/cpython@872cbc6 (original) (raw)

`@@ -52,6 +52,18 @@

`

52

52

`#endif // !Py_INTERNAL_OPCODE_H

`

53

53

`"""

`

54

54

``

``

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

+

55

67

`DEFINE = "#define {:<38} {:>3}\n"

`

56

68

``

57

69

`UINT32_MASK = (1<<32)-1

`

`@@ -67,7 +79,9 @@ def write_int_array_from_ops(name, ops, out):

`

67

79

`assert bits == 0

`

68

80

`out.write(f"}};\n")

`

69

81

``

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'):

`

71

85

`opcode = {}

`

72

86

`if hasattr(tokenize, 'open'):

`

73

87

`fp = tokenize.open(opcode_py) # Python 3.2+

`

`@@ -107,9 +121,11 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna

`

107

121

`opname_including_specialized[next_op] = name

`

108

122

`used[next_op] = True

`

109

123

``

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:

`

111

126

`fobj.write(header)

`

112

127

`iobj.write(internal_header)

`

``

128

`+

nobj.write(intrinsic_header)

`

113

129

``

114

130

`for name in opname:

`

115

131

`if name in opmap:

`

`@@ -172,6 +188,22 @@ def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/interna

`

172

188

`for i, (op, _) in enumerate(opcode["_nb_ops"]):

`

173

189

`fobj.write(DEFINE.format(op, i))

`

174

190

``

``

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

+

175

207

`fobj.write("\n")

`

176

208

`fobj.write("/* Defined in Lib/opcode.py */\n")

`

177

209

`fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}")

`