1 # python code-writer for OpenPOWER ISA pseudo-code parsing
4 from soc
.decoder
.pseudo
.pagereader
import ISA
5 from soc
.decoder
.power_pseudo
import convert_to_python
8 fdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
9 fdir
= os
.path
.split(fdir
)[0]
10 return os
.path
.join(fdir
, "isa")
12 def create_args(reglist
, extra
=None):
19 return ', '.join(args
)
22 # auto-generated by pywriter.py, do not edit or commit
24 from soc.decoder.isa import ISACaller
25 from soc.decoder.helpers import (EXTS64, EXTZ64, ROTL64, ROTL32, MASK,)
31 class PyISAWriter(ISA
):
35 def write_pysource(self
, pagename
):
36 instrs
= isa
.page
[pagename
]
37 isadir
= get_isasrc_dir()
38 fname
= os
.path
.join(isadir
, "%s.py" % pagename
)
39 with
open(fname
, "w") as f
:
41 f
.write(header
% pagename
) # write out header
42 # go through all instructions
45 print (fname
, d
.opcode
)
46 pcode
= '\n'.join(d
.pcode
) + '\n'
48 pycode
, rused
= convert_to_python(pcode
)
49 # create list of arguments to call
50 regs
= rused
['read_regs'] + rused
['uninit_regs']
51 args
= create_args(regs
, 'self')
52 # create list of arguments to return
53 retargs
= create_args(rused
['write_regs'])
54 f
.write(" def %s(%s):\n" % (page
.replace(".", "_"), args
))
55 pycode
= pycode
.split("\n")
56 pycode
= '\n'.join(map(lambda x
: " %s" % x
, pycode
))
57 pycode
= pycode
.rstrip()
58 f
.write(pycode
+ '\n')
60 f
.write(" return (%s,)\n\n" % retargs
)
63 # accumulate the instruction info
64 iinfo
= "(%s, %s, %s, %s)" % \
65 (page
, rused
['read_regs'],
66 rused
['uninit_regs'], rused
['write_regs'])
67 iinf
+= " instrs['%s'] = %s\n" % (pagename
, iinfo
)
68 # write out initialisation of info, for ISACaller to use
69 f
.write(" instrs = {}\n")
72 if __name__
== '__main__':
74 isa
.write_pysource('comparefixed')
75 isa
.write_pysource('fixedarith')