xref: /aosp_15_r20/external/OpenCL-ICD-Loader/scripts/gen_print_layer.py (revision 1cddb830dba8aa7c1cc1039338e56b3b9fa24952)
1#!/usr/bin/python3
2
3# Copyright (c) 2020 The Khronos Group Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import gen
18from mako.template import Template
19from mako.exceptions import RichTraceback
20
21if __name__ == "__main__":
22    args = gen.parse_args()
23    spec = gen.load_spec(args)
24    apisigs = gen.get_apisigs(spec)
25    (coreapis, extapis) = gen.get_apis(spec, apisigs)
26
27    try:
28        # Create the layer cpp file from the API dictionary:
29        test = open(args.directory + '/icd_print_layer_generated.c', 'wb')
30        icd_layer_generated_template = Template(filename='icd_print_layer_generated.c.mako')
31        test.write(
32          icd_layer_generated_template.render_unicode(
33              spec=spec,
34              apisigs=apisigs,
35              coreapis=coreapis,
36              extapis=extapis).
37          encode('utf-8', 'replace'))
38    except:
39        traceback = RichTraceback()
40        for (filename, lineno, function, line) in traceback.traceback:
41            print('%s(%s) : error in %s' % (filename, lineno, function))
42            print('    ', line)
43        print('%s: %s' % (str(traceback.error.__class__.__name__), traceback.error))
44