Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
#!/usr/bin/env python
2
 
3
# (C) Copyright IBM Corporation 2004, 2005
4
# (C) Copyright Apple Inc. 2011
5
# All Rights Reserved.
6
#
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:
13
#
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
16
# Software.
17
#
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
24
# IN THE SOFTWARE.
25
#
26
# Authors:
27
#    Jeremy Huddleston 
28
#
29
# Based on code ogiginally by:
30
#    Ian Romanick 
31
 
32
import license
33
import gl_XML, glX_XML
34
import sys, getopt
35
 
36
header = """/* GLXEXT is the define used in the xserver when the GLX extension is being
37
 * built.  Hijack this to determine whether this file is being built for the
38
 * server or the client.
39
 */
40
#ifdef HAVE_DIX_CONFIG_H
41
#include 
42
#endif
43
 
44
#if (defined(GLXEXT) && defined(HAVE_BACKTRACE)) \\
45
	|| (!defined(GLXEXT) && defined(DEBUG) && !defined(_WIN32_WCE) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__OpenBSD__))
46
#define USE_BACKTRACE
47
#endif
48
 
49
#ifdef USE_BACKTRACE
50
#include 
51
#endif
52
 
53
#include 
54
#include 
55
#include 
56
 
57
#include "main/glheader.h"
58
 
59
#include "glapi.h"
60
#include "glapitable.h"
61
 
62
#ifdef GLXEXT
63
#include "os.h"
64
#endif
65
 
66
static void
67
__glapi_gentable_NoOp(void) {
68
    const char *fstr = "Unknown";
69
 
70
    /* Silence potential GCC warning for some #ifdef paths.
71
     */
72
    (void) fstr;
73
#if defined(USE_BACKTRACE)
74
#if !defined(GLXEXT)
75
    if (getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
76
#endif
77
    {
78
        void *frames[2];
79
 
80
        if(backtrace(frames, 2) == 2) {
81
            Dl_info info;
82
            dladdr(frames[1], &info);
83
            if(info.dli_sname)
84
                fstr = info.dli_sname;
85
        }
86
 
87
#if !defined(GLXEXT)
88
        fprintf(stderr, "Call to unimplemented API: %s\\n", fstr);
89
#endif
90
    }
91
#endif
92
#if defined(GLXEXT)
93
    LogMessage(X_ERROR, "GLX: Call to unimplemented API: %s\\n", fstr);
94
#endif
95
}
96
 
97
static void
98
__glapi_gentable_set_remaining_noop(struct _glapi_table *disp) {
99
    GLuint entries = _glapi_get_dispatch_table_size();
100
    void **dispatch = (void **) disp;
101
    int i;
102
 
103
    /* ISO C is annoying sometimes */
104
    union {_glapi_proc p; void *v;} p;
105
    p.p = __glapi_gentable_NoOp;
106
 
107
    for(i=0; i < entries; i++)
108
        if(dispatch[i] == NULL)
109
            dispatch[i] = p.v;
110
}
111
 
112
struct _glapi_table *
113
_glapi_create_table_from_handle(void *handle, const char *symbol_prefix) {
114
    struct _glapi_table *disp = calloc(1, sizeof(struct _glapi_table));
115
    char symboln[512];
116
 
117
    if(!disp)
118
        return NULL;
119
 
120
    if(symbol_prefix == NULL)
121
        symbol_prefix = "";
122
"""
123
 
124
footer = """
125
    __glapi_gentable_set_remaining_noop(disp);
126
 
127
    return disp;
128
}
129
"""
130
 
131
body_template = """
132
    if(!disp->%(name)s) {
133
        void ** procp = (void **) &disp->%(name)s;
134
        snprintf(symboln, sizeof(symboln), "%%s%(entry_point)s", symbol_prefix);
135
        *procp = dlsym(handle, symboln);
136
    }
137
"""
138
 
139
class PrintCode(gl_XML.gl_print_base):
140
 
141
    def __init__(self):
142
        gl_XML.gl_print_base.__init__(self)
143
 
144
        self.name = "gl_gen_table.py (from Mesa)"
145
        self.license = license.bsd_license_template % ( \
146
"""Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
147
(C) Copyright IBM Corporation 2004, 2005
148
(C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM")
149
 
150
        return
151
 
152
 
153
    def get_stack_size(self, f):
154
        size = 0
155
        for p in f.parameterIterator():
156
            if p.is_padding:
157
                continue
158
 
159
            size += p.get_stack_size()
160
 
161
        return size
162
 
163
 
164
    def printRealHeader(self):
165
        print header
166
        return
167
 
168
 
169
    def printRealFooter(self):
170
        print footer
171
        return
172
 
173
 
174
    def printBody(self, api):
175
        for f in api.functionIterateByOffset():
176
            for entry_point in f.entry_points:
177
                vars = { 'entry_point' : entry_point,
178
                         'name' : f.name }
179
 
180
                print body_template % vars
181
        return
182
 
183
def show_usage():
184
    print "Usage: %s [-f input_file_name]" % sys.argv[0]
185
    sys.exit(1)
186
 
187
if __name__ == '__main__':
188
    file_name = "gl_API.xml"
189
 
190
    try:
191
        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
192
    except Exception,e:
193
        show_usage()
194
 
195
    for (arg,val) in args:
196
        if arg == "-f":
197
            file_name = val
198
 
199
    printer = PrintCode()
200
 
201
    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
202
    printer.Print(api)