1bf215546Sopenharmony_ci
2bf215546Sopenharmony_citemplate = """\
3bf215546Sopenharmony_ci/* Copyright (C) 2018 Red Hat
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22bf215546Sopenharmony_ci * IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef _NIR_INTRINSICS_
26bf215546Sopenharmony_ci#define _NIR_INTRINSICS_
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci<% opcode_names = sorted(INTR_OPCODES) %>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_citypedef enum {
31bf215546Sopenharmony_ci% for name in opcode_names:
32bf215546Sopenharmony_ci   nir_intrinsic_${name},
33bf215546Sopenharmony_ci% endfor
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci   nir_last_intrinsic = nir_intrinsic_${opcode_names[-1]},
36bf215546Sopenharmony_ci   nir_num_intrinsics = nir_last_intrinsic + 1
37bf215546Sopenharmony_ci} nir_intrinsic_op;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_citypedef enum {
40bf215546Sopenharmony_ci% for index in INTR_INDICES:
41bf215546Sopenharmony_ci   NIR_INTRINSIC_${index.name.upper()},
42bf215546Sopenharmony_ci% endfor
43bf215546Sopenharmony_ci   NIR_INTRINSIC_NUM_INDEX_FLAGS,
44bf215546Sopenharmony_ci} nir_intrinsic_index_flag;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ciextern const char *nir_intrinsic_index_names[NIR_INTRINSIC_NUM_INDEX_FLAGS];
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci#endif /* _NIR_INTRINSICS_ */"""
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cifrom nir_intrinsics import INTR_OPCODES, INTR_INDICES
51bf215546Sopenharmony_cifrom mako.template import Template
52bf215546Sopenharmony_ciimport argparse
53bf215546Sopenharmony_ciimport os
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_cidef main():
57bf215546Sopenharmony_ci    parser = argparse.ArgumentParser()
58bf215546Sopenharmony_ci    parser.add_argument('--outdir', required=True,
59bf215546Sopenharmony_ci                        help='Directory to put the generated files in')
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci    args = parser.parse_args()
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci    path = os.path.join(args.outdir, 'nir_intrinsics.h')
64bf215546Sopenharmony_ci    with open(path, 'w') as f:
65bf215546Sopenharmony_ci        f.write(Template(template).render(INTR_OPCODES=INTR_OPCODES, INTR_INDICES=INTR_INDICES))
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ciif __name__ == '__main__':
68bf215546Sopenharmony_ci    main()
69bf215546Sopenharmony_ci
70