3 # (C) Copyright IBM Corporation 2004, 2005
4 # (C) Copyright Apple Inc. 2011
5 # Copyright (C) 2015 Intel Corporation
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the "Software"),
10 # to deal in the Software without restriction, including without limitation
11 # on the rights to use, copy, modify, merge, publish, distribute, sub
12 # license, and/or sell copies of the Software, and to permit persons to whom
13 # the Software is furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice (including the next
16 # paragraph) shall be included in all copies or substantial portions of the
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 # Jeremy Huddleston <jeremyhu@apple.com>
30 # Based on code ogiginally by:
31 # Ian Romanick <idr@us.ibm.com>
36 import gl_XML
, glX_XML
38 header
= """/* GLXEXT is the define used in the xserver when the GLX extension is being
39 * built. Hijack this to determine whether this file is being built for the
40 * server or the client.
42 #ifdef HAVE_DIX_CONFIG_H
43 #include <dix-config.h>
46 #if (defined(GLXEXT) && defined(HAVE_BACKTRACE)) \\
47 || (!defined(GLXEXT) && defined(DEBUG) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__))
61 #include "main/glheader.h"
64 #include "glapitable.h"
71 __glapi_gentable_NoOp(void) {
72 const char *fstr = "Unknown";
74 /* Silence potential GCC warning for some #ifdef paths.
77 #if defined(USE_BACKTRACE)
79 if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
84 if(backtrace(frames, 2) == 2) {
86 dladdr(frames[1], &info);
88 fstr = info.dli_sname;
92 fprintf(stderr, "Call to unimplemented API: %s\\n", fstr);
97 LogMessage(X_ERROR, "GLX: Call to unimplemented API: %s\\n", fstr);
102 __glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
103 GLuint entries = _glapi_get_dispatch_table_size();
104 void **dispatch = (void **) disp;
107 /* ISO C is annoying sometimes */
108 union {_glapi_proc p; void *v;} p;
109 p.p = __glapi_gentable_NoOp;
111 for(i=0; i < entries; i++)
112 if(dispatch[i] == NULL)
116 struct _glapi_table *
117 _glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
118 struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(_glapi_proc));
124 if(symbol_prefix == NULL)
129 __glapi_gentable_set_remaining_noop(disp);
136 if(!disp->%(name)s) {
137 void ** procp = (void **) &disp->%(name)s;
138 snprintf(symboln, sizeof(symboln), "%%s%(entry_point)s", symbol_prefix);
140 *procp = GetProcAddress(handle, symboln);
142 *procp = dlsym(handle, symboln);
147 class PrintCode(gl_XML
.gl_print_base
):
150 gl_XML
.gl_print_base
.__init
__(self
)
152 self
.name
= "gl_gentable.py (from Mesa)"
153 self
.license
= license
.bsd_license_template
% ( \
154 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
155 (C) Copyright IBM Corporation 2004, 2005
156 (C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM")
161 def get_stack_size(self
, f
):
163 for p
in f
.parameterIterator():
167 size
+= p
.get_stack_size()
172 def printRealHeader(self
):
177 def printRealFooter(self
):
182 def printBody(self
, api
):
183 for f
in api
.functionIterateByOffset():
184 for entry_point
in f
.entry_points
:
185 vars = { 'entry_point' : entry_point
,
188 print body_template
% vars
193 """Parse arguments and return a namespace object."""
194 parser
= argparse
.ArgumentParser()
195 parser
.add_argument('-f',
197 default
='gl_API.xml',
198 help='An XML file description of an API')
200 return parser
.parse_args()
203 if __name__
== '__main__':
206 printer
= PrintCode()
208 api
= gl_XML
.parse_GL_API(args
.filename
, glX_XML
.glx_item_factory())