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,)
26 from soc.decoder.selectable_int import SelectableInt
27 from soc.decoder.selectable_int import selectconcat as concat
33 class PyISAWriter(ISA
):
37 def write_pysource(self
, pagename
):
38 instrs
= isa
.page
[pagename
]
39 isadir
= get_isasrc_dir()
40 fname
= os
.path
.join(isadir
, "%s.py" % pagename
)
41 with
open(fname
, "w") as f
:
43 f
.write(header
% pagename
) # write out header
44 # go through all instructions
47 print (fname
, d
.opcode
)
48 pcode
= '\n'.join(d
.pcode
) + '\n'
50 pycode
, rused
= convert_to_python(pcode
)
51 # create list of arguments to call
52 regs
= rused
['read_regs'] + rused
['uninit_regs']
53 args
= create_args(regs
, 'self')
54 # create list of arguments to return
55 retargs
= create_args(rused
['write_regs'])
56 # write out function. pre-pend "op_" because some instrs are
57 # also python keywords (cmp). also replace "." with "_"
58 op_fname
="op_%s" % page
.replace(".", "_")
59 f
.write(" def %s(%s):\n" % (op_fname
, args
))
60 pycode
= pycode
.split("\n")
61 pycode
= '\n'.join(map(lambda x
: " %s" % x
, pycode
))
62 pycode
= pycode
.rstrip()
63 f
.write(pycode
+ '\n')
65 f
.write(" return (%s,)\n\n" % retargs
)
68 # accumulate the instruction info
69 iinfo
= "(%s, %s, %s, %s)" % \
70 (op_fname
, rused
['read_regs'],
71 rused
['uninit_regs'], rused
['write_regs'])
72 iinf
+= " instrs['%s'] = %s\n" % (page
, iinfo
)
73 # write out initialisation of info, for ISACaller to use
74 f
.write(" instrs = {}\n")
77 if __name__
== '__main__':
79 isa
.write_pysource('comparefixed')
80 isa
.write_pysource('fixedarith')