diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-08-11 16:42:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-11 16:42:01 (GMT) |
commit | caa41a4f1db0112690cf610bab7d9c6dce9ff1ce (patch) | |
tree | 43d745b50aede9468e8e9bc2d281e99cba54a1d6 /Tools/build | |
parent | 52e0797f8e1c631eecf24cb3f997ace336f52271 (diff) | |
download | cpython-caa41a4f1db0112690cf610bab7d9c6dce9ff1ce.zip cpython-caa41a4f1db0112690cf610bab7d9c6dce9ff1ce.tar.gz cpython-caa41a4f1db0112690cf610bab7d9c6dce9ff1ce.tar.bz2 |
gh-105481: split opcode_ids.h out of opcode.h so that it can be generated separately (#107866)
Diffstat (limited to 'Tools/build')
-rw-r--r-- | Tools/build/generate_opcode_h.py | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/Tools/build/generate_opcode_h.py b/Tools/build/generate_opcode_h.py index 3a81732..67f4a2c 100644 --- a/Tools/build/generate_opcode_h.py +++ b/Tools/build/generate_opcode_h.py @@ -6,7 +6,7 @@ import tokenize SCRIPT_NAME = "Tools/build/generate_opcode_h.py" PYTHON_OPCODE = "Lib/opcode.py" -header = f""" +opcode_h_header = f""" // Auto-generated by {SCRIPT_NAME} from {PYTHON_OPCODE} #ifndef Py_OPCODE_H @@ -15,11 +15,11 @@ header = f""" extern "C" {{ #endif +#include "opcode_ids.h" -/* Instruction opcodes for compiled code */ """.lstrip() -footer = """ +opcode_h_footer = """ #ifdef __cplusplus } @@ -27,6 +27,27 @@ footer = """ #endif /* !Py_OPCODE_H */ """ +opcode_ids_h_header = f""" +// Auto-generated by {SCRIPT_NAME} from {PYTHON_OPCODE} + +#ifndef Py_OPCODE_IDS_H +#define Py_OPCODE_IDS_H +#ifdef __cplusplus +extern "C" {{ +#endif + + +/* Instruction opcodes for compiled code */ +""".lstrip() + +opcode_ids_h_footer = """ + +#ifdef __cplusplus +} +#endif +#endif /* !Py_OPCODE_IDS_H */ +""" + internal_header = f""" // Auto-generated by {SCRIPT_NAME} from {PYTHON_OPCODE} @@ -63,9 +84,10 @@ def get_python_module_dict(filename): def main(opcode_py, _opcode_metadata_py='Lib/_opcode_metadata.py', - outfile='Include/opcode.h', + opcode_ids_h='Include/opcode_ids.h', + opcode_h='Include/opcode.h', opcode_targets_h='Python/opcode_targets.h', - internaloutfile='Include/internal/pycore_opcode.h'): + internal_opcode_h='Include/internal/pycore_opcode.h'): _opcode_metadata = get_python_module_dict(_opcode_metadata_py) @@ -91,9 +113,8 @@ def main(opcode_py, opname_including_specialized[next_op] = name used[next_op] = True - with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj: - fobj.write(header) - iobj.write(internal_header) + with open(opcode_ids_h, 'w') as fobj: + fobj.write(opcode_ids_h_header) for name in opname: if name in opmap: @@ -107,6 +128,20 @@ def main(opcode_py, for name, op in specialized_opmap.items(): fobj.write(DEFINE.format(name, op)) + fobj.write(opcode_ids_h_footer) + + with open(opcode_h, 'w') as fobj: + fobj.write(opcode_h_header) + + fobj.write("\n") + for i, (op, _) in enumerate(opcode["_nb_ops"]): + fobj.write(DEFINE.format(op, i)) + + fobj.write(opcode_h_footer) + + with open(internal_opcode_h, 'w') as iobj: + iobj.write(internal_header) + iobj.write("\nextern const uint8_t _PyOpcode_Caches[256];\n") iobj.write("\nextern const uint8_t _PyOpcode_Deopt[256];\n") iobj.write("\n#ifdef NEED_OPCODE_TABLES\n") @@ -129,10 +164,6 @@ def main(opcode_py, iobj.write("};\n") iobj.write("#endif // NEED_OPCODE_TABLES\n") - fobj.write("\n") - for i, (op, _) in enumerate(opcode["_nb_ops"]): - fobj.write(DEFINE.format(op, i)) - iobj.write("\n") iobj.write(f"\nextern const char *const _PyOpcode_OpName[{NUM_OPCODES}];\n") iobj.write("\n#ifdef NEED_OPCODE_TABLES\n") @@ -151,7 +182,6 @@ def main(opcode_py, iobj.write(f" case {i}: \\\n") iobj.write(" ;\n") - fobj.write(footer) iobj.write(internal_footer) with open(opcode_targets_h, "w") as f: @@ -164,8 +194,9 @@ def main(opcode_py, f.write(",\n".join([f" &&{s}" for s in targets])) f.write("\n};\n") - print(f"{outfile} regenerated from {opcode_py}") + print(f"{opcode_h} regenerated from {opcode_py}") if __name__ == '__main__': - main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]) + main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], + sys.argv[5], sys.argv[6]) |