1 # python code-writer for OpenPOWER ISA pseudo-code parsing
7 from openpower
.decoder
.pseudo
.functionreader
import ISAFunctions
8 from openpower
.decoder
.power_pseudo
import convert_to_pure_python
11 def get_isafn_src_dir():
12 fdir
= os
.path
.abspath(os
.path
.dirname(__file__
))
13 fdir
= os
.path
.split(fdir
)[0]
14 return os
.path
.join(fdir
, "isafunctions")
18 # auto-generated by pyfnwriter.py, do not edit or commit
20 from openpower.decoder.isa.caller import inject
21 from openpower.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32,
23 ne, eq, gt, ge, lt, le, ltu, gtu, length,
24 trunc_divs, trunc_rems, MULS, DIVS, MODS,
27 FPADD32, FPSUB32, FPMUL32, FPDIV32,
28 FPADD64, FPSUB64, FPMUL64, FPDIV64,
30 from openpower.decoder.selectable_int import SelectableInt
31 from openpower.decoder.selectable_int import selectconcat as concat
37 class PyISAFnWriter(ISAFunctions
):
39 ISAFunctions
.__init
__(self
)
40 self
.pages_written
= []
42 def write_pysource(self
, pagename
):
43 self
.pages_written
.append(pagename
)
44 function
= self
.fns
[pagename
]
45 isadir
= get_isafn_src_dir()
46 fname
= os
.path
.join(isadir
, "%s.py" % pagename
)
47 with
open(fname
, "w") as f
:
48 f
.write(header
% function
['desc']) # write out header
49 # go through all instructions
50 pcode
= function
['pcode']
52 pycode
= convert_to_pure_python(pcode
)
58 write_isa_class
= True
59 if len(sys
.argv
) == 1: # quick way to do it
61 sources
= isa
.fns
.keys()
63 sources
= sys
.argv
[1:]
64 if sources
[0] == "noall": # don't rewrite all.py
65 write_isa_class
= False
67 print ("sources", write_isa_class
, sources
)
68 for source
in sources
:
69 isa
.write_pysource(source
)
71 if __name__
== '__main__':