diff --git a/Makefile.pre.in b/Makefile.pre.in --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -304,6 +304,13 @@ PGENOBJS= $(POBJS) $(PGOBJS) ########################################################################## +# opcode.h generation +OPCODE_H_DIR= Include +OPCODE_H_SCRIPT= Tools/scripts/generate_opcode_h.py +OPCODE_H= $(srcdir)/$(OPCODE_H_DIR)/opcode.h +OPCODE_H_GEN= @OPCODEHGEN@ $(OPCODE_H_SCRIPT) Lib/ $(OPCODE_H) +# +########################################################################## # AST AST_H_DIR= Include AST_H= $(AST_H_DIR)/Python-ast.h @@ -695,6 +702,9 @@ $(MKDIR_P) $(AST_C_DIR) $(ASDLGEN) -c $(AST_C_DIR) $(AST_ASDL) +$(OPCODE_H): + $(OPCODE_H_GEN) + Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H) Python/getplatform.o: $(srcdir)/Python/getplatform.c @@ -806,7 +816,7 @@ $(srcdir)/Include/node.h \ $(srcdir)/Include/object.h \ $(srcdir)/Include/objimpl.h \ - $(srcdir)/Include/opcode.h \ + $(OPCODE_H) \ $(srcdir)/Include/osdefs.h \ $(srcdir)/Include/patchlevel.h \ $(srcdir)/Include/pgen.h \ diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py new file mode 100644 --- /dev/null +++ b/Tools/scripts/generate_opcode_h.py @@ -0,0 +1,51 @@ +# This script generates the opcode.h header file. + +import sys +sys.path.insert(0, sys.argv[1]) +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]) diff --git a/configure b/configure --- a/configure +++ b/configure @@ -667,6 +667,7 @@ INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM +OPCODEHGEN PYTHON ASDLGEN ac_ct_READELF @@ -6013,6 +6014,57 @@ fi +for ac_prog in python$PACKAGE_VERSION python3 python +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_PYTHON+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$PYTHON"; then + ac_cv_prog_PYTHON="$PYTHON" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_PYTHON="$ac_prog" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +PYTHON=$ac_cv_prog_PYTHON +if test -n "$PYTHON"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5 +$as_echo "$PYTHON" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + test -n "$PYTHON" && break +done +test -n "$PYTHON" || PYTHON="not-found" + +if test "$PYTHON" = not-found; then + OPCODEHGEN="@echo python: $PYTHON! cannot run Tools/scripts/generate_opcode_h.py" +else + OPCODEHGEN="$PYTHON" +fi + + + case $MACHDEP in bsdos*|hp*|HP*) # install -d does not work on BSDI or HP-UX diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -1017,6 +1017,15 @@ ASDLGEN="$PYTHON" fi +AC_SUBST(OPCODEHGEN) +AC_CHECK_PROGS(PYTHON, python$PACKAGE_VERSION python3 python, not-found) +if test "$PYTHON" = not-found; then + OPCODEHGEN="@echo python: $PYTHON! cannot run Tools/scripts/generate_opcode_h.py" +else + OPCODEHGEN="$PYTHON" +fi + + case $MACHDEP in bsdos*|hp*|HP*)