2011-06-10 00:59:49 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# (C) Copyright IBM Corporation 2004, 2005
|
|
|
|
# (C) Copyright Apple Inc. 2011
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
# copy of this software and associated documentation files (the "Software"),
|
|
|
|
# to deal in the Software without restriction, including without limitation
|
|
|
|
# on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
# license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
# the Software is furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice (including the next
|
|
|
|
# paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
# Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
# IN THE SOFTWARE.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Jeremy Huddleston <jeremyhu@apple.com>
|
|
|
|
#
|
|
|
|
# Based on code ogiginally by:
|
|
|
|
# Ian Romanick <idr@us.ibm.com>
|
|
|
|
|
|
|
|
import license
|
|
|
|
import gl_XML, glX_XML
|
|
|
|
import sys, getopt
|
|
|
|
|
2011-12-05 23:24:49 +00:00
|
|
|
header = """/* GLXEXT is the define used in the xserver when the GLX extension is being
|
|
|
|
* built. Hijack this to determine whether this file is being built for the
|
|
|
|
* server or the client.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(GLXEXT) && defined(HAVE_BACKTRACE)) \\
|
2014-09-22 06:57:10 +01:00
|
|
|
|| (!defined(GLXEXT) && defined(DEBUG) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__))
|
2011-12-05 23:24:49 +00:00
|
|
|
#define USE_BACKTRACE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_BACKTRACE
|
2011-06-14 20:34:49 +01:00
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2013-10-11 02:13:25 +01:00
|
|
|
#ifndef _WIN32
|
2011-06-10 00:59:49 +01:00
|
|
|
#include <dlfcn.h>
|
2013-10-11 02:13:25 +01:00
|
|
|
#endif
|
2011-06-10 00:59:49 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-10-23 22:06:32 +01:00
|
|
|
#include "main/glheader.h"
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
#include "glapi.h"
|
|
|
|
#include "glapitable.h"
|
|
|
|
|
2011-12-05 23:24:49 +00:00
|
|
|
#ifdef GLXEXT
|
|
|
|
#include "os.h"
|
|
|
|
#endif
|
|
|
|
|
2011-06-14 20:34:49 +01:00
|
|
|
static void
|
|
|
|
__glapi_gentable_NoOp(void) {
|
2011-12-05 23:24:49 +00:00
|
|
|
const char *fstr = "Unknown";
|
|
|
|
|
|
|
|
/* Silence potential GCC warning for some #ifdef paths.
|
|
|
|
*/
|
|
|
|
(void) fstr;
|
|
|
|
#if defined(USE_BACKTRACE)
|
|
|
|
#if !defined(GLXEXT)
|
|
|
|
if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
|
|
|
|
#endif
|
|
|
|
{
|
2011-06-14 20:34:49 +01:00
|
|
|
void *frames[2];
|
|
|
|
|
|
|
|
if(backtrace(frames, 2) == 2) {
|
|
|
|
Dl_info info;
|
|
|
|
dladdr(frames[1], &info);
|
|
|
|
if(info.dli_sname)
|
|
|
|
fstr = info.dli_sname;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:24:49 +00:00
|
|
|
#if !defined(GLXEXT)
|
2011-06-14 20:34:49 +01:00
|
|
|
fprintf(stderr, "Call to unimplemented API: %s\\n", fstr);
|
2011-12-05 23:24:49 +00:00
|
|
|
#endif
|
2011-06-14 20:34:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
2011-12-05 23:24:49 +00:00
|
|
|
#if defined(GLXEXT)
|
|
|
|
LogMessage(X_ERROR, "GLX: Call to unimplemented API: %s\\n", fstr);
|
|
|
|
#endif
|
2011-06-14 20:34:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
|
|
|
|
GLuint entries = _glapi_get_dispatch_table_size();
|
|
|
|
void **dispatch = (void **) disp;
|
2014-08-13 21:47:28 +01:00
|
|
|
unsigned i;
|
2011-06-14 20:34:49 +01:00
|
|
|
|
|
|
|
/* ISO C is annoying sometimes */
|
|
|
|
union {_glapi_proc p; void *v;} p;
|
|
|
|
p.p = __glapi_gentable_NoOp;
|
|
|
|
|
|
|
|
for(i=0; i < entries; i++)
|
|
|
|
if(dispatch[i] == NULL)
|
|
|
|
dispatch[i] = p.v;
|
|
|
|
}
|
|
|
|
|
2011-06-10 00:59:49 +01:00
|
|
|
struct _glapi_table *
|
|
|
|
_glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
|
2014-09-03 22:18:18 +01:00
|
|
|
struct _glapi_table *disp = calloc(_glapi_get_dispatch_table_size(), sizeof(_glapi_proc));
|
2011-06-10 00:59:49 +01:00
|
|
|
char symboln[512];
|
|
|
|
|
|
|
|
if(!disp)
|
2011-06-13 19:35:18 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(symbol_prefix == NULL)
|
|
|
|
symbol_prefix = "";
|
2011-06-10 00:59:49 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
footer = """
|
2011-06-14 20:34:49 +01:00
|
|
|
__glapi_gentable_set_remaining_noop(disp);
|
|
|
|
|
2011-06-10 00:59:49 +01:00
|
|
|
return disp;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
body_template = """
|
|
|
|
if(!disp->%(name)s) {
|
2011-06-14 20:34:49 +01:00
|
|
|
void ** procp = (void **) &disp->%(name)s;
|
2011-06-13 19:35:18 +01:00
|
|
|
snprintf(symboln, sizeof(symboln), "%%s%(entry_point)s", symbol_prefix);
|
2014-06-10 02:07:07 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
*procp = GetProcAddress(handle, symboln);
|
|
|
|
#else
|
2011-06-14 20:34:49 +01:00
|
|
|
*procp = dlsym(handle, symboln);
|
2014-06-10 02:07:07 +01:00
|
|
|
#endif
|
2011-06-10 00:59:49 +01:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
class PrintCode(gl_XML.gl_print_base):
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
def __init__(self):
|
|
|
|
gl_XML.gl_print_base.__init__(self)
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2014-08-13 21:47:28 +01:00
|
|
|
self.name = "gl_gentable.py (from Mesa)"
|
2012-10-10 15:20:57 +01:00
|
|
|
self.license = license.bsd_license_template % ( \
|
2011-06-10 00:59:49 +01:00
|
|
|
"""Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
|
|
|
|
(C) Copyright IBM Corporation 2004, 2005
|
|
|
|
(C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM")
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
return
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
def get_stack_size(self, f):
|
|
|
|
size = 0
|
|
|
|
for p in f.parameterIterator():
|
|
|
|
if p.is_padding:
|
|
|
|
continue
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
size += p.get_stack_size()
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
return size
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
def printRealHeader(self):
|
|
|
|
print header
|
|
|
|
return
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
def printRealFooter(self):
|
|
|
|
print footer
|
|
|
|
return
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
def printBody(self, api):
|
|
|
|
for f in api.functionIterateByOffset():
|
|
|
|
for entry_point in f.entry_points:
|
|
|
|
vars = { 'entry_point' : entry_point,
|
|
|
|
'name' : f.name }
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
print body_template % vars
|
|
|
|
return
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
def show_usage():
|
2012-10-10 15:20:57 +01:00
|
|
|
print "Usage: %s [-f input_file_name]" % sys.argv[0]
|
|
|
|
sys.exit(1)
|
2011-06-10 00:59:49 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-10-10 15:20:57 +01:00
|
|
|
file_name = "gl_API.xml"
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
try:
|
|
|
|
(args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
|
|
|
|
except Exception,e:
|
|
|
|
show_usage()
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
for (arg,val) in args:
|
|
|
|
if arg == "-f":
|
|
|
|
file_name = val
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
printer = PrintCode()
|
2011-06-10 00:59:49 +01:00
|
|
|
|
2012-10-10 15:20:57 +01:00
|
|
|
api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
|
|
|
|
printer.Print(api)
|