9d8923cf8dbdb85b60274e450d6759852e2f653c
2 # (C) Copyright IBM Corporation 2004, 2005
3 # (C) Copyright Apple Inc. 2011
4 # Copyright (C) 2015 Intel Corporation
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # on the rights to use, copy, modify, merge, publish, distribute, sub
11 # license, and/or sell copies of the Software, and to permit persons to whom
12 # the Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice (including the next
15 # paragraph) shall be included in all copies or substantial portions of the
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 # Jeremy Huddleston <jeremyhu@apple.com>
29 # Based on code ogiginally by:
30 # Ian Romanick <idr@us.ibm.com>
32 from __future__
import print_function
37 import gl_XML
, glX_XML
39 header
= """/* GLXEXT is the define used in the xserver when the GLX extension is being
40 * built. Hijack this to determine whether this file is being built for the
41 * server or the client.
43 #ifdef HAVE_DIX_CONFIG_H
44 #include <dix-config.h>
47 #if (defined(GLXEXT) && defined(HAVE_BACKTRACE)) \\
48 || (!defined(GLXEXT) && defined(DEBUG) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__))
63 #include "main/glheader.h"
66 #include "glapitable.h"
73 __glapi_gentable_NoOp(void) {
74 const char *fstr = "Unknown";
76 /* Silence potential GCC warning for some #ifdef paths.
79 #if defined(USE_BACKTRACE)
81 if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
86 if(backtrace(frames, 2) == 2) {
88 dladdr(frames[1], &info);
90 fstr = info.dli_sname;
94 fprintf(stderr, "Call to unimplemented API: %s\\n", fstr);
99 LogMessage(X_ERROR, "GLX: Call to unimplemented API: %s\\n", fstr);
104 __glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
105 GLuint entries = _glapi_get_dispatch_table_size();
106 void **dispatch = (void **) disp;
109 /* ISO C is annoying sometimes */
110 union {_glapi_proc p; void *v;} p;
111 p.p = __glapi_gentable_NoOp;
113 for(i=0; i < entries; i++)
114 if(dispatch[i] == NULL)
121 struct _glapi_table *
122 _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
123 struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(_glapi_proc));
129 if(symbol_prefix == NULL)
132 /* Note: This code relies on _glapi_table_func_names being sorted by the
133 * entry point index of each function.
135 for (int func_index = 0; func_index < GLAPI_TABLE_COUNT; ++func_index) {
136 const char *name = _glapi_table_func_names[func_index];
137 void ** procp = &((void **)disp)[func_index];
139 snprintf(symboln, sizeof(symboln), \"%s%s\", symbol_prefix, name);
141 *procp = GetProcAddress(handle, symboln);
143 *procp = dlsym(handle, symboln);
146 __glapi_gentable_set_remaining_noop(disp);
152 _glapi_table_patch(struct _glapi_table *table, const char *name, void *wrapper)
154 for (int func_index = 0; func_index < GLAPI_TABLE_COUNT; ++func_index) {
155 if (!strcmp(_glapi_table_func_names[func_index], name)) {
156 ((void **)table)[func_index] = wrapper;
160 fprintf(stderr, "could not patch %s in dispatch table\\n", name);
166 class PrintCode(gl_XML
.gl_print_base
):
169 gl_XML
.gl_print_base
.__init
__(self
)
171 self
.name
= "gl_gentable.py (from Mesa)"
172 self
.license
= license
.bsd_license_template
% ( \
173 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
174 (C) Copyright IBM Corporation 2004, 2005
175 (C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM")
180 def get_stack_size(self
, f
):
182 for p
in f
.parameterIterator():
186 size
+= p
.get_stack_size()
191 def printRealHeader(self
):
196 def printRealFooter(self
):
201 def printBody(self
, api
):
203 # Determine how many functions have a defined offset.
205 for f
in api
.functions_by_name
.values():
209 # Build the mapping from offset to function name.
210 funcnames
= [None] * func_count
211 for f
in api
.functions_by_name
.values():
213 if not (funcnames
[f
.offset
] is None):
214 raise Exception("Function table has more than one function with same offset (offset %d, func %s)" % (f
.offset
, f
.name
))
215 funcnames
[f
.offset
] = f
.name
217 # Check that the table has no gaps. We expect a function at every offset,
218 # and the code which generates the table relies on this.
219 for i
in range(0, func_count
):
220 if funcnames
[i
] is None:
221 raise Exception("Function table has no function at offset %d" % (i
))
223 print("#define GLAPI_TABLE_COUNT %d" % func_count
)
224 print("static const char * const _glapi_table_func_names[GLAPI_TABLE_COUNT] = {")
225 for i
in range(0, func_count
):
226 print(" /* %5d */ \"%s\"," % (i
, funcnames
[i
]))
233 """Parse arguments and return a namespace object."""
234 parser
= argparse
.ArgumentParser()
235 parser
.add_argument('-f',
237 default
='gl_API.xml',
238 help='An XML file description of an API')
240 return parser
.parse_args()
247 printer
= PrintCode()
249 api
= gl_XML
.parse_GL_API(args
.filename
, glX_XML
.glx_item_factory())
253 if __name__
== '__main__':