mirror of
https://github.com/python/cpython.git
synced 2025-09-18 22:50:26 +00:00
Reintroduce Python2 support in generate_opcode_h.py
Issue #28821. Add also a message to show that the command did something :-)
This commit is contained in:
parent
50c13f216e
commit
213cc388c7
1 changed files with 9 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
# This script generates the opcode.h header file.
|
# This script generates the opcode.h header file.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import tokenize
|
||||||
|
|
||||||
header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */
|
header = """/* Auto-generated by Tools/scripts/generate_opcode_h.py */
|
||||||
#ifndef Py_OPCODE_H
|
#ifndef Py_OPCODE_H
|
||||||
#define Py_OPCODE_H
|
#define Py_OPCODE_H
|
||||||
|
@ -32,12 +34,14 @@ enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE,
|
||||||
#endif /* !Py_OPCODE_H */
|
#endif /* !Py_OPCODE_H */
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import tokenize
|
|
||||||
|
|
||||||
|
|
||||||
def main(opcode_py, outfile='Include/opcode.h'):
|
def main(opcode_py, outfile='Include/opcode.h'):
|
||||||
opcode = {}
|
opcode = {}
|
||||||
with tokenize.open(opcode_py) as fp:
|
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()
|
code = fp.read()
|
||||||
exec(code, opcode)
|
exec(code, opcode)
|
||||||
opmap = opcode['opmap']
|
opmap = opcode['opmap']
|
||||||
|
@ -51,6 +55,8 @@ def main(opcode_py, outfile='Include/opcode.h'):
|
||||||
('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT']))
|
('HAVE_ARGUMENT', opcode['HAVE_ARGUMENT']))
|
||||||
fobj.write(footer)
|
fobj.write(footer)
|
||||||
|
|
||||||
|
print("%s regenerated from %s" % (outfile, opcode_py))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv[1], sys.argv[2])
|
main(sys.argv[1], sys.argv[2])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue