Debian Codegraph @

src/imagination/pco/pco_info.c.py

raw
1 # Copyright © 2024 Imagination Technologies Ltd.
2 # SPDX-License-Identifier: MIT
3
4 from mako.template import Template, exceptions
5 from pco_ops import *
6 from pco_map import *
7
8 template = """/*
9 * Copyright © 2024 Imagination Technologies Ltd.
10 *
11 * SPDX-License-Identifier: MIT
12 */
13
14 /**
15 * \\file pco_info.c
16 *
17 * \\brief PCO info structures.
18 */
19
20 #include "pco_common.h"
21 #include "pco_internal.h"
22 #include "pco_isa.h"
23 #include "pco_ops.h"
24
25 const struct pco_op_info pco_op_info[_PCO_OP_COUNT] = {
26 % for op in ops.values():
27 [${op.cname.upper()}] = {
28 .str = "${op.name}",
29 .num_dests = ${op.num_dests},
30 .num_srcs = ${op.num_srcs},
31 .mods = ${op.cop_mods},
32 .mod_map = {
33 % for mod, index in op.op_mod_map.items():
34 [${mod}] = ${index},
35 % endfor
36 },
37 .dest_mods = {
38 % for index, cdest_mods in op.cdest_mods.items():
39 [${index}] = ${cdest_mods},
40 % endfor
41 },
42 .src_mods = {
43 % for index, csrc_mods in op.csrc_mods.items():
44 [${index}] = ${csrc_mods},
45 % endfor
46 },
47 .type = PCO_OP_TYPE_${op.op_type.upper()},
48 .has_target_cf_node = ${str(op.has_target_cf_node).lower()},
49 % if op.bname in group_maps:
50 .dest_intrn_map = {
51 % for index, val in group_maps[op.bname].dest_intrn_map:
52 [${index}] = ${val},
53 % endfor
54 },
55 .src_intrn_map = {
56 % for index, val in group_maps[op.bname].src_intrn_map:
57 [${index}] = ${val},
58 % endfor
59 },
60 % endif
61 #ifndef NDEBUG
62 % if op.bname in encode_maps:
63 .grp_dest_maps = {
64 % for phase, dests, _ in encode_maps[op.bname].op_ref_maps:
65 [${phase}] = {
66 % for dest in dests:
67 [${loop.index}] = ${dest},
68 % endfor
69 },
70 % endfor
71 },
72 .grp_src_maps = {
73 % for phase, _, srcs in encode_maps[op.bname].op_ref_maps:
74 [${phase}] = {
75 % for src in srcs:
76 [${loop.index}] = ${src},
77 % endfor
78 },
79 % endfor
80 },
81 % endif
82 #endif /* NDEBUG */
83 },
84 % endfor
85 };
86
87 const struct pco_op_mod_info pco_op_mod_info[_PCO_OP_MOD_COUNT] = {
88 % for name, op_mod in op_mods.items():
89 [${op_mod.cname}] = {
90 .print_early = ${str(op_mod.t.print_early).lower()},
91 .type = ${op_mod.ctype},
92 % if op_mod.t.base_type == BaseType.enum:
93 .is_bitset = ${str(op_mod.t.enum.is_bitset).lower()},
94 .strs = (const char * []){
95 % for elem in op_mod.t.enum.elems.values():
96 [${elem.cname}] = "${elem.string}",
97 % endfor
98 },
99 % else:
100 .str = "${name}",
101 % endif
102 % if op_mod.t.nzdefault is not None:
103 .nzdefault = ${op_mod.t.nzdefault},
104 % endif
105 },
106 % endfor
107 };
108
109 const struct pco_ref_mod_info pco_ref_mod_info[_PCO_REF_MOD_COUNT] = {
110 % for name, ref_mod in ref_mods.items():
111 [${ref_mod.cname}] = {
112 .type = ${ref_mod.ctype},
113 % if ref_mod.t.base_type == BaseType.enum:
114 .is_bitset = ${str(ref_mod.t.enum.is_bitset).lower()},
115 .strs = (const char * []){
116 % for elem in ref_mod.t.enum.elems.values():
117 [${elem.cname}] = "${elem.string}",
118 % endfor
119 },
120 % else:
121 .str = "${name}",
122 % endif
123 },
124 % endfor
125 };"""
126
127 def main():
128 try:
129 print(Template(template).render(BaseType=BaseType, ops=ops, op_mods=op_mods, ref_mods=ref_mods, group_maps=group_maps, encode_maps=encode_maps))
130 except:
131 raise Exception(exceptions.text_error_template().render())
132
133 if __name__ == '__main__':
134 main()