2010-09-04 01:20:41 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This file is part of pycdc.
|
|
|
|
#
|
|
|
|
# pycdc is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# pycdc is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with pycdc. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2014-06-10 19:20:56 -07:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
sys.stderr.write('Usage: %s in_dir out_dir\n' % sys.argv[0])
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if not os.path.exists(sys.argv[2]):
|
|
|
|
os.mkdir(sys.argv[2])
|
|
|
|
|
2015-10-01 16:06:09 -07:00
|
|
|
maplist = [ 10, 11, 13, 14, 15, 16,
|
2012-05-26 13:10:46 -07:00
|
|
|
20, 21, 22, 23, 24, 25, 26, 27,
|
2023-11-09 11:11:37 -08:00
|
|
|
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 310, 311, 312 ]
|
2010-09-04 01:20:41 -07:00
|
|
|
|
2012-05-26 13:10:46 -07:00
|
|
|
for mapver in maplist:
|
2014-06-10 19:20:56 -07:00
|
|
|
infile = open(os.path.join(sys.argv[1], 'python_%d.map' % mapver), 'rt')
|
|
|
|
outfile = open(os.path.join(sys.argv[2], 'python_%d.cpp' % mapver), 'wt')
|
2010-09-04 01:20:41 -07:00
|
|
|
|
2012-05-23 18:48:17 -07:00
|
|
|
idToOpcode = {}
|
|
|
|
opcodeToId = {}
|
|
|
|
for ln in infile.readlines():
|
|
|
|
fileid, code = ln.split()
|
2012-05-26 13:10:46 -07:00
|
|
|
idToOpcode[int(fileid)] = code
|
|
|
|
opcodeToId[code] = int(fileid)
|
2012-05-23 18:48:17 -07:00
|
|
|
|
|
|
|
outfile.write('/* This file was auto-generated with comp_map.py. DO NOT EDIT! */\n\n')
|
2014-06-10 19:20:56 -07:00
|
|
|
outfile.write('#include "bytecode.h"\n\n')
|
2012-05-26 13:10:46 -07:00
|
|
|
outfile.write('int python_%d_map(int id)\n' % mapver)
|
2012-05-23 18:48:17 -07:00
|
|
|
outfile.write('{\n')
|
|
|
|
outfile.write(' switch (id) {\n')
|
2012-05-26 13:10:46 -07:00
|
|
|
for i in sorted(idToOpcode):
|
|
|
|
outfile.write(' case %d: return Pyc::%s;\n' % (i, idToOpcode[i]))
|
2012-05-23 18:48:17 -07:00
|
|
|
outfile.write(' default: return Pyc::PYC_INVALID_OPCODE;\n')
|
|
|
|
outfile.write(' }\n')
|
|
|
|
outfile.write('}\n\n')
|
2012-05-26 13:10:46 -07:00
|
|
|
outfile.write('int python_%d_unmap(int id)\n' % mapver)
|
2012-05-23 18:48:17 -07:00
|
|
|
outfile.write('{\n')
|
|
|
|
outfile.write(' switch (id) {\n')
|
2012-05-26 13:10:46 -07:00
|
|
|
for i in sorted(opcodeToId):
|
|
|
|
outfile.write(' case Pyc::%s: return %d;\n' % (i, opcodeToId[i]))
|
2012-05-23 18:48:17 -07:00
|
|
|
outfile.write(' default: return -1;\n')
|
|
|
|
outfile.write(' }\n')
|
|
|
|
outfile.write('}\n')
|
|
|
|
|
|
|
|
infile.close()
|
|
|
|
outfile.close()
|