arm/kvm: convert to kvm_get_one_reg
[qemu/ar7.git] / target / hexagon / gen_op_regs.py
bloba8a7712129c40c8def63c73ecabd9f6a230d4038
1 #!/usr/bin/env python3
3 ##
4 ## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
5 ##
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/>.
20 import sys
21 import re
22 import string
23 import hex_common
27 ## Generate the register and immediate operands for each instruction
29 def calculate_regid_reg(tag):
30 def letter_inc(x):
31 return chr(ord(x) + 1)
33 ordered_implregs = ["SP", "FP", "LR"]
34 srcdst_lett = "X"
35 src_lett = "S"
36 dst_lett = "D"
37 retstr = ""
38 mapdict = {}
39 for reg in ordered_implregs:
40 reg_rd = 0
41 reg_wr = 0
42 if ("A_IMPLICIT_WRITES_" + reg) in hex_common.attribdict[tag]:
43 reg_wr = 1
44 if reg_rd and reg_wr:
45 retstr += srcdst_lett
46 mapdict[srcdst_lett] = reg
47 srcdst_lett = letter_inc(srcdst_lett)
48 elif reg_rd:
49 retstr += src_lett
50 mapdict[src_lett] = reg
51 src_lett = letter_inc(src_lett)
52 elif reg_wr:
53 retstr += dst_lett
54 mapdict[dst_lett] = reg
55 dst_lett = letter_inc(dst_lett)
56 return retstr, mapdict
59 def calculate_regid_letters(tag):
60 retstr, mapdict = calculate_regid_reg(tag)
61 return retstr
64 def strip_reg_prefix(x):
65 y = x.replace("UREG.", "")
66 y = y.replace("MREG.", "")
67 return y.replace("GREG.", "")
70 def main():
71 hex_common.read_semantics_file(sys.argv[1])
72 hex_common.read_attribs_file(sys.argv[2])
73 tagregs = hex_common.get_tagregs(full=True)
74 tagimms = hex_common.get_tagimms()
76 with open(sys.argv[3], "w") as f:
77 for tag in hex_common.tags:
78 regs = tagregs[tag]
79 rregs = []
80 wregs = []
81 regids = ""
82 for regtype, regid, _, numregs in regs:
83 if hex_common.is_read(regid):
84 if regid[0] not in regids:
85 regids += regid[0]
86 rregs.append(regtype + regid + numregs)
87 if hex_common.is_written(regid):
88 wregs.append(regtype + regid + numregs)
89 if regid[0] not in regids:
90 regids += regid[0]
91 for attrib in hex_common.attribdict[tag]:
92 if hex_common.attribinfo[attrib]["rreg"]:
93 rregs.append(strip_reg_prefix(attribinfo[attrib]["rreg"]))
94 if hex_common.attribinfo[attrib]["wreg"]:
95 wregs.append(strip_reg_prefix(attribinfo[attrib]["wreg"]))
96 regids += calculate_regid_letters(tag)
97 f.write(
98 f'REGINFO({tag},"{regids}",\t/*RD:*/\t"{",".join(rregs)}",'
99 f'\t/*WR:*/\t"{",".join(wregs)}")\n'
102 for tag in hex_common.tags:
103 imms = tagimms[tag]
104 f.write(f"IMMINFO({tag}")
105 if not imms:
106 f.write(""",'u',0,0,'U',0,0""")
107 for sign, size, shamt in imms:
108 if sign == "r":
109 sign = "s"
110 if not shamt:
111 shamt = "0"
112 f.write(f""",'{sign}',{size},{shamt}""")
113 if len(imms) == 1:
114 if sign.isupper():
115 myu = "u"
116 else:
117 myu = "U"
118 f.write(f""",'{myu}',0,0""")
119 f.write(")\n")
122 if __name__ == "__main__":
123 main()