summaryrefslogtreecommitdiff
path: root/Tools/scripts/generate_opcode_h.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/scripts/generate_opcode_h.py')
-rw-r--r--Tools/scripts/generate_opcode_h.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Tools/scripts/generate_opcode_h.py b/Tools/scripts/generate_opcode_h.py
index 948b56f900..6622a3c815 100644
--- a/Tools/scripts/generate_opcode_h.py
+++ b/Tools/scripts/generate_opcode_h.py
@@ -1,6 +1,8 @@
# This script generates the opcode.h header file.
import sys
+import tokenize
+
header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */
#ifndef Py_OPCODE_H
#define Py_OPCODE_H
@@ -35,7 +37,13 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE,
def main(opcode_py, outfile='Include/opcode.h'):
opcode = {}
- exec(open(opcode_py).read(), opcode)
+ if hasattr(tokenize, 'open'):
+ fp = tokenize.open(opcode_py) # Python 3.2+
+ else:
+ fp = open(opcode_py) # Python 2.7
+ with fp:
+ code = fp.read()
+ exec(code, opcode)
opmap = opcode['opmap']
with open(outfile, 'w') as fobj:
fobj.write(header)
@@ -47,6 +55,8 @@ def main(opcode_py, outfile='Include/opcode.h'):
('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT']))
fobj.write(footer)
+ print("%s regenerated from %s" % (outfile, opcode_py))
+
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2])