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_ci# This script generates the file api_exec_init.c, which contains
24bf215546Sopenharmony_ci# _mesa_initialize_exec_table().  It is responsible for populating all
25bf215546Sopenharmony_ci# entries in the "exec" dispatch table that aren't dynamic.
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ciimport argparse
28bf215546Sopenharmony_ciimport collections
29bf215546Sopenharmony_ciimport license
30bf215546Sopenharmony_ciimport gl_XML
31bf215546Sopenharmony_ciimport sys
32bf215546Sopenharmony_ciimport apiexec
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ciexec_flavor_map = {
36bf215546Sopenharmony_ci    'vtxfmt': None,
37bf215546Sopenharmony_ci    'dlist': '_mesa_',
38bf215546Sopenharmony_ci    'mesa': '_mesa_',
39bf215546Sopenharmony_ci    'skip': None,
40bf215546Sopenharmony_ci    }
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ciheader = """/**
44bf215546Sopenharmony_ci * \\file api_exec_init.c
45bf215546Sopenharmony_ci * Initialize dispatch table.
46bf215546Sopenharmony_ci */
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci#include "api_exec_decl.h"
50bf215546Sopenharmony_ci#include "glapi/glapi.h"
51bf215546Sopenharmony_ci#include "main/context.h"
52bf215546Sopenharmony_ci#include "main/dispatch.h"
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci/**
56bf215546Sopenharmony_ci * Initialize a context's exec table with pointers to Mesa's supported
57bf215546Sopenharmony_ci * GL functions.
58bf215546Sopenharmony_ci *
59bf215546Sopenharmony_ci * This function depends on ctx->Version.
60bf215546Sopenharmony_ci *
61bf215546Sopenharmony_ci * \param ctx  GL context to which \c exec belongs.
62bf215546Sopenharmony_ci */
63bf215546Sopenharmony_civoid
64bf215546Sopenharmony_ci_mesa_initialize_exec_table(struct gl_context *ctx)
65bf215546Sopenharmony_ci{
66bf215546Sopenharmony_ci   struct _glapi_table *exec;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   exec = ctx->Exec;
69bf215546Sopenharmony_ci   assert(exec != NULL);
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci   assert(ctx->Version > 0);
72bf215546Sopenharmony_ci"""
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cifooter = """
76bf215546Sopenharmony_ci}
77bf215546Sopenharmony_ci"""
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ciclass PrintCode(gl_XML.gl_print_base):
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci    def __init__(self):
83bf215546Sopenharmony_ci        gl_XML.gl_print_base.__init__(self)
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci        self.name = 'api_exec_init.py'
86bf215546Sopenharmony_ci        self.license = license.bsd_license_template % (
87bf215546Sopenharmony_ci            'Copyright (C) 2012 Intel Corporation',
88bf215546Sopenharmony_ci            'Intel Corporation')
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci    def printRealHeader(self):
91bf215546Sopenharmony_ci        print(header)
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci    def printRealFooter(self):
94bf215546Sopenharmony_ci        print(footer)
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci    def printBody(self, api):
97bf215546Sopenharmony_ci        # Collect SET_* calls by the condition under which they should
98bf215546Sopenharmony_ci        # be called.
99bf215546Sopenharmony_ci        settings_by_condition = collections.defaultdict(lambda: [])
100bf215546Sopenharmony_ci        for f in api.functionIterateAll():
101bf215546Sopenharmony_ci            if f.exec_flavor not in exec_flavor_map:
102bf215546Sopenharmony_ci                raise Exception(
103bf215546Sopenharmony_ci                    'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
104bf215546Sopenharmony_ci            condition = apiexec.get_api_condition(f)
105bf215546Sopenharmony_ci            if not condition:
106bf215546Sopenharmony_ci                continue
107bf215546Sopenharmony_ci            prefix = exec_flavor_map[f.exec_flavor]
108bf215546Sopenharmony_ci            if prefix is None:
109bf215546Sopenharmony_ci                # This function is not implemented, or is dispatched
110bf215546Sopenharmony_ci                # via vtxfmt.
111bf215546Sopenharmony_ci                continue
112bf215546Sopenharmony_ci            if f.has_no_error_variant:
113bf215546Sopenharmony_ci                no_error_condition = '_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition)
114bf215546Sopenharmony_ci                error_condition = '!_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition)
115bf215546Sopenharmony_ci                settings_by_condition[no_error_condition].append(
116bf215546Sopenharmony_ci                    'SET_{0}(exec, {1}{0}_no_error);'.format(f.name, prefix, f.name))
117bf215546Sopenharmony_ci                settings_by_condition[error_condition].append(
118bf215546Sopenharmony_ci                    'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
119bf215546Sopenharmony_ci            else:
120bf215546Sopenharmony_ci                settings_by_condition[condition].append(
121bf215546Sopenharmony_ci                    'SET_{0}(exec, {1}{0});'.format(f.name, prefix, f.name))
122bf215546Sopenharmony_ci        # Print out an if statement for each unique condition, with
123bf215546Sopenharmony_ci        # the SET_* calls nested inside it.
124bf215546Sopenharmony_ci        for condition in sorted(settings_by_condition.keys()):
125bf215546Sopenharmony_ci            print('   if ({0}) {{'.format(condition))
126bf215546Sopenharmony_ci            for setting in sorted(settings_by_condition[condition]):
127bf215546Sopenharmony_ci                print('      {0}'.format(setting))
128bf215546Sopenharmony_ci            print('   }')
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ciif __name__ == '__main__':
132bf215546Sopenharmony_ci    apiexec.print_glapi_file(PrintCode())
133