]> git.proxmox.com Git - mirror_qemu.git/blame - target/hexagon/gen_op_regs.py
target/s390x/cpu topology: activate CPU topology
[mirror_qemu.git] / target / hexagon / gen_op_regs.py
CommitLineData
793958c9
TS
1#!/usr/bin/env python3
2
3##
cd6c4edf 4## Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
793958c9
TS
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.
10##
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.
15##
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/>.
18##
19
20import sys
21import re
22import string
23import hex_common
24
5bb322e2 25
793958c9
TS
26##
27## Generate the register and immediate operands for each instruction
28##
29def calculate_regid_reg(tag):
5bb322e2
ML
30 def letter_inc(x):
31 return chr(ord(x) + 1)
32
33 ordered_implregs = ["SP", "FP", "LR"]
34 srcdst_lett = "X"
35 src_lett = "S"
36 dst_lett = "D"
793958c9
TS
37 retstr = ""
38 mapdict = {}
39 for reg in ordered_implregs:
40 reg_rd = 0
41 reg_wr = 0
5bb322e2
ML
42 if ("A_IMPLICIT_WRITES_" + reg) in hex_common.attribdict[tag]:
43 reg_wr = 1
793958c9
TS
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)
5bb322e2
ML
56 return retstr, mapdict
57
793958c9
TS
58
59def calculate_regid_letters(tag):
5bb322e2 60 retstr, mapdict = calculate_regid_reg(tag)
793958c9
TS
61 return retstr
62
5bb322e2 63
793958c9 64def strip_reg_prefix(x):
5bb322e2
ML
65 y = x.replace("UREG.", "")
66 y = y.replace("MREG.", "")
67 return y.replace("GREG.", "")
68
793958c9
TS
69
70def main():
71 hex_common.read_semantics_file(sys.argv[1])
72 hex_common.read_attribs_file(sys.argv[2])
3608c241 73 tagregs = hex_common.get_tagregs(full=True)
793958c9
TS
74 tagimms = hex_common.get_tagimms()
75
5bb322e2 76 with open(sys.argv[3], "w") as f:
793958c9
TS
77 for tag in hex_common.tags:
78 regs = tagregs[tag]
79 rregs = []
80 wregs = []
81 regids = ""
3608c241 82 for regtype, regid, _, numregs in regs:
793958c9 83 if hex_common.is_read(regid):
5bb322e2
ML
84 if regid[0] not in regids:
85 regids += regid[0]
86 rregs.append(regtype + regid + numregs)
793958c9 87 if hex_common.is_written(regid):
5bb322e2
ML
88 wregs.append(regtype + regid + numregs)
89 if regid[0] not in regids:
90 regids += regid[0]
793958c9 91 for attrib in hex_common.attribdict[tag]:
5bb322e2
ML
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"]))
793958c9 96 regids += calculate_regid_letters(tag)
5bb322e2
ML
97 f.write(
98 f'REGINFO({tag},"{regids}",\t/*RD:*/\t"{",".join(rregs)}",'
99 f'\t/*WR:*/\t"{",".join(wregs)}")\n'
100 )
793958c9
TS
101
102 for tag in hex_common.tags:
103 imms = tagimms[tag]
5bb322e2 104 f.write(f"IMMINFO({tag}")
793958c9 105 if not imms:
5bb322e2
ML
106 f.write(""",'u',0,0,'U',0,0""")
107 for sign, size, shamt in imms:
108 if sign == "r":
109 sign = "s"
793958c9
TS
110 if not shamt:
111 shamt = "0"
5bb322e2 112 f.write(f""",'{sign}',{size},{shamt}""")
793958c9
TS
113 if len(imms) == 1:
114 if sign.isupper():
5bb322e2 115 myu = "u"
793958c9 116 else:
5bb322e2
ML
117 myu = "U"
118 f.write(f""",'{myu}',0,0""")
119 f.write(")\n")
120
793958c9
TS
121
122if __name__ == "__main__":
123 main()