diff -r fe532dccf8f6 Makefile.pre.in --- a/Makefile.pre.in Mon Apr 14 10:30:43 2014 -0400 +++ b/Makefile.pre.in Tue Apr 15 03:38:37 2014 +0530 @@ -323,6 +323,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 @@ -760,6 +767,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 @@ -871,7 +881,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 -r fe532dccf8f6 Tools/scripts/generate_opcode_h.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tools/scripts/generate_opcode_h.py Tue Apr 15 03:38:37 2014 +0530 @@ -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 -r fe532dccf8f6 configure --- a/configure Mon Apr 14 10:30:43 2014 -0400 +++ b/configure Tue Apr 15 03:38:37 2014 +0530 @@ -670,6 +670,7 @@ INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM +OPCODEHGEN PYTHON ASDLGEN ac_ct_READELF @@ -6048,6 +6049,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 -r fe532dccf8f6 configure.ac --- a/configure.ac Mon Apr 14 10:30:43 2014 -0400 +++ b/configure.ac Tue Apr 15 03:38:37 2014 +0530 @@ -1036,6 +1036,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*)