1bf215546Sopenharmony_ci
2bf215546Sopenharmony_ci# Copyright (C) 2012 Intel Corporation
3bf215546Sopenharmony_ci#
4bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci#
11bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci# Software.
14bf215546Sopenharmony_ci#
15bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci# IN THE SOFTWARE.
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ciimport getopt
24bf215546Sopenharmony_ciimport gl_XML
25bf215546Sopenharmony_ciimport license
26bf215546Sopenharmony_ciimport marshal_XML
27bf215546Sopenharmony_ciimport sys
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ciheader = """
31bf215546Sopenharmony_ci#ifndef MARSHAL_GENERATED_H
32bf215546Sopenharmony_ci#define MARSHAL_GENERATED_H
33bf215546Sopenharmony_ci"""
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_cifooter = """
36bf215546Sopenharmony_ci#endif /* MARSHAL_GENERATED_H */
37bf215546Sopenharmony_ci"""
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ciclass PrintCode(gl_XML.gl_print_base):
41bf215546Sopenharmony_ci    def __init__(self):
42bf215546Sopenharmony_ci        super(PrintCode, self).__init__()
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci        self.name = 'gl_marshal_h.py'
45bf215546Sopenharmony_ci        self.license = license.bsd_license_template % (
46bf215546Sopenharmony_ci            'Copyright (C) 2012 Intel Corporation', 'INTEL CORPORATION')
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci    def printRealHeader(self):
49bf215546Sopenharmony_ci        print(header)
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci    def printRealFooter(self):
52bf215546Sopenharmony_ci        print(footer)
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci    def printBody(self, api):
55bf215546Sopenharmony_ci        print('#include "GL/gl.h"')
56bf215546Sopenharmony_ci        print('')
57bf215546Sopenharmony_ci        print('enum marshal_dispatch_cmd_id')
58bf215546Sopenharmony_ci        print('{')
59bf215546Sopenharmony_ci        for func in api.functionIterateAll():
60bf215546Sopenharmony_ci            flavor = func.marshal_flavor()
61bf215546Sopenharmony_ci            if flavor in ('skip', 'sync'):
62bf215546Sopenharmony_ci                continue
63bf215546Sopenharmony_ci            print('   DISPATCH_CMD_{0},'.format(func.name))
64bf215546Sopenharmony_ci        print('   NUM_DISPATCH_CMD,')
65bf215546Sopenharmony_ci        print('};')
66bf215546Sopenharmony_ci        print('')
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci        for func in api.functionIterateAll():
69bf215546Sopenharmony_ci            flavor = func.marshal_flavor()
70bf215546Sopenharmony_ci            if flavor in ('custom', 'async'):
71bf215546Sopenharmony_ci                print('struct marshal_cmd_{0};'.format(func.name))
72bf215546Sopenharmony_ci                print(('uint32_t _mesa_unmarshal_{0}(struct gl_context *ctx, '
73bf215546Sopenharmony_ci                       'const struct marshal_cmd_{0} *cmd, const uint64_t *last);').format(func.name))
74bf215546Sopenharmony_ci                print('{0} GLAPIENTRY _mesa_marshal_{1}({2});'.format(func.return_type, func.name, func.get_parameter_string()))
75bf215546Sopenharmony_ci            elif flavor == 'sync':
76bf215546Sopenharmony_ci                print('{0} GLAPIENTRY _mesa_marshal_{1}({2});'.format(func.return_type, func.name, func.get_parameter_string()))
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cidef show_usage():
80bf215546Sopenharmony_ci    print('Usage: %s [-f input_file_name]' % sys.argv[0])
81bf215546Sopenharmony_ci    sys.exit(1)
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ciif __name__ == '__main__':
85bf215546Sopenharmony_ci    file_name = 'gl_API.xml'
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci    try:
88bf215546Sopenharmony_ci        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
89bf215546Sopenharmony_ci    except Exception:
90bf215546Sopenharmony_ci        show_usage()
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci    for (arg,val) in args:
93bf215546Sopenharmony_ci        if arg == '-f':
94bf215546Sopenharmony_ci            file_name = val
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci    printer = PrintCode()
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci    api = gl_XML.parse_GL_API(file_name, marshal_XML.marshal_item_factory())
99bf215546Sopenharmony_ci    printer.Print(api)
100