summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBrandt Bucher <brandt@python.org>2021-11-11 06:56:22 (GMT)
committerGitHub <noreply@github.com>2021-11-11 06:56:22 (GMT)
commit9178f533ff5ea7462a2ca22cfa67afd78dad433b (patch)
tree2341d2dbc7fbee0585e0d37a04c07b07c8036d57 /Tools
parent1cbaa505d007e11c4a1f0d2073d72b6c02c7147c (diff)
downloadcpython-9178f533ff5ea7462a2ca22cfa67afd78dad433b.zip
cpython-9178f533ff5ea7462a2ca22cfa67afd78dad433b.tar.gz
cpython-9178f533ff5ea7462a2ca22cfa67afd78dad433b.tar.bz2
bpo-45636: Merge all numeric operators (GH-29482)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/scripts/generate_opcode_h.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py
index dca9bbc..0ee4b95 100644
--- a/Tools/scripts/generate_opcode_h.py
+++ b/Tools/scripts/generate_opcode_h.py
@@ -12,7 +12,7 @@ extern "C" {
#endif
- /* Instruction opcodes for compiled code */
+/* Instruction opcodes for compiled code */
""".lstrip()
footer = """
@@ -28,6 +28,8 @@ footer = """
#endif /* !Py_OPCODE_H */
"""
+DEFINE = "#define {:<31} {:>3}\n"
+
UINT32_MASK = (1<<32)-1
def write_int_array_from_ops(name, ops, out):
@@ -62,17 +64,16 @@ def main(opcode_py, outfile='Include/opcode.h'):
fobj.write(header)
for name in opcode['opname']:
if name in opmap:
- fobj.write("#define %-23s %3s\n" % (name, opmap[name]))
+ fobj.write(DEFINE.format(name, opmap[name]))
if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT
- fobj.write("#define %-23s %3d\n" %
- ('HAVE_ARGUMENT', opcode['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 %-23s %3s\n" % (name, next_op))
+ fobj.write(DEFINE.format(name, next_op))
used[next_op] = True
- fobj.write("#define DO_TRACING 255\n")
+ fobj.write(DEFINE.format('DO_TRACING', 255))
fobj.write("#ifdef NEED_OPCODE_JUMP_TABLES\n")
write_int_array_from_ops("_PyOpcode_RelativeJump", opcode['hasjrel'], fobj)
write_int_array_from_ops("_PyOpcode_Jump", opcode['hasjrel'] + opcode['hasjabs'], fobj)
@@ -84,10 +85,14 @@ def main(opcode_py, outfile='Include/opcode.h'):
fobj.write(f"\n || ((op) == {op}) \\")
fobj.write("\n )\n")
+ fobj.write("\n")
+ for i, (op, _) in enumerate(opcode["_nb_ops"]):
+ fobj.write(DEFINE.format(op, i))
+
fobj.write(footer)
- print("%s regenerated from %s" % (outfile, opcode_py))
+ print(f"{outfile} regenerated from {opcode_py}")
if __name__ == '__main__':