diff options
author | 2020-08-04 17:30:11 +0100 | |
---|---|---|
committer | 2020-08-04 17:30:11 +0100 | |
commit | 582aaf19e8b94a70c1f96792197770d604ba0fdf (patch) | |
tree | 5f7934d5792806ac1f21c023734eebfb031b0117 /Tools | |
parent | bpo-40275: Use new test.support helper submodules in tests (GH-21727) (diff) | |
download | cpython-582aaf19e8b94a70c1f96792197770d604ba0fdf.tar.gz cpython-582aaf19e8b94a70c1f96792197770d604ba0fdf.tar.bz2 cpython-582aaf19e8b94a70c1f96792197770d604ba0fdf.zip |
bpo-41463: Generate information about jumps from 'opcode.py' rather than duplicating it in 'compile.c' (GH-21714)
Generate information about jumps from 'opcode.py' rather than duplicate it in 'compile.c'
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/scripts/generate_opcode_h.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py index 873f82156e..cba13b2421 100644 --- a/Tools/scripts/generate_opcode_h.py +++ b/Tools/scripts/generate_opcode_h.py @@ -30,6 +30,18 @@ footer = """ #endif /* !Py_OPCODE_H */ """ +UINT32_MASK = (1<<32)-1 + +def write_int_array_from_ops(name, ops, out): + bits = 0 + for op in ops: + bits |= 1<<op + out.write(f"static uint32_t {name}[8] = {{\n") + for i in range(8): + out.write(f" {bits & UINT32_MASK}U,\n") + bits >>= 32 + assert bits == 0 + out.write(f"}};\n") def main(opcode_py, outfile='Include/opcode.h'): opcode = {} @@ -41,6 +53,8 @@ def main(opcode_py, outfile='Include/opcode.h'): code = fp.read() exec(code, opcode) opmap = opcode['opmap'] + hasjrel = opcode['hasjrel'] + hasjabs = opcode['hasjabs'] with open(outfile, 'w') as fobj: fobj.write(header) for name in opcode['opname']: @@ -49,8 +63,13 @@ def main(opcode_py, outfile='Include/opcode.h'): if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT fobj.write("#define %-23s %3d\n" % ('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT'])) + 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) + fobj.write("#endif /* OPCODE_TABLES */\n") fobj.write(footer) + print("%s regenerated from %s" % (outfile, opcode_py)) |