Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / target / hexagon / gen_helper_protos.py
blobc82b0f54e4d8e10e85cfba6c8fa6979c0ecf54da
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
26 ## Generate the DEF_HELPER prototype for an instruction
27 ## For A2_add: Rd32=add(Rs32,Rt32)
28 ## We produce:
29 ## DEF_HELPER_3(A2_add, s32, env, s32, s32)
31 def gen_helper_prototype(f, tag, tagregs, tagimms):
32 regs = tagregs[tag]
33 imms = tagimms[tag]
35 declared = []
36 ret_type = hex_common.helper_ret_type(tag, regs).proto_arg
37 declared.append(ret_type)
39 for arg in hex_common.helper_args(tag, regs, imms):
40 declared.append(arg.proto_arg)
42 arguments = ", ".join(declared)
43 f.write(f"DEF_HELPER_{len(declared) - 1}({tag}, {arguments})\n")
46 def main():
47 hex_common.read_semantics_file(sys.argv[1])
48 hex_common.read_attribs_file(sys.argv[2])
49 hex_common.read_overrides_file(sys.argv[3])
50 hex_common.read_overrides_file(sys.argv[4])
51 ## Whether or not idef-parser is enabled is
52 ## determined by the number of arguments to
53 ## this script:
55 ## 5 args. -> not enabled,
56 ## 6 args. -> idef-parser enabled.
58 ## The 6:th arg. then holds a list of the successfully
59 ## parsed instructions.
60 is_idef_parser_enabled = len(sys.argv) > 6
61 if is_idef_parser_enabled:
62 hex_common.read_idef_parser_enabled_file(sys.argv[5])
63 hex_common.calculate_attribs()
64 hex_common.init_registers()
65 tagregs = hex_common.get_tagregs()
66 tagimms = hex_common.get_tagimms()
68 output_file = sys.argv[-1]
69 with open(output_file, "w") as f:
70 for tag in hex_common.tags:
71 ## Skip the priv instructions
72 if "A_PRIV" in hex_common.attribdict[tag]:
73 continue
74 ## Skip the guest instructions
75 if "A_GUEST" in hex_common.attribdict[tag]:
76 continue
77 ## Skip the diag instructions
78 if tag == "Y6_diag":
79 continue
80 if tag == "Y6_diag0":
81 continue
82 if tag == "Y6_diag1":
83 continue
85 if hex_common.skip_qemu_helper(tag):
86 continue
87 if hex_common.is_idef_parser_enabled(tag):
88 continue
90 gen_helper_prototype(f, tag, tagregs, tagimms)
93 if __name__ == "__main__":
94 main()