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