1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/pc/instrs/arch_i.py

79 lines
1.7 KiB
Python
Raw Normal View History

2019-05-16 19:59:14 +02:00
#!/usr/bin/python3
2019-05-15 21:47:08 +02:00
# The OS/K Team licences 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-05-16 20:09:20 +02:00
fi = open("INSTRS")
hd = open("arch_i.h", "w")
2019-05-19 19:54:29 +02:00
ls = open("instrs.lst", "w")
2019-05-15 21:47:08 +02:00
count = 0
2019-05-29 16:57:22 +02:00
hd.write("// Auto-generated by arch_i.py from INSTRS\n\n");
2019-05-16 19:49:51 +02:00
2019-05-15 21:47:08 +02:00
hd.write("#ifdef _NEED_ARCH_I\n")
hd.write("instr_t arch_i[] =\n{\n\n")
hd.write("#endif\n")
def getflag(s):
if s == "r":
return "P_REG"
if s == "i":
return "P_IMM"
if s == "m":
return "P_MEM"
return "__ERROR__"
for _, line in enumerate(fi):
if line[0] == '#' or line[0] == ' ' or line[0] == '\n':
continue
2019-05-16 16:48:45 +02:00
tok = line.strip().split(' ')
2019-05-15 21:47:08 +02:00
if len(tok) == 1:
2019-05-16 16:48:45 +02:00
name = tok[0]
2019-05-15 21:47:08 +02:00
p1 = "NOPRM"
p2 = "NOPRM"
elif len(tok) == 2:
name = "{}_{}".format(tok[0], tok[1].strip())
2019-05-16 16:48:45 +02:00
p1 = getflag(tok[1])
2019-05-15 21:47:08 +02:00
p2 = "NOPRM"
elif len(tok) == 3:
name = "{}_{}_{}".format(tok[0], tok[1], tok[2].strip())
p1 = getflag(tok[1])
2019-05-16 16:48:45 +02:00
p2 = getflag(tok[2])
2019-05-15 21:47:08 +02:00
else:
name = "__ERROR__"
p1 = "__ERROR__"
p2 = "__ERROR__"
2019-05-19 19:54:29 +02:00
ls.write("{}\n".format(name));
2019-05-15 21:47:08 +02:00
hd.write("#ifdef _NEED_ARCH_I\n")
hd.write('{{ "{}", "{}", {}, {}, i_{} }},\n'\
2019-05-16 16:48:45 +02:00
.format(tok[0], name, p1, p2, tok[0]))
hd.write("#else\n")
hd.write("#define I_{} {}\n".format(name.upper(), count))
hd.write("extern void i_{}(ctx_t *, acc_t *, acc_t *);\n"
.format(tok[0]))
2019-05-15 21:47:08 +02:00
hd.write("#endif\n\n")
count = count + 1
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()
fi.close()