Path: blob/21.2-virgl/src/compiler/nir/nir_intrinsics_c.py
4545 views
from functools import reduce1import operator23template = """\4/* Copyright (C) 2018 Red Hat5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice (including the next14* paragraph) shall be included in all copies or substantial portions of the15* Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL20* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS23* IN THE SOFTWARE.24*/2526#include "nir.h"2728const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = {29% for name, opcode in sorted(INTR_OPCODES.items()):30{31.name = "${name}",32.num_srcs = ${opcode.num_srcs},33% if opcode.src_components:34.src_components = {35${", ".join(str(comp) for comp in opcode.src_components)}36},37% endif38.has_dest = ${"true" if opcode.has_dest else "false"},39.dest_components = ${max(opcode.dest_components, 0)},40.dest_bit_sizes = ${hex(reduce(operator.or_, opcode.bit_sizes, 0))},41.bit_size_src = ${opcode.bit_size_src},42.num_indices = ${opcode.num_indices},43% if opcode.indices:44.indices = {45% for i in range(len(opcode.indices)):46NIR_INTRINSIC_${opcode.indices[i].name.upper()},47% endfor48},49.index_map = {50% for i in range(len(opcode.indices)):51[NIR_INTRINSIC_${opcode.indices[i].name.upper()}] = ${i + 1},52% endfor53},54% endif55.flags = ${"0" if len(opcode.flags) == 0 else " | ".join(opcode.flags)},56},57% endfor58};5960const char *nir_intrinsic_index_names[NIR_INTRINSIC_NUM_INDEX_FLAGS] = {61% for index in INTR_INDICES:62"${index.name}",63% endfor64};65"""6667from nir_intrinsics import INTR_OPCODES, INTR_INDICES68from mako.template import Template69import argparse70import os7172def main():73parser = argparse.ArgumentParser()74parser.add_argument('--outdir', required=True,75help='Directory to put the generated files in')7677args = parser.parse_args()7879path = os.path.join(args.outdir, 'nir_intrinsics.c')80with open(path, 'wb') as f:81f.write(Template(template, output_encoding='utf-8').render(82INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES,83reduce=reduce, operator=operator))8485if __name__ == '__main__':86main()87888990