mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
79 lines
1.7 KiB
Python
79 lines
1.7 KiB
Python
#!/usr/bin/python3
|
|
|
|
# The OS/K Team licences this file to you under the MIT license.
|
|
# See the LICENSE file in the project root for more information.
|
|
|
|
fi = open("INSTRS")
|
|
hd = open("arch_i.h", "w")
|
|
ls = open("instrs.lst", "w")
|
|
|
|
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")
|
|
|
|
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
|
|
|
|
tok = line.strip().split(' ')
|
|
|
|
if len(tok) == 1:
|
|
name = tok[0]
|
|
p1 = "NOPRM"
|
|
p2 = "NOPRM"
|
|
|
|
elif len(tok) == 2:
|
|
name = "{}_{}".format(tok[0], tok[1].strip())
|
|
p1 = getflag(tok[1])
|
|
p2 = "NOPRM"
|
|
|
|
elif len(tok) == 3:
|
|
name = "{}_{}_{}".format(tok[0], tok[1], tok[2].strip())
|
|
p1 = getflag(tok[1])
|
|
p2 = getflag(tok[2])
|
|
|
|
else:
|
|
name = "__ERROR__"
|
|
p1 = "__ERROR__"
|
|
p2 = "__ERROR__"
|
|
|
|
ls.write("{}\n".format(name));
|
|
|
|
hd.write("#ifdef _NEED_ARCH_I\n")
|
|
hd.write('{{ "{}", "{}", {}, {}, i_{} }},\n'\
|
|
.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]))
|
|
hd.write("#endif\n\n")
|
|
|
|
count = count + 1
|
|
|
|
hd.write("#ifdef _NEED_ARCH_I\n")
|
|
hd.write("};\n")
|
|
hd.write("#else\n")
|
|
hd.write("#define NINSTRS {}\n\n".format(count))
|
|
hd.write("#endif\n")
|
|
|
|
ls.close()
|
|
hd.close()
|
|
fi.close()
|
|
|