Merge tag 'pull-riscv-to-apply-20240806-2' of https://github.com/alistair23/qemu...
[qemu/kevin.git] / target / hexagon / gen_analyze_funcs.py
blob54bac197240173283e5ab69752e9a296b74bd1bb
1 #!/usr/bin/env python3
3 ##
4 ## Copyright(c) 2022-2024 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 code to analyze the instruction
28 ## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;}
29 ## We produce:
30 ## static void analyze_A2_add(DisasContext *ctx)
31 ## {
32 ## Insn *insn G_GNUC_UNUSED = ctx->insn;
33 ## const int RdN = insn->regno[0];
34 ## ctx_log_reg_write(ctx, RdN, false);
35 ## const int RsN = insn->regno[1];
36 ## ctx_log_reg_read(ctx, RsN);
37 ## const int RtN = insn->regno[2];
38 ## ctx_log_reg_read(ctx, RtN);
39 ## }
41 def gen_analyze_func(f, tag, regs, imms):
42 f.write(f"static void analyze_{tag}(DisasContext *ctx)\n")
43 f.write("{\n")
45 f.write(" Insn *insn G_GNUC_UNUSED = ctx->insn;\n")
46 if (hex_common.is_hvx_insn(tag)):
47 if hex_common.has_hvx_helper(tag):
48 f.write(
49 " const bool G_GNUC_UNUSED insn_has_hvx_helper = true;\n"
51 f.write(" ctx_start_hvx_insn(ctx);\n")
52 else:
53 f.write(
54 " const bool G_GNUC_UNUSED insn_has_hvx_helper = false;\n"
57 ## Declare all the registers
58 for regno, register in enumerate(regs):
59 reg_type, reg_id = register
60 reg = hex_common.get_register(tag, reg_type, reg_id)
61 reg.decl_reg_num(f, regno)
63 ## Analyze the register reads
64 for regno, register in enumerate(regs):
65 reg_type, reg_id = register
66 reg = hex_common.get_register(tag, reg_type, reg_id)
67 if reg.is_read():
68 reg.analyze_read(f, regno)
70 ## Analyze the register writes
71 for regno, register in enumerate(regs):
72 reg_type, reg_id = register
73 reg = hex_common.get_register(tag, reg_type, reg_id)
74 if reg.is_written():
75 reg.analyze_write(f, tag, regno)
77 f.write("}\n\n")
80 def main():
81 hex_common.read_common_files()
82 tagregs = hex_common.get_tagregs()
83 tagimms = hex_common.get_tagimms()
85 with open(sys.argv[-1], "w") as f:
86 f.write("#ifndef HEXAGON_ANALYZE_FUNCS_C_INC\n")
87 f.write("#define HEXAGON_ANALYZE_FUNCS_C_INC\n\n")
89 for tag in hex_common.tags:
90 gen_analyze_func(f, tag, tagregs[tag], tagimms[tag])
92 f.write("#endif /* HEXAGON_ANALYZE_FUNCS_C_INC */\n")
95 if __name__ == "__main__":
96 main()