2019-05-16 19:59:14 +02:00
|
|
|
#!/usr/bin/python3
|
2019-05-15 21:47:08 +02:00
|
|
|
|
2019-05-30 12:44:56 +02:00
|
|
|
# The OS/K Team licenses this file to you under the MIT license.
|
2019-05-15 21:56:42 +02:00
|
|
|
# See the LICENSE file in the project root for more information.
|
2019-05-15 21:47:08 +02:00
|
|
|
|
2019-06-02 16:33:28 +02:00
|
|
|
from tempfile import TemporaryFile
|
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
def parse_1(fi, fp):
|
|
|
|
global count
|
|
|
|
|
|
|
|
# "instr ri ri" => "instr r r\ninstr r i\ninstr i r..."
|
|
|
|
# not optimal but will do for now
|
|
|
|
for _, line in enumerate(fi):
|
|
|
|
if line[0] == '#' or line[0] == ' ' or line[0] == '\n':
|
|
|
|
continue
|
|
|
|
|
|
|
|
line = line.strip()
|
2019-05-30 12:44:56 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
if line[:8] == "include ":
|
|
|
|
_, fn = line.split(' ', 1)
|
|
|
|
fi2 = open(fn[1:-1])
|
|
|
|
parse_1(fi2, fp)
|
|
|
|
continue
|
2019-05-30 12:44:56 +02:00
|
|
|
|
2019-08-03 17:41:44 +02:00
|
|
|
fp.write("{}\n".format(line))
|
2019-06-02 16:33:28 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
def parse_2(fp):
|
|
|
|
global count
|
|
|
|
fp.seek(0)
|
2019-06-16 11:58:12 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
for _, line in enumerate(fp):
|
|
|
|
tok = line.strip().split(' ')
|
2019-06-16 11:58:12 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
assert(len(tok) > 0)
|
2019-05-15 21:47:08 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
deprecated = ''
|
|
|
|
if tok[0][0] == '!':
|
|
|
|
assert(len(tok[0]) > 1)
|
|
|
|
deprecated = '__'
|
|
|
|
tok[0] = tok[0][1:]
|
2019-05-30 12:44:56 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
if len(tok) == 1:
|
|
|
|
name = tok[0]
|
2019-08-03 17:41:44 +02:00
|
|
|
n = 0
|
2019-05-19 19:54:29 +02:00
|
|
|
|
2019-06-23 12:40:18 +02:00
|
|
|
else:
|
2019-08-03 17:41:44 +02:00
|
|
|
assert(len(tok) == 2)
|
|
|
|
n = tok[1]
|
2019-05-15 21:47:08 +02:00
|
|
|
|
2019-08-03 17:41:44 +02:00
|
|
|
ls.write("{}{}\n".format(deprecated, tok[0]))
|
2019-06-23 12:40:18 +02:00
|
|
|
|
|
|
|
hd.write("#ifdef _NEED_ARCH_I\n")
|
2019-08-03 17:41:44 +02:00
|
|
|
hd.write('{{ "{}{}", {}, i_{} }},\n'\
|
|
|
|
.format(deprecated, tok[0], n, tok[0]))
|
2019-06-23 12:40:18 +02:00
|
|
|
hd.write("#else\n")
|
2019-08-03 17:41:44 +02:00
|
|
|
hd.write("#define I_{} {}\n".format(tok[0].upper(), count))
|
2019-07-01 21:46:36 +02:00
|
|
|
hd.write("extern bool i_{}(ctx_t *, acc_t *, acc_t *, acc_t *, ulong *, ulong *, ulong *);\n"
|
2019-06-23 12:40:18 +02:00
|
|
|
.format(tok[0]))
|
|
|
|
hd.write("#endif\n\n")
|
|
|
|
|
|
|
|
count = count + 1
|
|
|
|
|
|
|
|
fi = open("INSTRS")
|
2019-07-18 22:49:31 +02:00
|
|
|
hd = open("../ob/arch_i.h", "w")
|
|
|
|
ls = open("../ob/instrs.lst", "w")
|
2019-06-23 12:40:18 +02:00
|
|
|
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
hd.write("// Auto-generated by arch_i.py from INSTRS\n\n");
|
|
|
|
|
|
|
|
hd.write("#ifdef _NEED_ARCH_I\n")
|
|
|
|
hd.write("instr_t arch_i[] =\n{\n\n")
|
|
|
|
hd.write("#endif\n")
|
|
|
|
|
|
|
|
fp = TemporaryFile(mode="w+")
|
|
|
|
parse_1(fi, fp)
|
|
|
|
parse_2(fp)
|
2019-05-15 21:47:08 +02:00
|
|
|
|
|
|
|
hd.write("#ifdef _NEED_ARCH_I\n")
|
|
|
|
hd.write("};\n")
|
2019-05-16 16:48:45 +02:00
|
|
|
hd.write("#else\n")
|
|
|
|
hd.write("#define NINSTRS {}\n\n".format(count))
|
2019-05-15 21:47:08 +02:00
|
|
|
hd.write("#endif\n")
|
|
|
|
|
2019-05-19 19:54:29 +02:00
|
|
|
ls.close()
|
2019-05-15 21:47:08 +02:00
|
|
|
hd.close()
|
|
|
|
|