diff options
author | Kushal Das <kushaldas@gmail.com> | 2014-04-15 18:20:06 (GMT) |
---|---|---|
committer | Kushal Das <kushaldas@gmail.com> | 2014-04-15 18:20:06 (GMT) |
commit | 02d23a212a1e8e45a29e06d3f91e119610b682a3 (patch) | |
tree | b80ae813af32578a07c9fbe75dc60dfee0fb7af8 /Tools | |
parent | cec96144755bc75bc82d34a27e17ebe4eb300992 (diff) | |
download | cpython-02d23a212a1e8e45a29e06d3f91e119610b682a3.zip cpython-02d23a212a1e8e45a29e06d3f91e119610b682a3.tar.gz cpython-02d23a212a1e8e45a29e06d3f91e119610b682a3.tar.bz2 |
Closes Issue 17861: Autogenerate Include/opcode.h from opcode.py.
It includes required changes in Makefile.pre.in and configure.ac
among other files.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/scripts/generate_opcode_h.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py new file mode 100644 index 0000000..b315491 --- /dev/null +++ b/Tools/scripts/generate_opcode_h.py @@ -0,0 +1,53 @@ +# This script generates the opcode.h header file. + +import sys +if len(sys.argv) > 0: + sys.path.insert(0, sys.argv[1]) +# Importing module from our given src directory. +import opcode +header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */ +#ifndef Py_OPCODE_H +#define Py_OPCODE_H +#ifdef __cplusplus +extern "C" { +#endif + + + /* Instruction opcodes for compiled code */ +""" + +footer = """ +/* EXCEPT_HANDLER is a special, implicit block type which is created when + entering an except handler. It is not an opcode but we define it here + as we want it to be available to both frameobject.c and ceval.c, while + remaining private.*/ +#define EXCEPT_HANDLER 257 + + +enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, + PyCmp_GT=Py_GT, PyCmp_GE=Py_GE, PyCmp_IN, PyCmp_NOT_IN, + PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD}; + +#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) + +#ifdef __cplusplus +} +#endif +#endif /* !Py_OPCODE_H */ +""" + + +def main(outfile='Include/opcode.h'): + with open(outfile, 'w') as fobj: + fobj.write(header) + for name in opcode.opname: + if name in opcode.opmap: + fobj.write("#define %-20s\t%-3s\n" % (name, opcode.opmap[name])) + if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT + fobj.write("#define %-20s\t%-3d\n" % + ('HAVE_ARGUMENT', opcode.HAVE_ARGUMENT)) + fobj.write(footer) + + +if __name__ == '__main__': + main(sys.argv[2]) |