• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2COPYRIGHT = """\
3/*
4 * Copyright 2024 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26"""
27
28import argparse
29import os
30import sys
31
32from mako.template import Template
33from mako import exceptions
34
35sys.path.append(f"{os.path.dirname(sys.argv[0])}/../dev")
36import intel_device_info
37
38template = COPYRIGHT + """
39
40/* DO NOT EDIT - This file generated automatically by intel_device_serialize_c.py script */
41
42#include "dev/intel_device_info.h"
43#include "brw_compiler.h"
44#define SHA_UPDATE_FIELD(field)     _mesa_sha1_update(ctx, &devinfo->field, sizeof(devinfo->field))
45
46void
47brw_device_sha1_update(struct mesa_sha1 *ctx,
48                       const struct intel_device_info *devinfo) {
49% for member in compiler_fields:
50   SHA_UPDATE_FIELD(${member.name});
51% endfor
52}
53
54#undef SHA_UPDATE_FIELD
55
56"""
57
58def main():
59    """print intel_device_serialize.c at the specified path"""
60    parser = argparse.ArgumentParser()
61    parser.add_argument('--outdir', required=True,
62                        help='Directory to put the generated files in')
63    args = parser.parse_args()
64    path = os.path.join(args.outdir, 'brw_device_sha1_gen.c')
65    device_members = intel_device_info.TYPES_BY_NAME["intel_device_info"].members
66    compiler_fields = [field for field in device_members if field.compiler_field]
67    with open(path, 'w', encoding='utf-8') as f:
68        try:
69            f.write(Template(template).render(compiler_fields=compiler_fields))
70        except:
71            print(exceptions.text_error_template().render(compiler_fields=compiler_fields))
72
73if __name__ == "__main__":
74    main()
75