1template = """/* 2 * Copyright 2021 Alyssa Rosenzweig 3 * SPDX-License-Identifier: MIT 4 */ 5 6#include "agx_opcodes.h" 7 8<% 9def make_encoding(encoding): 10 if encoding is None: 11 return "{ 0 }" 12 13 return "{{ {}, {}, {} }}".format(hex(encoding.exact), encoding.length_short, int(encoding.extensible)) 14%> 15 16const struct agx_opcode_info agx_opcodes_info[AGX_NUM_OPCODES] = { 17% for opcode in opcodes: 18<% 19 op = opcodes[opcode] 20 imms = ["AGX_IMMEDIATE_" + imm.name.upper() for imm in op.imms] 21 if len(imms) == 0: 22 imms = ["0"] 23%> 24 [AGX_OPCODE_${opcode.upper()}] = { 25 "${opcode}", ${op.srcs}, ${op.dests}, ${" | ".join(imms)}, 26 ${make_encoding(op.encoding_32)}, 27 ${make_encoding(op.encoding_16)}, 28 AGX_SCHEDULE_CLASS_${op.schedule_class.upper()}, 29 ${int(op.is_float)}, 30 ${int(op.can_eliminate)}, 31 ${int(op.can_reorder)}, 32 }, 33% endfor 34}; 35""" 36 37from mako.template import Template 38from agx_opcodes import opcodes 39 40print(Template(template).render(opcodes=opcodes)) 41