4 ## Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
26 ## Generate the register and immediate operands for each instruction
28 def calculate_regid_reg(tag
):
29 def letter_inc(x
): return chr(ord(x
)+1)
30 ordered_implregs
= [ 'SP','FP','LR' ]
36 for reg
in ordered_implregs
:
39 if ('A_IMPLICIT_WRITES_'+reg
) in hex_common
.attribdict
[tag
]: reg_wr
= 1
42 mapdict
[srcdst_lett
] = reg
43 srcdst_lett
= letter_inc(srcdst_lett
)
46 mapdict
[src_lett
] = reg
47 src_lett
= letter_inc(src_lett
)
50 mapdict
[dst_lett
] = reg
51 dst_lett
= letter_inc(dst_lett
)
54 def calculate_regid_letters(tag
):
55 retstr
,mapdict
= calculate_regid_reg(tag
)
58 def strip_reg_prefix(x
):
59 y
=x
.replace('UREG.','')
60 y
=y
.replace('MREG.','')
61 return y
.replace('GREG.','')
64 hex_common
.read_semantics_file(sys
.argv
[1])
65 hex_common
.read_attribs_file(sys
.argv
[2])
66 tagregs
= hex_common
.get_tagregs()
67 tagimms
= hex_common
.get_tagimms()
69 with
open(sys
.argv
[3], 'w') as f
:
70 for tag
in hex_common
.tags
:
75 for regtype
,regid
,toss
,numregs
in regs
:
76 if hex_common
.is_read(regid
):
77 if regid
[0] not in regids
: regids
+= regid
[0]
78 rregs
.append(regtype
+regid
+numregs
)
79 if hex_common
.is_written(regid
):
80 wregs
.append(regtype
+regid
+numregs
)
81 if regid
[0] not in regids
: regids
+= regid
[0]
82 for attrib
in hex_common
.attribdict
[tag
]:
83 if hex_common
.attribinfo
[attrib
]['rreg']:
84 rregs
.append(strip_reg_prefix(attribinfo
[attrib
]['rreg']))
85 if hex_common
.attribinfo
[attrib
]['wreg']:
86 wregs
.append(strip_reg_prefix(attribinfo
[attrib
]['wreg']))
87 regids
+= calculate_regid_letters(tag
)
88 f
.write('REGINFO(%s,"%s",\t/*RD:*/\t"%s",\t/*WR:*/\t"%s")\n' % \
89 (tag
,regids
,",".join(rregs
),",".join(wregs
)))
91 for tag
in hex_common
.tags
:
93 f
.write( 'IMMINFO(%s' % tag
)
95 f
.write(''','u',0,0,'U',0,0''')
96 for sign
,size
,shamt
in imms
:
97 if sign
== 'r': sign
= 's'
100 f
.write(''','%s',%s,%s''' % (sign
,size
,shamt
))
106 f
.write(''','%s',0,0''' % myu
)
109 if __name__
== "__main__":