kvisc/instr/instrs.py

73 lines
1.6 KiB
Python
Raw Normal View History

2019-05-15 21:47:08 +02:00
#!/usr/bin/python
# 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
fi = open("instr/INSTRS")
hd = open("instr/arch_i.h", "w")
count = 0
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__"
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")
hd.close()
fi.close()