glapi: Reformat python code generation scripts to use 4-space indentation.
authorPaul Berry <stereotype441@gmail.com>
Wed, 10 Oct 2012 14:20:57 +0000 (07:20 -0700)
committerPaul Berry <stereotype441@gmail.com>
Wed, 10 Oct 2012 18:19:14 +0000 (11:19 -0700)
This brings us into accordance with the official Python style guide
(http://www.python.org/dev/peps/pep-0008/#indentation).

To preserve the indentation of the c code that is generated by these
scripts, I've avoided re-indenting triple-quoted strings (unless those
strings appear to be docstrings).

Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
21 files changed:
src/mapi/glapi/gen/extension_helper.py
src/mapi/glapi/gen/glX_XML.py
src/mapi/glapi/gen/glX_doc.py
src/mapi/glapi/gen/glX_proto_common.py
src/mapi/glapi/gen/glX_proto_recv.py
src/mapi/glapi/gen/glX_proto_send.py
src/mapi/glapi/gen/glX_proto_size.py
src/mapi/glapi/gen/glX_server_table.py
src/mapi/glapi/gen/gl_SPARC_asm.py
src/mapi/glapi/gen/gl_XML.py
src/mapi/glapi/gen/gl_apitemp.py
src/mapi/glapi/gen/gl_enums.py
src/mapi/glapi/gen/gl_gentable.py
src/mapi/glapi/gen/gl_offsets.py
src/mapi/glapi/gen/gl_procs.py
src/mapi/glapi/gen/gl_table.py
src/mapi/glapi/gen/gl_x86-64_asm.py
src/mapi/glapi/gen/gl_x86_asm.py
src/mapi/glapi/gen/mesadef.py
src/mapi/glapi/gen/remap_helper.py
src/mapi/glapi/gen/typeexpr.py

index 2c83b4e0d107c2689be65422215bc70ccad65cee..da633dc61601709a68616876865014d01080bc38 100644 (file)
@@ -103,222 +103,222 @@ vtxfmt = [
 ]
 
 def all_entrypoints_in_abi(f, abi, api):
-       for n in f.entry_points:
-               [category, num] = api.get_category_for_name( n )
-               if category not in abi:
-                       return 0
+    for n in f.entry_points:
+        [category, num] = api.get_category_for_name( n )
+        if category not in abi:
+            return 0
 
-       return 1
+    return 1
 
 
 def any_entrypoints_in_abi(f, abi, api):
-       for n in f.entry_points:
-               [category, num] = api.get_category_for_name( n )
-               if category in abi:
-                       return 1
+    for n in f.entry_points:
+        [category, num] = api.get_category_for_name( n )
+        if category in abi:
+            return 1
 
-       return 0
+    return 0
 
 
 def condition_for_function(f, abi, all_not_in_ABI):
-       """Create a C-preprocessor condition for the function.
-       
-       There are two modes of operation.  If all_not_in_ABI is set, a
-       condition is only created is all of the entry-point names for f are
-       not in the selected ABI.  If all_not_in_ABI is not set, a condition
-       is created if any entryp-point name is not in the selected ABI.
-       """
+    """Create a C-preprocessor condition for the function.
 
-       condition = []
-       for n in f.entry_points:
-               [category, num] = api.get_category_for_name( n )
-               if category not in abi:
-                       condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) )
-               elif all_not_in_ABI:
-                       return []
+    There are two modes of operation.  If all_not_in_ABI is set, a
+    condition is only created is all of the entry-point names for f are
+    not in the selected ABI.  If all_not_in_ABI is not set, a condition
+    is created if any entryp-point name is not in the selected ABI.
+    """
 
-       return condition
+    condition = []
+    for n in f.entry_points:
+        [category, num] = api.get_category_for_name( n )
+        if category not in abi:
+            condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) )
+        elif all_not_in_ABI:
+            return []
+
+    return condition
 
 
 class PrintGlExtensionGlue(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+
+        self.name = "extension_helper.py (from Mesa)"
+        self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
+        return
+
 
-               self.name = "extension_helper.py (from Mesa)"
-               self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
-               return
+    def printRealHeader(self):
+        print '#include "utils.h"'
+        print '#include "main/dispatch.h"'
+        print ''
+        return
 
 
-       def printRealHeader(self):
-               print '#include "utils.h"'
-               print '#include "main/dispatch.h"'
-               print ''
-               return
+    def printBody(self, api):
+        abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
 
+        category_list = {}
 
-       def printBody(self, api):
-               abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
+        print '#ifndef NULL'
+        print '# define NULL 0'
+        print '#endif'
+        print ''
 
-               category_list = {}
+        for f in api.functionIterateAll():
+            condition = condition_for_function(f, abi, 0)
+            if len(condition):
+                print '#if %s' % (string.join(condition, " || "))
+                print 'static const char %s_names[] =' % (f.name)
 
-               print '#ifndef NULL'
-               print '# define NULL 0'
-               print '#endif'
-               print ''
+                parameter_signature = ''
+                for p in f.parameterIterator():
+                    if p.is_padding:
+                        continue
 
-               for f in api.functionIterateAll():
-                       condition = condition_for_function(f, abi, 0)
-                       if len(condition):
-                               print '#if %s' % (string.join(condition, " || "))
-                               print 'static const char %s_names[] =' % (f.name)
+                    # FIXME: This is a *really* ugly hack. :(
 
-                               parameter_signature = ''
-                               for p in f.parameterIterator():
-                                       if p.is_padding:
-                                               continue
+                    tn = p.type_expr.get_base_type_node()
+                    if p.is_pointer():
+                        parameter_signature += 'p'
+                    elif tn.integer:
+                        parameter_signature += 'i'
+                    elif tn.size == 4:
+                        parameter_signature += 'f'
+                    else:
+                        parameter_signature += 'd'
 
-                                       # FIXME: This is a *really* ugly hack. :(
+                print '    "%s\\0" /* Parameter signature */' % (parameter_signature)
 
-                                       tn = p.type_expr.get_base_type_node()
-                                       if p.is_pointer():
-                                               parameter_signature += 'p'
-                                       elif tn.integer:
-                                               parameter_signature += 'i'
-                                       elif tn.size == 4:
-                                               parameter_signature += 'f'
-                                       else:
-                                               parameter_signature += 'd'
+                for n in f.entry_points:
+                    print '    "gl%s\\0"' % (n)
 
-                               print '    "%s\\0" /* Parameter signature */' % (parameter_signature)
+                    [category, num] = api.get_category_for_name( n )
+                    if category not in abi:
+                        c = gl_XML.real_category_name(category)
+                        if not category_list.has_key(c):
+                            category_list[ c ] = []
 
-                               for n in f.entry_points:
-                                       print '    "gl%s\\0"' % (n)
+                        category_list[ c ].append( f )
 
-                                       [category, num] = api.get_category_for_name( n )
-                                       if category not in abi:
-                                               c = gl_XML.real_category_name(category)
-                                               if not category_list.has_key(c):
-                                                       category_list[ c ] = []
+                print '    "";'
+                print '#endif'
+                print ''
 
-                                               category_list[ c ].append( f )
+        keys = category_list.keys()
+        keys.sort()
 
-                               print '    "";'
-                               print '#endif'
-                               print ''
+        for category in keys:
+            print '#if defined(need_%s)' % (category)
+            print 'static const struct dri_extension_function %s_functions[] = {' % (category)
 
-               keys = category_list.keys()
-               keys.sort()
+            for f in category_list[ category ]:
+                # A function either has an offset that is
+                # assigned by the ABI, or it has a remap
+                # index.
+                if any_entrypoints_in_abi(f, abi, api):
+                    index_name = "-1"
+                    offset = f.offset
+                else:
+                    index_name = "%s_remap_index" % (f.name)
+                    offset = -1
 
-               for category in keys:
-                       print '#if defined(need_%s)' % (category)
-                       print 'static const struct dri_extension_function %s_functions[] = {' % (category)
-                       
-                       for f in category_list[ category ]:
-                               # A function either has an offset that is
-                               # assigned by the ABI, or it has a remap
-                               # index.
-                               if any_entrypoints_in_abi(f, abi, api):
-                                       index_name = "-1"
-                                       offset = f.offset
-                               else:
-                                       index_name = "%s_remap_index" % (f.name)
-                                       offset = -1
+                print '    { %s_names, %s, %d },' % (f.name, index_name, offset)
 
-                               print '    { %s_names, %s, %d },' % (f.name, index_name, offset)
 
+            print '    { NULL, 0, 0 }'
+            print '};'
+            print '#endif'
+            print ''
 
-                       print '    { NULL, 0, 0 }'
-                       print '};'
-                       print '#endif'
-                       print ''
-               
-               return
+        return
 
 
 class PrintInitDispatch(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+
+        self.name = "extension_helper.py (from Mesa)"
+        self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
+        return
+
+
+    def do_function_body(self, api, abi, vtxfmt_only):
+        last_condition_string = None
+        for f in api.functionIterateByOffset():
+            if (f.name in vtxfmt) and not vtxfmt_only:
+                continue
 
-               self.name = "extension_helper.py (from Mesa)"
-               self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
-               return
+            if (f.name not in vtxfmt) and vtxfmt_only:
+                continue
 
+            condition = condition_for_function(f, abi, 1)
+            condition_string = string.join(condition, " || ")
 
-       def do_function_body(self, api, abi, vtxfmt_only):
-               last_condition_string = None
-               for f in api.functionIterateByOffset():
-                       if (f.name in vtxfmt) and not vtxfmt_only:
-                               continue
+            if condition_string != last_condition_string:
+                if last_condition_string:
+                    print '#endif /* %s */' % (last_condition_string)
 
-                       if (f.name not in vtxfmt) and vtxfmt_only:
-                               continue
+                if condition_string:
+                    print '#if %s' % (condition_string)
 
-                       condition = condition_for_function(f, abi, 1)
-                       condition_string = string.join(condition, " || ")
+            if vtxfmt_only:
+                print '   disp->%s = vfmt->%s;' % (f.name, f.name)
+            else:
+                print '   disp->%s = _mesa_%s;' % (f.name, f.name)
 
-                       if condition_string != last_condition_string:
-                               if last_condition_string:
-                                       print '#endif /* %s */' % (last_condition_string)
+            last_condition_string = condition_string
 
-                               if condition_string:
-                                       print '#if %s' % (condition_string)
-                               
-                       if vtxfmt_only:
-                               print '   disp->%s = vfmt->%s;' % (f.name, f.name)
-                       else:
-                               print '   disp->%s = _mesa_%s;' % (f.name, f.name)
+        if last_condition_string:
+            print '#endif /* %s */' % (last_condition_string)
 
-                       last_condition_string = condition_string
 
-               if last_condition_string:
-                       print '#endif /* %s */' % (last_condition_string)
-               
 
+    def printBody(self, api):
+        abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
 
-       def printBody(self, api):
-               abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
-               
-               print 'void driver_init_exec_table(struct _glapi_table *disp)'
-               print '{'
-               self.do_function_body(api, abi, 0)
-               print '}'
-               print ''
-               print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)'
-               print '{'
-               self.do_function_body(api, abi, 1)
-               print '}'
+        print 'void driver_init_exec_table(struct _glapi_table *disp)'
+        print '{'
+        self.do_function_body(api, abi, 0)
+        print '}'
+        print ''
+        print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)'
+        print '{'
+        self.do_function_body(api, abi, 1)
+        print '}'
 
-               return
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
-       print "    -m output_mode   Output mode can be one of 'extensions' or 'exec_init'."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+    print "    -m output_mode   Output mode can be one of 'extensions' or 'exec_init'."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-    
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
-       except Exception,e:
-               show_usage()
-
-       mode = "extensions"
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               if arg == '-m':
-                       mode = val
-
-
-       api = gl_XML.parse_GL_API( file_name )
-
-       if mode == "extensions":
-               printer = PrintGlExtensionGlue()
-       elif mode == "exec_init":
-               printer = PrintInitDispatch()
-       else:
-               show_usage()
-
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
+    except Exception,e:
+        show_usage()
+
+    mode = "extensions"
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        if arg == '-m':
+            mode = val
+
+
+    api = gl_XML.parse_GL_API( file_name )
+
+    if mode == "extensions":
+        printer = PrintGlExtensionGlue()
+    elif mode == "exec_init":
+        printer = PrintInitDispatch()
+    else:
+        show_usage()
+
+    printer.Print( api )
index 4c2e0f95bf4ff3a7763cd94a5725b2b172b94d02..975321a76ab6f63ad2ff138aa09066d1db6f0a6c 100644 (file)
@@ -31,540 +31,540 @@ import sys, getopt, string
 
 
 class glx_item_factory(gl_XML.gl_item_factory):
-       """Factory to create GLX protocol oriented objects derived from gl_item."""
-    
-       def create_item(self, name, element, context):
-               if name == "function":
-                       return glx_function(element, context)
-               elif name == "enum":
-                       return glx_enum(element, context)
-               elif name == "api":
-                       return glx_api(self)
-               else:
-                       return gl_XML.gl_item_factory.create_item(self, name, element, context)
+    """Factory to create GLX protocol oriented objects derived from gl_item."""
+
+    def create_item(self, name, element, context):
+        if name == "function":
+            return glx_function(element, context)
+        elif name == "enum":
+            return glx_enum(element, context)
+        elif name == "api":
+            return glx_api(self)
+        else:
+            return gl_XML.gl_item_factory.create_item(self, name, element, context)
 
 
 class glx_enum(gl_XML.gl_enum):
-       def __init__(self, element, context):
-               gl_XML.gl_enum.__init__(self, element, context)
-               
-               self.functions = {}
+    def __init__(self, element, context):
+        gl_XML.gl_enum.__init__(self, element, context)
+
+        self.functions = {}
+
+        child = element.children
+        while child:
+            if child.type == "element" and child.name == "size":
+                n = child.nsProp( "name", None )
+                c = child.nsProp( "count", None )
+                m = child.nsProp( "mode", None )
 
-               child = element.children
-               while child:
-                       if child.type == "element" and child.name == "size":
-                               n = child.nsProp( "name", None )
-                               c = child.nsProp( "count", None )
-                               m = child.nsProp( "mode", None )
-                               
-                               if not c:
-                                       c = self.default_count
-                               else:
-                                       c = int(c)
+                if not c:
+                    c = self.default_count
+                else:
+                    c = int(c)
 
-                               if m == "get":
-                                       mode = 0
-                               else:
-                                       mode = 1
+                if m == "get":
+                    mode = 0
+                else:
+                    mode = 1
 
-                               if not self.functions.has_key(n):
-                                       self.functions[ n ] = [c, mode]
+                if not self.functions.has_key(n):
+                    self.functions[ n ] = [c, mode]
 
-                       child = child.next
+            child = child.next
 
-               return
+        return
 
 
 class glx_function(gl_XML.gl_function):
-       def __init__(self, element, context):
-               self.glx_rop = 0
-               self.glx_sop = 0
-               self.glx_vendorpriv = 0
-
-               self.glx_vendorpriv_names = []
-
-               # If this is set to true, it means that GLdouble parameters should be
-               # written to the GLX protocol packet in the order they appear in the
-               # prototype.  This is different from the "classic" ordering.  In the
-               # classic ordering GLdoubles are written to the protocol packet first,
-               # followed by non-doubles.  NV_vertex_program was the first extension
-               # to break with this tradition.
-
-               self.glx_doubles_in_order = 0
+    def __init__(self, element, context):
+        self.glx_rop = 0
+        self.glx_sop = 0
+        self.glx_vendorpriv = 0
+
+        self.glx_vendorpriv_names = []
+
+        # If this is set to true, it means that GLdouble parameters should be
+        # written to the GLX protocol packet in the order they appear in the
+        # prototype.  This is different from the "classic" ordering.  In the
+        # classic ordering GLdoubles are written to the protocol packet first,
+        # followed by non-doubles.  NV_vertex_program was the first extension
+        # to break with this tradition.
+
+        self.glx_doubles_in_order = 0
+
+        self.vectorequiv = None
+        self.output = None
+        self.can_be_large = 0
+        self.reply_always_array = 0
+        self.dimensions_in_reply = 0
+        self.img_reset = None
+
+        self.server_handcode = 0
+        self.client_handcode = 0
+        self.ignore = 0
+
+        self.count_parameter_list = []
+        self.counter_list = []
+        self.parameters_by_name = {}
+        self.offsets_calculated = 0
+
+        gl_XML.gl_function.__init__(self, element, context)
+        return
+
+
+    def process_element(self, element):
+        gl_XML.gl_function.process_element(self, element)
+
+        # If the function already has a vector equivalent set, don't
+        # set it again.  This can happen if an alias to a function
+        # appears after the function that it aliases.
+
+        if not self.vectorequiv:
+            self.vectorequiv = element.nsProp("vectorequiv", None)
+
+
+        name = element.nsProp("name", None)
+        if name == self.name:
+            for param in self.parameters:
+                self.parameters_by_name[ param.name ] = param
+
+                if len(param.count_parameter_list):
+                    self.count_parameter_list.extend( param.count_parameter_list )
+
+                if param.counter and param.counter not in self.counter_list:
+                    self.counter_list.append(param.counter)
+
+
+        child = element.children
+        while child:
+            if child.type == "element" and child.name == "glx":
+                rop = child.nsProp( 'rop', None )
+                sop = child.nsProp( 'sop', None )
+                vop = child.nsProp( 'vendorpriv', None )
+
+                if rop:
+                    self.glx_rop = int(rop)
+
+                if sop:
+                    self.glx_sop = int(sop)
+
+                if vop:
+                    self.glx_vendorpriv = int(vop)
+                    self.glx_vendorpriv_names.append(name)
+
+                self.img_reset = child.nsProp( 'img_reset', None )
+
+                # The 'handcode' attribute can be one of 'true',
+                # 'false', 'client', or 'server'.
+
+                handcode = child.nsProp( 'handcode', None )
+                if handcode == "false":
+                    self.server_handcode = 0
+                    self.client_handcode = 0
+                elif handcode == "true":
+                    self.server_handcode = 1
+                    self.client_handcode = 1
+                elif handcode == "client":
+                    self.server_handcode = 0
+                    self.client_handcode = 1
+                elif handcode == "server":
+                    self.server_handcode = 1
+                    self.client_handcode = 0
+                else:
+                    raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name))
+
+                self.ignore               = gl_XML.is_attr_true( child, 'ignore' )
+                self.can_be_large         = gl_XML.is_attr_true( child, 'large' )
+                self.glx_doubles_in_order = gl_XML.is_attr_true( child, 'doubles_in_order' )
+                self.reply_always_array   = gl_XML.is_attr_true( child, 'always_array' )
+                self.dimensions_in_reply  = gl_XML.is_attr_true( child, 'dimensions_in_reply' )
+
+            child = child.next
+
+
+        # Do some validation of the GLX protocol information.  As
+        # new tests are discovered, they should be added here.
+
+        for param in self.parameters:
+            if param.is_output and self.glx_rop != 0:
+                raise RuntimeError("Render / RenderLarge commands cannot have outputs (%s)." % (self.name))
+
+        return
+
+
+    def has_variable_size_request(self):
+        """Determine if the GLX request packet is variable sized.
+
+        The GLX request packet is variable sized in several common
+        situations.
+
+        1. The function has a non-output parameter that is counted
+           by another parameter (e.g., the 'textures' parameter of
+           glDeleteTextures).
+
+        2. The function has a non-output parameter whose count is
+           determined by another parameter that is an enum (e.g., the
+           'params' parameter of glLightfv).
+
+        3. The function has a non-output parameter that is an
+           image.
+
+        4. The function must be hand-coded on the server.
+        """
+
+        if self.glx_rop == 0:
+            return 0
+
+        if self.server_handcode or self.images:
+            return 1
+
+        for param in self.parameters:
+            if not param.is_output:
+                if param.counter or len(param.count_parameter_list):
+                    return 1
+
+        return 0
+
+
+    def variable_length_parameter(self):
+        for param in self.parameters:
+            if not param.is_output:
+                if param.counter or len(param.count_parameter_list):
+                    return param
+
+        return None
+
+
+    def calculate_offsets(self):
+        if not self.offsets_calculated:
+            # Calculate the offset of the first function parameter
+            # in the GLX command packet.  This byte offset is
+            # measured from the end of the Render / RenderLarge
+            # header.  The offset for all non-pixel commends is
+            # zero.  The offset for pixel commands depends on the
+            # number of dimensions of the pixel data.
+
+            if len(self.images) and not self.images[0].is_output:
+                [dim, junk, junk, junk, junk] = self.images[0].get_dimensions()
+
+                # The base size is the size of the pixel pack info
+                # header used by images with the specified number
+                # of dimensions.
+
+                if dim <=  2:
+                    offset = 20
+                elif dim <= 4:
+                    offset = 36
+                else:
+                    raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name))
+            else:
+                offset = 0
+
+            for param in self.parameterIterateGlxSend():
+                if param.img_null_flag:
+                    offset += 4
+
+                if param.name != self.img_reset:
+                    param.offset = offset
+                    if not param.is_variable_length() and not param.is_client_only:
+                        offset += param.size()
+
+                if self.pad_after( param ):
+                    offset += 4
+
+
+            self.offsets_calculated = 1
+        return
+
+
+    def offset_of(self, param_name):
+        self.calculate_offsets()
+        return self.parameters_by_name[ param_name ].offset
+
+
+    def parameterIterateGlxSend(self, include_variable_parameters = 1):
+        """Create an iterator for parameters in GLX request order."""
+
+        # The parameter lists are usually quite short, so it's easier
+        # (i.e., less code) to just generate a new list with the
+        # required elements than it is to create a new iterator class.
+
+        temp = [ [],  [], [] ]
+        for param in self.parameters:
+            if param.is_output: continue
+
+            if param.is_variable_length():
+                temp[2].append( param )
+            elif not self.glx_doubles_in_order and param.is_64_bit():
+                temp[0].append( param )
+            else:
+                temp[1].append( param )
+
+        parameters = temp[0]
+        parameters.extend( temp[1] )
+        if include_variable_parameters:
+            parameters.extend( temp[2] )
+        return parameters.__iter__()
+
+
+    def parameterIterateCounters(self):
+        temp = []
+        for name in self.counter_list:
+            temp.append( self.parameters_by_name[ name ] )
+
+        return temp.__iter__()
+
+
+    def parameterIterateOutputs(self):
+        temp = []
+        for p in self.parameters:
+            if p.is_output:
+                temp.append( p )
+
+        return temp
+
+
+    def command_fixed_length(self):
+        """Return the length, in bytes as an integer, of the
+        fixed-size portion of the command."""
+
+        if len(self.parameters) == 0:
+            return 0
+
+        self.calculate_offsets()
+
+        size = 0
+        for param in self.parameterIterateGlxSend(0):
+            if param.name != self.img_reset and not param.is_client_only:
+                if size == 0:
+                    size = param.offset + param.size()
+                else:
+                    size += param.size()
+
+                if self.pad_after( param ):
+                    size += 4
+
+        for param in self.images:
+            if param.img_null_flag or param.is_output:
+                size += 4
+
+        return size
+
+
+    def command_variable_length(self):
+        """Return the length, as a string, of the variable-sized
+        portion of the command."""
+
+        size_string = ""
+        for p in self.parameterIterateGlxSend():
+            if (not p.is_output) and (p.is_variable_length() or p.is_image()):
+                # FIXME Replace the 1 in the size_string call
+                # FIXME w/0 to eliminate some un-needed parnes
+                # FIXME This would already be done, but it
+                # FIXME adds some extra diffs to the generated
+                # FIXME code.
+
+                size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1))
+
+        return size_string
+
+
+    def command_length(self):
+        size = self.command_fixed_length()
 
-               self.vectorequiv = None
-               self.output = None
-               self.can_be_large = 0
-               self.reply_always_array = 0
-               self.dimensions_in_reply = 0
-               self.img_reset = None
-
-               self.server_handcode = 0
-               self.client_handcode = 0
-               self.ignore = 0
-
-               self.count_parameter_list = []
-               self.counter_list = []
-               self.parameters_by_name = {}
-               self.offsets_calculated = 0
-
-               gl_XML.gl_function.__init__(self, element, context)
-               return
-
-
-       def process_element(self, element):
-               gl_XML.gl_function.process_element(self, element)
-
-               # If the function already has a vector equivalent set, don't
-               # set it again.  This can happen if an alias to a function
-               # appears after the function that it aliases.
-
-               if not self.vectorequiv:
-                       self.vectorequiv = element.nsProp("vectorequiv", None)
-
-
-               name = element.nsProp("name", None)
-               if name == self.name:
-                       for param in self.parameters:
-                               self.parameters_by_name[ param.name ] = param
-                               
-                               if len(param.count_parameter_list):
-                                       self.count_parameter_list.extend( param.count_parameter_list )
-                               
-                               if param.counter and param.counter not in self.counter_list:
-                                       self.counter_list.append(param.counter)
+        if self.glx_rop != 0:
+            size += 4
 
+        size = ((size + 3) & ~3)
+        return "%u%s" % (size, self.command_variable_length())
 
-               child = element.children
-               while child:
-                       if child.type == "element" and child.name == "glx":
-                               rop = child.nsProp( 'rop', None )
-                               sop = child.nsProp( 'sop', None )
-                               vop = child.nsProp( 'vendorpriv', None )
-
-                               if rop:
-                                       self.glx_rop = int(rop)
-
-                               if sop:
-                                       self.glx_sop = int(sop)
-
-                               if vop:
-                                       self.glx_vendorpriv = int(vop)
-                                       self.glx_vendorpriv_names.append(name)
-
-                               self.img_reset = child.nsProp( 'img_reset', None )
-
-                               # The 'handcode' attribute can be one of 'true',
-                               # 'false', 'client', or 'server'.
-
-                               handcode = child.nsProp( 'handcode', None )
-                               if handcode == "false":
-                                       self.server_handcode = 0
-                                       self.client_handcode = 0
-                               elif handcode == "true":
-                                       self.server_handcode = 1
-                                       self.client_handcode = 1
-                               elif handcode == "client":
-                                       self.server_handcode = 0
-                                       self.client_handcode = 1
-                               elif handcode == "server":
-                                       self.server_handcode = 1
-                                       self.client_handcode = 0
-                               else:
-                                       raise RuntimeError('Invalid handcode mode "%s" in function "%s".' % (handcode, self.name))
-
-                               self.ignore               = gl_XML.is_attr_true( child, 'ignore' )
-                               self.can_be_large         = gl_XML.is_attr_true( child, 'large' )
-                               self.glx_doubles_in_order = gl_XML.is_attr_true( child, 'doubles_in_order' )
-                               self.reply_always_array   = gl_XML.is_attr_true( child, 'always_array' )
-                               self.dimensions_in_reply  = gl_XML.is_attr_true( child, 'dimensions_in_reply' )
-
-                       child = child.next
-
-
-               # Do some validation of the GLX protocol information.  As
-               # new tests are discovered, they should be added here.
-
-               for param in self.parameters:
-                       if param.is_output and self.glx_rop != 0:
-                               raise RuntimeError("Render / RenderLarge commands cannot have outputs (%s)." % (self.name))
-
-               return
-
-
-       def has_variable_size_request(self):
-               """Determine if the GLX request packet is variable sized.
-
-               The GLX request packet is variable sized in several common
-               situations.
-               
-               1. The function has a non-output parameter that is counted
-                  by another parameter (e.g., the 'textures' parameter of
-                  glDeleteTextures).
-                  
-               2. The function has a non-output parameter whose count is
-                  determined by another parameter that is an enum (e.g., the
-                  'params' parameter of glLightfv).
-                  
-               3. The function has a non-output parameter that is an
-                  image.
-
-               4. The function must be hand-coded on the server.
-               """
-
-               if self.glx_rop == 0:
-                       return 0
-
-               if self.server_handcode or self.images:
-                       return 1
-
-               for param in self.parameters:
-                       if not param.is_output:
-                               if param.counter or len(param.count_parameter_list):
-                                       return 1
-
-               return 0
-
-
-       def variable_length_parameter(self):
-               for param in self.parameters:
-                       if not param.is_output:
-                               if param.counter or len(param.count_parameter_list):
-                                       return param
-                               
-               return None
 
+    def opcode_real_value(self):
+        """Get the true numeric value of the GLX opcode
 
-       def calculate_offsets(self):
-               if not self.offsets_calculated:
-                       # Calculate the offset of the first function parameter
-                       # in the GLX command packet.  This byte offset is
-                       # measured from the end of the Render / RenderLarge
-                       # header.  The offset for all non-pixel commends is
-                       # zero.  The offset for pixel commands depends on the
-                       # number of dimensions of the pixel data.
-
-                       if len(self.images) and not self.images[0].is_output:
-                               [dim, junk, junk, junk, junk] = self.images[0].get_dimensions()
-
-                               # The base size is the size of the pixel pack info
-                               # header used by images with the specified number
-                               # of dimensions.
-
-                               if dim <=  2:
-                                       offset = 20
-                               elif dim <= 4:
-                                       offset = 36
-                               else:
-                                       raise RuntimeError('Invalid number of dimensions %u for parameter "%s" in function "%s".' % (dim, self.image.name, self.name))
-                       else:
-                               offset = 0
-
-                       for param in self.parameterIterateGlxSend():
-                               if param.img_null_flag:
-                                       offset += 4
-
-                               if param.name != self.img_reset:
-                                       param.offset = offset
-                                       if not param.is_variable_length() and not param.is_client_only:
-                                               offset += param.size()
-                                       
-                               if self.pad_after( param ):
-                                       offset += 4
+        Behaves similarly to opcode_value, except for
+        X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
+        In these cases the value for the GLX opcode field (i.e.,
+        16 for X_GLXVendorPrivate or 17 for
+        X_GLXVendorPrivateWithReply) is returned.  For other 'single'
+        commands, the opcode for the command (e.g., 101 for
+        X_GLsop_NewList) is returned."""
 
+        if self.glx_vendorpriv != 0:
+            if self.needs_reply():
+                return 17
+            else:
+                return 16
+        else:
+            return self.opcode_value()
 
-                       self.offsets_calculated = 1
-               return
 
+    def opcode_value(self):
+        """Get the unique protocol opcode for the glXFunction"""
 
-       def offset_of(self, param_name):
-               self.calculate_offsets()
-               return self.parameters_by_name[ param_name ].offset
+        if (self.glx_rop == 0) and self.vectorequiv:
+            equiv = self.context.functions_by_name[ self.vectorequiv ]
+            self.glx_rop = equiv.glx_rop
 
 
-       def parameterIterateGlxSend(self, include_variable_parameters = 1):
-               """Create an iterator for parameters in GLX request order."""
+        if self.glx_rop != 0:
+            return self.glx_rop
+        elif self.glx_sop != 0:
+            return self.glx_sop
+        elif self.glx_vendorpriv != 0:
+            return self.glx_vendorpriv
+        else:
+            return -1
 
-               # The parameter lists are usually quite short, so it's easier
-               # (i.e., less code) to just generate a new list with the
-               # required elements than it is to create a new iterator class.
-               
-               temp = [ [],  [], [] ]
-               for param in self.parameters:
-                       if param.is_output: continue
-
-                       if param.is_variable_length():
-                               temp[2].append( param )
-                       elif not self.glx_doubles_in_order and param.is_64_bit():
-                               temp[0].append( param )
-                       else:
-                               temp[1].append( param )
 
-               parameters = temp[0]
-               parameters.extend( temp[1] )
-               if include_variable_parameters:
-                       parameters.extend( temp[2] )
-               return parameters.__iter__()
+    def opcode_rop_basename(self):
+        """Return either the name to be used for GLX protocol enum.
 
+        Returns either the name of the function or the name of the
+        name of the equivalent vector (e.g., glVertex3fv for
+        glVertex3f) function."""
 
-       def parameterIterateCounters(self):
-               temp = []
-               for name in self.counter_list:
-                       temp.append( self.parameters_by_name[ name ] )
+        if self.vectorequiv == None:
+            return self.name
+        else:
+            return self.vectorequiv
 
-               return temp.__iter__()
 
+    def opcode_name(self):
+        """Get the unique protocol enum name for the glXFunction"""
 
-       def parameterIterateOutputs(self):
-               temp = []
-               for p in self.parameters:
-                       if p.is_output:
-                               temp.append( p )
+        if (self.glx_rop == 0) and self.vectorequiv:
+            equiv = self.context.functions_by_name[ self.vectorequiv ]
+            self.glx_rop = equiv.glx_rop
+            self.glx_doubles_in_order = equiv.glx_doubles_in_order
 
-               return temp
 
+        if self.glx_rop != 0:
+            return "X_GLrop_%s" % (self.opcode_rop_basename())
+        elif self.glx_sop != 0:
+            return "X_GLsop_%s" % (self.name)
+        elif self.glx_vendorpriv != 0:
+            return "X_GLvop_%s" % (self.name)
+        else:
+            raise RuntimeError('Function "%s" has no opcode.' % (self.name))
 
-       def command_fixed_length(self):
-               """Return the length, in bytes as an integer, of the
-               fixed-size portion of the command."""
-
-               if len(self.parameters) == 0:
-                       return 0
-               
-               self.calculate_offsets()
 
-               size = 0
-               for param in self.parameterIterateGlxSend(0):
-                       if param.name != self.img_reset and not param.is_client_only:
-                               if size == 0:
-                                       size = param.offset + param.size()
-                               else:
-                                       size += param.size()
+    def opcode_vendor_name(self, name):
+        if name in self.glx_vendorpriv_names:
+            return "X_GLvop_%s" % (name)
+        else:
+            raise RuntimeError('Function "%s" has no VendorPrivate opcode.' % (name))
 
-                               if self.pad_after( param ):
-                                       size += 4
 
-               for param in self.images:
-                       if param.img_null_flag or param.is_output:
-                               size += 4
+    def opcode_real_name(self):
+        """Get the true protocol enum name for the GLX opcode
 
-               return size
+        Behaves similarly to opcode_name, except for
+        X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
+        In these cases the string 'X_GLXVendorPrivate' or
+        'X_GLXVendorPrivateWithReply' is returned.  For other
+        single or render commands 'X_GLsop' or 'X_GLrop' plus the
+        name of the function returned."""
 
+        if self.glx_vendorpriv != 0:
+            if self.needs_reply():
+                return "X_GLXVendorPrivateWithReply"
+            else:
+                return "X_GLXVendorPrivate"
+        else:
+            return self.opcode_name()
 
-       def command_variable_length(self):
-               """Return the length, as a string, of the variable-sized
-               portion of the command."""
 
-               size_string = ""
-               for p in self.parameterIterateGlxSend():
-                       if (not p.is_output) and (p.is_variable_length() or p.is_image()):
-                               # FIXME Replace the 1 in the size_string call
-                               # FIXME w/0 to eliminate some un-needed parnes
-                               # FIXME This would already be done, but it
-                               # FIXME adds some extra diffs to the generated
-                               # FIXME code.
+    def needs_reply(self):
+        try:
+            x = self._needs_reply
+        except Exception, e:
+            x = 0
+            if self.return_type != 'void':
+                x = 1
 
-                               size_string = size_string + " + __GLX_PAD(%s)" % (p.size_string(1))
+            for param in self.parameters:
+                if param.is_output:
+                    x = 1
+                    break
 
-               return size_string
+            self._needs_reply = x
 
+        return x
 
-       def command_length(self):
-               size = self.command_fixed_length()
 
-               if self.glx_rop != 0:
-                       size += 4
+    def pad_after(self, p):
+        """Returns the name of the field inserted after the
+        specified field to pad out the command header."""
 
-               size = ((size + 3) & ~3)
-               return "%u%s" % (size, self.command_variable_length())
-
-
-       def opcode_real_value(self):
-               """Get the true numeric value of the GLX opcode
-               
-               Behaves similarly to opcode_value, except for
-               X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
-               In these cases the value for the GLX opcode field (i.e.,
-               16 for X_GLXVendorPrivate or 17 for
-               X_GLXVendorPrivateWithReply) is returned.  For other 'single'
-               commands, the opcode for the command (e.g., 101 for
-               X_GLsop_NewList) is returned."""
-
-               if self.glx_vendorpriv != 0:
-                       if self.needs_reply():
-                               return 17
-                       else:
-                               return 16
-               else:
-                       return self.opcode_value()
+        for image in self.images:
+            if image.img_pad_dimensions:
+                if not image.height:
+                    if p.name == image.width:
+                        return "height"
+                    elif p.name == image.img_xoff:
+                        return "yoffset"
+                elif not image.extent:
+                    if p.name == image.depth:
+                        # Should this be "size4d"?
+                        return "extent"
+                    elif p.name == image.img_zoff:
+                        return "woffset"
 
+        return None
 
-       def opcode_value(self):
-               """Get the unique protocol opcode for the glXFunction"""
 
-               if (self.glx_rop == 0) and self.vectorequiv:
-                       equiv = self.context.functions_by_name[ self.vectorequiv ]
-                       self.glx_rop = equiv.glx_rop
+    def has_different_protocol(self, name):
+        """Returns true if the named version of the function uses different protocol from the other versions.
 
+        Some functions, such as glDeleteTextures and
+        glDeleteTexturesEXT are functionally identical, but have
+        different protocol.  This function returns true if the
+        named function is an alias name and that named version uses
+        different protocol from the function that is aliased.
+        """
 
-               if self.glx_rop != 0:
-                       return self.glx_rop
-               elif self.glx_sop != 0:
-                       return self.glx_sop
-               elif self.glx_vendorpriv != 0:
-                       return self.glx_vendorpriv
-               else:
-                       return -1
-       
-
-       def opcode_rop_basename(self):
-               """Return either the name to be used for GLX protocol enum.
-               
-               Returns either the name of the function or the name of the
-               name of the equivalent vector (e.g., glVertex3fv for
-               glVertex3f) function."""
-
-               if self.vectorequiv == None:
-                       return self.name
-               else:
-                       return self.vectorequiv
-
-
-       def opcode_name(self):
-               """Get the unique protocol enum name for the glXFunction"""
-
-               if (self.glx_rop == 0) and self.vectorequiv:
-                       equiv = self.context.functions_by_name[ self.vectorequiv ]
-                       self.glx_rop = equiv.glx_rop
-                       self.glx_doubles_in_order = equiv.glx_doubles_in_order
-
-
-               if self.glx_rop != 0:
-                       return "X_GLrop_%s" % (self.opcode_rop_basename())
-               elif self.glx_sop != 0:
-                       return "X_GLsop_%s" % (self.name)
-               elif self.glx_vendorpriv != 0:
-                       return "X_GLvop_%s" % (self.name)
-               else:
-                       raise RuntimeError('Function "%s" has no opcode.' % (self.name))
-
+        return (name in self.glx_vendorpriv_names) and self.glx_sop
 
-       def opcode_vendor_name(self, name):
-               if name in self.glx_vendorpriv_names:
-                       return "X_GLvop_%s" % (name)
-               else:
-                       raise RuntimeError('Function "%s" has no VendorPrivate opcode.' % (name))
-
-
-       def opcode_real_name(self):
-               """Get the true protocol enum name for the GLX opcode
-               
-               Behaves similarly to opcode_name, except for
-               X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands.
-               In these cases the string 'X_GLXVendorPrivate' or
-               'X_GLXVendorPrivateWithReply' is returned.  For other
-               single or render commands 'X_GLsop' or 'X_GLrop' plus the
-               name of the function returned."""
 
-               if self.glx_vendorpriv != 0:
-                       if self.needs_reply():
-                               return "X_GLXVendorPrivateWithReply"
-                       else:
-                               return "X_GLXVendorPrivate"
-               else:
-                       return self.opcode_name()
-
-
-       def needs_reply(self):
-               try:
-                       x = self._needs_reply
-               except Exception, e:
-                       x = 0
-                       if self.return_type != 'void':
-                               x = 1
-
-                       for param in self.parameters:
-                               if param.is_output:
-                                       x = 1
-                                       break
-
-                       self._needs_reply = x
-
-               return x
-
-
-       def pad_after(self, p):
-               """Returns the name of the field inserted after the
-               specified field to pad out the command header."""
+    def static_glx_name(self, name):
+        if self.has_different_protocol(name):
+            for n in self.glx_vendorpriv_names:
+                if n in self.static_entry_points:
+                    return n
 
-               for image in self.images:
-                       if image.img_pad_dimensions:
-                               if not image.height:
-                                       if p.name == image.width:
-                                               return "height"
-                                       elif p.name == image.img_xoff:
-                                               return "yoffset"
-                               elif not image.extent:
-                                       if p.name == image.depth:
-                                               # Should this be "size4d"?
-                                               return "extent"
-                                       elif p.name == image.img_zoff:
-                                               return "woffset"
-
-               return None
-
-
-       def has_different_protocol(self, name):
-               """Returns true if the named version of the function uses different protocol from the other versions.
-               
-               Some functions, such as glDeleteTextures and
-               glDeleteTexturesEXT are functionally identical, but have
-               different protocol.  This function returns true if the
-               named function is an alias name and that named version uses
-               different protocol from the function that is aliased.
-               """
+        return self.static_name(name)
 
-               return (name in self.glx_vendorpriv_names) and self.glx_sop
 
+    def client_supported_for_indirect(self):
+        """Returns true if the function is supported on the client
+        side for indirect rendering."""
 
-       def static_glx_name(self, name):
-               if self.has_different_protocol(name):
-                       for n in self.glx_vendorpriv_names:
-                               if n in self.static_entry_points:
-                                       return n
-                               
-               return self.static_name(name)
-
-
-       def client_supported_for_indirect(self):
-               """Returns true if the function is supported on the client
-               side for indirect rendering."""
-
-               return not self.ignore and (self.offset != -1) and (self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.client_handcode)
+        return not self.ignore and (self.offset != -1) and (self.glx_rop or self.glx_sop or self.glx_vendorpriv or self.vectorequiv or self.client_handcode)
 
 
 class glx_function_iterator:
-       """Class to iterate over a list of glXFunctions"""
+    """Class to iterate over a list of glXFunctions"""
 
-       def __init__(self, context):
-               self.iterator = context.functionIterateByOffset()
-               return
+    def __init__(self, context):
+        self.iterator = context.functionIterateByOffset()
+        return
 
 
-       def __iter__(self):
-               return self
+    def __iter__(self):
+        return self
 
 
-       def next(self):
-               f = self.iterator.next()
+    def next(self):
+        f = self.iterator.next()
 
-               if f.client_supported_for_indirect():
-                       return f
-               else:
-                       return self.next()
+        if f.client_supported_for_indirect():
+            return f
+        else:
+            return self.next()
 
 
 class glx_api(gl_XML.gl_api):
-       def functionIterateGlx(self):
-               return glx_function_iterator(self)
+    def functionIterateGlx(self):
+        return glx_function_iterator(self)
 
index e9fbbe6f169ff9a51a9df48fc82f21dfc822d4ef..35d068894836ece1eb208a078719da4cc70730a8 100644 (file)
@@ -30,251 +30,251 @@ import sys, getopt
 
 
 class glx_doc_item_factory(glX_proto_common.glx_proto_item_factory):
-       """Factory to create GLX protocol documentation oriented objects derived from glItem."""
-    
-       def create_item(self, name, element, context):
-               if name == "parameter":
-                       return glx_doc_parameter(element, context)
-               else:
-                       return glX_proto_common.glx_proto_item_factory.create_item(self, name, element, context)
+    """Factory to create GLX protocol documentation oriented objects derived from glItem."""
+
+    def create_item(self, name, element, context):
+        if name == "parameter":
+            return glx_doc_parameter(element, context)
+        else:
+            return glX_proto_common.glx_proto_item_factory.create_item(self, name, element, context)
 
 
 class glx_doc_parameter(gl_XML.gl_parameter):
-       def packet_type(self, type_dict):
-               """Get the type string for the packet header
-               
-               GLX protocol documentation uses type names like CARD32,
-               FLOAT64, LISTofCARD8, and ENUM.  This function converts the
-               type of the parameter to one of these names."""
-
-               list_of = ""
-               if self.is_array():
-                       list_of = "LISTof"
-
-               t_name = self.get_base_type_string()
-               if not type_dict.has_key( t_name ):
-                       type_name = "CARD8"
-               else:
-                       type_name = type_dict[ t_name ]
-
-               return "%s%s" % (list_of, type_name)
-
-
-       def packet_size(self):
-               p = None
-               s = self.size()
-               if s == 0:
-                       a_prod = "n"
-                       b_prod = self.p_type.size
-
-                       if not self.count_parameter_list and self.counter:
-                               a_prod = self.counter
-                       elif self.count_parameter_list and not self.counter or self.is_output:
-                               pass
-                       elif self.count_parameter_list and self.counter:
-                               b_prod = self.counter
-                       else:
-                               raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name))
-
-                       ss = "%s*%s" % (a_prod, b_prod)
-
-                       return [ss, p]
-               else:
-                       if s % 4 != 0:
-                               p = "p"
-
-                       return [str(s), p]
+    def packet_type(self, type_dict):
+        """Get the type string for the packet header
+
+        GLX protocol documentation uses type names like CARD32,
+        FLOAT64, LISTofCARD8, and ENUM.  This function converts the
+        type of the parameter to one of these names."""
+
+        list_of = ""
+        if self.is_array():
+            list_of = "LISTof"
+
+        t_name = self.get_base_type_string()
+        if not type_dict.has_key( t_name ):
+            type_name = "CARD8"
+        else:
+            type_name = type_dict[ t_name ]
+
+        return "%s%s" % (list_of, type_name)
+
+
+    def packet_size(self):
+        p = None
+        s = self.size()
+        if s == 0:
+            a_prod = "n"
+            b_prod = self.p_type.size
+
+            if not self.count_parameter_list and self.counter:
+                a_prod = self.counter
+            elif self.count_parameter_list and not self.counter or self.is_output:
+                pass
+            elif self.count_parameter_list and self.counter:
+                b_prod = self.counter
+            else:
+                raise RuntimeError("Parameter '%s' to function '%s' has size 0." % (self.name, self.context.name))
+
+            ss = "%s*%s" % (a_prod, b_prod)
+
+            return [ss, p]
+        else:
+            if s % 4 != 0:
+                p = "p"
+
+            return [str(s), p]
 
 class PrintGlxProtoText(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
-               self.license = ""
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+        self.license = ""
+
+
+    def printHeader(self):
+        return
+
+
+    def body_size(self, f):
+        # At some point, refactor this function and
+        # glXFunction::command_payload_length.
+
+        size = 0;
+        size_str = ""
+        pad_str = ""
+        plus = ""
+        for p in f.parameterIterateGlxSend():
+            [s, pad] = p.packet_size()
+            try: 
+                size += int(s)
+            except Exception,e:
+                size_str += "%s%s" % (plus, s)
+                plus = "+"
+
+            if pad != None:
+                pad_str = pad
+
+        return [size, size_str, pad_str]
+
+
+    def print_render_header(self, f):
+        [size, size_str, pad_str] = self.body_size(f)
+        size += 4;
+
+        if size_str == "":
+            s = "%u" % ((size + 3) & ~3)
+        elif pad_str != "":
+            s = "%u+%s+%s" % (size, size_str, pad_str)
+        else:
+            s = "%u+%s" % (size, size_str)
+
+        print '            2        %-15s rendering command length' % (s)
+        print '            2        %-4u            rendering command opcode' % (f.glx_rop)
+        return
+
+
+    def print_single_header(self, f):
+        [size, size_str, pad_str] = self.body_size(f)
+        size = ((size + 3) / 4) + 2;
+
+        if f.glx_vendorpriv != 0:
+            size += 1
+
+        print '            1        CARD8           opcode (X assigned)'
+        print '            1        %-4u            GLX opcode (%s)' % (f.opcode_real_value(), f.opcode_real_name())
+
+        if size_str == "":
+            s = "%u" % (size)
+        elif pad_str != "":
+            s = "%u+((%s+%s)/4)" % (size, size_str, pad_str)
+        else:
+            s = "%u+((%s)/4)" % (size, size_str)
+
+        print '            2        %-15s request length' % (s)
+
+        if f.glx_vendorpriv != 0:
+            print '            4        %-4u            vendor specific opcode' % (f.opcode_value())
+
+        print '            4        GLX_CONTEXT_TAG context tag'
+
+        return
+
+
+    def print_reply(self, f):
+        print '          =>'
+        print '            1        1               reply'
+        print '            1                        unused'
+        print '            2        CARD16          sequence number'
+
+        if f.output == None:
+            print '            4        0               reply length'
+        elif f.reply_always_array:
+            print '            4        m               reply length'
+        else:
+            print '            4        m               reply length, m = (n == 1 ? 0 : n)'
+
+
+        output = None
+        for x in f.parameterIterateOutputs():
+            output = x
+            break
+
+
+        unused = 24
+        if f.return_type != 'void':
+            print '            4        %-15s return value' % (f.return_type)
+            unused -= 4
+        elif output != None:
+            print '            4                        unused'
+            unused -= 4
+
+        if output != None:
+            print '            4        CARD32          n'
+            unused -= 4
+
+        if output != None:
+            if not f.reply_always_array:
+                print ''
+                print '            if (n = 1) this follows:'
+                print ''
+                print '            4        CARD32          %s' % (output.name)
+                print '            %-2u                       unused' % (unused - 4)
+                print ''
+                print '            otherwise this follows:'
+                print ''
+
+            print '            %-2u                       unused' % (unused)
 
+            [s, pad] = output.packet_size()
+            print '            %-8s %-15s %s' % (s, output.packet_type( self.type_map ), output.name)
+            if pad != None:
+                try:
+                    bytes = int(s)
+                    bytes = 4 - (bytes & 3)
+                    print '            %-8u %-15s unused' % (bytes, "")
+                except Exception,e:
+                    print '            %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s)
+        else:
+            print '            %-2u                       unused' % (unused)
 
-       def printHeader(self):
-               return
+
+    def print_body(self, f):
+        for p in f.parameterIterateGlxSend():
+            [s, pad] = p.packet_size()
+            print '            %-8s %-15s %s' % (s, p.packet_type( self.type_map ), p.name)
+            if pad != None:
+                try:
+                    bytes = int(s)
+                    bytes = 4 - (bytes & 3)
+                    print '            %-8u %-15s unused' % (bytes, "")
+                except Exception,e:
+                    print '            %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s)
+
+    def printBody(self, api):
+        self.type_map = {}
+        for t in api.typeIterate():
+            self.type_map[ "GL" + t.name ] = t.glx_name
 
 
-       def body_size(self, f):
-               # At some point, refactor this function and
-               # glXFunction::command_payload_length.
-
-               size = 0;
-               size_str = ""
-               pad_str = ""
-               plus = ""
-               for p in f.parameterIterateGlxSend():
-                       [s, pad] = p.packet_size()
-                       try: 
-                               size += int(s)
-                       except Exception,e:
-                               size_str += "%s%s" % (plus, s)
-                               plus = "+"
-
-                       if pad != None:
-                               pad_str = pad
-
-               return [size, size_str, pad_str]
-
-
-       def print_render_header(self, f):
-               [size, size_str, pad_str] = self.body_size(f)
-               size += 4;
-
-               if size_str == "":
-                       s = "%u" % ((size + 3) & ~3)
-               elif pad_str != "":
-                       s = "%u+%s+%s" % (size, size_str, pad_str)
-               else:
-                       s = "%u+%s" % (size, size_str)
-
-               print '            2        %-15s rendering command length' % (s)
-               print '            2        %-4u            rendering command opcode' % (f.glx_rop)
-               return
-
-
-       def print_single_header(self, f):
-               [size, size_str, pad_str] = self.body_size(f)
-               size = ((size + 3) / 4) + 2;
-
-               if f.glx_vendorpriv != 0:
-                       size += 1
-
-               print '            1        CARD8           opcode (X assigned)'
-               print '            1        %-4u            GLX opcode (%s)' % (f.opcode_real_value(), f.opcode_real_name())
-
-               if size_str == "":
-                       s = "%u" % (size)
-               elif pad_str != "":
-                       s = "%u+((%s+%s)/4)" % (size, size_str, pad_str)
-               else:
-                       s = "%u+((%s)/4)" % (size, size_str)
-
-               print '            2        %-15s request length' % (s)
-
-               if f.glx_vendorpriv != 0:
-                       print '            4        %-4u            vendor specific opcode' % (f.opcode_value())
-                       
-               print '            4        GLX_CONTEXT_TAG context tag'
-
-               return
-               
-
-       def print_reply(self, f):
-               print '          =>'
-               print '            1        1               reply'
-               print '            1                        unused'
-               print '            2        CARD16          sequence number'
-
-               if f.output == None:
-                       print '            4        0               reply length'
-               elif f.reply_always_array:
-                       print '            4        m               reply length'
-               else:
-                       print '            4        m               reply length, m = (n == 1 ? 0 : n)'
-
-
-               output = None
-               for x in f.parameterIterateOutputs():
-                       output = x
-                       break
-
-
-               unused = 24
-               if f.return_type != 'void':
-                       print '            4        %-15s return value' % (f.return_type)
-                       unused -= 4
-               elif output != None:
-                       print '            4                        unused'
-                       unused -= 4
-
-               if output != None:
-                       print '            4        CARD32          n'
-                       unused -= 4
-
-               if output != None:
-                       if not f.reply_always_array:
-                               print ''
-                               print '            if (n = 1) this follows:'
-                               print ''
-                               print '            4        CARD32          %s' % (output.name)
-                               print '            %-2u                       unused' % (unused - 4)
-                               print ''
-                               print '            otherwise this follows:'
-                               print ''
-
-                       print '            %-2u                       unused' % (unused)
-
-                       [s, pad] = output.packet_size()
-                       print '            %-8s %-15s %s' % (s, output.packet_type( self.type_map ), output.name)
-                       if pad != None:
-                               try:
-                                       bytes = int(s)
-                                       bytes = 4 - (bytes & 3)
-                                       print '            %-8u %-15s unused' % (bytes, "")
-                               except Exception,e:
-                                       print '            %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s)
-               else:
-                       print '            %-2u                       unused' % (unused)
-
-
-       def print_body(self, f):
-               for p in f.parameterIterateGlxSend():
-                       [s, pad] = p.packet_size()
-                       print '            %-8s %-15s %s' % (s, p.packet_type( self.type_map ), p.name)
-                       if pad != None:
-                               try:
-                                       bytes = int(s)
-                                       bytes = 4 - (bytes & 3)
-                                       print '            %-8u %-15s unused' % (bytes, "")
-                               except Exception,e:
-                                       print '            %-8s %-15s unused, %s=pad(%s)' % (pad, "", pad, s)
-
-       def printBody(self, api):
-               self.type_map = {}
-               for t in api.typeIterate():
-                       self.type_map[ "GL" + t.name ] = t.glx_name
-
-
-               # At some point this should be expanded to support pixel
-               # functions, but I'm not going to lose any sleep over it now.
-
-               for f in api.functionIterateByOffset():
-                       if f.client_handcode or f.server_handcode or f.vectorequiv or len(f.get_images()):
-                               continue
-
-
-                       if f.glx_rop:
-                               print '        %s' % (f.name)
-                               self.print_render_header(f)
-                       elif f.glx_sop or f.glx_vendorpriv:
-                               print '        %s' % (f.name)
-                               self.print_single_header(f)
-                       else:
-                               continue
-
-                       self.print_body(f)
-
-                       if f.needs_reply():
-                               self.print_reply(f)
-
-                       print ''
-               return
+        # At some point this should be expanded to support pixel
+        # functions, but I'm not going to lose any sleep over it now.
+
+        for f in api.functionIterateByOffset():
+            if f.client_handcode or f.server_handcode or f.vectorequiv or len(f.get_images()):
+                continue
+
+
+            if f.glx_rop:
+                print '        %s' % (f.name)
+                self.print_render_header(f)
+            elif f.glx_sop or f.glx_vendorpriv:
+                print '        %s' % (f.name)
+                self.print_single_header(f)
+            else:
+                continue
+
+            self.print_body(f)
+
+            if f.needs_reply():
+                self.print_reply(f)
+
+            print ''
+        return
 
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
+    file_name = "gl_API.xml"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:")
+    except Exception,e:
+        show_usage()
 
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
 
-       api = gl_XML.parse_GL_API( file_name, glx_doc_item_factory() )
+    api = gl_XML.parse_GL_API( file_name, glx_doc_item_factory() )
 
-       printer = PrintGlxProtoText()
-       printer.Print( api )
+    printer = PrintGlxProtoText()
+    printer.Print( api )
index 6f094e22b3174437ac00ad7a0358422b685e957e..86d9189a908216050fc6d10c62976824c56af8af 100644 (file)
@@ -30,66 +30,66 @@ import string
 
 
 class glx_proto_item_factory(glX_XML.glx_item_factory):
-       """Factory to create GLX protocol oriented objects derived from gl_item."""
-    
-       def create_item(self, name, element, context):
-               if name == "type":
-                       return glx_proto_type(element, context)
-               else:
-                       return glX_XML.glx_item_factory.create_item(self, name, element, context)
+    """Factory to create GLX protocol oriented objects derived from gl_item."""
+
+    def create_item(self, name, element, context):
+        if name == "type":
+            return glx_proto_type(element, context)
+        else:
+            return glX_XML.glx_item_factory.create_item(self, name, element, context)
 
 
 class glx_proto_type(gl_XML.gl_type):
-       def __init__(self, element, context):
-               gl_XML.gl_type.__init__(self, element, context)
+    def __init__(self, element, context):
+        gl_XML.gl_type.__init__(self, element, context)
 
-               self.glx_name = element.nsProp( "glx_name", None )
-               return
+        self.glx_name = element.nsProp( "glx_name", None )
+        return
 
 
 class glx_print_proto(gl_XML.gl_print_base):
-       def size_call(self, func, outputs_also = 0):
-               """Create C code to calculate 'compsize'.
+    def size_call(self, func, outputs_also = 0):
+        """Create C code to calculate 'compsize'.
+
+        Creates code to calculate 'compsize'.  If the function does
+        not need 'compsize' to be calculated, None will be
+        returned."""
 
-               Creates code to calculate 'compsize'.  If the function does
-               not need 'compsize' to be calculated, None will be
-               returned."""
-       
-               compsize = None
+        compsize = None
 
-               for param in func.parameterIterator():
-                       if outputs_also or not param.is_output:
-                               if param.is_image():
-                                       [dim, w, h, d, junk] = param.get_dimensions()
+        for param in func.parameterIterator():
+            if outputs_also or not param.is_output:
+                if param.is_image():
+                    [dim, w, h, d, junk] = param.get_dimensions()
 
-                                       compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target)
-                                       if not param.img_send_null:
-                                               compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize)
+                    compsize = '__glImageSize(%s, %s, %s, %s, %s, %s)' % (w, h, d, param.img_format, param.img_type, param.img_target)
+                    if not param.img_send_null:
+                        compsize = '(%s != NULL) ? %s : 0' % (param.name, compsize)
 
-                                       return compsize
+                    return compsize
 
-                               elif len(param.count_parameter_list):
-                                       parameters = string.join( param.count_parameter_list, "," )
-                                       compsize = "__gl%s_size(%s)" % (func.name, parameters)
+                elif len(param.count_parameter_list):
+                    parameters = string.join( param.count_parameter_list, "," )
+                    compsize = "__gl%s_size(%s)" % (func.name, parameters)
 
-                                       return compsize
+                    return compsize
 
-               return None
+        return None
 
 
-       def emit_packet_size_calculation(self, f, bias):
-               # compsize is only used in the command size calculation if
-               # the function has a non-output parameter that has a non-empty
-               # counter_parameter_list.
+    def emit_packet_size_calculation(self, f, bias):
+        # compsize is only used in the command size calculation if
+        # the function has a non-output parameter that has a non-empty
+        # counter_parameter_list.
 
-               compsize = self.size_call(f)
-               if compsize:
-                       print '    const GLuint compsize = %s;' % (compsize)
+        compsize = self.size_call(f)
+        if compsize:
+            print '    const GLuint compsize = %s;' % (compsize)
 
-               if bias:
-                       print '    const GLuint cmdlen = %s - %u;' % (f.command_length(), bias)
-               else:
-                       print '    const GLuint cmdlen = %s;' % (f.command_length())
+        if bias:
+            print '    const GLuint cmdlen = %s - %u;' % (f.command_length(), bias)
+        else:
+            print '    const GLuint cmdlen = %s;' % (f.command_length())
 
-               #print ''
-               return compsize
+        #print ''
+        return compsize
index b577bb6bd63afb3028c615b803df7857b926a493..42b85a525c6c0f07087f4628b78046f2aac4bfac 100644 (file)
@@ -30,526 +30,526 @@ import sys, getopt, string
 
 
 class PrintGlxDispatch_h(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "glX_proto_recv.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
+        self.name = "glX_proto_recv.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
 
-               self.header_tag = "_INDIRECT_DISPATCH_H_"
-               return
+        self.header_tag = "_INDIRECT_DISPATCH_H_"
+        return
 
 
-       def printRealHeader(self):
-               print '#  include <X11/Xfuncproto.h>'
-               print ''
-               print 'struct __GLXclientStateRec;'
-               print ''
-               return
+    def printRealHeader(self):
+        print '#  include <X11/Xfuncproto.h>'
+        print ''
+        print 'struct __GLXclientStateRec;'
+        print ''
+        return
 
 
-       def printBody(self, api):
-               for func in api.functionIterateAll():
-                       if not func.ignore and not func.vectorequiv:
-                               if func.glx_rop:
-                                       print 'extern _X_HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name)
-                                       print 'extern _X_HIDDEN void __glXDispSwap_%s(GLbyte * pc);' % (func.name)
-                               elif func.glx_sop or func.glx_vendorpriv:
-                                       print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name)
-                                       print 'extern _X_HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name)
+    def printBody(self, api):
+        for func in api.functionIterateAll():
+            if not func.ignore and not func.vectorequiv:
+                if func.glx_rop:
+                    print 'extern _X_HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name)
+                    print 'extern _X_HIDDEN void __glXDispSwap_%s(GLbyte * pc);' % (func.name)
+                elif func.glx_sop or func.glx_vendorpriv:
+                    print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name)
+                    print 'extern _X_HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name)
 
-                                       if func.glx_sop and func.glx_vendorpriv:
-                                               n = func.glx_vendorpriv_names[0]
-                                               print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n)
-                                               print 'extern _X_HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n)
+                    if func.glx_sop and func.glx_vendorpriv:
+                        n = func.glx_vendorpriv_names[0]
+                        print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n)
+                        print 'extern _X_HIDDEN int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n)
 
-               return
+        return
 
 
 class PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto):
-       def __init__(self, do_swap):
-               gl_XML.gl_print_base.__init__(self)
-               self.name = "glX_proto_recv.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
-
-               self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ]
-               self.do_swap = do_swap
-               return
-
-
-       def printRealHeader(self):
-               print '#include <X11/Xmd.h>'
-               print '#include <GL/gl.h>'
-               print '#include <GL/glxproto.h>'
-
-               print '#include <inttypes.h>'
-               print '#include "indirect_size.h"'
-               print '#include "indirect_size_get.h"'
-               print '#include "indirect_dispatch.h"'
-               print '#include "glxserver.h"'
-               print '#include "glxbyteorder.h"'
-               print '#include "indirect_util.h"'
-               print '#include "singlesize.h"'
-               print '#include "glapi.h"'
-               print '#include "glapitable.h"'
-               print '#include "glthread.h"'
-               print '#include "dispatch.h"'
-               print ''
-               print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
-               print ''
-               print 'typedef struct {'
-               print '    __GLX_PIXEL_3D_HDR;'
-               print '} __GLXpixel3DHeader;'
-               print ''
-               print 'extern GLboolean __glXErrorOccured( void );'
-               print 'extern void __glXClearErrorOccured( void );'
-               print ''
-               print 'static const unsigned dummy_answer[2] = {0, 0};'
-               print ''
-               return
-
-
-       def printBody(self, api):
-               if self.do_swap:
-                       self.emit_swap_wrappers(api)
-
-
-               for func in api.functionIterateByOffset():
-                       if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv):
-                               self.printFunction(func, func.name)
-                               if func.glx_sop and func.glx_vendorpriv:
-                                       self.printFunction(func, func.glx_vendorpriv_names[0])
-                                       
-
-               return
-
-
-       def printFunction(self, f, name):
-               if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0):
-                       return
-
-               if not self.do_swap:
-                       base = '__glXDisp'
-               else:
-                       base = '__glXDispSwap'
-
-               if f.glx_rop:
-                       print 'void %s_%s(GLbyte * pc)' % (base, name)
-               else:
-                       print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name)
-
-               print '{'
-
-               if f.glx_rop or f.vectorequiv:
-                       self.printRenderFunction(f)
-               elif f.glx_sop or f.glx_vendorpriv:
-                       if len(f.get_images()) == 0: 
-                               self.printSingleFunction(f, name)
-               else:
-                       print "/* Missing GLX protocol for %s. */" % (name)
-
-               print '}'
-               print ''
-               return
-
-
-       def swap_name(self, bytes):
-               return 'bswap_%u_array' % (8 * bytes)
-
-
-       def emit_swap_wrappers(self, api):
-               self.type_map = {}
-               already_done = [ ]
-
-               for t in api.typeIterate():
-                       te = t.get_type_expression()
-                       t_size = te.get_element_size()
-
-                       if t_size > 1 and t.glx_name:
-                               
-                               t_name = "GL" + t.name
-                               self.type_map[ t_name ] = t.glx_name
-
-                               if t.glx_name not in already_done:
-                                       real_name = self.real_types[t_size]
-
-                                       print 'static %s' % (t_name)
-                                       print 'bswap_%s( const void * src )' % (t.glx_name)
-                                       print '{'
-                                       print '    union { %s dst; %s ret; } x;' % (real_name, t_name)
-                                       print '    x.dst = bswap_%u( *(%s *) src );' % (t_size * 8, real_name)
-                                       print '    return x.ret;'
-                                       print '}'
-                                       print ''
-                                       already_done.append( t.glx_name )
-
-               for bits in [16, 32, 64]:
-                       print 'static void *'
-                       print 'bswap_%u_array( uint%u_t * src, unsigned count )' % (bits, bits)
-                       print '{'
-                       print '    unsigned  i;'
-                       print ''
-                       print '    for ( i = 0 ; i < count ; i++ ) {'
-                       print '        uint%u_t temp = bswap_%u( src[i] );' % (bits, bits)
-                       print '        src[i] = temp;'
-                       print '    }'
-                       print ''
-                       print '    return src;'
-                       print '}'
-                       print ''
-                       
-
-       def fetch_param(self, param):
-               t = param.type_string()
-               o = param.offset
-               element_size = param.size() / param.get_element_count()
-
-               if self.do_swap and (element_size != 1):
-                       if param.is_array():
-                               real_name = self.real_types[ element_size ]
-
-                               swap_func = self.swap_name( element_size )
-                               return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count)
-                       else:
-                               t_name = param.get_base_type_string()
-                               return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o)
-               else:
-                       if param.is_array():
-                               return ' (%-8s)(pc + %2u)' % (t, o)
-                       else:
-                               return '*(%-8s *)(pc + %2u)' % (t, o)
-                               
-               return None
-
-
-       def emit_function_call(self, f, retval_assign, indent):
-               list = []
-
-               for param in f.parameterIterator():
-                       if param.is_padding:
-                               continue
-
-                       if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list):
-                               location = param.name
-                       else:
-                               location = self.fetch_param(param)
-
-                       list.append( '%s        %s' % (indent, location) )
-                       
-
-               if len( list ):
-                       print '%s    %sCALL_%s( GET_DISPATCH(), (' % (indent, retval_assign, f.name)
-                       print string.join( list, ",\n" )
-                       print '%s    ) );' % (indent)
-               else:
-                       print '%s    %sCALL_%s( GET_DISPATCH(), () );' % (indent, retval_assign, f.name)
-               return
-
-
-       def common_func_print_just_start(self, f, indent):
-               align64 = 0
-               need_blank = 0
-
-
-               f.calculate_offsets()
-               for param in f.parameterIterateGlxSend():
-                       # If any parameter has a 64-bit base type, then we
-                       # have to do alignment magic for the while thing.
-
-                       if param.is_64_bit():
-                               align64 = 1
-
-
-                       # FIXME img_null_flag is over-loaded.  In addition to
-                       # FIXME being used for images, it is used to signify
-                       # FIXME NULL data pointers for vertex buffer object
-                       # FIXME related functions.  Re-name it to null_data
-                       # FIXME or something similar.
-
-                       if param.img_null_flag:
-                               print '%s    const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4)
-                               cond = '(ptr_is_null != 0) ? NULL : '
-                       else:
-                               cond = ""
-
-
-                       type_string = param.type_string()
-
-                       if param.is_image():
-                               offset = f.offset_of( param.name )
-
-                               print '%s    %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset)
-                               
-                               if param.depth:
-                                       print '%s    __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent)
-                               else:
-                                       print '%s    __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent)
-
-                               need_blank = 1
-                       elif param.is_counter or param.name in f.count_parameter_list:
-                               location = self.fetch_param(param)
-                               print '%s    const %s %s = %s;' % (indent, type_string, param.name, location)
-                               need_blank = 1
-                       elif len(param.count_parameter_list):
-                               if param.size() == 1 and not self.do_swap:
-                                       location = self.fetch_param(param)
-                                       print '%s    %s %s = %s%s;' % (indent, type_string, param.name, cond, location)
-                               else:
-                                       print '%s    %s %s;' % (indent, type_string, param.name)
-                               need_blank = 1
-
-
-
-               if need_blank:
-                       print ''
-
-               if align64:
-                       print '#ifdef __GLX_ALIGN64'
-
-                       if f.has_variable_size_request():
-                               self.emit_packet_size_calculation(f, 4)
-                               s = "cmdlen"
-                       else:
-                               s = str((f.command_fixed_length() + 3) & ~3)
-
-                       print '    if ((unsigned long)(pc) & 7) {'
-                       print '        (void) memmove(pc-4, pc, %s);' % (s)
-                       print '        pc -= 4;'
-                       print '    }'
-                       print '#endif'
-                       print ''
-
-
-               need_blank = 0
-               if self.do_swap:
-                       for param in f.parameterIterateGlxSend():
-                               if param.count_parameter_list:
-                                       o = param.offset
-                                       count = param.get_element_count()
-                                       type_size = param.size() / count
-                                       
-                                       if param.counter:
-                                               count_name = param.counter
-                                       else:
-                                               count_name = str(count)
-
-                                       # This is basically an ugly special-
-                                       # case for glCallLists.
-
-                                       if type_size == 1:
-                                               x = [] 
-                                               x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] )
-                                               x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] )
-                                               x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] )
-
-                                               print '    switch(%s) {' % (param.count_parameter_list[0])
-                                               for sub in x:
-                                                       for t_name in sub[1]:
-                                                               print '    case GL_%s:' % (t_name)
-
-                                                       if sub[0] == 1:
-                                                               print '        %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o)
-                                                       else:
-                                                               swap_func = self.swap_name(sub[0])
-                                                               print '        %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name)
-                                               print '    default:'
-                                               print '        return;'
-                                               print '    }'
-                                       else:
-                                               swap_func = self.swap_name(type_size)
-                                               compsize = self.size_call(f, 1)
-                                               print '    %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize)
-
-                                       need_blank = 1
-
-               else:
-                       for param in f.parameterIterateGlxSend():
-                               if param.count_parameter_list:
-                                       print '%s    %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset)
-                                       need_blank = 1
-
-
-               if need_blank:
-                       print ''
-
-
-               return
-
-
-       def printSingleFunction(self, f, name):
-               if name not in f.glx_vendorpriv_names:
-                       print '    xGLXSingleReq * const req = (xGLXSingleReq *) pc;'
-               else:
-                       print '    xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;'
-
-               print '    int error;'
-
-               if self.do_swap:
-                   print '    __GLXcontext * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);'
-               else:
-                   print '    __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, &error);'
-
-               print ''
-               if name not in f.glx_vendorpriv_names:
-                       print '    pc += __GLX_SINGLE_HDR_SIZE;'
-               else:
-                       print '    pc += __GLX_VENDPRIV_HDR_SIZE;'
-
-               print '    if ( cx != NULL ) {'
-               self.common_func_print_just_start(f, "    ")
-               
-
-               if f.return_type != 'void':
-                       print '        %s retval;' % (f.return_type)
-                       retval_string = "retval"
-                       retval_assign = "retval = "
-               else:
-                       retval_string = "0"
-                       retval_assign = ""
-
-
-               type_size = 0
-               answer_string = "dummy_answer"
-               answer_count = "0"
-               is_array_string = "GL_FALSE"
-
-               for param in f.parameterIterateOutputs():
-                       answer_type = param.get_base_type_string()
-                       if answer_type == "GLvoid":
-                               answer_type = "GLubyte"
-
-
-                       c = param.get_element_count()
-                       type_size = (param.size() / c)
-                       if type_size == 1:
-                               size_scale = ""
-                       else:
-                               size_scale = " * %u" % (type_size)
-
-
-                       if param.count_parameter_list:
-                               print '        const GLuint compsize = %s;' % (self.size_call(f, 1))
-                               print '        %s answerBuffer[200];' %  (answer_type)
-                               print '        %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size )
-                               answer_string = param.name
-                               answer_count = "compsize"
-
-                               print ''
-                               print '        if (%s == NULL) return BadAlloc;' % (param.name)
-                               print '        __glXClearErrorOccured();'
-                               print ''
-                       elif param.counter:
-                               print '        %s answerBuffer[200];' %  (answer_type)
-                               print '        %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size)
-                               answer_string = param.name
-                               answer_count = param.counter
-                       elif c >= 1:
-                               print '        %s %s[%u];' % (answer_type, param.name, c)
-                               answer_string = param.name
-                               answer_count = "%u" % (c)
+    def __init__(self, do_swap):
+        gl_XML.gl_print_base.__init__(self)
+        self.name = "glX_proto_recv.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
+
+        self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ]
+        self.do_swap = do_swap
+        return
+
+
+    def printRealHeader(self):
+        print '#include <X11/Xmd.h>'
+        print '#include <GL/gl.h>'
+        print '#include <GL/glxproto.h>'
+
+        print '#include <inttypes.h>'
+        print '#include "indirect_size.h"'
+        print '#include "indirect_size_get.h"'
+        print '#include "indirect_dispatch.h"'
+        print '#include "glxserver.h"'
+        print '#include "glxbyteorder.h"'
+        print '#include "indirect_util.h"'
+        print '#include "singlesize.h"'
+        print '#include "glapi.h"'
+        print '#include "glapitable.h"'
+        print '#include "glthread.h"'
+        print '#include "dispatch.h"'
+        print ''
+        print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
+        print ''
+        print 'typedef struct {'
+        print '    __GLX_PIXEL_3D_HDR;'
+        print '} __GLXpixel3DHeader;'
+        print ''
+        print 'extern GLboolean __glXErrorOccured( void );'
+        print 'extern void __glXClearErrorOccured( void );'
+        print ''
+        print 'static const unsigned dummy_answer[2] = {0, 0};'
+        print ''
+        return
+
+
+    def printBody(self, api):
+        if self.do_swap:
+            self.emit_swap_wrappers(api)
+
+
+        for func in api.functionIterateByOffset():
+            if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv):
+                self.printFunction(func, func.name)
+                if func.glx_sop and func.glx_vendorpriv:
+                    self.printFunction(func, func.glx_vendorpriv_names[0])
+
+
+        return
+
+
+    def printFunction(self, f, name):
+        if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0):
+            return
+
+        if not self.do_swap:
+            base = '__glXDisp'
+        else:
+            base = '__glXDispSwap'
+
+        if f.glx_rop:
+            print 'void %s_%s(GLbyte * pc)' % (base, name)
+        else:
+            print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name)
+
+        print '{'
+
+        if f.glx_rop or f.vectorequiv:
+            self.printRenderFunction(f)
+        elif f.glx_sop or f.glx_vendorpriv:
+            if len(f.get_images()) == 0: 
+                self.printSingleFunction(f, name)
+        else:
+            print "/* Missing GLX protocol for %s. */" % (name)
+
+        print '}'
+        print ''
+        return
+
+
+    def swap_name(self, bytes):
+        return 'bswap_%u_array' % (8 * bytes)
+
+
+    def emit_swap_wrappers(self, api):
+        self.type_map = {}
+        already_done = [ ]
+
+        for t in api.typeIterate():
+            te = t.get_type_expression()
+            t_size = te.get_element_size()
+
+            if t_size > 1 and t.glx_name:
+
+                t_name = "GL" + t.name
+                self.type_map[ t_name ] = t.glx_name
+
+                if t.glx_name not in already_done:
+                    real_name = self.real_types[t_size]
+
+                    print 'static %s' % (t_name)
+                    print 'bswap_%s( const void * src )' % (t.glx_name)
+                    print '{'
+                    print '    union { %s dst; %s ret; } x;' % (real_name, t_name)
+                    print '    x.dst = bswap_%u( *(%s *) src );' % (t_size * 8, real_name)
+                    print '    return x.ret;'
+                    print '}'
+                    print ''
+                    already_done.append( t.glx_name )
+
+        for bits in [16, 32, 64]:
+            print 'static void *'
+            print 'bswap_%u_array( uint%u_t * src, unsigned count )' % (bits, bits)
+            print '{'
+            print '    unsigned  i;'
+            print ''
+            print '    for ( i = 0 ; i < count ; i++ ) {'
+            print '        uint%u_t temp = bswap_%u( src[i] );' % (bits, bits)
+            print '        src[i] = temp;'
+            print '    }'
+            print ''
+            print '    return src;'
+            print '}'
+            print ''
 
-                       if f.reply_always_array:
-                               is_array_string = "GL_TRUE"
 
+    def fetch_param(self, param):
+        t = param.type_string()
+        o = param.offset
+        element_size = param.size() / param.get_element_count()
 
-               self.emit_function_call(f, retval_assign, "    ")
+        if self.do_swap and (element_size != 1):
+            if param.is_array():
+                real_name = self.real_types[ element_size ]
 
+                swap_func = self.swap_name( element_size )
+                return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count)
+            else:
+                t_name = param.get_base_type_string()
+                return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o)
+        else:
+            if param.is_array():
+                return ' (%-8s)(pc + %2u)' % (t, o)
+            else:
+                return '*(%-8s *)(pc + %2u)' % (t, o)
 
-               if f.needs_reply():
-                       if self.do_swap:
-                               for param in f.parameterIterateOutputs():
-                                       c = param.get_element_count()
-                                       type_size = (param.size() / c)
+        return None
 
-                                       if type_size > 1:
-                                               swap_name = self.swap_name( type_size )
-                                               print '        (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count)
 
+    def emit_function_call(self, f, retval_assign, indent):
+        list = []
+
+        for param in f.parameterIterator():
+            if param.is_padding:
+                continue
+
+            if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list):
+                location = param.name
+            else:
+                location = self.fetch_param(param)
+
+            list.append( '%s        %s' % (indent, location) )
 
-                               reply_func = '__glXSendReplySwap'
-                       else:
-                               reply_func = '__glXSendReply'
 
-                       print '        %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string)
-               #elif f.note_unflushed:
-               #       print '        cx->hasUnflushedCommands = GL_TRUE;'
+        if len( list ):
+            print '%s    %sCALL_%s( GET_DISPATCH(), (' % (indent, retval_assign, f.name)
+            print string.join( list, ",\n" )
+            print '%s    ) );' % (indent)
+        else:
+            print '%s    %sCALL_%s( GET_DISPATCH(), () );' % (indent, retval_assign, f.name)
+        return
+
+
+    def common_func_print_just_start(self, f, indent):
+        align64 = 0
+        need_blank = 0
+
+
+        f.calculate_offsets()
+        for param in f.parameterIterateGlxSend():
+            # If any parameter has a 64-bit base type, then we
+            # have to do alignment magic for the while thing.
+
+            if param.is_64_bit():
+                align64 = 1
+
+
+            # FIXME img_null_flag is over-loaded.  In addition to
+            # FIXME being used for images, it is used to signify
+            # FIXME NULL data pointers for vertex buffer object
+            # FIXME related functions.  Re-name it to null_data
+            # FIXME or something similar.
+
+            if param.img_null_flag:
+                print '%s    const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4)
+                cond = '(ptr_is_null != 0) ? NULL : '
+            else:
+                cond = ""
+
+
+            type_string = param.type_string()
+
+            if param.is_image():
+                offset = f.offset_of( param.name )
+
+                print '%s    %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset)
+
+                if param.depth:
+                    print '%s    __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent)
+                else:
+                    print '%s    __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent)
+
+                need_blank = 1
+            elif param.is_counter or param.name in f.count_parameter_list:
+                location = self.fetch_param(param)
+                print '%s    const %s %s = %s;' % (indent, type_string, param.name, location)
+                need_blank = 1
+            elif len(param.count_parameter_list):
+                if param.size() == 1 and not self.do_swap:
+                    location = self.fetch_param(param)
+                    print '%s    %s %s = %s%s;' % (indent, type_string, param.name, cond, location)
+                else:
+                    print '%s    %s %s;' % (indent, type_string, param.name)
+                need_blank = 1
 
-               print '        error = Success;'
-               print '    }'
-               print ''
-               print '    return error;'
-               return
 
 
-       def printRenderFunction(self, f):
-               # There are 4 distinct phases in a rendering dispatch function.
-               # In the first phase we compute the sizes and offsets of each
-               # element in the command.  In the second phase we (optionally)
-               # re-align 64-bit data elements.  In the third phase we
-               # (optionally) byte-swap array data.  Finally, in the fourth
-               # phase we actually dispatch the function.
+        if need_blank:
+            print ''
 
-               self.common_func_print_just_start(f, "")
+        if align64:
+            print '#ifdef __GLX_ALIGN64'
 
-               images = f.get_images()
-               if len(images):
-                       if self.do_swap:
-                               pre = "bswap_CARD32( & "
-                               post = " )"
-                       else:
-                               pre = ""
-                               post = ""
+            if f.has_variable_size_request():
+                self.emit_packet_size_calculation(f, 4)
+                s = "cmdlen"
+            else:
+                s = str((f.command_fixed_length() + 3) & ~3)
 
-                       img = images[0]
+            print '    if ((unsigned long)(pc) & 7) {'
+            print '        (void) memmove(pc-4, pc, %s);' % (s)
+            print '        pc -= 4;'
+            print '    }'
+            print '#endif'
+            print ''
 
-                       # swapBytes and lsbFirst are single byte fields, so
-                       # the must NEVER be byte-swapped.
 
-                       if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"):
-                               print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES,   hdr->swapBytes) );'
+        need_blank = 0
+        if self.do_swap:
+            for param in f.parameterIterateGlxSend():
+                if param.count_parameter_list:
+                    o = param.offset
+                    count = param.get_element_count()
+                    type_size = param.size() / count
 
-                       print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST,    hdr->lsbFirst) );'
+                    if param.counter:
+                        count_name = param.counter
+                    else:
+                        count_name = str(count)
 
-                       print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH,   (GLint) %shdr->rowLength%s) );' % (pre, post)
-                       if img.depth:
-                               print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s) );' % (pre, post)
-                       print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS,    (GLint) %shdr->skipRows%s) );' % (pre, post)
-                       if img.depth:
-                               print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_IMAGES,  (GLint) %shdr->skipImages%s) );' % (pre, post)
-                       print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS,  (GLint) %shdr->skipPixels%s) );' % (pre, post)
-                       print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT,    (GLint) %shdr->alignment%s) );' % (pre, post)
-                       print ''
+                    # This is basically an ugly special-
+                    # case for glCallLists.
 
+                    if type_size == 1:
+                        x = [] 
+                        x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] )
+                        x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] )
+                        x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] )
+
+                        print '    switch(%s) {' % (param.count_parameter_list[0])
+                        for sub in x:
+                            for t_name in sub[1]:
+                                print '    case GL_%s:' % (t_name)
+
+                            if sub[0] == 1:
+                                print '        %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o)
+                            else:
+                                swap_func = self.swap_name(sub[0])
+                                print '        %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name)
+                        print '    default:'
+                        print '        return;'
+                        print '    }'
+                    else:
+                        swap_func = self.swap_name(type_size)
+                        compsize = self.size_call(f, 1)
+                        print '    %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize)
+
+                    need_blank = 1
+
+        else:
+            for param in f.parameterIterateGlxSend():
+                if param.count_parameter_list:
+                    print '%s    %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset)
+                    need_blank = 1
+
+
+        if need_blank:
+            print ''
 
-               self.emit_function_call(f, "", "")
-               return
+
+        return
+
+
+    def printSingleFunction(self, f, name):
+        if name not in f.glx_vendorpriv_names:
+            print '    xGLXSingleReq * const req = (xGLXSingleReq *) pc;'
+        else:
+            print '    xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;'
+
+        print '    int error;'
+
+        if self.do_swap:
+            print '    __GLXcontext * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);'
+        else:
+            print '    __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, &error);'
+
+        print ''
+        if name not in f.glx_vendorpriv_names:
+            print '    pc += __GLX_SINGLE_HDR_SIZE;'
+        else:
+            print '    pc += __GLX_VENDPRIV_HDR_SIZE;'
+
+        print '    if ( cx != NULL ) {'
+        self.common_func_print_just_start(f, "    ")
+
+
+        if f.return_type != 'void':
+            print '        %s retval;' % (f.return_type)
+            retval_string = "retval"
+            retval_assign = "retval = "
+        else:
+            retval_string = "0"
+            retval_assign = ""
+
+
+        type_size = 0
+        answer_string = "dummy_answer"
+        answer_count = "0"
+        is_array_string = "GL_FALSE"
+
+        for param in f.parameterIterateOutputs():
+            answer_type = param.get_base_type_string()
+            if answer_type == "GLvoid":
+                answer_type = "GLubyte"
+
+
+            c = param.get_element_count()
+            type_size = (param.size() / c)
+            if type_size == 1:
+                size_scale = ""
+            else:
+                size_scale = " * %u" % (type_size)
+
+
+            if param.count_parameter_list:
+                print '        const GLuint compsize = %s;' % (self.size_call(f, 1))
+                print '        %s answerBuffer[200];' %  (answer_type)
+                print '        %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size )
+                answer_string = param.name
+                answer_count = "compsize"
+
+                print ''
+                print '        if (%s == NULL) return BadAlloc;' % (param.name)
+                print '        __glXClearErrorOccured();'
+                print ''
+            elif param.counter:
+                print '        %s answerBuffer[200];' %  (answer_type)
+                print '        %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size)
+                answer_string = param.name
+                answer_count = param.counter
+            elif c >= 1:
+                print '        %s %s[%u];' % (answer_type, param.name, c)
+                answer_string = param.name
+                answer_count = "%u" % (c)
+
+            if f.reply_always_array:
+                is_array_string = "GL_TRUE"
+
+
+        self.emit_function_call(f, retval_assign, "    ")
+
+
+        if f.needs_reply():
+            if self.do_swap:
+                for param in f.parameterIterateOutputs():
+                    c = param.get_element_count()
+                    type_size = (param.size() / c)
+
+                    if type_size > 1:
+                        swap_name = self.swap_name( type_size )
+                        print '        (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count)
+
+
+                reply_func = '__glXSendReplySwap'
+            else:
+                reply_func = '__glXSendReply'
+
+            print '        %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string)
+        #elif f.note_unflushed:
+        #      print '        cx->hasUnflushedCommands = GL_TRUE;'
+
+        print '        error = Success;'
+        print '    }'
+        print ''
+        print '    return error;'
+        return
+
+
+    def printRenderFunction(self, f):
+        # There are 4 distinct phases in a rendering dispatch function.
+        # In the first phase we compute the sizes and offsets of each
+        # element in the command.  In the second phase we (optionally)
+        # re-align 64-bit data elements.  In the third phase we
+        # (optionally) byte-swap array data.  Finally, in the fourth
+        # phase we actually dispatch the function.
+
+        self.common_func_print_just_start(f, "")
+
+        images = f.get_images()
+        if len(images):
+            if self.do_swap:
+                pre = "bswap_CARD32( & "
+                post = " )"
+            else:
+                pre = ""
+                post = ""
+
+            img = images[0]
+
+            # swapBytes and lsbFirst are single byte fields, so
+            # the must NEVER be byte-swapped.
+
+            if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"):
+                print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SWAP_BYTES,   hdr->swapBytes) );'
+
+            print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_LSB_FIRST,    hdr->lsbFirst) );'
+
+            print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ROW_LENGTH,   (GLint) %shdr->rowLength%s) );' % (pre, post)
+            if img.depth:
+                print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s) );' % (pre, post)
+            print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS,    (GLint) %shdr->skipRows%s) );' % (pre, post)
+            if img.depth:
+                print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_IMAGES,  (GLint) %shdr->skipImages%s) );' % (pre, post)
+            print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS,  (GLint) %shdr->skipPixels%s) );' % (pre, post)
+            print '    CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_ALIGNMENT,    (GLint) %shdr->alignment%s) );' % (pre, post)
+            print ''
+
+
+        self.emit_function_call(f, "", "")
+        return
 
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s")
-       except Exception,e:
-               show_usage()
-
-       mode = "dispatch_c"
-       do_swap = 0
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       mode = val
-               elif arg == "-s":
-                       do_swap = 1
-
-       if mode == "dispatch_c":
-               printer = PrintGlxDispatchFunctions(do_swap)
-       elif mode == "dispatch_h":
-               printer = PrintGlxDispatch_h()
-       else:
-               show_usage()
-
-       api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() )
-
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:s")
+    except Exception,e:
+        show_usage()
+
+    mode = "dispatch_c"
+    do_swap = 0
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            mode = val
+        elif arg == "-s":
+            do_swap = 1
+
+    if mode == "dispatch_c":
+        printer = PrintGlxDispatchFunctions(do_swap)
+    elif mode == "dispatch_h":
+        printer = PrintGlxDispatch_h()
+    else:
+        show_usage()
+
+    api = gl_XML.parse_GL_API( file_name, glX_proto_common.glx_proto_item_factory() )
+
+    printer.Print( api )
index 2cb0cf4ef8b7fa61703d6de4165dac5543cd49a3..fbc0dd3fab7da2f3fe51415782622b240a3f93be 100644 (file)
@@ -45,153 +45,153 @@ def convertStringForXCB(str):
     return tmp
 
 def hash_pixel_function(func):
-       """Generate a 'unique' key for a pixel function.  The key is based on
-       the parameters written in the command packet.  This includes any
-       padding that might be added for the original function and the 'NULL
-       image' flag."""
+    """Generate a 'unique' key for a pixel function.  The key is based on
+    the parameters written in the command packet.  This includes any
+    padding that might be added for the original function and the 'NULL
+    image' flag."""
 
 
-       h = ""
-       hash_pre = ""
-       hash_suf = ""
-       for param in func.parameterIterateGlxSend():
-               if param.is_image():
-                       [dim, junk, junk, junk, junk] = param.get_dimensions()
+    h = ""
+    hash_pre = ""
+    hash_suf = ""
+    for param in func.parameterIterateGlxSend():
+        if param.is_image():
+            [dim, junk, junk, junk, junk] = param.get_dimensions()
 
-                       d = (dim + 1) & ~1
-                       hash_pre = "%uD%uD_" % (d - 1, d)
+            d = (dim + 1) & ~1
+            hash_pre = "%uD%uD_" % (d - 1, d)
 
-                       if param.img_null_flag:
-                               hash_suf = "_NF"
+            if param.img_null_flag:
+                hash_suf = "_NF"
 
-               h += "%u" % (param.size())
+        h += "%u" % (param.size())
 
-               if func.pad_after(param):
-                       h += "4"
+        if func.pad_after(param):
+            h += "4"
 
 
-       n = func.name.replace("%uD" % (dim), "")
-       n = "__glx_%s_%uD%uD" % (n, d - 1, d)
+    n = func.name.replace("%uD" % (dim), "")
+    n = "__glx_%s_%uD%uD" % (n, d - 1, d)
 
-       h = hash_pre + h + hash_suf
-       return [h, n]
+    h = hash_pre + h + hash_suf
+    return [h, n]
 
 
 class glx_pixel_function_stub(glX_XML.glx_function):
-       """Dummy class used to generate pixel "utility" functions that are
-       shared by multiple dimension image functions.  For example, these
-       objects are used to generate shared functions used to send GLX
-       protocol for TexImage1D and TexImage2D, TexSubImage1D and
-       TexSubImage2D, etc."""
+    """Dummy class used to generate pixel "utility" functions that are
+    shared by multiple dimension image functions.  For example, these
+    objects are used to generate shared functions used to send GLX
+    protocol for TexImage1D and TexImage2D, TexSubImage1D and
+    TexSubImage2D, etc."""
 
-       def __init__(self, func, name):
-               # The parameters to the utility function are the same as the
-               # parameters to the real function except for the added "pad"
-               # parameters.
+    def __init__(self, func, name):
+        # The parameters to the utility function are the same as the
+        # parameters to the real function except for the added "pad"
+        # parameters.
 
-               self.name = name
-               self.images = []
-               self.parameters = []
-               self.parameters_by_name = {}
-               for _p in func.parameterIterator():
-                       p = copy.copy(_p)
-                       self.parameters.append(p)
-                       self.parameters_by_name[ p.name ] = p
+        self.name = name
+        self.images = []
+        self.parameters = []
+        self.parameters_by_name = {}
+        for _p in func.parameterIterator():
+            p = copy.copy(_p)
+            self.parameters.append(p)
+            self.parameters_by_name[ p.name ] = p
 
 
-                       if p.is_image():
-                               self.images.append(p)
-                               p.height = "height"
+            if p.is_image():
+                self.images.append(p)
+                p.height = "height"
 
-                               if p.img_yoff == None:
-                                       p.img_yoff = "yoffset"
+                if p.img_yoff == None:
+                    p.img_yoff = "yoffset"
 
-                               if p.depth:
-                                       if p.extent == None:
-                                               p.extent = "extent"
+                if p.depth:
+                    if p.extent == None:
+                        p.extent = "extent"
 
-                                       if p.img_woff == None:
-                                               p.img_woff = "woffset"
+                    if p.img_woff == None:
+                        p.img_woff = "woffset"
 
 
-                       pad_name = func.pad_after(p)
-                       if pad_name:
-                               pad = copy.copy(p)
-                               pad.name = pad_name
-                               self.parameters.append(pad)
-                               self.parameters_by_name[ pad.name ] = pad
-                               
+            pad_name = func.pad_after(p)
+            if pad_name:
+                pad = copy.copy(p)
+                pad.name = pad_name
+                self.parameters.append(pad)
+                self.parameters_by_name[ pad.name ] = pad
 
-               self.return_type = func.return_type
 
-               self.glx_rop = ~0
-               self.glx_sop = 0
-               self.glx_vendorpriv = 0
+        self.return_type = func.return_type
 
-               self.glx_doubles_in_order = func.glx_doubles_in_order
+        self.glx_rop = ~0
+        self.glx_sop = 0
+        self.glx_vendorpriv = 0
 
-               self.vectorequiv = None
-               self.output = None
-               self.can_be_large = func.can_be_large
-               self.reply_always_array = func.reply_always_array
-               self.dimensions_in_reply = func.dimensions_in_reply
-               self.img_reset = None
+        self.glx_doubles_in_order = func.glx_doubles_in_order
 
-               self.server_handcode = 0
-               self.client_handcode = 0
-               self.ignore = 0
+        self.vectorequiv = None
+        self.output = None
+        self.can_be_large = func.can_be_large
+        self.reply_always_array = func.reply_always_array
+        self.dimensions_in_reply = func.dimensions_in_reply
+        self.img_reset = None
 
-               self.count_parameter_list = func.count_parameter_list
-               self.counter_list = func.counter_list
-               self.offsets_calculated = 0
-               return
+        self.server_handcode = 0
+        self.client_handcode = 0
+        self.ignore = 0
+
+        self.count_parameter_list = func.count_parameter_list
+        self.counter_list = func.counter_list
+        self.offsets_calculated = 0
+        return
 
 
 class PrintGlxProtoStubs(glX_proto_common.glx_print_proto):
-       def __init__(self):
-               glX_proto_common.glx_print_proto.__init__(self)
-               self.name = "glX_proto_send.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM")
-
-
-               self.last_category = ""
-               self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32]
-               self.pixel_stubs = {}
-               self.debug = 0
-               return
-
-       def printRealHeader(self):
-               print ''
-               print '#include <GL/gl.h>'
-               print '#include "indirect.h"'
-               print '#include "glxclient.h"'
-               print '#include "indirect_size.h"'
-               print '#include "glapi.h"'
-               print '#include "glthread.h"'
-               print '#include <GL/glxproto.h>'
-               print '#include <X11/Xlib-xcb.h>'
-               print '#include <xcb/xcb.h>'
-               print '#include <xcb/glx.h>'
-
-               print ''
-               print '#define __GLX_PAD(n) (((n) + 3) & ~3)'
-               print ''
-               self.printFastcall()
-               self.printNoinline()
-               print ''
-               print '#ifndef __GNUC__'
-               print '#  define __builtin_expect(x, y) x'
-               print '#endif'
-               print ''
-               print '/* If the size and opcode values are known at compile-time, this will, on'
-               print ' * x86 at least, emit them with a single instruction.'
-               print ' */'
-               print '#define emit_header(dest, op, size)            \\'
-               print '    do { union { short s[2]; int i; } temp;    \\'
-               print '         temp.s[0] = (size); temp.s[1] = (op); \\'
-               print '         *((int *)(dest)) = temp.i; } while(0)'
-               print ''
-               print """NOINLINE CARD32
+    def __init__(self):
+        glX_proto_common.glx_print_proto.__init__(self)
+        self.name = "glX_proto_send.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004, 2005", "IBM")
+
+
+        self.last_category = ""
+        self.generic_sizes = [3, 4, 6, 8, 12, 16, 24, 32]
+        self.pixel_stubs = {}
+        self.debug = 0
+        return
+
+    def printRealHeader(self):
+        print ''
+        print '#include <GL/gl.h>'
+        print '#include "indirect.h"'
+        print '#include "glxclient.h"'
+        print '#include "indirect_size.h"'
+        print '#include "glapi.h"'
+        print '#include "glthread.h"'
+        print '#include <GL/glxproto.h>'
+        print '#include <X11/Xlib-xcb.h>'
+        print '#include <xcb/xcb.h>'
+        print '#include <xcb/glx.h>'
+
+        print ''
+        print '#define __GLX_PAD(n) (((n) + 3) & ~3)'
+        print ''
+        self.printFastcall()
+        self.printNoinline()
+        print ''
+        print '#ifndef __GNUC__'
+        print '#  define __builtin_expect(x, y) x'
+        print '#endif'
+        print ''
+        print '/* If the size and opcode values are known at compile-time, this will, on'
+        print ' * x86 at least, emit them with a single instruction.'
+        print ' */'
+        print '#define emit_header(dest, op, size)            \\'
+        print '    do { union { short s[2]; int i; } temp;    \\'
+        print '         temp.s[0] = (size); temp.s[1] = (op); \\'
+        print '         *((int *)(dest)) = temp.i; } while(0)'
+        print ''
+        print """NOINLINE CARD32
 __glXReadReply( Display *dpy, size_t size, void * dest, GLboolean reply_is_always_array )
 {
     xGLXSingleReply reply;
@@ -305,60 +305,60 @@ const GLuint __glXDefaultPixelStore[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 1 };
 #define default_pixel_store_4D_size 36
 """
 
-               for size in self.generic_sizes:
-                       self.print_generic_function(size)
-               return
+        for size in self.generic_sizes:
+            self.print_generic_function(size)
+        return
 
 
-       def printBody(self, api):
+    def printBody(self, api):
 
-               self.pixel_stubs = {}
-               generated_stubs = []
+        self.pixel_stubs = {}
+        generated_stubs = []
 
-               for func in api.functionIterateGlx():
-                       if func.client_handcode: continue
+        for func in api.functionIterateGlx():
+            if func.client_handcode: continue
 
-                       # If the function is a pixel function with a certain
-                       # GLX protocol signature, create a fake stub function
-                       # for it.  For example, create a single stub function
-                       # that is used to implement both glTexImage1D and
-                       # glTexImage2D.
+            # If the function is a pixel function with a certain
+            # GLX protocol signature, create a fake stub function
+            # for it.  For example, create a single stub function
+            # that is used to implement both glTexImage1D and
+            # glTexImage2D.
 
-                       if func.glx_rop != 0:
-                               do_it = 0
-                               for image in func.get_images():
-                                       if image.img_pad_dimensions:
-                                               do_it = 1
-                                               break
+            if func.glx_rop != 0:
+                do_it = 0
+                for image in func.get_images():
+                    if image.img_pad_dimensions:
+                        do_it = 1
+                        break
 
 
-                               if do_it:
-                                       [h, n] = hash_pixel_function(func)
+                if do_it:
+                    [h, n] = hash_pixel_function(func)
 
 
-                                       self.pixel_stubs[ func.name ] = n
-                                       if h not in generated_stubs:
-                                               generated_stubs.append(h)
+                    self.pixel_stubs[ func.name ] = n
+                    if h not in generated_stubs:
+                        generated_stubs.append(h)
 
-                                               fake_func = glx_pixel_function_stub( func, n )
-                                               self.printFunction(fake_func, fake_func.name)
+                        fake_func = glx_pixel_function_stub( func, n )
+                        self.printFunction(fake_func, fake_func.name)
 
 
-                       self.printFunction(func, func.name)
-                       if func.glx_sop and func.glx_vendorpriv:
-                               self.printFunction(func, func.glx_vendorpriv_names[0])
+            self.printFunction(func, func.name)
+            if func.glx_sop and func.glx_vendorpriv:
+                self.printFunction(func, func.glx_vendorpriv_names[0])
 
-               self.printGetProcAddress(api)
-               return
+        self.printGetProcAddress(api)
+        return
 
-       def printGetProcAddress(self, api):
-               procs = {}
-               for func in api.functionIterateGlx():
-                       for n in func.entry_points:
-                               if func.has_different_protocol(n):
-                                       procs[n] = func.static_glx_name(n)
+    def printGetProcAddress(self, api):
+        procs = {}
+        for func in api.functionIterateGlx():
+            for n in func.entry_points:
+                if func.has_different_protocol(n):
+                    procs[n] = func.static_glx_name(n)
 
-               print """
+        print """
 #ifdef GLX_SHARED_GLAPI
 
 static const struct proc_pair
@@ -366,12 +366,12 @@ static const struct proc_pair
    const char *name;
    _glapi_proc proc;
 } proc_pairs[%d] = {""" % len(procs)
-               names = procs.keys()
-               names.sort()
-               for i in xrange(len(names)):
-                       comma = ',' if i < len(names) - 1 else ''
-                       print '   { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)
-               print """};
+        names = procs.keys()
+        names.sort()
+        for i in xrange(len(names)):
+            comma = ',' if i < len(names) - 1 else ''
+            print '   { "%s", (_glapi_proc) gl%s }%s' % (names[i], procs[names[i]], comma)
+        print """};
 
 static int
 __indirect_get_proc_compare(const void *key, const void *memb)
@@ -397,64 +397,64 @@ __indirect_get_proc_address(const char *name)
 
 #endif /* GLX_SHARED_GLAPI */
 """
-               return
-
-
-       def printFunction(self, func, name):
-               footer = '}\n'
-               if func.glx_rop == ~0:
-                       print 'static %s' % (func.return_type)
-                       print '%s( unsigned opcode, unsigned dim, %s )' % (func.name, func.get_parameter_string())
-                       print '{'
-               else:
-                       if func.has_different_protocol(name):
-                               if func.return_type == "void":
-                                       ret_string = ''
-                               else:
-                                       ret_string = "return "
-
-                               func_name = func.static_glx_name(name)
-                               print '#define %s %d' % (func.opcode_vendor_name(name), func.glx_vendorpriv)
-                               print '%s gl%s(%s)' % (func.return_type, func_name, func.get_parameter_string())
-                               print '{'
-                               print '    struct glx_context * const gc = __glXGetCurrentContext();'
-                               print ''
-                               print '#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)'
-                               print '    if (gc->isDirect) {'
-                               print '        const _glapi_proc *const disp_table = (_glapi_proc *)GET_DISPATCH();'
-                               print '        PFNGL%sPROC p =' % (name.upper())
-                               print '            (PFNGL%sPROC) disp_table[%d];' % (name.upper(), func.offset)
-                               print '    %sp(%s);' % (ret_string, func.get_called_parameter_string())
-                               print '    } else'
-                               print '#endif'
-                               print '    {'
-
-                               footer = '}\n}\n'
-                       else:
-                               print '#define %s %d' % (func.opcode_name(), func.opcode_value())
-
-                               print '%s __indirect_gl%s(%s)' % (func.return_type, name, func.get_parameter_string())
-                               print '{'
-
-
-               if func.glx_rop != 0 or func.vectorequiv != None:
-                       if len(func.images):
-                               self.printPixelFunction(func)
-                       else:
-                               self.printRenderFunction(func)
-               elif func.glx_sop != 0 or func.glx_vendorpriv != 0:
-                       self.printSingleFunction(func, name)
-                       pass
-               else:
-                       print "/* Missing GLX protocol for %s. */" % (name)
-
-               print footer
-               return
-
-
-       def print_generic_function(self, n):
-               size = (n + 3) & ~3
-               print """static FASTCALL NOINLINE void
+        return
+
+
+    def printFunction(self, func, name):
+        footer = '}\n'
+        if func.glx_rop == ~0:
+            print 'static %s' % (func.return_type)
+            print '%s( unsigned opcode, unsigned dim, %s )' % (func.name, func.get_parameter_string())
+            print '{'
+        else:
+            if func.has_different_protocol(name):
+                if func.return_type == "void":
+                    ret_string = ''
+                else:
+                    ret_string = "return "
+
+                func_name = func.static_glx_name(name)
+                print '#define %s %d' % (func.opcode_vendor_name(name), func.glx_vendorpriv)
+                print '%s gl%s(%s)' % (func.return_type, func_name, func.get_parameter_string())
+                print '{'
+                print '    struct glx_context * const gc = __glXGetCurrentContext();'
+                print ''
+                print '#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)'
+                print '    if (gc->isDirect) {'
+                print '        const _glapi_proc *const disp_table = (_glapi_proc *)GET_DISPATCH();'
+                print '        PFNGL%sPROC p =' % (name.upper())
+                print '            (PFNGL%sPROC) disp_table[%d];' % (name.upper(), func.offset)
+                print '    %sp(%s);' % (ret_string, func.get_called_parameter_string())
+                print '    } else'
+                print '#endif'
+                print '    {'
+
+                footer = '}\n}\n'
+            else:
+                print '#define %s %d' % (func.opcode_name(), func.opcode_value())
+
+                print '%s __indirect_gl%s(%s)' % (func.return_type, name, func.get_parameter_string())
+                print '{'
+
+
+        if func.glx_rop != 0 or func.vectorequiv != None:
+            if len(func.images):
+                self.printPixelFunction(func)
+            else:
+                self.printRenderFunction(func)
+        elif func.glx_sop != 0 or func.glx_vendorpriv != 0:
+            self.printSingleFunction(func, name)
+            pass
+        else:
+            print "/* Missing GLX protocol for %s. */" % (name)
+
+        print footer
+        return
+
+
+    def print_generic_function(self, n):
+        size = (n + 3) & ~3
+        print """static FASTCALL NOINLINE void
 generic_%u_byte( GLint rop, const void * ptr )
 {
     struct glx_context * const gc = __glXGetCurrentContext();
@@ -466,473 +466,473 @@ generic_%u_byte( GLint rop, const void * ptr )
     if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }
 }
 """ % (n, size + 4, size)
-               return
-
-
-       def common_emit_one_arg(self, p, pc, adjust, extra_offset):
-               if p.is_array():
-                       src_ptr = p.name
-               else:
-                       src_ptr = "&" + p.name
-
-               if p.is_padding:
-                       print '(void) memset((void *)(%s + %u), 0, %s);' \
-                           % (pc, p.offset + adjust, p.size_string() )
-               elif not extra_offset:
-                       print '(void) memcpy((void *)(%s + %u), (void *)(%s), %s);' \
-                           % (pc, p.offset + adjust, src_ptr, p.size_string() )
-               else:
-                       print '(void) memcpy((void *)(%s + %u + %s), (void *)(%s), %s);' \
-                           % (pc, p.offset + adjust, extra_offset, src_ptr, p.size_string() )
-
-       def common_emit_args(self, f, pc, adjust, skip_vla):
-               extra_offset = None
-
-               for p in f.parameterIterateGlxSend( not skip_vla ):
-                       if p.name != f.img_reset:
-                               self.common_emit_one_arg(p, pc, adjust, extra_offset)
-                               
-                               if p.is_variable_length():
-                                       temp = p.size_string()
-                                       if extra_offset:
-                                               extra_offset += " + %s" % (temp)
-                                       else:
-                                               extra_offset = temp
-
-               return
-
-
-       def pixel_emit_args(self, f, pc, large):
-               """Emit the arguments for a pixel function.  This differs from
-               common_emit_args in that pixel functions may require padding
-               be inserted (i.e., for the missing width field for
-               TexImage1D), and they may also require a 'NULL image' flag
-               be inserted before the image data."""
-
-               if large:
-                       adjust = 8
-               else:
-                       adjust = 4
-
-               for param in f.parameterIterateGlxSend():
-                       if not param.is_image():
-                               self.common_emit_one_arg(param, pc, adjust, None)
-
-                               if f.pad_after(param):
-                                       print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset + param.size()) + adjust)
-
-                       else:
-                               [dim, width, height, depth, extent] = param.get_dimensions()
-                               if f.glx_rop == ~0:
-                                       dim_str = "dim"
-                               else:
-                                       dim_str = str(dim)
-
-                               if param.is_padding:
-                                       print '(void) memset((void *)(%s + %u), 0, %s);' \
-                                       % (pc, (param.offset - 4) + adjust, param.size_string() )
-
-                               if param.img_null_flag:
-                                       if large:
-                                               print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset - 4) + adjust)
-                                       else:
-                                               print '(void) memcpy((void *)(%s + %u), (void *)((%s == NULL) ? one : zero), 4);' % (pc, (param.offset - 4) + adjust, param.name)
-
-
-                               pixHeaderPtr = "%s + %u" % (pc, adjust)
-                               pcPtr = "%s + %u" % (pc, param.offset + adjust)
-
-                               if not large:
-                                       if param.img_send_null:
-                                               condition = '(compsize > 0) && (%s != NULL)' % (param.name)
-                                       else:
-                                               condition = 'compsize > 0'
-
-                                       print 'if (%s) {' % (condition)
-                                       print '    (*gc->fillImage)(gc, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr)
-                                       print '} else {'
-                                       print '    (void) memcpy( %s, default_pixel_store_%uD, default_pixel_store_%uD_size );' % (pixHeaderPtr, dim, dim)
-                                       print '}'
-                               else:
-                                       print '__glXSendLargeImage(gc, compsize, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr)
-
-               return
-
-
-       def large_emit_begin(self, f, op_name = None):
-               if not op_name:
-                       op_name = f.opcode_real_name()
-
-               print 'const GLint op = %s;' % (op_name)
-               print 'const GLuint cmdlenLarge = cmdlen + 4;'
-               print 'GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);'
-               print '(void) memcpy((void *)(pc + 0), (void *)(&cmdlenLarge), 4);'
-               print '(void) memcpy((void *)(pc + 4), (void *)(&op), 4);'
-               return
-
-
-       def common_func_print_just_start(self, f, name):
-               print '    struct glx_context * const gc = __glXGetCurrentContext();'
-
-               # The only reason that single and vendor private commands need
-               # a variable called 'dpy' is becuase they use the SyncHandle
-               # macro.  For whatever brain-dead reason, that macro is hard-
-               # coded to use a variable called 'dpy' instead of taking a
-               # parameter.
-
-               # FIXME Simplify the logic related to skip_condition and
-               # FIXME condition_list in this function.  Basically, remove
-               # FIXME skip_condition, and just append the "dpy != NULL" type
-               # FIXME condition to condition_list from the start.  The only
-               # FIXME reason it's done in this confusing way now is to
-               # FIXME minimize the diffs in the generated code.
-
-               if not f.glx_rop:
-                       for p in f.parameterIterateOutputs():
-                               if p.is_image() and (p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP"):
-                                       print '    const __GLXattribute * const state = gc->client_state_private;'
-                                       break
-
-                       print '    Display * const dpy = gc->currentDpy;'
-                       skip_condition = "dpy != NULL"
-               elif f.can_be_large:
-                       skip_condition = "gc->currentDpy != NULL"
-               else:
-                       skip_condition = None
-
-
-               if f.return_type != 'void':
-                       print '    %s retval = (%s) 0;' % (f.return_type, f.return_type)
-
-
-               if name != None and name not in f.glx_vendorpriv_names:
-                       print '#ifndef USE_XCB'
-               self.emit_packet_size_calculation(f, 0)
-               if name != None and name not in f.glx_vendorpriv_names:
-                       print '#endif'
-
-               condition_list = []
-               for p in f.parameterIterateCounters():
-                       condition_list.append( "%s >= 0" % (p.name) )
-                       # 'counter' parameters cannot be negative
-                       print "    if (%s < 0) {" % p.name
-                       print "        __glXSetError(gc, GL_INVALID_VALUE);"
-                       if f.return_type != 'void':
-                               print "        return 0;"
-                       else:
-                               print "        return;"
-                       print "    }"
-
-               if skip_condition:
-                       condition_list.append( skip_condition )
-
-               if len( condition_list ) > 0:
-                       if len( condition_list ) > 1:
-                               skip_condition = "(%s)" % (string.join( condition_list, ") && (" ))
-                       else:
-                               skip_condition = "%s" % (condition_list.pop(0))
-
-                       print '    if (__builtin_expect(%s, 1)) {' % (skip_condition)
-                       return 1
-               else:
-                       return 0
-
-
-       def printSingleFunction(self, f, name):
-               self.common_func_print_just_start(f, name)
-
-               if self.debug:
-                       print '        printf( "Enter %%s...\\n", "gl%s" );' % (f.name)
-
-               if name not in f.glx_vendorpriv_names:
-
-                       # XCB specific:
-                       print '#ifdef USE_XCB'
-                       if self.debug:
-                               print '        printf("\\tUsing XCB.\\n");'
-                       print '        xcb_connection_t *c = XGetXCBConnection(dpy);'
-                       print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
-                       xcb_name = 'xcb_glx%s' % convertStringForXCB(name)
-
-                       iparams=[]
-                       extra_iparams = []
-                       output = None
-                       for p in f.parameterIterator():
-                               if p.is_output:
-                                       output = p
-
-                                       if p.is_image():
-                                               if p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP":
-                                                       extra_iparams.append("state->storePack.swapEndian")
-                                               else:
-                                                       extra_iparams.append("0")
-                                       
-                                               # Hardcode this in.  lsb_first param (apparently always GL_FALSE)
-                                               # also present in GetPolygonStipple, but taken care of above.
-                                               if xcb_name == "xcb_glx_read_pixels": 
-                                                       extra_iparams.append("0")
-                               else:
-                                       iparams.append(p.name)
-
-
-                       xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams + extra_iparams))
-
-                       if f.needs_reply():
-                               print '        %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request)
-                               if output:
-                                       if output.is_image():
-                                               [dim, w, h, d, junk] = output.get_dimensions()
-                                               if f.dimensions_in_reply:
-                                                       w = "reply->width"
-                                                       h = "reply->height"
-                                                       d = "reply->depth"
-                                                       if dim < 2:
-                                                               h = "1"
-                                                       else:
-                                                               print '        if (%s == 0) { %s = 1; }' % (h, h)
-                                                       if dim < 3:
-                                                               d = "1"
-                                                       else:
-                                                               print '        if (%s == 0) { %s = 1; }' % (d, d)
-
-                                               print '        __glEmptyImage(gc, 3, %s, %s, %s, %s, %s, %s_data(reply), %s);' % (w, h, d, output.img_format, output.img_type, xcb_name, output.name)
-                                       else:
-                                               if f.reply_always_array:
-                                                       print '        (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string())
-                                               else:
-                                                       print '        if (%s_data_length(reply) == 0)' % (xcb_name)
-                                                       print '            (void)memcpy(%s, &reply->datum, sizeof(reply->datum));' % (output.name)
-                                                       print '        else'
-                                                       print '            (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string())
-
-                               if f.return_type != 'void':
-                                       print '        retval = reply->ret_val;'
-                               print '        free(reply);'
-                       else:
-                               print '        ' + xcb_request + ';'
-                       print '#else'
-                       # End of XCB specific.
-
-
-               if f.parameters != []:
-                       pc_decl = "GLubyte const * pc ="
-               else:
-                       pc_decl = "(void)"
-
-               if name in f.glx_vendorpriv_names:
-                       print '        %s __glXSetupVendorRequest(gc, %s, %s, cmdlen);' % (pc_decl, f.opcode_real_name(), f.opcode_vendor_name(name))
-               else:
-                       print '        %s __glXSetupSingleRequest(gc, %s, cmdlen);' % (pc_decl, f.opcode_name())
-
-               self.common_emit_args(f, "pc", 0, 0)
-
-               images = f.get_images()
-
-               for img in images:
-                       if img.is_output:
-                               o = f.command_fixed_length() - 4
-                               print '        *(int32_t *)(pc + %u) = 0;' % (o)
-                               if img.img_format != "GL_COLOR_INDEX" or img.img_type != "GL_BITMAP":
-                                       print '        * (int8_t *)(pc + %u) = state->storePack.swapEndian;' % (o)
-               
-                               if f.img_reset:
-                                       print '        * (int8_t *)(pc + %u) = %s;' % (o + 1, f.img_reset)
-
-
-               return_name = ''
-               if f.needs_reply():
-                       if f.return_type != 'void':
-                               return_name = " retval"
-                               return_str = " retval = (%s)" % (f.return_type)
-                       else:
-                               return_str = " (void)"
-
-                       got_reply = 0
-
-                       for p in f.parameterIterateOutputs():
-                               if p.is_image():
-                                       [dim, w, h, d, junk] = p.get_dimensions()
-                                       if f.dimensions_in_reply:
-                                               print "        __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name)
-                                       else:
-                                               print "        __glXReadPixelReply(dpy, gc, %u, %s, %s, %s, %s, %s, %s, GL_FALSE);" % (dim, w, h, d, p.img_format, p.img_type, p.name)
-
-                                       got_reply = 1
-                               else:
-                                       if f.reply_always_array:
-                                               aa = "GL_TRUE"
-                                       else:
-                                               aa = "GL_FALSE"
-
-                                       # gl_parameter.size() returns the size
-                                       # of the entire data item.  If the
-                                       # item is a fixed-size array, this is
-                                       # the size of the whole array.  This
-                                       # is not what __glXReadReply wants. It
-                                       # wants the size of a single data
-                                       # element in the reply packet.
-                                       # Dividing by the array size (1 for
-                                       # non-arrays) gives us this.
-
-                                       s = p.size() / p.get_element_count()
-                                       print "       %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa)
-                                       got_reply = 1
-
-
-                       # If a reply wasn't read to fill an output parameter,
-                       # read a NULL reply to get the return value.
-
-                       if not got_reply:
-                               print "       %s __glXReadReply(dpy, 0, NULL, GL_FALSE);" % (return_str)
-
-
-               elif self.debug:
-                       # Only emit the extra glFinish call for functions
-                       # that don't already require a reply from the server.
-                       print '        __indirect_glFinish();'
-
-               if self.debug:
-                       print '        printf( "Exit %%s.\\n", "gl%s" );' % (name)
-
+        return
+
+
+    def common_emit_one_arg(self, p, pc, adjust, extra_offset):
+        if p.is_array():
+            src_ptr = p.name
+        else:
+            src_ptr = "&" + p.name
+
+        if p.is_padding:
+            print '(void) memset((void *)(%s + %u), 0, %s);' \
+                % (pc, p.offset + adjust, p.size_string() )
+        elif not extra_offset:
+            print '(void) memcpy((void *)(%s + %u), (void *)(%s), %s);' \
+                % (pc, p.offset + adjust, src_ptr, p.size_string() )
+        else:
+            print '(void) memcpy((void *)(%s + %u + %s), (void *)(%s), %s);' \
+                % (pc, p.offset + adjust, extra_offset, src_ptr, p.size_string() )
 
-               print '        UnlockDisplay(dpy); SyncHandle();'
+    def common_emit_args(self, f, pc, adjust, skip_vla):
+        extra_offset = None
 
-               if name not in f.glx_vendorpriv_names:
-                       print '#endif /* USE_XCB */'
+        for p in f.parameterIterateGlxSend( not skip_vla ):
+            if p.name != f.img_reset:
+                self.common_emit_one_arg(p, pc, adjust, extra_offset)
 
-               print '    }'
-               print '    return%s;' % (return_name)
-               return
+                if p.is_variable_length():
+                    temp = p.size_string()
+                    if extra_offset:
+                        extra_offset += " + %s" % (temp)
+                    else:
+                        extra_offset = temp
 
+        return
 
-       def printPixelFunction(self, f):
-               if self.pixel_stubs.has_key( f.name ):
-                       # Normally gl_function::get_parameter_string could be
-                       # used.  However, this call needs to have the missing
-                       # dimensions (e.g., a fake height value for
-                       # glTexImage1D) added in.
 
-                       p_string = ""
-                       for param in f.parameterIterateGlxSend():
-                               if param.is_padding:
-                                       continue
+    def pixel_emit_args(self, f, pc, large):
+        """Emit the arguments for a pixel function.  This differs from
+        common_emit_args in that pixel functions may require padding
+        be inserted (i.e., for the missing width field for
+        TexImage1D), and they may also require a 'NULL image' flag
+        be inserted before the image data."""
 
-                               p_string += ", " + param.name
+        if large:
+            adjust = 8
+        else:
+            adjust = 4
+
+        for param in f.parameterIterateGlxSend():
+            if not param.is_image():
+                self.common_emit_one_arg(param, pc, adjust, None)
+
+                if f.pad_after(param):
+                    print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset + param.size()) + adjust)
+
+            else:
+                [dim, width, height, depth, extent] = param.get_dimensions()
+                if f.glx_rop == ~0:
+                    dim_str = "dim"
+                else:
+                    dim_str = str(dim)
+
+                if param.is_padding:
+                    print '(void) memset((void *)(%s + %u), 0, %s);' \
+                    % (pc, (param.offset - 4) + adjust, param.size_string() )
+
+                if param.img_null_flag:
+                    if large:
+                        print '(void) memcpy((void *)(%s + %u), zero, 4);' % (pc, (param.offset - 4) + adjust)
+                    else:
+                        print '(void) memcpy((void *)(%s + %u), (void *)((%s == NULL) ? one : zero), 4);' % (pc, (param.offset - 4) + adjust, param.name)
+
+
+                pixHeaderPtr = "%s + %u" % (pc, adjust)
+                pcPtr = "%s + %u" % (pc, param.offset + adjust)
+
+                if not large:
+                    if param.img_send_null:
+                        condition = '(compsize > 0) && (%s != NULL)' % (param.name)
+                    else:
+                        condition = 'compsize > 0'
+
+                    print 'if (%s) {' % (condition)
+                    print '    (*gc->fillImage)(gc, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr)
+                    print '} else {'
+                    print '    (void) memcpy( %s, default_pixel_store_%uD, default_pixel_store_%uD_size );' % (pixHeaderPtr, dim, dim)
+                    print '}'
+                else:
+                    print '__glXSendLargeImage(gc, compsize, %s, %s, %s, %s, %s, %s, %s, %s, %s);' % (dim_str, width, height, depth, param.img_format, param.img_type, param.name, pcPtr, pixHeaderPtr)
+
+        return
+
+
+    def large_emit_begin(self, f, op_name = None):
+        if not op_name:
+            op_name = f.opcode_real_name()
+
+        print 'const GLint op = %s;' % (op_name)
+        print 'const GLuint cmdlenLarge = cmdlen + 4;'
+        print 'GLubyte * const pc = __glXFlushRenderBuffer(gc, gc->pc);'
+        print '(void) memcpy((void *)(pc + 0), (void *)(&cmdlenLarge), 4);'
+        print '(void) memcpy((void *)(pc + 4), (void *)(&op), 4);'
+        return
+
+
+    def common_func_print_just_start(self, f, name):
+        print '    struct glx_context * const gc = __glXGetCurrentContext();'
+
+        # The only reason that single and vendor private commands need
+        # a variable called 'dpy' is becuase they use the SyncHandle
+        # macro.  For whatever brain-dead reason, that macro is hard-
+        # coded to use a variable called 'dpy' instead of taking a
+        # parameter.
+
+        # FIXME Simplify the logic related to skip_condition and
+        # FIXME condition_list in this function.  Basically, remove
+        # FIXME skip_condition, and just append the "dpy != NULL" type
+        # FIXME condition to condition_list from the start.  The only
+        # FIXME reason it's done in this confusing way now is to
+        # FIXME minimize the diffs in the generated code.
+
+        if not f.glx_rop:
+            for p in f.parameterIterateOutputs():
+                if p.is_image() and (p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP"):
+                    print '    const __GLXattribute * const state = gc->client_state_private;'
+                    break
+
+            print '    Display * const dpy = gc->currentDpy;'
+            skip_condition = "dpy != NULL"
+        elif f.can_be_large:
+            skip_condition = "gc->currentDpy != NULL"
+        else:
+            skip_condition = None
+
+
+        if f.return_type != 'void':
+            print '    %s retval = (%s) 0;' % (f.return_type, f.return_type)
+
+
+        if name != None and name not in f.glx_vendorpriv_names:
+            print '#ifndef USE_XCB'
+        self.emit_packet_size_calculation(f, 0)
+        if name != None and name not in f.glx_vendorpriv_names:
+            print '#endif'
+
+        condition_list = []
+        for p in f.parameterIterateCounters():
+            condition_list.append( "%s >= 0" % (p.name) )
+            # 'counter' parameters cannot be negative
+            print "    if (%s < 0) {" % p.name
+            print "        __glXSetError(gc, GL_INVALID_VALUE);"
+            if f.return_type != 'void':
+                print "        return 0;"
+            else:
+                print "        return;"
+            print "    }"
+
+        if skip_condition:
+            condition_list.append( skip_condition )
+
+        if len( condition_list ) > 0:
+            if len( condition_list ) > 1:
+                skip_condition = "(%s)" % (string.join( condition_list, ") && (" ))
+            else:
+                skip_condition = "%s" % (condition_list.pop(0))
+
+            print '    if (__builtin_expect(%s, 1)) {' % (skip_condition)
+            return 1
+        else:
+            return 0
+
+
+    def printSingleFunction(self, f, name):
+        self.common_func_print_just_start(f, name)
+
+        if self.debug:
+            print '        printf( "Enter %%s...\\n", "gl%s" );' % (f.name)
+
+        if name not in f.glx_vendorpriv_names:
+
+            # XCB specific:
+            print '#ifdef USE_XCB'
+            if self.debug:
+                print '        printf("\\tUsing XCB.\\n");'
+            print '        xcb_connection_t *c = XGetXCBConnection(dpy);'
+            print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
+            xcb_name = 'xcb_glx%s' % convertStringForXCB(name)
+
+            iparams=[]
+            extra_iparams = []
+            output = None
+            for p in f.parameterIterator():
+                if p.is_output:
+                    output = p
+
+                    if p.is_image():
+                        if p.img_format != "GL_COLOR_INDEX" or p.img_type != "GL_BITMAP":
+                            extra_iparams.append("state->storePack.swapEndian")
+                        else:
+                            extra_iparams.append("0")
+
+                        # Hardcode this in.  lsb_first param (apparently always GL_FALSE)
+                        # also present in GetPolygonStipple, but taken care of above.
+                        if xcb_name == "xcb_glx_read_pixels": 
+                            extra_iparams.append("0")
+                else:
+                    iparams.append(p.name)
+
+
+            xcb_request = '%s(%s)' % (xcb_name, ", ".join(["c", "gc->currentContextTag"] + iparams + extra_iparams))
+
+            if f.needs_reply():
+                print '        %s_reply_t *reply = %s_reply(c, %s, NULL);' % (xcb_name, xcb_name, xcb_request)
+                if output:
+                    if output.is_image():
+                        [dim, w, h, d, junk] = output.get_dimensions()
+                        if f.dimensions_in_reply:
+                            w = "reply->width"
+                            h = "reply->height"
+                            d = "reply->depth"
+                            if dim < 2:
+                                h = "1"
+                            else:
+                                print '        if (%s == 0) { %s = 1; }' % (h, h)
+                            if dim < 3:
+                                d = "1"
+                            else:
+                                print '        if (%s == 0) { %s = 1; }' % (d, d)
+
+                        print '        __glEmptyImage(gc, 3, %s, %s, %s, %s, %s, %s_data(reply), %s);' % (w, h, d, output.img_format, output.img_type, xcb_name, output.name)
+                    else:
+                        if f.reply_always_array:
+                            print '        (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string())
+                        else:
+                            print '        if (%s_data_length(reply) == 0)' % (xcb_name)
+                            print '            (void)memcpy(%s, &reply->datum, sizeof(reply->datum));' % (output.name)
+                            print '        else'
+                            print '            (void)memcpy(%s, %s_data(reply), %s_data_length(reply) * sizeof(%s));' % (output.name, xcb_name, xcb_name, output.get_base_type_string())
+
+                if f.return_type != 'void':
+                    print '        retval = reply->ret_val;'
+                print '        free(reply);'
+            else:
+                print '        ' + xcb_request + ';'
+            print '#else'
+            # End of XCB specific.
+
+
+        if f.parameters != []:
+            pc_decl = "GLubyte const * pc ="
+        else:
+            pc_decl = "(void)"
+
+        if name in f.glx_vendorpriv_names:
+            print '        %s __glXSetupVendorRequest(gc, %s, %s, cmdlen);' % (pc_decl, f.opcode_real_name(), f.opcode_vendor_name(name))
+        else:
+            print '        %s __glXSetupSingleRequest(gc, %s, cmdlen);' % (pc_decl, f.opcode_name())
 
-                               if param.is_image():
-                                       [dim, junk, junk, junk, junk] = param.get_dimensions()
+        self.common_emit_args(f, "pc", 0, 0)
 
-                               if f.pad_after(param):
-                                       p_string += ", 1"
+        images = f.get_images()
 
-                       print '    %s(%s, %u%s );' % (self.pixel_stubs[f.name] , f.opcode_name(), dim, p_string)
-                       return
+        for img in images:
+            if img.is_output:
+                o = f.command_fixed_length() - 4
+                print '        *(int32_t *)(pc + %u) = 0;' % (o)
+                if img.img_format != "GL_COLOR_INDEX" or img.img_type != "GL_BITMAP":
+                    print '        * (int8_t *)(pc + %u) = state->storePack.swapEndian;' % (o)
 
+                if f.img_reset:
+                    print '        * (int8_t *)(pc + %u) = %s;' % (o + 1, f.img_reset)
 
-               if self.common_func_print_just_start(f, None):
-                       trailer = "    }"
-               else:
-                       trailer = None
 
+        return_name = ''
+        if f.needs_reply():
+            if f.return_type != 'void':
+                return_name = " retval"
+                return_str = " retval = (%s)" % (f.return_type)
+            else:
+                return_str = " (void)"
 
-               if f.can_be_large:
-                       print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {'
-                       print '    if ( (gc->pc + cmdlen) > gc->bufEnd ) {'
-                       print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
-                       print '    }'
+            got_reply = 0
 
-               if f.glx_rop == ~0:
-                       opcode = "opcode"
-               else:
-                       opcode = f.opcode_real_name()
+            for p in f.parameterIterateOutputs():
+                if p.is_image():
+                    [dim, w, h, d, junk] = p.get_dimensions()
+                    if f.dimensions_in_reply:
+                        print "        __glXReadPixelReply(dpy, gc, %u, 0, 0, 0, %s, %s, %s, GL_TRUE);" % (dim, p.img_format, p.img_type, p.name)
+                    else:
+                        print "        __glXReadPixelReply(dpy, gc, %u, %s, %s, %s, %s, %s, %s, GL_FALSE);" % (dim, w, h, d, p.img_format, p.img_type, p.name)
 
-               print 'emit_header(gc->pc, %s, cmdlen);' % (opcode)
+                    got_reply = 1
+                else:
+                    if f.reply_always_array:
+                        aa = "GL_TRUE"
+                    else:
+                        aa = "GL_FALSE"
 
-               self.pixel_emit_args( f, "gc->pc", 0 )
-               print 'gc->pc += cmdlen;'
-               print 'if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }'
+                    # gl_parameter.size() returns the size
+                    # of the entire data item.  If the
+                    # item is a fixed-size array, this is
+                    # the size of the whole array.  This
+                    # is not what __glXReadReply wants. It
+                    # wants the size of a single data
+                    # element in the reply packet.
+                    # Dividing by the array size (1 for
+                    # non-arrays) gives us this.
 
-               if f.can_be_large:
-                       print '}'
-                       print 'else {'
+                    s = p.size() / p.get_element_count()
+                    print "       %s __glXReadReply(dpy, %s, %s, %s);" % (return_str, s, p.name, aa)
+                    got_reply = 1
 
-                       self.large_emit_begin(f, opcode)
-                       self.pixel_emit_args(f, "pc", 1)
 
-                       print '}'
+            # If a reply wasn't read to fill an output parameter,
+            # read a NULL reply to get the return value.
 
-               if trailer: print trailer
-               return
+            if not got_reply:
+                print "       %s __glXReadReply(dpy, 0, NULL, GL_FALSE);" % (return_str)
 
 
-       def printRenderFunction(self, f):
-               # There is a class of GL functions that take a single pointer
-               # as a parameter.  This pointer points to a fixed-size chunk
-               # of data, and the protocol for this functions is very
-               # regular.  Since they are so regular and there are so many
-               # of them, special case them with generic functions.  On
-               # x86, this saves about 26KB in the libGL.so binary.
+        elif self.debug:
+            # Only emit the extra glFinish call for functions
+            # that don't already require a reply from the server.
+            print '        __indirect_glFinish();'
 
-               if f.variable_length_parameter() == None and len(f.parameters) == 1:
-                       p = f.parameters[0]
-                       if p.is_pointer():
-                               cmdlen = f.command_fixed_length()
-                               if cmdlen in self.generic_sizes:
-                                       print '    generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name)
-                                       return
+        if self.debug:
+            print '        printf( "Exit %%s.\\n", "gl%s" );' % (name)
 
-               if self.common_func_print_just_start(f, None):
-                       trailer = "    }"
-               else:
-                       trailer = None
 
-               if self.debug:
-                       print 'printf( "Enter %%s...\\n", "gl%s" );' % (f.name)
+        print '        UnlockDisplay(dpy); SyncHandle();'
 
-               if f.can_be_large:
-                       print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {'
-                       print '    if ( (gc->pc + cmdlen) > gc->bufEnd ) {'
-                       print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
-                       print '    }'
+        if name not in f.glx_vendorpriv_names:
+            print '#endif /* USE_XCB */'
 
-               print 'emit_header(gc->pc, %s, cmdlen);' % (f.opcode_real_name())
+        print '    }'
+        print '    return%s;' % (return_name)
+        return
 
-               self.common_emit_args(f, "gc->pc", 4, 0)
-               print 'gc->pc += cmdlen;'
-               print 'if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }'
 
-               if f.can_be_large:
-                       print '}'
-                       print 'else {'
+    def printPixelFunction(self, f):
+        if self.pixel_stubs.has_key( f.name ):
+            # Normally gl_function::get_parameter_string could be
+            # used.  However, this call needs to have the missing
+            # dimensions (e.g., a fake height value for
+            # glTexImage1D) added in.
 
-                       self.large_emit_begin(f)
-                       self.common_emit_args(f, "pc", 8, 1)
+            p_string = ""
+            for param in f.parameterIterateGlxSend():
+                if param.is_padding:
+                    continue
 
-                       p = f.variable_length_parameter()
-                       print '    __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (p.offset + 8, p.name, p.size_string())
-                       print '}'
+                p_string += ", " + param.name
 
-               if self.debug:
-                       print '__indirect_glFinish();'
-                       print 'printf( "Exit %%s.\\n", "gl%s" );' % (f.name)
+                if param.is_image():
+                    [dim, junk, junk, junk, junk] = param.get_dimensions()
 
-               if trailer: print trailer
-               return
+                if f.pad_after(param):
+                    p_string += ", 1"
+
+            print '    %s(%s, %u%s );' % (self.pixel_stubs[f.name] , f.opcode_name(), dim, p_string)
+            return
+
+
+        if self.common_func_print_just_start(f, None):
+            trailer = "    }"
+        else:
+            trailer = None
+
+
+        if f.can_be_large:
+            print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {'
+            print '    if ( (gc->pc + cmdlen) > gc->bufEnd ) {'
+            print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
+            print '    }'
+
+        if f.glx_rop == ~0:
+            opcode = "opcode"
+        else:
+            opcode = f.opcode_real_name()
+
+        print 'emit_header(gc->pc, %s, cmdlen);' % (opcode)
+
+        self.pixel_emit_args( f, "gc->pc", 0 )
+        print 'gc->pc += cmdlen;'
+        print 'if (gc->pc > gc->limit) { (void) __glXFlushRenderBuffer(gc, gc->pc); }'
+
+        if f.can_be_large:
+            print '}'
+            print 'else {'
+
+            self.large_emit_begin(f, opcode)
+            self.pixel_emit_args(f, "pc", 1)
+
+            print '}'
+
+        if trailer: print trailer
+        return
+
+
+    def printRenderFunction(self, f):
+        # There is a class of GL functions that take a single pointer
+        # as a parameter.  This pointer points to a fixed-size chunk
+        # of data, and the protocol for this functions is very
+        # regular.  Since they are so regular and there are so many
+        # of them, special case them with generic functions.  On
+        # x86, this saves about 26KB in the libGL.so binary.
+
+        if f.variable_length_parameter() == None and len(f.parameters) == 1:
+            p = f.parameters[0]
+            if p.is_pointer():
+                cmdlen = f.command_fixed_length()
+                if cmdlen in self.generic_sizes:
+                    print '    generic_%u_byte( %s, %s );' % (cmdlen, f.opcode_real_name(), p.name)
+                    return
+
+        if self.common_func_print_just_start(f, None):
+            trailer = "    }"
+        else:
+            trailer = None
+
+        if self.debug:
+            print 'printf( "Enter %%s...\\n", "gl%s" );' % (f.name)
+
+        if f.can_be_large:
+            print 'if (cmdlen <= gc->maxSmallRenderCommandSize) {'
+            print '    if ( (gc->pc + cmdlen) > gc->bufEnd ) {'
+            print '        (void) __glXFlushRenderBuffer(gc, gc->pc);'
+            print '    }'
+
+        print 'emit_header(gc->pc, %s, cmdlen);' % (f.opcode_real_name())
+
+        self.common_emit_args(f, "gc->pc", 4, 0)
+        print 'gc->pc += cmdlen;'
+        print 'if (__builtin_expect(gc->pc > gc->limit, 0)) { (void) __glXFlushRenderBuffer(gc, gc->pc); }'
+
+        if f.can_be_large:
+            print '}'
+            print 'else {'
+
+            self.large_emit_begin(f)
+            self.common_emit_args(f, "pc", 8, 1)
+
+            p = f.variable_length_parameter()
+            print '    __glXSendLargeCommand(gc, pc, %u, %s, %s);' % (p.offset + 8, p.name, p.size_string())
+            print '}'
+
+        if self.debug:
+            print '__indirect_glFinish();'
+            print 'printf( "Exit %%s.\\n", "gl%s" );' % (f.name)
+
+        if trailer: print trailer
+        return
 
 
 class PrintGlxProtoInit_c(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "glX_proto_send.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "glX_proto_send.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 (C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM")
-               return
+        return
 
 
-       def printRealHeader(self):
-               print """/**
+    def printRealHeader(self):
+        print """/**
  * \\file indirect_init.c
  * Initialize indirect rendering dispatch table.
  *
@@ -977,53 +977,53 @@ struct _glapi_table * __glXNewIndirectAPI( void )
 
     /* now, initialize the entries we understand */"""
 
-       def printRealFooter(self):
-               print """
+    def printRealFooter(self):
+        print """
     return (struct _glapi_table *) table;
 }
 """
-               return
+        return
 
 
-       def printBody(self, api):
-               for [name, number] in api.categoryIterate():
-                       if number != None:
-                               preamble = '\n    /* %3u. %s */\n' % (int(number), name)
-                       else:
-                               preamble = '\n    /* %s */\n' % (name)
+    def printBody(self, api):
+        for [name, number] in api.categoryIterate():
+            if number != None:
+                preamble = '\n    /* %3u. %s */\n' % (int(number), name)
+            else:
+                preamble = '\n    /* %s */\n' % (name)
 
-                       for func in api.functionIterateByCategory(name):
-                               if func.client_supported_for_indirect():
-                                       if preamble:
-                                               print preamble
-                                               preamble = None
+            for func in api.functionIterateByCategory(name):
+                if func.client_supported_for_indirect():
+                    if preamble:
+                        print preamble
+                        preamble = None
 
-                                       if func.is_abi():
-                                               print '    table[{offset}] = (_glapi_proc) __indirect_gl{name};'.format(name = func.name, offset = func.offset)
-                                       else:
-                                               print '    o = _glapi_get_proc_offset("gl{0}");'.format(func.name)
-                                               print '    assert(o > 0);'
-                                               print '    table[o] = (_glapi_proc) __indirect_gl{0};'.format(func.name)
+                    if func.is_abi():
+                        print '    table[{offset}] = (_glapi_proc) __indirect_gl{name};'.format(name = func.name, offset = func.offset)
+                    else:
+                        print '    o = _glapi_get_proc_offset("gl{0}");'.format(func.name)
+                        print '    assert(o > 0);'
+                        print '    table[o] = (_glapi_proc) __indirect_gl{0};'.format(func.name)
 
-               return
+        return
 
 
 class PrintGlxProtoInit_h(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "glX_proto_send.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "glX_proto_send.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 (C) Copyright IBM Corporation 2004""", "PRECISION INSIGHT, IBM")
-               self.header_tag = "_INDIRECT_H_"
+        self.header_tag = "_INDIRECT_H_"
 
-               self.last_category = ""
-               return
+        self.last_category = ""
+        return
 
 
-       def printRealHeader(self):
-               print """/**
+    def printRealHeader(self):
+        print """/**
  * \\file
  * Prototypes for indirect rendering functions.
  *
@@ -1031,10 +1031,10 @@ class PrintGlxProtoInit_h(gl_XML.gl_print_base):
  * \\author Ian Romanick <idr@us.ibm.com>
  */
 """
-               self.printFastcall()
-               self.printNoinline()
+        self.printFastcall()
+        self.printNoinline()
 
-               print """
+        print """
 #include <X11/Xfuncproto.h>
 #include "glxclient.h"
 
@@ -1054,67 +1054,67 @@ extern _X_HIDDEN NOINLINE FASTCALL GLubyte * __glXSetupVendorRequest(
 """
 
 
-       def printBody(self, api):
-               for func in api.functionIterateGlx():
-                       params = func.get_parameter_string()
+    def printBody(self, api):
+        for func in api.functionIterateGlx():
+            params = func.get_parameter_string()
+
+            print 'extern _X_HIDDEN %s __indirect_gl%s(%s);' % (func.return_type, func.name, params)
 
-                       print 'extern _X_HIDDEN %s __indirect_gl%s(%s);' % (func.return_type, func.name, params)
+            for n in func.entry_points:
+                if func.has_different_protocol(n):
+                    asdf = func.static_glx_name(n)
+                    if asdf not in func.static_entry_points:
+                        print 'extern _X_HIDDEN %s gl%s(%s);' % (func.return_type, asdf, params)
+                        # give it a easy-to-remember name
+                        if func.client_handcode:
+                            print '#define gl_dispatch_stub_%s gl%s' % (n, asdf)
+                    else:
+                        print 'GLAPI %s GLAPIENTRY gl%s(%s);' % (func.return_type, asdf, params)
 
-                       for n in func.entry_points:
-                               if func.has_different_protocol(n):
-                                       asdf = func.static_glx_name(n)
-                                       if asdf not in func.static_entry_points:
-                                               print 'extern _X_HIDDEN %s gl%s(%s);' % (func.return_type, asdf, params)
-                                               # give it a easy-to-remember name
-                                               if func.client_handcode:
-                                                       print '#define gl_dispatch_stub_%s gl%s' % (n, asdf)
-                                       else:
-                                               print 'GLAPI %s GLAPIENTRY gl%s(%s);' % (func.return_type, asdf, params)
-                                               
-                                       break
+                    break
 
-               print ''
-               print '#ifdef GLX_SHARED_GLAPI'
-               print 'extern _X_HIDDEN void (*__indirect_get_proc_address(const char *name))(void);'
-               print '#endif'
+        print ''
+        print '#ifdef GLX_SHARED_GLAPI'
+        print 'extern _X_HIDDEN void (*__indirect_get_proc_address(const char *name))(void);'
+        print '#endif'
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m output_mode] [-d]" % sys.argv[0]
-       print "    -m output_mode   Output mode can be one of 'proto', 'init_c' or 'init_h'."
-       print "    -d               Enable extra debug information in the generated code."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m output_mode] [-d]" % sys.argv[0]
+    print "    -m output_mode   Output mode can be one of 'proto', 'init_c' or 'init_h'."
+    print "    -d               Enable extra debug information in the generated code."
+    sys.exit(1)
 
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:d")
-       except Exception,e:
-               show_usage()
-
-       debug = 0
-       mode = "proto"
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       mode = val
-               elif arg == "-d":
-                       debug = 1
-
-       if mode == "proto":
-               printer = PrintGlxProtoStubs()
-       elif mode == "init_c":
-               printer = PrintGlxProtoInit_c()
-       elif mode == "init_h":
-               printer = PrintGlxProtoInit_h()
-       else:
-               show_usage()
-
-
-       printer.debug = debug
-       api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
-
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:d")
+    except Exception,e:
+        show_usage()
+
+    debug = 0
+    mode = "proto"
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            mode = val
+        elif arg == "-d":
+            debug = 1
+
+    if mode == "proto":
+        printer = PrintGlxProtoStubs()
+    elif mode == "init_c":
+        printer = PrintGlxProtoInit_c()
+    elif mode == "init_h":
+        printer = PrintGlxProtoInit_h()
+    else:
+        show_usage()
+
+
+    printer.debug = debug
+    api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
+
+    printer.Print( api )
index b31d1c650507c392b44e97cd9d34a3fd6ad154bd..7db816b2c0159aa909e90545a7ba6cce72f4a185 100644 (file)
@@ -31,346 +31,346 @@ import sys, getopt, copy, string
 
 
 class glx_enum_function:
-       def __init__(self, func_name, enum_dict):
-               self.name = func_name
-               self.mode = 1
-               self.sig = None
+    def __init__(self, func_name, enum_dict):
+        self.name = func_name
+        self.mode = 1
+        self.sig = None
 
-               # "enums" is a set of lists.  The element in the set is the
-               # value of the enum.  The list is the list of names for that
-               # value.  For example, [0x8126] = {"POINT_SIZE_MIN",
-               # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT",
-               # "POINT_SIZE_MIN_SGIS"}.
+        # "enums" is a set of lists.  The element in the set is the
+        # value of the enum.  The list is the list of names for that
+        # value.  For example, [0x8126] = {"POINT_SIZE_MIN",
+        # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT",
+        # "POINT_SIZE_MIN_SGIS"}.
 
-               self.enums = {}
+        self.enums = {}
 
-               # "count" is indexed by count values.  Each element of count
-               # is a list of index to "enums" that have that number of
-               # associated data elements.  For example, [4] = 
-               # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
-               # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here,
-               # but the actual hexadecimal values would be in the array).
+        # "count" is indexed by count values.  Each element of count
+        # is a list of index to "enums" that have that number of
+        # associated data elements.  For example, [4] = 
+        # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
+        # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here,
+        # but the actual hexadecimal values would be in the array).
 
-               self.count = {}
+        self.count = {}
 
 
-               # Fill self.count and self.enums using the dictionary of enums
-               # that was passed in.  The generic Get functions (e.g.,
-               # GetBooleanv and friends) are handled specially here.  In
-               # the data the generic Get functions are refered to as "Get".
+        # Fill self.count and self.enums using the dictionary of enums
+        # that was passed in.  The generic Get functions (e.g.,
+        # GetBooleanv and friends) are handled specially here.  In
+        # the data the generic Get functions are refered to as "Get".
 
-               if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]:
-                       match_name = "Get"
-               else:
-                       match_name = func_name
-
-               mode_set = 0
-               for enum_name in enum_dict:
-                       e = enum_dict[ enum_name ]
+        if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]:
+            match_name = "Get"
+        else:
+            match_name = func_name
 
-                       if e.functions.has_key( match_name ):
-                               [count, mode] = e.functions[ match_name ]
+        mode_set = 0
+        for enum_name in enum_dict:
+            e = enum_dict[ enum_name ]
 
-                               if mode_set and mode != self.mode:
-                                       raise RuntimeError("Not all enums for %s have the same mode." % (func_name))
+            if e.functions.has_key( match_name ):
+                [count, mode] = e.functions[ match_name ]
 
-                               self.mode = mode
+                if mode_set and mode != self.mode:
+                    raise RuntimeError("Not all enums for %s have the same mode." % (func_name))
 
-                               if self.enums.has_key( e.value ):
-                                       if e.name not in self.enums[ e.value ]:
-                                               self.enums[ e.value ].append( e )
-                               else:
-                                       if not self.count.has_key( count ):
-                                               self.count[ count ] = []
-
-                                       self.enums[ e.value ] = [ e ]
-                                       self.count[ count ].append( e.value )
+                self.mode = mode
 
+                if self.enums.has_key( e.value ):
+                    if e.name not in self.enums[ e.value ]:
+                        self.enums[ e.value ].append( e )
+                else:
+                    if not self.count.has_key( count ):
+                        self.count[ count ] = []
 
-               return
-
+                    self.enums[ e.value ] = [ e ]
+                    self.count[ count ].append( e.value )
 
-       def signature( self ):
-               if self.sig == None:
-                       self.sig = ""
-                       for i in self.count:
-                               if i == None:
-                                       raise RuntimeError("i is None.  WTF?")
 
-                               self.count[i].sort()
-                               for e in self.count[i]:
-                                       self.sig += "%04x,%d," % (e, i)
+        return
 
-               return self.sig
-
-
-       def is_set( self ):
-               return self.mode
-
-
-       def PrintUsingTable(self):
-               """Emit the body of the __gl*_size function using a pair
-               of look-up tables and a mask.  The mask is calculated such
-               that (e & mask) is unique for all the valid values of e for
-               this function.  The result of (e & mask) is used as an index
-               into the first look-up table.  If it matches e, then the
-               same entry of the second table is returned.  Otherwise zero
-               is returned.
-               
-               It seems like this should cause better code to be generated.
-               However, on x86 at least, the resulting .o file is about 20%
-               larger then the switch-statment version.  I am leaving this
-               code in because the results may be different on other
-               platforms (e.g., PowerPC or x86-64)."""
-
-               return 0
-               count = 0
-               for a in self.enums:
-                       count += 1
-
-               if self.count.has_key(-1):
-                       return 0
-
-               # Determine if there is some mask M, such that M = (2^N) - 1,
-               # that will generate unique values for all of the enums.
-
-               mask = 0
-               for i in [1, 2, 3, 4, 5, 6, 7, 8]:
-                       mask = (1 << i) - 1
-
-                       fail = 0;
-                       for a in self.enums:
-                               for b in self.enums:
-                                       if a != b:
-                                               if (a & mask) == (b & mask):
-                                                       fail = 1;
-
-                       if not fail:
-                               break;
-                       else:
-                               mask = 0
 
-               if (mask != 0) and (mask < (2 * count)):
-                       masked_enums = {}
-                       masked_count = {}
-
-                       for i in range(0, mask + 1):
-                               masked_enums[i] = "0";
-                               masked_count[i] = 0;
-
-                       for c in self.count:
-                               for e in self.count[c]:
-                                       i = e & mask
-                                       enum_obj = self.enums[e][0]
-                                       masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name )
-                                       masked_count[i] = c
-
-
-                       print '    static const GLushort a[%u] = {' % (mask + 1)
-                       for e in masked_enums:
-                               print '        %s, ' % (masked_enums[e])
-                       print '    };'
-
-                       print '    static const GLubyte b[%u] = {' % (mask + 1)
-                       for c in masked_count:
-                               print '        %u, ' % (masked_count[c])
-                       print '    };'
-
-                       print '    const unsigned idx = (e & 0x%02xU);' % (mask)
-                       print ''
-                       print '    return (e == a[idx]) ? (GLint) b[idx] : 0;'
-                       return 1;
-               else:
-                       return 0;
-
-
-       def PrintUsingSwitch(self, name):
-               """Emit the body of the __gl*_size function using a 
-               switch-statement."""
-
-               print '    switch( e ) {'
-
-               for c in self.count:
-                       for e in self.count[c]:
-                               first = 1
-
-                               # There may be multiple enums with the same
-                               # value.  This happens has extensions are
-                               # promoted from vendor-specific or EXT to
-                               # ARB and to the core.  Emit the first one as
-                               # a case label, and emit the others as
-                               # commented-out case labels.
-
-                               list = {}
-                               for enum_obj in self.enums[e]:
-                                       list[ enum_obj.priority() ] = enum_obj.name
-
-                               keys = list.keys()
-                               keys.sort()
-                               for k in keys:
-                                       j = list[k]
-                                       if first:
-                                               print '        case GL_%s:' % (j)
-                                               first = 0
-                                       else:
-                                               print '/*      case GL_%s:*/' % (j)
-                                       
-                       if c == -1:
-                               print '            return __gl%s_variable_size( e );' % (name)
-                       else:
-                               print '            return %u;' % (c)
-                                       
-               print '        default: return 0;'
-               print '    }'
-
-
-       def Print(self, name):
-               print '_X_INTERNAL PURE FASTCALL GLint'
-               print '__gl%s_size( GLenum e )' % (name)
-               print '{'
-
-               if not self.PrintUsingTable():
-                       self.PrintUsingSwitch(name)
-
-               print '}'
-               print ''
+    def signature( self ):
+        if self.sig == None:
+            self.sig = ""
+            for i in self.count:
+                if i == None:
+                    raise RuntimeError("i is None.  WTF?")
+
+                self.count[i].sort()
+                for e in self.count[i]:
+                    self.sig += "%04x,%d," % (e, i)
+
+        return self.sig
+
+
+    def is_set( self ):
+        return self.mode
+
+
+    def PrintUsingTable(self):
+        """Emit the body of the __gl*_size function using a pair
+        of look-up tables and a mask.  The mask is calculated such
+        that (e & mask) is unique for all the valid values of e for
+        this function.  The result of (e & mask) is used as an index
+        into the first look-up table.  If it matches e, then the
+        same entry of the second table is returned.  Otherwise zero
+        is returned.
+
+        It seems like this should cause better code to be generated.
+        However, on x86 at least, the resulting .o file is about 20%
+        larger then the switch-statment version.  I am leaving this
+        code in because the results may be different on other
+        platforms (e.g., PowerPC or x86-64)."""
+
+        return 0
+        count = 0
+        for a in self.enums:
+            count += 1
+
+        if self.count.has_key(-1):
+            return 0
+
+        # Determine if there is some mask M, such that M = (2^N) - 1,
+        # that will generate unique values for all of the enums.
+
+        mask = 0
+        for i in [1, 2, 3, 4, 5, 6, 7, 8]:
+            mask = (1 << i) - 1
+
+            fail = 0;
+            for a in self.enums:
+                for b in self.enums:
+                    if a != b:
+                        if (a & mask) == (b & mask):
+                            fail = 1;
+
+            if not fail:
+                break;
+            else:
+                mask = 0
+
+        if (mask != 0) and (mask < (2 * count)):
+            masked_enums = {}
+            masked_count = {}
+
+            for i in range(0, mask + 1):
+                masked_enums[i] = "0";
+                masked_count[i] = 0;
+
+            for c in self.count:
+                for e in self.count[c]:
+                    i = e & mask
+                    enum_obj = self.enums[e][0]
+                    masked_enums[i] = '0x%04x /* %s */' % (e, enum_obj.name )
+                    masked_count[i] = c
+
+
+            print '    static const GLushort a[%u] = {' % (mask + 1)
+            for e in masked_enums:
+                print '        %s, ' % (masked_enums[e])
+            print '    };'
+
+            print '    static const GLubyte b[%u] = {' % (mask + 1)
+            for c in masked_count:
+                print '        %u, ' % (masked_count[c])
+            print '    };'
+
+            print '    const unsigned idx = (e & 0x%02xU);' % (mask)
+            print ''
+            print '    return (e == a[idx]) ? (GLint) b[idx] : 0;'
+            return 1;
+        else:
+            return 0;
+
+
+    def PrintUsingSwitch(self, name):
+        """Emit the body of the __gl*_size function using a 
+        switch-statement."""
+
+        print '    switch( e ) {'
+
+        for c in self.count:
+            for e in self.count[c]:
+                first = 1
+
+                # There may be multiple enums with the same
+                # value.  This happens has extensions are
+                # promoted from vendor-specific or EXT to
+                # ARB and to the core.  Emit the first one as
+                # a case label, and emit the others as
+                # commented-out case labels.
+
+                list = {}
+                for enum_obj in self.enums[e]:
+                    list[ enum_obj.priority() ] = enum_obj.name
+
+                keys = list.keys()
+                keys.sort()
+                for k in keys:
+                    j = list[k]
+                    if first:
+                        print '        case GL_%s:' % (j)
+                        first = 0
+                    else:
+                        print '/*      case GL_%s:*/' % (j)
+
+            if c == -1:
+                print '            return __gl%s_variable_size( e );' % (name)
+            else:
+                print '            return %u;' % (c)
+
+        print '        default: return 0;'
+        print '    }'
+
+
+    def Print(self, name):
+        print '_X_INTERNAL PURE FASTCALL GLint'
+        print '__gl%s_size( GLenum e )' % (name)
+        print '{'
+
+        if not self.PrintUsingTable():
+            self.PrintUsingSwitch(name)
+
+        print '}'
+        print ''
 
 
 class glx_server_enum_function(glx_enum_function):
-       def __init__(self, func, enum_dict):
-               glx_enum_function.__init__(self, func.name, enum_dict)
-               
-               self.function = func
-               return
+    def __init__(self, func, enum_dict):
+        glx_enum_function.__init__(self, func.name, enum_dict)
 
+        self.function = func
+        return
 
-       def signature( self ):
-               if self.sig == None:
-                       sig = glx_enum_function.signature(self)
 
-                       p = self.function.variable_length_parameter()
-                       if p:
-                               sig += "%u" % (p.size())
+    def signature( self ):
+        if self.sig == None:
+            sig = glx_enum_function.signature(self)
 
-                       self.sig = sig
+            p = self.function.variable_length_parameter()
+            if p:
+                sig += "%u" % (p.size())
 
-               return self.sig;
+            self.sig = sig
 
+        return self.sig;
 
-       def Print(self, name, printer):
-               f = self.function
-               printer.common_func_print_just_header( f )
 
-               fixup = []
-               
-               foo = {}
-               for param_name in f.count_parameter_list:
-                       o = f.offset_of( param_name )
-                       foo[o] = param_name
+    def Print(self, name, printer):
+        f = self.function
+        printer.common_func_print_just_header( f )
 
-               for param_name in f.counter_list:
-                       o = f.offset_of( param_name )
-                       foo[o] = param_name
+        fixup = []
 
-               keys = foo.keys()
-               keys.sort()
-               for o in keys:
-                       p = f.parameters_by_name[ foo[o] ]
+        foo = {}
+        for param_name in f.count_parameter_list:
+            o = f.offset_of( param_name )
+            foo[o] = param_name
 
-                       printer.common_emit_one_arg(p, "pc", 0)
-                       fixup.append( p.name )
+        for param_name in f.counter_list:
+            o = f.offset_of( param_name )
+            foo[o] = param_name
 
+        keys = foo.keys()
+        keys.sort()
+        for o in keys:
+            p = f.parameters_by_name[ foo[o] ]
 
-               print '    GLsizei compsize;'
-               print ''
+            printer.common_emit_one_arg(p, "pc", 0)
+            fixup.append( p.name )
 
-               printer.common_emit_fixups(fixup)
 
-               print ''
-               print '    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
-               p = f.variable_length_parameter()
-               print '    return __GLX_PAD(%s);' % (p.size_string())
+        print '    GLsizei compsize;'
+        print ''
 
-               print '}'
-               print ''
+        printer.common_emit_fixups(fixup)
+
+        print ''
+        print '    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
+        p = f.variable_length_parameter()
+        print '    return __GLX_PAD(%s);' % (p.size_string())
+
+        print '}'
+        print ''
 
 
 class PrintGlxSizeStubs_common(gl_XML.gl_print_base):
-       do_get = (1 << 0)
-       do_set = (1 << 1)
+    do_get = (1 << 0)
+    do_set = (1 << 1)
 
-       def __init__(self, which_functions):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, which_functions):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "glX_proto_size.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
+        self.name = "glX_proto_size.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
 
-               self.emit_set = ((which_functions & PrintGlxSizeStubs_common.do_set) != 0)
-               self.emit_get = ((which_functions & PrintGlxSizeStubs_common.do_get) != 0)
-               return
+        self.emit_set = ((which_functions & PrintGlxSizeStubs_common.do_set) != 0)
+        self.emit_get = ((which_functions & PrintGlxSizeStubs_common.do_get) != 0)
+        return
 
 
 class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
-       def printRealHeader(self):
-               print ''
-               print '#include <X11/Xfuncproto.h>'
-               print '#include <GL/gl.h>'
-               if self.emit_get:
-                       print '#include "indirect_size_get.h"'
-                       print '#include "glxserver.h"'
-                       print '#include "indirect_util.h"'
-               
-               print '#include "indirect_size.h"'
-
-               print ''
-               self.printPure()
-               print ''
-               self.printFastcall()
-               print ''
-               print ''
-               print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(GLX_USE_APPLEGL)'
-               print '#  undef HAVE_ALIAS'
-               print '#endif'
-               print '#ifdef HAVE_ALIAS'
-               print '#  define ALIAS2(from,to) \\'
-               print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
-               print '        __attribute__ ((alias( # to )));'
-               print '#  define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )'
-               print '#else'
-               print '#  define ALIAS(from,to) \\'
-               print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
-               print '    { return __gl ## to ## _size( e ); }'
-               print '#endif'
-               print ''
-               print ''
-
-
-       def printBody(self, api):
-               enum_sigs = {}
-               aliases = []
-
-               for func in api.functionIterateGlx():
-                       ef = glx_enum_function( func.name, api.enums_by_name )
-                       if len(ef.enums) == 0:
-                               continue
-
-                       if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
-                               sig = ef.signature()
-                               if enum_sigs.has_key( sig ):
-                                       aliases.append( [func.name, enum_sigs[ sig ]] )
-                               else:
-                                       enum_sigs[ sig ] = func.name
-                                       ef.Print( func.name )
-
-
-               for [alias_name, real_name] in aliases:
-                       print 'ALIAS( %s, %s )' % (alias_name, real_name)
-
-
-                               
+    def printRealHeader(self):
+        print ''
+        print '#include <X11/Xfuncproto.h>'
+        print '#include <GL/gl.h>'
+        if self.emit_get:
+            print '#include "indirect_size_get.h"'
+            print '#include "glxserver.h"'
+            print '#include "indirect_util.h"'
+
+        print '#include "indirect_size.h"'
+
+        print ''
+        self.printPure()
+        print ''
+        self.printFastcall()
+        print ''
+        print ''
+        print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(GLX_USE_APPLEGL)'
+        print '#  undef HAVE_ALIAS'
+        print '#endif'
+        print '#ifdef HAVE_ALIAS'
+        print '#  define ALIAS2(from,to) \\'
+        print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
+        print '        __attribute__ ((alias( # to )));'
+        print '#  define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )'
+        print '#else'
+        print '#  define ALIAS(from,to) \\'
+        print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
+        print '    { return __gl ## to ## _size( e ); }'
+        print '#endif'
+        print ''
+        print ''
+
+
+    def printBody(self, api):
+        enum_sigs = {}
+        aliases = []
+
+        for func in api.functionIterateGlx():
+            ef = glx_enum_function( func.name, api.enums_by_name )
+            if len(ef.enums) == 0:
+                continue
+
+            if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
+                sig = ef.signature()
+                if enum_sigs.has_key( sig ):
+                    aliases.append( [func.name, enum_sigs[ sig ]] )
+                else:
+                    enum_sigs[ sig ] = func.name
+                    ef.Print( func.name )
+
+
+        for [alias_name, real_name] in aliases:
+            print 'ALIAS( %s, %s )' % (alias_name, real_name)
+
+
+
 class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
-       def printRealHeader(self):
-               print """/**
+    def printRealHeader(self):
+        print """/**
  * \\file
  * Prototypes for functions used to determine the number of data elements in
  * various GLX protocol messages.
@@ -378,326 +378,326 @@ class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
  * \\author Ian Romanick <idr@us.ibm.com>
  */
 """
-               print '#include <X11/Xfuncproto.h>'
-               print ''
-               self.printPure();
-               print ''
-               self.printFastcall();
-               print ''
+        print '#include <X11/Xfuncproto.h>'
+        print ''
+        self.printPure();
+        print ''
+        self.printFastcall();
+        print ''
 
 
-       def printBody(self, api):
-               for func in api.functionIterateGlx():
-                       ef = glx_enum_function( func.name, api.enums_by_name )
-                       if len(ef.enums) == 0:
-                               continue
+    def printBody(self, api):
+        for func in api.functionIterateGlx():
+            ef = glx_enum_function( func.name, api.enums_by_name )
+            if len(ef.enums) == 0:
+                continue
 
-                       if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
-                               print 'extern _X_INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name)
+            if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
+                print 'extern _X_INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name)
 
 
 class PrintGlxReqSize_common(gl_XML.gl_print_base):
-       """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h.
+    """Common base class for PrintGlxSizeReq_h and PrintGlxSizeReq_h.
 
-       The main purpose of this common base class is to provide the infrastructure
-       for the derrived classes to iterate over the same set of functions.
-       """
+    The main purpose of this common base class is to provide the infrastructure
+    for the derrived classes to iterate over the same set of functions.
+    """
 
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "glX_proto_size.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
+        self.name = "glX_proto_size.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM")
 
 
 class PrintGlxReqSize_h(PrintGlxReqSize_common):
-       def __init__(self):
-               PrintGlxReqSize_common.__init__(self)
-               self.header_tag = "_INDIRECT_REQSIZE_H_"
+    def __init__(self):
+        PrintGlxReqSize_common.__init__(self)
+        self.header_tag = "_INDIRECT_REQSIZE_H_"
 
 
-       def printRealHeader(self):
-               print '#include <X11/Xfuncproto.h>'
-               print ''
-               self.printPure()
-               print ''
+    def printRealHeader(self):
+        print '#include <X11/Xfuncproto.h>'
+        print ''
+        self.printPure()
+        print ''
 
 
-       def printBody(self, api):
-               for func in api.functionIterateGlx():
-                       if not func.ignore and func.has_variable_size_request():
-                               print 'extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name)
+    def printBody(self, api):
+        for func in api.functionIterateGlx():
+            if not func.ignore and func.has_variable_size_request():
+                print 'extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name)
 
 
 class PrintGlxReqSize_c(PrintGlxReqSize_common):
-       """Create the server-side 'request size' functions.
-
-       Create the server-side functions that are used to determine what the
-       size of a varible length command should be.  The server then uses
-       this value to determine if the incoming command packed it malformed.
-       """
+    """Create the server-side 'request size' functions.
+
+    Create the server-side functions that are used to determine what the
+    size of a varible length command should be.  The server then uses
+    this value to determine if the incoming command packed it malformed.
+    """
+
+    def __init__(self):
+        PrintGlxReqSize_common.__init__(self)
+        self.counter_sigs = {}
+
+
+    def printRealHeader(self):
+        print ''
+        print '#include <GL/gl.h>'
+        print '#include "glxserver.h"'
+        print '#include "glxbyteorder.h"'
+        print '#include "indirect_size.h"'
+        print '#include "indirect_reqsize.h"'
+        print ''
+        print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
+        print ''
+        print '#if defined(__CYGWIN__) || defined(__MINGW32__)'
+        print '#  undef HAVE_ALIAS'
+        print '#endif'
+        print '#ifdef HAVE_ALIAS'
+        print '#  define ALIAS2(from,to) \\'
+        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
+        print '        __attribute__ ((alias( # to )));'
+        print '#  define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )'
+        print '#else'
+        print '#  define ALIAS(from,to) \\'
+        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
+        print '    { return __glX ## to ## ReqSize( pc, swap ); }'
+        print '#endif'
+        print ''
+        print ''
+
+
+    def printBody(self, api):
+        aliases = []
+        enum_functions = {}
+        enum_sigs = {}
+
+        for func in api.functionIterateGlx():
+            if not func.has_variable_size_request(): continue
+
+            ef = glx_server_enum_function( func, api.enums_by_name )
+            if len(ef.enums) == 0: continue
+
+            sig = ef.signature()
+
+            if not enum_functions.has_key(func.name):
+                enum_functions[ func.name ] = sig
+
+            if not enum_sigs.has_key( sig ):
+                enum_sigs[ sig ] = ef
+
+
+
+        for func in api.functionIterateGlx():
+            # Even though server-handcode fuctions are on "the
+            # list", and prototypes are generated for them, there
+            # isn't enough information to generate a size
+            # function.  If there was enough information, they
+            # probably wouldn't need to be handcoded in the first
+            # place!
+
+            if func.server_handcode: continue
+            if not func.has_variable_size_request(): continue
+
+            if enum_functions.has_key(func.name):
+                sig = enum_functions[func.name]
+                ef = enum_sigs[ sig ]
+
+                if ef.name != func.name:
+                    aliases.append( [func.name, ef.name] )
+                else:
+                    ef.Print( func.name, self )
+
+            elif func.images:
+                self.printPixelFunction(func)
+            elif func.has_variable_size_request():
+                a = self.printCountedFunction(func)
+                if a: aliases.append(a)
+
+
+        for [alias_name, real_name] in aliases:
+            print 'ALIAS( %s, %s )' % (alias_name, real_name)
+
+        return
+
+
+    def common_emit_fixups(self, fixup):
+        """Utility function to emit conditional byte-swaps."""
+
+        if fixup:
+            print '    if (swap) {'
+            for name in fixup:
+                print '        %s = bswap_32(%s);' % (name, name)
+            print '    }'
+
+        return
+
+
+    def common_emit_one_arg(self, p, pc, adjust):
+        offset = p.offset
+        dst = p.string()
+        src = '(%s *)' % (p.type_string())
+        print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust);
+        return
+
+
+    def common_func_print_just_header(self, f):
+        print 'int'
+        print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name)
+        print '{'
+
+
+    def printPixelFunction(self, f):
+        self.common_func_print_just_header(f)
 
-       def __init__(self):
-               PrintGlxReqSize_common.__init__(self)
-               self.counter_sigs = {}
-
-
-       def printRealHeader(self):
-               print ''
-               print '#include <GL/gl.h>'
-               print '#include "glxserver.h"'
-               print '#include "glxbyteorder.h"'
-               print '#include "indirect_size.h"'
-               print '#include "indirect_reqsize.h"'
-               print ''
-               print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
-               print ''
-               print '#if defined(__CYGWIN__) || defined(__MINGW32__)'
-               print '#  undef HAVE_ALIAS'
-               print '#endif'
-               print '#ifdef HAVE_ALIAS'
-               print '#  define ALIAS2(from,to) \\'
-               print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
-               print '        __attribute__ ((alias( # to )));'
-               print '#  define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )'
-               print '#else'
-               print '#  define ALIAS(from,to) \\'
-               print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
-               print '    { return __glX ## to ## ReqSize( pc, swap ); }'
-               print '#endif'
-               print ''
-               print ''
-
-
-       def printBody(self, api):
-               aliases = []
-               enum_functions = {}
-               enum_sigs = {}
-
-               for func in api.functionIterateGlx():
-                       if not func.has_variable_size_request(): continue
-
-                       ef = glx_server_enum_function( func, api.enums_by_name )
-                       if len(ef.enums) == 0: continue
-
-                       sig = ef.signature()
-
-                       if not enum_functions.has_key(func.name):
-                               enum_functions[ func.name ] = sig
-
-                       if not enum_sigs.has_key( sig ):
-                               enum_sigs[ sig ] = ef
-                       
-
-
-               for func in api.functionIterateGlx():
-                       # Even though server-handcode fuctions are on "the
-                       # list", and prototypes are generated for them, there
-                       # isn't enough information to generate a size
-                       # function.  If there was enough information, they
-                       # probably wouldn't need to be handcoded in the first
-                       # place!
-
-                       if func.server_handcode: continue
-                       if not func.has_variable_size_request(): continue
-
-                       if enum_functions.has_key(func.name):
-                               sig = enum_functions[func.name]
-                               ef = enum_sigs[ sig ]
-
-                               if ef.name != func.name:
-                                       aliases.append( [func.name, ef.name] )
-                               else:
-                                       ef.Print( func.name, self )
-
-                       elif func.images:
-                               self.printPixelFunction(func)
-                       elif func.has_variable_size_request():
-                               a = self.printCountedFunction(func)
-                               if a: aliases.append(a)
-
-
-               for [alias_name, real_name] in aliases:
-                       print 'ALIAS( %s, %s )' % (alias_name, real_name)
-
-               return
-
-
-       def common_emit_fixups(self, fixup):
-               """Utility function to emit conditional byte-swaps."""
-
-               if fixup:
-                       print '    if (swap) {'
-                       for name in fixup:
-                               print '        %s = bswap_32(%s);' % (name, name)
-                       print '    }'
-
-               return
-
-
-       def common_emit_one_arg(self, p, pc, adjust):
-               offset = p.offset
-               dst = p.string()
-               src = '(%s *)' % (p.type_string())
-               print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust);
-               return
-
-
-       def common_func_print_just_header(self, f):
-               print 'int'
-               print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name)
-               print '{'
-
-
-       def printPixelFunction(self, f):
-               self.common_func_print_just_header(f)
-               
-               f.offset_of( f.parameters[0].name )
-               [dim, w, h, d, junk] = f.get_images()[0].get_dimensions()
+        f.offset_of( f.parameters[0].name )
+        [dim, w, h, d, junk] = f.get_images()[0].get_dimensions()
 
-               print '    GLint row_length   = *  (GLint *)(pc +  4);'
+        print '    GLint row_length   = *  (GLint *)(pc +  4);'
 
-               if dim < 3:
-                       fixup = ['row_length', 'skip_rows', 'alignment']
-                       print '    GLint image_height = 0;'
-                       print '    GLint skip_images  = 0;'
-                       print '    GLint skip_rows    = *  (GLint *)(pc +  8);'
-                       print '    GLint alignment    = *  (GLint *)(pc + 16);'
-               else:
-                       fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment']
-                       print '    GLint image_height = *  (GLint *)(pc +  8);'
-                       print '    GLint skip_rows    = *  (GLint *)(pc + 16);'
-                       print '    GLint skip_images  = *  (GLint *)(pc + 20);'
-                       print '    GLint alignment    = *  (GLint *)(pc + 32);'
+        if dim < 3:
+            fixup = ['row_length', 'skip_rows', 'alignment']
+            print '    GLint image_height = 0;'
+            print '    GLint skip_images  = 0;'
+            print '    GLint skip_rows    = *  (GLint *)(pc +  8);'
+            print '    GLint alignment    = *  (GLint *)(pc + 16);'
+        else:
+            fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment']
+            print '    GLint image_height = *  (GLint *)(pc +  8);'
+            print '    GLint skip_rows    = *  (GLint *)(pc + 16);'
+            print '    GLint skip_images  = *  (GLint *)(pc + 20);'
+            print '    GLint alignment    = *  (GLint *)(pc + 32);'
 
-               img = f.images[0]
-               for p in f.parameterIterateGlxSend():
-                       if p.name in [w, h, d, img.img_format, img.img_type, img.img_target]:
-                               self.common_emit_one_arg(p, "pc", 0)
-                               fixup.append( p.name )
+        img = f.images[0]
+        for p in f.parameterIterateGlxSend():
+            if p.name in [w, h, d, img.img_format, img.img_type, img.img_target]:
+                self.common_emit_one_arg(p, "pc", 0)
+                fixup.append( p.name )
 
-               print ''
+        print ''
 
-               self.common_emit_fixups(fixup)
+        self.common_emit_fixups(fixup)
 
-               if img.img_null_flag:
-                       print ''
-                       print '    if (*(CARD32 *) (pc + %s))' % (img.offset - 4)
-                       print '        return 0;'
+        if img.img_null_flag:
+            print ''
+            print '       if (*(CARD32 *) (pc + %s))' % (img.offset - 4)
+            print '           return 0;'
 
-               print ''
-               print '    return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d )
-               print '                          image_height, row_length, skip_images,'
-               print '                          skip_rows, alignment);'
-               print '}'
-               print ''
-               return
+        print ''
+        print '    return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d )
+        print '                          image_height, row_length, skip_images,'
+        print '                          skip_rows, alignment);'
+        print '}'
+        print ''
+        return
 
 
-       def printCountedFunction(self, f):
+    def printCountedFunction(self, f):
 
-               sig = ""
-               offset = 0
-               fixup = []
-               params = []
-               plus = ''
-               size = ''
-               param_offsets = {}
+        sig = ""
+        offset = 0
+        fixup = []
+        params = []
+        plus = ''
+        size = ''
+        param_offsets = {}
 
-               # Calculate the offset of each counter parameter and the
-               # size string for the variable length parameter(s).  While
-               # that is being done, calculate a unique signature for this
-               # function.
+        # Calculate the offset of each counter parameter and the
+        # size string for the variable length parameter(s).  While
+        # that is being done, calculate a unique signature for this
+        # function.
 
-               for p in f.parameterIterateGlxSend():
-                       if p.is_counter:
-                               fixup.append( p.name )
-                               params.append( p )
-                       elif p.counter:
-                               s = p.size()
-                               if s == 0: s = 1
+        for p in f.parameterIterateGlxSend():
+            if p.is_counter:
+                fixup.append( p.name )
+                params.append( p )
+            elif p.counter:
+                s = p.size()
+                if s == 0: s = 1
 
-                               sig += "(%u,%u)" % (f.offset_of(p.counter), s)
-                               size += '%s%s' % (plus, p.size_string())
-                               plus = ' + '
+                sig += "(%u,%u)" % (f.offset_of(p.counter), s)
+                size += '%s%s' % (plus, p.size_string())
+                plus = ' + '
 
 
-               # If the calculated signature matches a function that has
-               # already be emitted, don't emit this function.  Instead, add
-               # it to the list of function aliases.
+        # If the calculated signature matches a function that has
+        # already be emitted, don't emit this function.  Instead, add
+        # it to the list of function aliases.
 
-               if self.counter_sigs.has_key(sig):
-                       n = self.counter_sigs[sig];
-                       alias = [f.name, n]
-               else:
-                       alias = None
-                       self.counter_sigs[sig] = f.name
+        if self.counter_sigs.has_key(sig):
+            n = self.counter_sigs[sig];
+            alias = [f.name, n]
+        else:
+            alias = None
+            self.counter_sigs[sig] = f.name
 
-                       self.common_func_print_just_header(f)
+            self.common_func_print_just_header(f)
 
-                       for p in params:
-                               self.common_emit_one_arg(p, "pc", 0)
+            for p in params:
+                self.common_emit_one_arg(p, "pc", 0)
 
 
-                       print ''
-                       self.common_emit_fixups(fixup)
-                       print ''
+            print ''
+            self.common_emit_fixups(fixup)
+            print ''
 
-                       print '    return __GLX_PAD(%s);' % (size)
-                       print '}'
-                       print ''
+            print '    return __GLX_PAD(%s);' % (size)
+            print '}'
+            print ''
 
-               return alias
+        return alias
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0]
-       print "    -m output_mode   Output mode can be one of 'size_c' or 'size_h'."
-       print "    --only-get       Only emit 'get'-type functions."
-       print "    --only-set       Only emit 'set'-type functions."
-       print ""
-       print "By default, both 'get' and 'set'-type functions are emitted."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0]
+    print "    -m output_mode   Output mode can be one of 'size_c' or 'size_h'."
+    print "    --only-get       Only emit 'get'-type functions."
+    print "    --only-set       Only emit 'set'-type functions."
+    print ""
+    print "By default, both 'get' and 'set'-type functions are emitted."
+    sys.exit(1)
 
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:h:", ["only-get", "only-set", "header-tag"])
-       except Exception,e:
-               show_usage()
-
-       mode = None
-       header_tag = None
-       which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set
-
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       mode = val
-               elif arg == "--only-get":
-                       which_functions = PrintGlxSizeStubs_common.do_get
-               elif arg == "--only-set":
-                       which_functions = PrintGlxSizeStubs_common.do_set
-               elif (arg == '-h') or (arg == "--header-tag"):
-                       header_tag = val
-
-       if mode == "size_c":
-               printer = PrintGlxSizeStubs_c( which_functions )
-       elif mode == "size_h":
-               printer = PrintGlxSizeStubs_h( which_functions )
-               if header_tag:
-                       printer.header_tag = header_tag
-       elif mode == "reqsize_c":
-               printer = PrintGlxReqSize_c()
-       elif mode == "reqsize_h":
-               printer = PrintGlxReqSize_h()
-       else:
-               show_usage()
-
-       api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
-
-
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:h:", ["only-get", "only-set", "header-tag"])
+    except Exception,e:
+        show_usage()
+
+    mode = None
+    header_tag = None
+    which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set
+
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            mode = val
+        elif arg == "--only-get":
+            which_functions = PrintGlxSizeStubs_common.do_get
+        elif arg == "--only-set":
+            which_functions = PrintGlxSizeStubs_common.do_set
+        elif (arg == '-h') or (arg == "--header-tag"):
+            header_tag = val
+
+    if mode == "size_c":
+        printer = PrintGlxSizeStubs_c( which_functions )
+    elif mode == "size_h":
+        printer = PrintGlxSizeStubs_h( which_functions )
+        if header_tag:
+            printer.header_tag = header_tag
+    elif mode == "reqsize_c":
+        printer = PrintGlxReqSize_c()
+    elif mode == "reqsize_h":
+        printer = PrintGlxReqSize_h()
+    else:
+        show_usage()
+
+    api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
+
+
+    printer.Print( api )
index 15397533f7518e62c42625ba5886d7ceefe5139c..47aa11116be923c3071baa4a2380938f7158ae42 100644 (file)
@@ -30,381 +30,381 @@ import sys, getopt
 
 
 def log2(value):
-       for i in range(0, 30):
-               p = 1 << i
-               if p >= value:
-                       return i
+    for i in range(0, 30):
+        p = 1 << i
+        if p >= value:
+            return i
 
-       return -1
+    return -1
 
 
 def round_down_to_power_of_two(n):
-       """Returns the nearest power-of-two less than or equal to n."""
+    """Returns the nearest power-of-two less than or equal to n."""
 
-       for i in range(30, 0, -1):
-               p = 1 << i
-               if p <= n:
-                       return p
+    for i in range(30, 0, -1):
+        p = 1 << i
+        if p <= n:
+            return p
 
-       return -1
+    return -1
 
 
 class function_table:
-       def __init__(self, name, do_size_check):
-               self.name_base = name
-               self.do_size_check = do_size_check
-
-
-               self.max_bits = 1
-               self.next_opcode_threshold = (1 << self.max_bits)
-               self.max_opcode = 0
-
-               self.functions = {}
-               self.lookup_table = []
-               
-               # Minimum number of opcodes in a leaf node.
-               self.min_op_bits = 3
-               self.min_op_count = (1 << self.min_op_bits)
-               return
+    def __init__(self, name, do_size_check):
+        self.name_base = name
+        self.do_size_check = do_size_check
 
 
-       def append(self, opcode, func):
-               self.functions[opcode] = func
+        self.max_bits = 1
+        self.next_opcode_threshold = (1 << self.max_bits)
+        self.max_opcode = 0
 
-               if opcode > self.max_opcode:
-                       self.max_opcode = opcode
+        self.functions = {}
+        self.lookup_table = []
 
-                       if opcode > self.next_opcode_threshold:
-                               bits = log2(opcode)
-                               if (1 << bits) <= opcode:
-                                       bits += 1
+        # Minimum number of opcodes in a leaf node.
+        self.min_op_bits = 3
+        self.min_op_count = (1 << self.min_op_bits)
+        return
 
-                               self.max_bits = bits
-                               self.next_opcode_threshold = 1 << bits
-               return
 
+    def append(self, opcode, func):
+        self.functions[opcode] = func
 
-       def divide_group(self, min_opcode, total):
-               """Divide the group starting min_opcode into subgroups.
-               Returns a tuple containing the number of bits consumed by
-               the node, the list of the children's tuple, and the number
-               of entries in the final array used by this node and its
-               children, and the depth of the subtree rooted at the node."""
-
-               remaining_bits = self.max_bits - total
-               next_opcode = min_opcode + (1 << remaining_bits)
-               empty_children = 0
-               
-               for M in range(0, remaining_bits):
-                       op_count = 1 << (remaining_bits - M);
-                       child_count = 1 << M;
-
-                       empty_children = 0
-                       full_children = 0
-                       for i in range(min_opcode, next_opcode, op_count):
-                               used = 0
-                               empty = 0
+        if opcode > self.max_opcode:
+            self.max_opcode = opcode
 
-                               for j in range(i, i + op_count):
-                                       if self.functions.has_key(j):
-                                               used += 1;
-                                       else:
-                                               empty += 1;
-                                               
+            if opcode > self.next_opcode_threshold:
+                bits = log2(opcode)
+                if (1 << bits) <= opcode:
+                    bits += 1
 
-                               if empty == op_count:
-                                       empty_children += 1
-
-                               if used == op_count:
-                                       full_children += 1
-
-                       if (empty_children > 0) or (full_children == child_count) or (op_count <= self.min_op_count):
-                               break
+                self.max_bits = bits
+                self.next_opcode_threshold = 1 << bits
+        return
 
 
-               # If all the remaining bits are used by this node, as is the
-               # case when M is 0 or remaining_bits, the node is a leaf.
-
-               if (M == 0) or (M == remaining_bits):
-                       return [remaining_bits, [], 0, 0]
-               else:
-                       children = []
-                       count = 1
-                       depth = 1
-                       all_children_are_nonempty_leaf_nodes = 1
-                       for i in range(min_opcode, next_opcode, op_count):
-                               n = self.divide_group(i, total + M)
+    def divide_group(self, min_opcode, total):
+        """Divide the group starting min_opcode into subgroups.
+        Returns a tuple containing the number of bits consumed by
+        the node, the list of the children's tuple, and the number
+        of entries in the final array used by this node and its
+        children, and the depth of the subtree rooted at the node."""
 
-                               if not (n[1] == [] and not self.is_empty_leaf(i, n[0])):
-                                       all_children_are_nonempty_leaf_nodes = 0
+        remaining_bits = self.max_bits - total
+        next_opcode = min_opcode + (1 << remaining_bits)
+        empty_children = 0
 
-                               children.append(n)
-                               count += n[2] + 1
-                               
-                               if n[3] >= depth:
-                                       depth = n[3] + 1
-
-                       # If all of the child nodes are non-empty leaf nodes, pull
-                       # them up and make this node a leaf.
-
-                       if all_children_are_nonempty_leaf_nodes:
-                               return [remaining_bits, [], 0, 0]
-                       else:
-                               return [M, children, count, depth]
-
-
-       def is_empty_leaf(self, base_opcode, M):
-               for op in range(base_opcode, base_opcode + (1 << M)):
-                       if self.functions.has_key(op):
-                               return 0
-                               break
-
-               return 1
-
-
-       def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth):
-               M = node[0]
-               children = node[1]
-               child_M = remaining_bits - M
-
-
-               # This actually an error condition.
-               if children == []:
-                       return
-
-               print '    /* [%u] -> opcode range [%u, %u], node depth %u */' % (base_entry, base_opcode, base_opcode + (1 << remaining_bits), depth)
-               print '    %u,' % (M)
-
-               base_entry += (1 << M) + 1
-
-               child_index = base_entry
-               child_base_opcode = base_opcode
-               for child in children:
-                       if child[1] == []:
-                               if self.is_empty_leaf(child_base_opcode, child_M):
-                                       print '    EMPTY_LEAF,'
-                               else:
-                                       # Emit the index of the next dispatch
-                                       # function.  Then add all the
-                                       # dispatch functions for this leaf
-                                       # node to the dispatch function
-                                       # lookup table.
-
-                                       print '    LEAF(%u),' % (len(self.lookup_table))
-
-                                       for op in range(child_base_opcode, child_base_opcode + (1 << child_M)):
-                                               if self.functions.has_key(op):
-                                                       func = self.functions[op]
-                                                       size = func.command_fixed_length()
-
-                                                       if func.glx_rop != 0:
-                                                               size += 4
-
-                                                       size = ((size + 3) & ~3)
-
-                                                       if func.has_variable_size_request():
-                                                               size_name = "__glX%sReqSize" % (func.name)
-                                                       else:
-                                                               size_name = ""
-
-                                                       if func.glx_vendorpriv == op:
-                                                               func_name = func.glx_vendorpriv_names[0]
-                                                       else:
-                                                               func_name = func.name
-
-                                                       temp = [op, "__glXDisp_%s" % (func_name), "__glXDispSwap_%s" % (func_name), size, size_name]
-                                               else:
-                                                       temp = [op, "NULL", "NULL", 0, ""]
-
-                                               self.lookup_table.append(temp)
-                       else:
-                               print '    %u,' % (child_index)
-                               child_index += child[2]
-
-                       child_base_opcode += 1 << child_M
-
-               print ''
-
-               child_index = base_entry
-               for child in children:
-                       if child[1] != []:
-                               self.dump_tree(child, base_opcode, remaining_bits - M, child_index, depth + 1)
-                               child_index += child[2]
-
-                       base_opcode += 1 << (remaining_bits - M)
-
-
-       def Print(self):
-               # Each dispatch table consists of two data structures.
-               #
-               # The first structure is an N-way tree where the opcode for
-               # the function is the key.  Each node switches on a range of
-               # bits from the opcode.  M bits are extracted from the opcde
-               # and are used as an index to select one of the N, where
-               # N = 2^M, children.
-               #
-               # The tree is stored as a flat array.  The first value is the
-               # number of bits, M, used by the node.  For inner nodes, the
-               # following 2^M values are indexes into the array for the
-               # child nodes.  For leaf nodes, the followign 2^M values are
-               # indexes into the second data structure.
-               #
-               # If an inner node's child index is 0, the child is an empty
-               # leaf node.  That is, none of the opcodes selectable from
-               # that child exist.  Since most of the possible opcode space
-               # is unused, this allows compact data storage.
-               #
-               # The second data structure is an array of pairs of function
-               # pointers.  Each function contains a pointer to a protocol
-               # decode function and a pointer to a byte-swapped protocol
-               # decode function.  Elements in this array are selected by the
-               # leaf nodes of the first data structure.
-               #
-               # As the tree is traversed, an accumulator is kept.  This
-               # accumulator counts the bits of the opcode consumed by the
-               # traversal.  When accumulator + M = B, where B is the
-               # maximum number of bits in an opcode, the traversal has
-               # reached a leaf node.  The traversal starts with the most
-               # significant bits and works down to the least significant
-               # bits.
-               #
-               # Creation of the tree is the most complicated part.  At
-               # each node the elements are divided into groups of 2^M
-               # elements.  The value of M selected is the smallest possible
-               # value where all of the groups are either empty or full, or
-               # the groups are a preset minimum size.  If all the children
-               # of a node are non-empty leaf nodes, the children are merged
-               # to create a single leaf node that replaces the parent.
-
-               tree = self.divide_group(0, 0)
-
-               print '/*****************************************************************/'
-               print '/* tree depth = %u */' % (tree[3])
-               print 'static const int_fast16_t %s_dispatch_tree[%u] = {' % (self.name_base, tree[2])
-               self.dump_tree(tree, 0, self.max_bits, 0, 1)
-               print '};\n'
-               
-               # After dumping the tree, dump the function lookup table.
-               
-               print 'static const void *%s_function_table[%u][2] = {' % (self.name_base, len(self.lookup_table))
-               index = 0
-               for func in self.lookup_table:
-                       opcode = func[0]
-                       name = func[1]
-                       name_swap = func[2]
-                       
-                       print '    /* [% 3u] = %5u */ {%s, %s},' % (index, opcode, name, name_swap)
-                       
-                       index += 1
-
-               print '};\n'
-               
-               if self.do_size_check:
-                       var_table = []
-
-                       print 'static const int_fast16_t %s_size_table[%u][2] = {' % (self.name_base, len(self.lookup_table))
-                       index = 0
-                       var_table = []
-                       for func in self.lookup_table:
-                               opcode = func[0]
-                               fixed = func[3]
-                               var = func[4]
-                               
-                               if var != "":
-                                       var_offset = "%2u" % (len(var_table))
-                                       var_table.append(var)
-                               else:
-                                       var_offset = "~0"
-
-                               print '    /* [%3u] = %5u */ {%3u, %s},' % (index, opcode, fixed, var_offset)
-                               index += 1
-
-                               
-                       print '};\n'
-
-
-                       print 'static const gl_proto_size_func %s_size_func_table[%u] = {' % (self.name_base, len(var_table))
-                       for func in var_table:
-                               print '   %s,' % (func)
-                       print '};\n'
-
-
-               print 'const struct __glXDispatchInfo %s_dispatch_info = {' % (self.name_base)
-               print '    %u,' % (self.max_bits)
-               print '    %s_dispatch_tree,' % (self.name_base)
-               print '    %s_function_table,' % (self.name_base)
-               if self.do_size_check:
-                       print '    %s_size_table,' % (self.name_base)
-                       print '    %s_size_func_table' % (self.name_base)
-               else:
-                       print '    NULL,'
-                       print '    NULL'
-               print '};\n'
-               return
+        for M in range(0, remaining_bits):
+            op_count = 1 << (remaining_bits - M);
+            child_count = 1 << M;
+
+            empty_children = 0
+            full_children = 0
+            for i in range(min_opcode, next_opcode, op_count):
+                used = 0
+                empty = 0
+
+                for j in range(i, i + op_count):
+                    if self.functions.has_key(j):
+                        used += 1;
+                    else:
+                        empty += 1;
+
+
+                if empty == op_count:
+                    empty_children += 1
+
+                if used == op_count:
+                    full_children += 1
+
+            if (empty_children > 0) or (full_children == child_count) or (op_count <= self.min_op_count):
+                break
+
+
+        # If all the remaining bits are used by this node, as is the
+        # case when M is 0 or remaining_bits, the node is a leaf.
+
+        if (M == 0) or (M == remaining_bits):
+            return [remaining_bits, [], 0, 0]
+        else:
+            children = []
+            count = 1
+            depth = 1
+            all_children_are_nonempty_leaf_nodes = 1
+            for i in range(min_opcode, next_opcode, op_count):
+                n = self.divide_group(i, total + M)
+
+                if not (n[1] == [] and not self.is_empty_leaf(i, n[0])):
+                    all_children_are_nonempty_leaf_nodes = 0
+
+                children.append(n)
+                count += n[2] + 1
+
+                if n[3] >= depth:
+                    depth = n[3] + 1
+
+            # If all of the child nodes are non-empty leaf nodes, pull
+            # them up and make this node a leaf.
+
+            if all_children_are_nonempty_leaf_nodes:
+                return [remaining_bits, [], 0, 0]
+            else:
+                return [M, children, count, depth]
+
+
+    def is_empty_leaf(self, base_opcode, M):
+        for op in range(base_opcode, base_opcode + (1 << M)):
+            if self.functions.has_key(op):
+                return 0
+                break
+
+        return 1
+
+
+    def dump_tree(self, node, base_opcode, remaining_bits, base_entry, depth):
+        M = node[0]
+        children = node[1]
+        child_M = remaining_bits - M
+
+
+        # This actually an error condition.
+        if children == []:
+            return
+
+        print '    /* [%u] -> opcode range [%u, %u], node depth %u */' % (base_entry, base_opcode, base_opcode + (1 << remaining_bits), depth)
+        print '    %u,' % (M)
+
+        base_entry += (1 << M) + 1
+
+        child_index = base_entry
+        child_base_opcode = base_opcode
+        for child in children:
+            if child[1] == []:
+                if self.is_empty_leaf(child_base_opcode, child_M):
+                    print '    EMPTY_LEAF,'
+                else:
+                    # Emit the index of the next dispatch
+                    # function.  Then add all the
+                    # dispatch functions for this leaf
+                    # node to the dispatch function
+                    # lookup table.
+
+                    print '    LEAF(%u),' % (len(self.lookup_table))
+
+                    for op in range(child_base_opcode, child_base_opcode + (1 << child_M)):
+                        if self.functions.has_key(op):
+                            func = self.functions[op]
+                            size = func.command_fixed_length()
+
+                            if func.glx_rop != 0:
+                                size += 4
+
+                            size = ((size + 3) & ~3)
+
+                            if func.has_variable_size_request():
+                                size_name = "__glX%sReqSize" % (func.name)
+                            else:
+                                size_name = ""
+
+                            if func.glx_vendorpriv == op:
+                                func_name = func.glx_vendorpriv_names[0]
+                            else:
+                                func_name = func.name
+
+                            temp = [op, "__glXDisp_%s" % (func_name), "__glXDispSwap_%s" % (func_name), size, size_name]
+                        else:
+                            temp = [op, "NULL", "NULL", 0, ""]
+
+                        self.lookup_table.append(temp)
+            else:
+                print '    %u,' % (child_index)
+                child_index += child[2]
+
+            child_base_opcode += 1 << child_M
+
+        print ''
+
+        child_index = base_entry
+        for child in children:
+            if child[1] != []:
+                self.dump_tree(child, base_opcode, remaining_bits - M, child_index, depth + 1)
+                child_index += child[2]
+
+            base_opcode += 1 << (remaining_bits - M)
+
+
+    def Print(self):
+        # Each dispatch table consists of two data structures.
+        #
+        # The first structure is an N-way tree where the opcode for
+        # the function is the key.  Each node switches on a range of
+        # bits from the opcode.  M bits are extracted from the opcde
+        # and are used as an index to select one of the N, where
+        # N = 2^M, children.
+        #
+        # The tree is stored as a flat array.  The first value is the
+        # number of bits, M, used by the node.  For inner nodes, the
+        # following 2^M values are indexes into the array for the
+        # child nodes.  For leaf nodes, the followign 2^M values are
+        # indexes into the second data structure.
+        #
+        # If an inner node's child index is 0, the child is an empty
+        # leaf node.  That is, none of the opcodes selectable from
+        # that child exist.  Since most of the possible opcode space
+        # is unused, this allows compact data storage.
+        #
+        # The second data structure is an array of pairs of function
+        # pointers.  Each function contains a pointer to a protocol
+        # decode function and a pointer to a byte-swapped protocol
+        # decode function.  Elements in this array are selected by the
+        # leaf nodes of the first data structure.
+        #
+        # As the tree is traversed, an accumulator is kept.  This
+        # accumulator counts the bits of the opcode consumed by the
+        # traversal.  When accumulator + M = B, where B is the
+        # maximum number of bits in an opcode, the traversal has
+        # reached a leaf node.  The traversal starts with the most
+        # significant bits and works down to the least significant
+        # bits.
+        #
+        # Creation of the tree is the most complicated part.  At
+        # each node the elements are divided into groups of 2^M
+        # elements.  The value of M selected is the smallest possible
+        # value where all of the groups are either empty or full, or
+        # the groups are a preset minimum size.  If all the children
+        # of a node are non-empty leaf nodes, the children are merged
+        # to create a single leaf node that replaces the parent.
+
+        tree = self.divide_group(0, 0)
+
+        print '/*****************************************************************/'
+        print '/* tree depth = %u */' % (tree[3])
+        print 'static const int_fast16_t %s_dispatch_tree[%u] = {' % (self.name_base, tree[2])
+        self.dump_tree(tree, 0, self.max_bits, 0, 1)
+        print '};\n'
+
+        # After dumping the tree, dump the function lookup table.
+
+        print 'static const void *%s_function_table[%u][2] = {' % (self.name_base, len(self.lookup_table))
+        index = 0
+        for func in self.lookup_table:
+            opcode = func[0]
+            name = func[1]
+            name_swap = func[2]
+
+            print '    /* [% 3u] = %5u */ {%s, %s},' % (index, opcode, name, name_swap)
+
+            index += 1
+
+        print '};\n'
+
+        if self.do_size_check:
+            var_table = []
+
+            print 'static const int_fast16_t %s_size_table[%u][2] = {' % (self.name_base, len(self.lookup_table))
+            index = 0
+            var_table = []
+            for func in self.lookup_table:
+                opcode = func[0]
+                fixed = func[3]
+                var = func[4]
+
+                if var != "":
+                    var_offset = "%2u" % (len(var_table))
+                    var_table.append(var)
+                else:
+                    var_offset = "~0"
+
+                print '    /* [%3u] = %5u */ {%3u, %s},' % (index, opcode, fixed, var_offset)
+                index += 1
+
+
+            print '};\n'
+
+
+            print 'static const gl_proto_size_func %s_size_func_table[%u] = {' % (self.name_base, len(var_table))
+            for func in var_table:
+                print '   %s,' % (func)
+
+            print '};\n'
+
+
+        print 'const struct __glXDispatchInfo %s_dispatch_info = {' % (self.name_base)
+        print '    %u,' % (self.max_bits)
+        print '    %s_dispatch_tree,' % (self.name_base)
+        print '    %s_function_table,' % (self.name_base)
+        if self.do_size_check:
+            print '    %s_size_table,' % (self.name_base)
+            print '    %s_size_func_table' % (self.name_base)
+        else:
+            print '    NULL,'
+            print '    NULL'
+        print '};\n'
+        return
 
 
 class PrintGlxDispatchTables(glX_proto_common.glx_print_proto):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
-               self.name = "glX_server_table.py (from Mesa)"
-               self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005, 2006", "IBM")
-
-               self.rop_functions = function_table("Render", 1)
-               self.sop_functions = function_table("Single", 0)
-               self.vop_functions = function_table("VendorPriv", 0)
-               return
-
-
-       def printRealHeader(self):
-               print '#include <inttypes.h>'
-               print '#include "glxserver.h"'
-               print '#include "glxext.h"'
-               print '#include "indirect_dispatch.h"'
-               print '#include "indirect_reqsize.h"'
-               print '#include "indirect_table.h"'
-               print ''
-               return
-
-
-       def printBody(self, api):
-               for f in api.functionIterateAll():
-                       if not f.ignore and f.vectorequiv == None:
-                               if f.glx_rop != 0:
-                                       self.rop_functions.append(f.glx_rop, f)
-                               if f.glx_sop != 0:
-                                       self.sop_functions.append(f.glx_sop, f)
-                               if f.glx_vendorpriv != 0:
-                                       self.vop_functions.append(f.glx_vendorpriv, f)
-
-               self.sop_functions.Print()
-               self.rop_functions.Print()
-               self.vop_functions.Print()
-               return
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+        self.name = "glX_server_table.py (from Mesa)"
+        self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005, 2006", "IBM")
+
+        self.rop_functions = function_table("Render", 1)
+        self.sop_functions = function_table("Single", 0)
+        self.vop_functions = function_table("VendorPriv", 0)
+        return
+
+
+    def printRealHeader(self):
+        print '#include <inttypes.h>'
+        print '#include "glxserver.h"'
+        print '#include "glxext.h"'
+        print '#include "indirect_dispatch.h"'
+        print '#include "indirect_reqsize.h"'
+        print '#include "indirect_table.h"'
+        print ''
+        return
+
+
+    def printBody(self, api):
+        for f in api.functionIterateAll():
+            if not f.ignore and f.vectorequiv == None:
+                if f.glx_rop != 0:
+                    self.rop_functions.append(f.glx_rop, f)
+                if f.glx_sop != 0:
+                    self.sop_functions.append(f.glx_sop, f)
+                if f.glx_vendorpriv != 0:
+                    self.vop_functions.append(f.glx_vendorpriv, f)
+
+        self.sop_functions.Print()
+        self.rop_functions.Print()
+        self.vop_functions.Print()
+        return
 
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
+    file_name = "gl_API.xml"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m")
+    except Exception,e:
+        show_usage()
 
-       mode = "table_c"
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       mode = val
+    mode = "table_c"
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            mode = val
 
-       if mode == "table_c":
-               printer = PrintGlxDispatchTables()
-       else:
-               show_usage()
+    if mode == "table_c":
+        printer = PrintGlxDispatchTables()
+    else:
+        show_usage()
 
 
-       api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
+    api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
 
 
-       printer.Print( api )
+    printer.Print( api )
index 553959687e0e4f76daf8753f3caecec8882eb2e1..23e23295bec8164b95631e7a85a8630d6c07f4a1 100644 (file)
@@ -30,244 +30,244 @@ import gl_XML, glX_XML
 import sys, getopt
 
 class PrintGenericStubs(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
-               self.name = "gl_SPARC_asm.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+        self.name = "gl_SPARC_asm.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
 
 
-       def printRealHeader(self):
-               print '#ifdef __arch64__'
-               print '#define GL_OFF(N)\t((N) * 8)'
-               print '#define GL_LL\t\tldx'
-               print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)'
-               print '#define GL_STACK_SIZE\t128'
-               print '#else'
-               print '#define GL_OFF(N)\t((N) * 4)'
-               print '#define GL_LL\t\tld'
-               print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)'
-               print '#define GL_STACK_SIZE\t64'
-               print '#endif'
-               print ''
-               print '#define GLOBL_FN(x) .globl x ; .type x, @function'
-               print '#define HIDDEN(x) .hidden x'
-               print ''
-               print '\t.register %g2, #scratch'
-               print '\t.register %g3, #scratch'
-               print ''
-               print '\t.text'
-               print ''
-               print '\tGLOBL_FN(__glapi_sparc_icache_flush)'
-               print '\tHIDDEN(__glapi_sparc_icache_flush)'
-               print '\t.type\t__glapi_sparc_icache_flush, @function'
-               print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
-               print '\tflush\t%o0'
-               print '\tretl'
-               print '\t nop'
-               print ''
-               print '\t.align\t32'
-               print ''
-               print '\t.type\t__glapi_sparc_get_pc, @function'
-               print '__glapi_sparc_get_pc:'
-               print '\tretl'
-               print '\t add\t%o7, %g2, %g2'
-               print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc'
-               print ''
-               print '#ifdef GLX_USE_TLS'
-               print ''
-               print '\tGLOBL_FN(__glapi_sparc_get_dispatch)'
-               print '\tHIDDEN(__glapi_sparc_get_dispatch)'
-               print '__glapi_sparc_get_dispatch:'
-               print '\tmov\t%o7, %g1'
-               print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
-               print '\tcall\t__glapi_sparc_get_pc'
-               print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
-               print '\tmov\t%g1, %o7'
-               print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
-               print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
-               print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
-               print '\tretl'
-               print '\t mov\t%g2, %o0'
-               print ''
-               print '\t.data'
-               print '\t.align\t32'
-               print ''
-               print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */'
-               print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */'
-               print '\tGLOBL_FN(__glapi_sparc_tls_stub)'
-               print '\tHIDDEN(__glapi_sparc_tls_stub)'
-               print '__glapi_sparc_tls_stub: /* Call offset in %g3 */'
-               print '\tmov\t%o7, %g1'
-               print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
-               print '\tcall\t__glapi_sparc_get_pc'
-               print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
-               print '\tmov\t%g1, %o7'
-               print '\tsrl\t%g3, 10, %g3'
-               print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
-               print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
-               print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
-               print '\tGL_LL\t[%g7+%g2], %g1'
-               print '\tGL_LL\t[%g1 + %g3], %g1'
-               print '\tjmp\t%g1'
-               print '\t nop'
-               print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub'
-               print ''
-               print '#define GL_STUB(fn, off)\t\t\t\t\\'
-               print '\tGLOBL_FN(fn);\t\t\t\t\t\\'
-               print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\'
-               print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\'
-               print '\t.size\tfn,.-fn;'
-               print ''
-               print '#elif defined(HAVE_PTHREAD)'
-               print ''
-               print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */'
-               print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */'
-               print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */'
-               print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */'
-               print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */'
-               print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */'
-               print ''
-               print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */'
-               print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */'
-               print ''
-               print '\t.data'
-               print '\t.align\t32'
-               print ''
-               print '\tGLOBL_FN(__glapi_sparc_pthread_stub)'
-               print '\tHIDDEN(__glapi_sparc_pthread_stub)'
-               print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */'
-               print '\tmov\t%o7, %g1'
-               print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
-               print '\tcall\t__glapi_sparc_get_pc'
-               print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
-               print '\tmov\t%g1, %o7'
-               print '\tsethi\t%hi(_glapi_Dispatch), %g1'
-               print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
-               print '\tsrl\t%g3, 10, %g3'
-               print '\tGL_LL\t[%g2+%g1], %g2'
-               print '\tGL_LL\t[%g2], %g1'
-               print '\tcmp\t%g1, 0'
-               print '\tbe\t2f'
-               print '\t nop'
-               print '1:\tGL_LL\t[%g1 + %g3], %g1'
-               print '\tjmp\t%g1'
-               print '\t nop'
-               print '2:\tsave\t%sp, GL_STACK_SIZE, %sp'
-               print '\tmov\t%g3, %l0'
-               print '\tcall\t_glapi_get_dispatch'
-               print '\t nop'
-               print '\tmov\t%o0, %g1'
-               print '\tmov\t%l0, %g3'
-               print '\tba\t1b'
-               print '\t restore %g0, %g0, %g0'
-               print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub'
-               print ''
-               print '#define GL_STUB(fn, off)\t\t\t\\'
-               print '\tGLOBL_FN(fn);\t\t\t\t\\'
-               print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\'
-               print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
-               print '\t.size\tfn,.-fn;'
-               print ''
-               print '#else /* Non-threaded version. */'
-               print ''
-               print '\t.type  __glapi_sparc_nothread_stub, @function'
-               print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */'
-               print '\tmov\t%o7, %g1'
-               print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
-               print '\tcall\t__glapi_sparc_get_pc'
-               print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
-               print '\tmov\t%g1, %o7'
-               print '\tsrl\t%g3, 10, %g3'
-               print '\tsethi\t%hi(_glapi_Dispatch), %g1'
-               print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
-               print '\tGL_LL\t[%g2+%g1], %g2'
-               print '\tGL_LL\t[%g2], %g1'
-               print '\tGL_LL\t[%g1 + %g3], %g1'
-               print '\tjmp\t%g1'
-               print '\t nop'
-               print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub'
-               print ''
-               print '#define GL_STUB(fn, off)\t\t\t\\'
-               print '\tGLOBL_FN(fn);\t\t\t\t\\'
-               print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\'
-               print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
-               print '\t.size\tfn,.-fn;'
-               print ''
-               print '#endif'
-               print ''
-               print '#define GL_STUB_ALIAS(fn, alias)         \\'
-               print ' .globl  fn;                             \\'
-               print ' .set    fn, alias'
-               print ''
-               print '\t.text'
-               print '\t.align\t32'
-               print ''
-               print '\t.globl\tgl_dispatch_functions_start'
-               print '\tHIDDEN(gl_dispatch_functions_start)'
-               print 'gl_dispatch_functions_start:'
-               print ''
-               return
+    def printRealHeader(self):
+        print '#ifdef __arch64__'
+        print '#define GL_OFF(N)\t((N) * 8)'
+        print '#define GL_LL\t\tldx'
+        print '#define GL_TIE_LD(SYM)\t%tie_ldx(SYM)'
+        print '#define GL_STACK_SIZE\t128'
+        print '#else'
+        print '#define GL_OFF(N)\t((N) * 4)'
+        print '#define GL_LL\t\tld'
+        print '#define GL_TIE_LD(SYM)\t%tie_ld(SYM)'
+        print '#define GL_STACK_SIZE\t64'
+        print '#endif'
+        print ''
+        print '#define GLOBL_FN(x) .globl x ; .type x, @function'
+        print '#define HIDDEN(x) .hidden x'
+        print ''
+        print '\t.register %g2, #scratch'
+        print '\t.register %g3, #scratch'
+        print ''
+        print '\t.text'
+        print ''
+        print '\tGLOBL_FN(__glapi_sparc_icache_flush)'
+        print '\tHIDDEN(__glapi_sparc_icache_flush)'
+        print '\t.type\t__glapi_sparc_icache_flush, @function'
+        print '__glapi_sparc_icache_flush: /* %o0 = insn_addr */'
+        print '\tflush\t%o0'
+        print '\tretl'
+        print '\t nop'
+        print ''
+        print '\t.align\t32'
+        print ''
+        print '\t.type\t__glapi_sparc_get_pc, @function'
+        print '__glapi_sparc_get_pc:'
+        print '\tretl'
+        print '\t add\t%o7, %g2, %g2'
+        print '\t.size\t__glapi_sparc_get_pc, .-__glapi_sparc_get_pc'
+        print ''
+        print '#ifdef GLX_USE_TLS'
+        print ''
+        print '\tGLOBL_FN(__glapi_sparc_get_dispatch)'
+        print '\tHIDDEN(__glapi_sparc_get_dispatch)'
+        print '__glapi_sparc_get_dispatch:'
+        print '\tmov\t%o7, %g1'
+        print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
+        print '\tcall\t__glapi_sparc_get_pc'
+        print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
+        print '\tmov\t%g1, %o7'
+        print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
+        print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
+        print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
+        print '\tretl'
+        print '\t mov\t%g2, %o0'
+        print ''
+        print '\t.data'
+        print '\t.align\t32'
+        print ''
+        print '\t/* --> sethi %hi(_glapi_tls_Dispatch), %g1 */'
+        print '\t/* --> or %g1, %lo(_glapi_tls_Dispatch), %g1 */'
+        print '\tGLOBL_FN(__glapi_sparc_tls_stub)'
+        print '\tHIDDEN(__glapi_sparc_tls_stub)'
+        print '__glapi_sparc_tls_stub: /* Call offset in %g3 */'
+        print '\tmov\t%o7, %g1'
+        print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
+        print '\tcall\t__glapi_sparc_get_pc'
+        print '\tadd\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
+        print '\tmov\t%g1, %o7'
+        print '\tsrl\t%g3, 10, %g3'
+        print '\tsethi\t%tie_hi22(_glapi_tls_Dispatch), %g1'
+        print '\tadd\t%g1, %tie_lo10(_glapi_tls_Dispatch), %g1'
+        print '\tGL_LL\t[%g2 + %g1], %g2, GL_TIE_LD(_glapi_tls_Dispatch)'
+        print '\tGL_LL\t[%g7+%g2], %g1'
+        print '\tGL_LL\t[%g1 + %g3], %g1'
+        print '\tjmp\t%g1'
+        print '\t nop'
+        print '\t.size\t__glapi_sparc_tls_stub, .-__glapi_sparc_tls_stub'
+        print ''
+        print '#define GL_STUB(fn, off)\t\t\t\t\\'
+        print '\tGLOBL_FN(fn);\t\t\t\t\t\\'
+        print 'fn:\tba\t__glapi_sparc_tls_stub;\t\t\t\\'
+        print '\t sethi\tGL_OFF(off), %g3;\t\t\t\\'
+        print '\t.size\tfn,.-fn;'
+        print ''
+        print '#elif defined(HAVE_PTHREAD)'
+        print ''
+        print '\t/* 64-bit 0x00 --> sethi %hh(_glapi_Dispatch), %g1 */'
+        print '\t/* 64-bit 0x04 --> sethi %lm(_glapi_Dispatch), %g2 */'
+        print '\t/* 64-bit 0x08 --> or %g1, %hm(_glapi_Dispatch), %g1 */'
+        print '\t/* 64-bit 0x0c --> sllx %g1, 32, %g1 */'
+        print '\t/* 64-bit 0x10 --> add %g1, %g2, %g1 */'
+        print '\t/* 64-bit 0x14 --> ldx [%g1 + %lo(_glapi_Dispatch)], %g1 */'
+        print ''
+        print '\t/* 32-bit 0x00 --> sethi %hi(_glapi_Dispatch), %g1 */'
+        print '\t/* 32-bit 0x04 --> ld [%g1 + %lo(_glapi_Dispatch)], %g1 */'
+        print ''
+        print '\t.data'
+        print '\t.align\t32'
+        print ''
+        print '\tGLOBL_FN(__glapi_sparc_pthread_stub)'
+        print '\tHIDDEN(__glapi_sparc_pthread_stub)'
+        print '__glapi_sparc_pthread_stub: /* Call offset in %g3 */'
+        print '\tmov\t%o7, %g1'
+        print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
+        print '\tcall\t__glapi_sparc_get_pc'
+        print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
+        print '\tmov\t%g1, %o7'
+        print '\tsethi\t%hi(_glapi_Dispatch), %g1'
+        print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
+        print '\tsrl\t%g3, 10, %g3'
+        print '\tGL_LL\t[%g2+%g1], %g2'
+        print '\tGL_LL\t[%g2], %g1'
+        print '\tcmp\t%g1, 0'
+        print '\tbe\t2f'
+        print '\t nop'
+        print '1:\tGL_LL\t[%g1 + %g3], %g1'
+        print '\tjmp\t%g1'
+        print '\t nop'
+        print '2:\tsave\t%sp, GL_STACK_SIZE, %sp'
+        print '\tmov\t%g3, %l0'
+        print '\tcall\t_glapi_get_dispatch'
+        print '\t nop'
+        print '\tmov\t%o0, %g1'
+        print '\tmov\t%l0, %g3'
+        print '\tba\t1b'
+        print '\t restore %g0, %g0, %g0'
+        print '\t.size\t__glapi_sparc_pthread_stub, .-__glapi_sparc_pthread_stub'
+        print ''
+        print '#define GL_STUB(fn, off)\t\t\t\\'
+        print '\tGLOBL_FN(fn);\t\t\t\t\\'
+        print 'fn:\tba\t__glapi_sparc_pthread_stub;\t\\'
+        print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
+        print '\t.size\tfn,.-fn;'
+        print ''
+        print '#else /* Non-threaded version. */'
+        print ''
+        print '\t.type __glapi_sparc_nothread_stub, @function'
+        print '__glapi_sparc_nothread_stub: /* Call offset in %g3 */'
+        print '\tmov\t%o7, %g1'
+        print '\tsethi\t%hi(_GLOBAL_OFFSET_TABLE_-4), %g2'
+        print '\tcall\t__glapi_sparc_get_pc'
+        print '\t add\t%g2, %lo(_GLOBAL_OFFSET_TABLE_+4), %g2'
+        print '\tmov\t%g1, %o7'
+        print '\tsrl\t%g3, 10, %g3'
+        print '\tsethi\t%hi(_glapi_Dispatch), %g1'
+        print '\tor\t%g1, %lo(_glapi_Dispatch), %g1'
+        print '\tGL_LL\t[%g2+%g1], %g2'
+        print '\tGL_LL\t[%g2], %g1'
+        print '\tGL_LL\t[%g1 + %g3], %g1'
+        print '\tjmp\t%g1'
+        print '\t nop'
+        print '\t.size\t__glapi_sparc_nothread_stub, .-__glapi_sparc_nothread_stub'
+        print ''
+        print '#define GL_STUB(fn, off)\t\t\t\\'
+        print '\tGLOBL_FN(fn);\t\t\t\t\\'
+        print 'fn:\tba\t__glapi_sparc_nothread_stub;\t\\'
+        print '\t sethi\tGL_OFF(off), %g3;\t\t\\'
+        print '\t.size\tfn,.-fn;'
+        print ''
+        print '#endif'
+        print ''
+        print '#define GL_STUB_ALIAS(fn, alias)                \\'
+        print '        .globl  fn;                             \\'
+        print '        .set    fn, alias'
+        print ''
+        print '\t.text'
+        print '\t.align\t32'
+        print ''
+        print '\t.globl\tgl_dispatch_functions_start'
+        print '\tHIDDEN(gl_dispatch_functions_start)'
+        print 'gl_dispatch_functions_start:'
+        print ''
+        return
 
-       def printRealFooter(self):
-               print ''
-               print '\t.globl\tgl_dispatch_functions_end'
-               print '\tHIDDEN(gl_dispatch_functions_end)'
-               print 'gl_dispatch_functions_end:'
-               return
+    def printRealFooter(self):
+        print ''
+        print '\t.globl\tgl_dispatch_functions_end'
+        print '\tHIDDEN(gl_dispatch_functions_end)'
+        print 'gl_dispatch_functions_end:'
+        return
 
-       def printBody(self, api):
-               for f in api.functionIterateByOffset():
-                       name = f.dispatch_name()
+    def printBody(self, api):
+        for f in api.functionIterateByOffset():
+            name = f.dispatch_name()
 
-                       print '\tGL_STUB(gl%s, %d)' % (name, f.offset)
+            print '\tGL_STUB(gl%s, %d)' % (name, f.offset)
 
-                       if not f.is_static_entry_point(f.name):
-                               print '\tHIDDEN(gl%s)' % (name)
+            if not f.is_static_entry_point(f.name):
+                print '\tHIDDEN(gl%s)' % (name)
 
-               for f in api.functionIterateByOffset():
-                       name = f.dispatch_name()
+        for f in api.functionIterateByOffset():
+            name = f.dispatch_name()
 
-                       if f.is_static_entry_point(f.name):
-                               for n in f.entry_points:
-                                       if n != f.name:
-                                               text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name)
+            if f.is_static_entry_point(f.name):
+                for n in f.entry_points:
+                    if n != f.name:
+                        text = '\tGL_STUB_ALIAS(gl%s, gl%s)' % (n, f.name)
 
-                                               if f.has_different_protocol(n):
-                                                       print '#ifndef GLX_INDIRECT_RENDERING'
-                                                       print text
-                                                       print '#endif'
-                                               else:
-                                                       print text
+                        if f.has_different_protocol(n):
+                            print '#ifndef GLX_INDIRECT_RENDERING'
+                            print text
+                            print '#endif'
+                        else:
+                            print text
 
-               return
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-       mode = "generic"
+    file_name = "gl_API.xml"
+    mode = "generic"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
+    except Exception,e:
+        show_usage()
 
-       for (arg,val) in args:
-               if arg == '-m':
-                       mode = val
-               elif arg == "-f":
-                       file_name = val
+    for (arg,val) in args:
+        if arg == '-m':
+            mode = val
+        elif arg == "-f":
+            file_name = val
 
-       if mode == "generic":
-               printer = PrintGenericStubs()
-       else:
-               print "ERROR: Invalid mode \"%s\" specified." % mode
-               show_usage()
+    if mode == "generic":
+        printer = PrintGenericStubs()
+    else:
+        print "ERROR: Invalid mode \"%s\" specified." % mode
+        show_usage()
 
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-       printer.Print(api)
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+    printer.Print(api)
index 340a581f134b670a074e9b39b72fea6c9daf644b..ce14a416d5a0959da736d5ef0d9a2522024b7f6f 100644 (file)
@@ -31,970 +31,970 @@ import typeexpr
 
 
 def parse_GL_API( file_name, factory = None ):
-       doc = libxml2.readFile( file_name, None, libxml2.XML_PARSE_XINCLUDE + libxml2.XML_PARSE_NOBLANKS + libxml2.XML_PARSE_DTDVALID + libxml2.XML_PARSE_DTDATTR + libxml2.XML_PARSE_DTDLOAD + libxml2.XML_PARSE_NOENT )
-       ret = doc.xincludeProcess()
+    doc = libxml2.readFile( file_name, None, libxml2.XML_PARSE_XINCLUDE + libxml2.XML_PARSE_NOBLANKS + libxml2.XML_PARSE_DTDVALID + libxml2.XML_PARSE_DTDATTR + libxml2.XML_PARSE_DTDLOAD + libxml2.XML_PARSE_NOENT )
+    ret = doc.xincludeProcess()
 
-       if not factory:
-               factory = gl_item_factory()
+    if not factory:
+        factory = gl_item_factory()
 
-       api = factory.create_item( "api", None, None )
-       api.process_element( doc )
+    api = factory.create_item( "api", None, None )
+    api.process_element( doc )
 
-       # After the XML has been processed, we need to go back and assign
-       # dispatch offsets to the functions that request that their offsets
-       # be assigned by the scripts.  Typically this means all functions
-       # that are not part of the ABI.
+    # After the XML has been processed, we need to go back and assign
+    # dispatch offsets to the functions that request that their offsets
+    # be assigned by the scripts.  Typically this means all functions
+    # that are not part of the ABI.
 
-       for func in api.functionIterateByCategory():
-               if func.assign_offset:
-                       func.offset = api.next_offset;
-                       api.next_offset += 1
+    for func in api.functionIterateByCategory():
+        if func.assign_offset:
+            func.offset = api.next_offset;
+            api.next_offset += 1
 
-       doc.freeDoc()
+    doc.freeDoc()
 
-       return api
+    return api
 
 
 def is_attr_true( element, name ):
-       """Read a name value from an element's attributes.
-       
-       The value read from the attribute list must be either 'true' or
-       'false'.  If the value is 'false', zero will be returned.  If the
-       value is 'true', non-zero will be returned.  An exception will be
-       raised for any other value."""
-
-       value = element.nsProp( name, None )
-       if value == "true":
-               return 1
-       elif value == "false":
-               return 0
-       else:
-               raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name))
+    """Read a name value from an element's attributes.
+
+    The value read from the attribute list must be either 'true' or
+    'false'.  If the value is 'false', zero will be returned.  If the
+    value is 'true', non-zero will be returned.  An exception will be
+    raised for any other value."""
+
+    value = element.nsProp( name, None )
+    if value == "true":
+        return 1
+    elif value == "false":
+        return 0
+    else:
+        raise RuntimeError('Invalid value "%s" for boolean "%s".' % (value, name))
 
 
 class gl_print_base:
-       """Base class of all API pretty-printers.
+    """Base class of all API pretty-printers.
+
+    In the model-view-controller pattern, this is the view.  Any derived
+    class will want to over-ride the printBody, printRealHader, and
+    printRealFooter methods.  Some derived classes may want to over-ride
+    printHeader and printFooter, or even Print (though this is unlikely).
+    """
+
+    def __init__(self):
+        # Name of the script that is generating the output file.
+        # Every derived class should set this to the name of its
+        # source file.
 
-       In the model-view-controller pattern, this is the view.  Any derived
-       class will want to over-ride the printBody, printRealHader, and
-       printRealFooter methods.  Some derived classes may want to over-ride
-       printHeader and printFooter, or even Print (though this is unlikely).
-       """
+        self.name = "a"
 
-       def __init__(self):
-               # Name of the script that is generating the output file.
-               # Every derived class should set this to the name of its
-               # source file.
 
-               self.name = "a"
+        # License on the *generated* source file.  This may differ
+        # from the license on the script that is generating the file.
+        # Every derived class should set this to some reasonable
+        # value.
+        #
+        # See license.py for an example of a reasonable value.
 
+        self.license = "The license for this file is unspecified."
 
-               # License on the *generated* source file.  This may differ
-               # from the license on the script that is generating the file.
-               # Every derived class should set this to some reasonable
-               # value.
-               #
-               # See license.py for an example of a reasonable value.
 
-               self.license = "The license for this file is unspecified."
+        # The header_tag is the name of the C preprocessor define
+        # used to prevent multiple inclusion.  Typically only
+        # generated C header files need this to be set.  Setting it
+        # causes code to be generated automatically in printHeader
+        # and printFooter.
 
-               
-               # The header_tag is the name of the C preprocessor define
-               # used to prevent multiple inclusion.  Typically only
-               # generated C header files need this to be set.  Setting it
-               # causes code to be generated automatically in printHeader
-               # and printFooter.
+        self.header_tag = None
 
-               self.header_tag = None
 
-               
-               # List of file-private defines that must be undefined at the
-               # end of the file.  This can be used in header files to define
-               # names for use in the file, then undefine them at the end of
-               # the header file.
+        # List of file-private defines that must be undefined at the
+        # end of the file.  This can be used in header files to define
+        # names for use in the file, then undefine them at the end of
+        # the header file.
 
-               self.undef_list = []
-               return
+        self.undef_list = []
+        return
 
 
-       def Print(self, api):
-               self.printHeader()
-               self.printBody(api)
-               self.printFooter()
-               return
+    def Print(self, api):
+        self.printHeader()
+        self.printBody(api)
+        self.printFooter()
+        return
 
 
-       def printHeader(self):
-               """Print the header associated with all files and call the printRealHeader method."""
+    def printHeader(self):
+        """Print the header associated with all files and call the printRealHeader method."""
 
-               print '/* DO NOT EDIT - This file generated automatically by %s script */' \
-                       % (self.name)
-               print ''
-               print '/*'
-               print ' * ' + self.license.replace('\n', '\n * ')
-               print ' */'
-               print ''
-               if self.header_tag:
-                   print '#if !defined( %s )' % (self.header_tag)
-                   print '#  define %s' % (self.header_tag)
-                   print ''
-               self.printRealHeader();
-               return
+        print '/* DO NOT EDIT - This file generated automatically by %s script */' \
+                % (self.name)
+        print ''
+        print '/*'
+        print ' * ' + self.license.replace('\n', '\n * ')
+        print ' */'
+        print ''
+        if self.header_tag:
+            print '#if !defined( %s )' % (self.header_tag)
+            print '#  define %s' % (self.header_tag)
+            print ''
+        self.printRealHeader();
+        return
 
 
-       def printFooter(self):
-               """Print the header associated with all files and call the printRealFooter method."""
+    def printFooter(self):
+        """Print the header associated with all files and call the printRealFooter method."""
 
-               self.printRealFooter()
+        self.printRealFooter()
 
-               if self.undef_list:
-                       print ''
-                       for u in self.undef_list:
-                               print "#  undef %s" % (u)
+        if self.undef_list:
+            print ''
+            for u in self.undef_list:
+                print "#  undef %s" % (u)
 
-               if self.header_tag:
-                       print ''
-                       print '#endif /* !defined( %s ) */' % (self.header_tag)
+        if self.header_tag:
+            print ''
+            print '#endif /* !defined( %s ) */' % (self.header_tag)
 
 
-       def printRealHeader(self):
-               """Print the "real" header for the created file.
+    def printRealHeader(self):
+        """Print the "real" header for the created file.
 
-               In the base class, this function is empty.  All derived
-               classes should over-ride this function."""
-               return
+        In the base class, this function is empty.  All derived
+        classes should over-ride this function."""
+        return
 
 
-       def printRealFooter(self):
-               """Print the "real" footer for the created file.
+    def printRealFooter(self):
+        """Print the "real" footer for the created file.
 
-               In the base class, this function is empty.  All derived
-               classes should over-ride this function."""
-               return
+        In the base class, this function is empty.  All derived
+        classes should over-ride this function."""
+        return
 
 
-       def printPure(self):
-               """Conditionally define `PURE' function attribute.
+    def printPure(self):
+        """Conditionally define `PURE' function attribute.
 
-               Conditionally defines a preprocessor macro `PURE' that wraps
-               GCC's `pure' function attribute.  The conditional code can be
-               easilly adapted to other compilers that support a similar
-               feature.
+        Conditionally defines a preprocessor macro `PURE' that wraps
+        GCC's `pure' function attribute.  The conditional code can be
+        easilly adapted to other compilers that support a similar
+        feature.
 
-               The name is also added to the file's undef_list.
-               """
-               self.undef_list.append("PURE")
-               print """#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+        The name is also added to the file's undef_list.
+        """
+        self.undef_list.append("PURE")
+        print """#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
 #    define PURE __attribute__((pure))
 #  else
 #    define PURE
 #  endif"""
-               return
+        return
 
 
-       def printFastcall(self):
-               """Conditionally define `FASTCALL' function attribute.
+    def printFastcall(self):
+        """Conditionally define `FASTCALL' function attribute.
 
-               Conditionally defines a preprocessor macro `FASTCALL' that
-               wraps GCC's `fastcall' function attribute.  The conditional
-               code can be easilly adapted to other compilers that support a
-               similar feature.
+        Conditionally defines a preprocessor macro `FASTCALL' that
+        wraps GCC's `fastcall' function attribute.  The conditional
+        code can be easilly adapted to other compilers that support a
+        similar feature.
 
-               The name is also added to the file's undef_list.
-               """
+        The name is also added to the file's undef_list.
+        """
 
-               self.undef_list.append("FASTCALL")
-               print """#  if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
+        self.undef_list.append("FASTCALL")
+        print """#  if defined(__i386__) && defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
 #    define FASTCALL __attribute__((fastcall))
 #  else
 #    define FASTCALL
 #  endif"""
-               return
+        return
 
 
-       def printVisibility(self, S, s):
-               """Conditionally define visibility function attribute.
+    def printVisibility(self, S, s):
+        """Conditionally define visibility function attribute.
 
-               Conditionally defines a preprocessor macro name S that wraps
-               GCC's visibility function attribute.  The visibility used is
-               the parameter s.  The conditional code can be easilly adapted
-               to other compilers that support a similar feature.
+        Conditionally defines a preprocessor macro name S that wraps
+        GCC's visibility function attribute.  The visibility used is
+        the parameter s.  The conditional code can be easilly adapted
+        to other compilers that support a similar feature.
 
-               The name is also added to the file's undef_list.
-               """
+        The name is also added to the file's undef_list.
+        """
 
-               self.undef_list.append(S)
-               print """#  if (defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) && defined(__ELF__))
+        self.undef_list.append(S)
+        print """#  if (defined(__GNUC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) && defined(__ELF__))
 #    define %s  __attribute__((visibility("%s")))
 #  else
 #    define %s
 #  endif""" % (S, s, S)
-               return
+        return
 
 
-       def printNoinline(self):
-               """Conditionally define `NOINLINE' function attribute.
+    def printNoinline(self):
+        """Conditionally define `NOINLINE' function attribute.
 
-               Conditionally defines a preprocessor macro `NOINLINE' that
-               wraps GCC's `noinline' function attribute.  The conditional
-               code can be easilly adapted to other compilers that support a
-               similar feature.
+        Conditionally defines a preprocessor macro `NOINLINE' that
+        wraps GCC's `noinline' function attribute.  The conditional
+        code can be easilly adapted to other compilers that support a
+        similar feature.
 
-               The name is also added to the file's undef_list.
-               """
+        The name is also added to the file's undef_list.
+        """
 
-               self.undef_list.append("NOINLINE")
-               print """#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+        self.undef_list.append("NOINLINE")
+        print """#  if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
 #    define NOINLINE __attribute__((noinline))
 #  else
 #    define NOINLINE
 #  endif"""
-               return
+        return
 
 
 def real_function_name(element):
-       name = element.nsProp( "name", None )
-       alias = element.nsProp( "alias", None )
-       
-       if alias:
-               return alias
-       else:
-               return name
+    name = element.nsProp( "name", None )
+    alias = element.nsProp( "alias", None )
+
+    if alias:
+        return alias
+    else:
+        return name
 
 
 def real_category_name(c):
-       if re.compile("[1-9][0-9]*[.][0-9]+").match(c):
-               return "GL_VERSION_" + c.replace(".", "_")
-       else:
-               return c
+    if re.compile("[1-9][0-9]*[.][0-9]+").match(c):
+        return "GL_VERSION_" + c.replace(".", "_")
+    else:
+        return c
 
 
 def classify_category(name, number):
-       """Based on the category name and number, select a numerical class for it.
-       
-       Categories are divided into four classes numbered 0 through 3.  The
-       classes are:
-
-               0. Core GL versions, sorted by version number.
-               1. ARB extensions, sorted by extension number.
-               2. Non-ARB extensions, sorted by extension number.
-               3. Un-numbered extensions, sorted by extension name.
-       """
-
-       try:
-               core_version = float(name)
-       except Exception,e:
-               core_version = 0.0
-
-       if core_version > 0.0:
-               cat_type = 0
-               key = name
-       elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"):
-               cat_type = 1
-               key = int(number)
-       else:
-               if number != None:
-                       cat_type = 2
-                       key = int(number)
-               else:
-                       cat_type = 3
-                       key = name
-
-
-       return [cat_type, key]
+    """Based on the category name and number, select a numerical class for it.
+
+    Categories are divided into four classes numbered 0 through 3.  The
+    classes are:
+
+            0. Core GL versions, sorted by version number.
+            1. ARB extensions, sorted by extension number.
+            2. Non-ARB extensions, sorted by extension number.
+            3. Un-numbered extensions, sorted by extension name.
+    """
+
+    try:
+        core_version = float(name)
+    except Exception,e:
+        core_version = 0.0
+
+    if core_version > 0.0:
+        cat_type = 0
+        key = name
+    elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"):
+        cat_type = 1
+        key = int(number)
+    else:
+        if number != None:
+            cat_type = 2
+            key = int(number)
+        else:
+            cat_type = 3
+            key = name
+
+
+    return [cat_type, key]
 
 
 def create_parameter_string(parameters, include_names):
-       """Create a parameter string from a list of gl_parameters."""
+    """Create a parameter string from a list of gl_parameters."""
 
-       list = []
-       for p in parameters:
-               if p.is_padding:
-                       continue
+    list = []
+    for p in parameters:
+        if p.is_padding:
+            continue
 
-               if include_names:
-                       list.append( p.string() )
-               else:
-                       list.append( p.type_string() )
+        if include_names:
+            list.append( p.string() )
+        else:
+            list.append( p.type_string() )
 
-       if len(list) == 0: list = ["void"]
+    if len(list) == 0: list = ["void"]
 
-       return string.join(list, ", ")
+    return string.join(list, ", ")
 
 
 class gl_item:
-       def __init__(self, element, context):
-               self.context = context
-               self.name = element.nsProp( "name", None )
-               self.category = real_category_name( element.parent.nsProp( "name", None ) )
-               return
+    def __init__(self, element, context):
+        self.context = context
+        self.name = element.nsProp( "name", None )
+        self.category = real_category_name( element.parent.nsProp( "name", None ) )
+        return
 
 
 class gl_type( gl_item ):
-       def __init__(self, element, context):
-               gl_item.__init__(self, element, context)
-               self.size = int( element.nsProp( "size", None ), 0 )
+    def __init__(self, element, context):
+        gl_item.__init__(self, element, context)
+        self.size = int( element.nsProp( "size", None ), 0 )
+
+        te = typeexpr.type_expression( None )
+        tn = typeexpr.type_node()
+        tn.size = int( element.nsProp( "size", None ), 0 )
+        tn.integer = not is_attr_true( element, "float" )
+        tn.unsigned = is_attr_true( element, "unsigned" )
+        tn.pointer = is_attr_true( element, "pointer" )
+        tn.name = "GL" + self.name
+        te.set_base_type_node( tn )
 
-               te = typeexpr.type_expression( None )
-               tn = typeexpr.type_node()
-               tn.size = int( element.nsProp( "size", None ), 0 )
-               tn.integer = not is_attr_true( element, "float" )
-               tn.unsigned = is_attr_true( element, "unsigned" )
-               tn.pointer = is_attr_true( element, "pointer" )
-               tn.name = "GL" + self.name
-               te.set_base_type_node( tn )
+        self.type_expr = te
+        return
 
-               self.type_expr = te
-               return
-       
 
-       def get_type_expression(self):
-               return self.type_expr
+    def get_type_expression(self):
+        return self.type_expr
 
 
 class gl_enum( gl_item ):
-       def __init__(self, element, context):
-               gl_item.__init__(self, element, context)
-               self.value = int( element.nsProp( "value", None ), 0 )
+    def __init__(self, element, context):
+        gl_item.__init__(self, element, context)
+        self.value = int( element.nsProp( "value", None ), 0 )
 
-               temp = element.nsProp( "count", None )
-               if not temp or temp == "?":
-                       self.default_count = -1
-               else:
-                       try:
-                               c = int(temp)
-                       except Exception,e:
-                               raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n))
+        temp = element.nsProp( "count", None )
+        if not temp or temp == "?":
+            self.default_count = -1
+        else:
+            try:
+                c = int(temp)
+            except Exception,e:
+                raise RuntimeError('Invalid count value "%s" for enum "%s" in function "%s" when an integer was expected.' % (temp, self.name, n))
 
-                       self.default_count = c
+            self.default_count = c
 
-               return
+        return
 
 
-       def priority(self):
-               """Calculate a 'priority' for this enum name.
-               
-               When an enum is looked up by number, there may be many
-               possible names, but only one is the 'prefered' name.  The
-               priority is used to select which name is the 'best'.
+    def priority(self):
+        """Calculate a 'priority' for this enum name.
 
-               Highest precedence is given to core GL name.  ARB extension
-               names have the next highest, followed by EXT extension names.
-               Vendor extension names are the lowest.
-               """
+        When an enum is looked up by number, there may be many
+        possible names, but only one is the 'prefered' name.  The
+        priority is used to select which name is the 'best'.
 
-               if self.name.endswith( "_BIT" ):
-                       bias = 1
-               else:
-                       bias = 0
+        Highest precedence is given to core GL name.  ARB extension
+        names have the next highest, followed by EXT extension names.
+        Vendor extension names are the lowest.
+        """
 
-               if self.category.startswith( "GL_VERSION_" ):
-                       priority = 0
-               elif self.category.startswith( "GL_ARB_" ):
-                       priority = 2
-               elif self.category.startswith( "GL_EXT_" ):
-                       priority = 4
-               else:
-                       priority = 6
+        if self.name.endswith( "_BIT" ):
+            bias = 1
+        else:
+            bias = 0
 
-               return priority + bias
+        if self.category.startswith( "GL_VERSION_" ):
+            priority = 0
+        elif self.category.startswith( "GL_ARB_" ):
+            priority = 2
+        elif self.category.startswith( "GL_EXT_" ):
+            priority = 4
+        else:
+            priority = 6
+
+        return priority + bias
 
 
 
 class gl_parameter:
-       def __init__(self, element, context):
-               self.name = element.nsProp( "name", None )
+    def __init__(self, element, context):
+        self.name = element.nsProp( "name", None )
+
+        ts = element.nsProp( "type", None )
+        self.type_expr = typeexpr.type_expression( ts, context )
 
-               ts = element.nsProp( "type", None )
-               self.type_expr = typeexpr.type_expression( ts, context )
+        temp = element.nsProp( "variable_param", None )
+        if temp:
+            self.count_parameter_list = temp.split( ' ' )
+        else:
+            self.count_parameter_list = []
 
-               temp = element.nsProp( "variable_param", None )
-               if temp:
-                       self.count_parameter_list = temp.split( ' ' )
-               else:
-                       self.count_parameter_list = []
+        # The count tag can be either a numeric string or the name of
+        # a variable.  If it is the name of a variable, the int(c)
+        # statement will throw an exception, and the except block will
+        # take over.
 
-               # The count tag can be either a numeric string or the name of
-               # a variable.  If it is the name of a variable, the int(c)
-               # statement will throw an exception, and the except block will
-               # take over.
+        c = element.nsProp( "count", None )
+        try: 
+            count = int(c)
+            self.count = count
+            self.counter = None
+        except Exception,e:
+            count = 1
+            self.count = 0
+            self.counter = c
 
-               c = element.nsProp( "count", None )
-               try: 
-                       count = int(c)
-                       self.count = count
-                       self.counter = None
-               except Exception,e:
-                       count = 1
-                       self.count = 0
-                       self.counter = c
-               
-               self.count_scale = int(element.nsProp( "count_scale", None ))
+        self.count_scale = int(element.nsProp( "count_scale", None ))
 
-               elements = (count * self.count_scale)
-               if elements == 1:
-                       elements = 0
+        elements = (count * self.count_scale)
+        if elements == 1:
+            elements = 0
 
-               #if ts == "GLdouble":
-               #       print '/* stack size -> %s = %u (before)*/' % (self.name, self.type_expr.get_stack_size())
-               #       print '/* # elements = %u */' % (elements)
-               self.type_expr.set_elements( elements )
-               #if ts == "GLdouble":
-               #       print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size())
+        #if ts == "GLdouble":
+        #      print '/* stack size -> %s = %u (before)*/' % (self.name, self.type_expr.get_stack_size())
+        #      print '/* # elements = %u */' % (elements)
+        self.type_expr.set_elements( elements )
+        #if ts == "GLdouble":
+        #      print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size())
 
-               self.is_client_only = is_attr_true( element, 'client_only' )
-               self.is_counter     = is_attr_true( element, 'counter' )
-               self.is_output      = is_attr_true( element, 'output' )
+        self.is_client_only = is_attr_true( element, 'client_only' )
+        self.is_counter     = is_attr_true( element, 'counter' )
+        self.is_output      = is_attr_true( element, 'output' )
 
 
-               # Pixel data has special parameters.
+        # Pixel data has special parameters.
 
-               self.width      = element.nsProp('img_width',  None)
-               self.height     = element.nsProp('img_height', None)
-               self.depth      = element.nsProp('img_depth',  None)
-               self.extent     = element.nsProp('img_extent', None)
+        self.width      = element.nsProp('img_width',  None)
+        self.height     = element.nsProp('img_height', None)
+        self.depth      = element.nsProp('img_depth',  None)
+        self.extent     = element.nsProp('img_extent', None)
 
-               self.img_xoff   = element.nsProp('img_xoff',   None)
-               self.img_yoff   = element.nsProp('img_yoff',   None)
-               self.img_zoff   = element.nsProp('img_zoff',   None)
-               self.img_woff   = element.nsProp('img_woff',   None)
+        self.img_xoff   = element.nsProp('img_xoff',   None)
+        self.img_yoff   = element.nsProp('img_yoff',   None)
+        self.img_zoff   = element.nsProp('img_zoff',   None)
+        self.img_woff   = element.nsProp('img_woff',   None)
 
-               self.img_format = element.nsProp('img_format', None)
-               self.img_type   = element.nsProp('img_type',   None)
-               self.img_target = element.nsProp('img_target', None)
+        self.img_format = element.nsProp('img_format', None)
+        self.img_type   = element.nsProp('img_type',   None)
+        self.img_target = element.nsProp('img_target', None)
 
-               self.img_pad_dimensions = is_attr_true( element, 'img_pad_dimensions' )
-               self.img_null_flag      = is_attr_true( element, 'img_null_flag' )
-               self.img_send_null      = is_attr_true( element, 'img_send_null' )
+        self.img_pad_dimensions = is_attr_true( element, 'img_pad_dimensions' )
+        self.img_null_flag      = is_attr_true( element, 'img_null_flag' )
+        self.img_send_null      = is_attr_true( element, 'img_send_null' )
 
-               self.is_padding = is_attr_true( element, 'padding' )
-               return
+        self.is_padding = is_attr_true( element, 'padding' )
+        return
 
 
-       def compatible(self, other):
-               return 1
+    def compatible(self, other):
+        return 1
 
 
-       def is_array(self):
-               return self.is_pointer()
+    def is_array(self):
+        return self.is_pointer()
 
 
-       def is_pointer(self):
-               return self.type_expr.is_pointer()
+    def is_pointer(self):
+        return self.type_expr.is_pointer()
 
 
-       def is_image(self):
-               if self.width:
-                       return 1
-               else:
-                       return 0
+    def is_image(self):
+        if self.width:
+            return 1
+        else:
+            return 0
 
 
-       def is_variable_length(self):
-               return len(self.count_parameter_list) or self.counter
+    def is_variable_length(self):
+        return len(self.count_parameter_list) or self.counter
 
 
-       def is_64_bit(self):
-               count = self.type_expr.get_element_count()
-               if count:
-                       if (self.size() / count) == 8:
-                               return 1
-               else:
-                       if self.size() == 8:
-                               return 1
+    def is_64_bit(self):
+        count = self.type_expr.get_element_count()
+        if count:
+            if (self.size() / count) == 8:
+                return 1
+        else:
+            if self.size() == 8:
+                return 1
 
-               return 0
+        return 0
 
 
-       def string(self):
-               return self.type_expr.original_string + " " + self.name
+    def string(self):
+        return self.type_expr.original_string + " " + self.name
 
 
-       def type_string(self):
-               return self.type_expr.original_string
+    def type_string(self):
+        return self.type_expr.original_string
 
 
-       def get_base_type_string(self):
-               return self.type_expr.get_base_name()
+    def get_base_type_string(self):
+        return self.type_expr.get_base_name()
 
 
-       def get_dimensions(self):
-               if not self.width:
-                       return [ 0, "0", "0", "0", "0" ]
+    def get_dimensions(self):
+        if not self.width:
+            return [ 0, "0", "0", "0", "0" ]
 
-               dim = 1
-               w = self.width
-               h = "1"
-               d = "1"
-               e = "1"
+        dim = 1
+        w = self.width
+        h = "1"
+        d = "1"
+        e = "1"
 
-               if self.height:
-                       dim = 2
-                       h = self.height
+        if self.height:
+            dim = 2
+            h = self.height
 
-               if self.depth:
-                       dim = 3
-                       d = self.depth
+        if self.depth:
+            dim = 3
+            d = self.depth
 
-               if self.extent:
-                       dim = 4
-                       e = self.extent
+        if self.extent:
+            dim = 4
+            e = self.extent
 
-               return [ dim, w, h, d, e ]
+        return [ dim, w, h, d, e ]
 
 
-       def get_stack_size(self):
-               return self.type_expr.get_stack_size()
+    def get_stack_size(self):
+        return self.type_expr.get_stack_size()
 
 
-       def size(self):
-               if self.is_image():
-                       return 0
-               else:
-                       return self.type_expr.get_element_size()
+    def size(self):
+        if self.is_image():
+            return 0
+        else:
+            return self.type_expr.get_element_size()
 
 
-       def get_element_count(self):
-               c = self.type_expr.get_element_count()
-               if c == 0:
-                       return 1
+    def get_element_count(self):
+        c = self.type_expr.get_element_count()
+        if c == 0:
+            return 1
 
-               return c
+        return c
 
 
-       def size_string(self, use_parens = 1):
-               s = self.size()
-               if self.counter or self.count_parameter_list:
-                       list = [ "compsize" ]
+    def size_string(self, use_parens = 1):
+        s = self.size()
+        if self.counter or self.count_parameter_list:
+            list = [ "compsize" ]
 
-                       if self.counter and self.count_parameter_list:
-                               list.append( self.counter )
-                       elif self.counter:
-                               list = [ self.counter ]
+            if self.counter and self.count_parameter_list:
+                list.append( self.counter )
+            elif self.counter:
+                list = [ self.counter ]
 
-                       if s > 1:
-                               list.append( str(s) )
+            if s > 1:
+                list.append( str(s) )
 
-                       if len(list) > 1 and use_parens :
-                               return "(%s)" % (string.join(list, " * "))
-                       else:
-                               return string.join(list, " * ")
+            if len(list) > 1 and use_parens :
+                return "(%s)" % (string.join(list, " * "))
+            else:
+                return string.join(list, " * ")
 
-               elif self.is_image():
-                       return "compsize"
-               else:
-                       return str(s)
+        elif self.is_image():
+            return "compsize"
+        else:
+            return str(s)
 
 
-       def format_string(self):
-               if self.type_expr.original_string == "GLenum":
-                       return "0x%x"
-               else:
-                       return self.type_expr.format_string()
+    def format_string(self):
+        if self.type_expr.original_string == "GLenum":
+            return "0x%x"
+        else:
+            return self.type_expr.format_string()
 
 
 
 class gl_function( gl_item ):
-       def __init__(self, element, context):
-               self.context = context
-               self.name = None
-
-               self.entry_points = []
-               self.return_type = "void"
-               self.parameters = []
-               self.offset = -1
-               self.initialized = 0
-               self.images = []
-
-               self.assign_offset = 0
-
-               self.static_entry_points = []
+    def __init__(self, element, context):
+        self.context = context
+        self.name = None
+
+        self.entry_points = []
+        self.return_type = "void"
+        self.parameters = []
+        self.offset = -1
+        self.initialized = 0
+        self.images = []
 
-               # Track the parameter string (for the function prototype)
-               # for each entry-point.  This is done because some functions
-               # change their prototype slightly when promoted from extension
-               # to ARB extension to core.  glTexImage3DEXT and glTexImage3D
-               # are good examples of this.  Scripts that need to generate
-               # code for these differing aliases need to real prototype
-               # for each entry-point.  Otherwise, they may generate code
-               # that won't compile.
-
-               self.entry_point_parameters = {}
-
-               self.process_element( element )
-
-               return
-
-       
-       def process_element(self, element):
-               name = element.nsProp( "name", None )
-               alias = element.nsProp( "alias", None )
-
-               if is_attr_true(element, "static_dispatch"):
-                       self.static_entry_points.append(name)
-
-               self.entry_points.append( name )
-               if alias:
-                       true_name = alias
-               else:
-                       true_name = name
-
-                       # Only try to set the offset when a non-alias
-                       # entry-point is being processes.
+        self.assign_offset = 0
 
-                       offset = element.nsProp( "offset", None )
-                       if offset:
-                               try:
-                                       o = int( offset )
-                                       self.offset = o
-                               except Exception, e:
-                                       self.offset = -1
-                                       if offset == "assign":
-                                               self.assign_offset = 1
-
-
-               if not self.name:
-                       self.name = true_name
-               elif self.name != true_name:
-                       raise RuntimeError("Function true name redefined.  Was %s, now %s." % (self.name, true_name))
-
-
-               # There are two possible cases.  The first time an entry-point
-               # with data is seen, self.initialized will be 0.  On that
-               # pass, we just fill in the data.  The next time an
-               # entry-point with data is seen, self.initialized will be 1.
-               # On that pass we have to make that the new values match the
-               # valuse from the previous entry-point.
-
-               parameters = []
-               return_type = "void"
-               child = element.children
-               while child:
-                       if child.type == "element":
-                               if child.name == "return":
-                                       return_type = child.nsProp( "type", None )
-                               elif child.name == "param":
-                                       param = self.context.factory.create_item( "parameter", child, self.context)
-                                       parameters.append( param )
-
-                       child = child.next
+        self.static_entry_points = []
 
+        # Track the parameter string (for the function prototype)
+        # for each entry-point.  This is done because some functions
+        # change their prototype slightly when promoted from extension
+        # to ARB extension to core.  glTexImage3DEXT and glTexImage3D
+        # are good examples of this.  Scripts that need to generate
+        # code for these differing aliases need to real prototype
+        # for each entry-point.  Otherwise, they may generate code
+        # that won't compile.
+
+        self.entry_point_parameters = {}
+
+        self.process_element( element )
+
+        return
+
+
+    def process_element(self, element):
+        name = element.nsProp( "name", None )
+        alias = element.nsProp( "alias", None )
+
+        if is_attr_true(element, "static_dispatch"):
+            self.static_entry_points.append(name)
+
+        self.entry_points.append( name )
+        if alias:
+            true_name = alias
+        else:
+            true_name = name
+
+            # Only try to set the offset when a non-alias
+            # entry-point is being processes.
 
-               if self.initialized:
-                       if self.return_type != return_type:
-                               raise RuntimeError( "Return type changed in %s.  Was %s, now %s." % (name, self.return_type, return_type))
+            offset = element.nsProp( "offset", None )
+            if offset:
+                try:
+                    o = int( offset )
+                    self.offset = o
+                except Exception, e:
+                    self.offset = -1
+                    if offset == "assign":
+                        self.assign_offset = 1
 
-                       if len(parameters) != len(self.parameters):
-                               raise RuntimeError( "Parameter count mismatch in %s.  Was %d, now %d." % (name, len(self.parameters), len(parameters)))
 
-                       for j in range(0, len(parameters)):
-                               p1 = parameters[j]
-                               p2 = self.parameters[j]
-                               if not p1.compatible( p2 ):
-                                       raise RuntimeError( 'Parameter type mismatch in %s.  "%s" was "%s", now "%s".' % (name, p2.name, p2.type_expr.original_string, p1.type_expr.original_string))
+        if not self.name:
+            self.name = true_name
+        elif self.name != true_name:
+            raise RuntimeError("Function true name redefined.  Was %s, now %s." % (self.name, true_name))
 
 
-               if true_name == name or not self.initialized:
-                       self.return_type = return_type
-                       self.parameters = parameters
+        # There are two possible cases.  The first time an entry-point
+        # with data is seen, self.initialized will be 0.  On that
+        # pass, we just fill in the data.  The next time an
+        # entry-point with data is seen, self.initialized will be 1.
+        # On that pass we have to make that the new values match the
+        # valuse from the previous entry-point.
 
-                       for param in self.parameters:
-                               if param.is_image():
-                                       self.images.append( param )
+        parameters = []
+        return_type = "void"
+        child = element.children
+        while child:
+            if child.type == "element":
+                if child.name == "return":
+                    return_type = child.nsProp( "type", None )
+                elif child.name == "param":
+                    param = self.context.factory.create_item( "parameter", child, self.context)
+                    parameters.append( param )
 
-               if element.children:
-                       self.initialized = 1
-                       self.entry_point_parameters[name] = parameters
-               else:
-                       self.entry_point_parameters[name] = []
+            child = child.next
 
-               return
 
-       def filter_entry_points(self, entry_point_list):
-               """Filter out entry points not in entry_point_list."""
-               if not self.initialized:
-                       raise RuntimeError('%s is not initialized yet' % self.name)
+        if self.initialized:
+            if self.return_type != return_type:
+                raise RuntimeError( "Return type changed in %s.  Was %s, now %s." % (name, self.return_type, return_type))
 
-               entry_points = []
-               for ent in self.entry_points:
-                       if ent not in entry_point_list:
-                               if ent in self.static_entry_points:
-                                       self.static_entry_points.remove(ent)
-                               self.entry_point_parameters.pop(ent)
-                       else:
-                               entry_points.append(ent)
+            if len(parameters) != len(self.parameters):
+                raise RuntimeError( "Parameter count mismatch in %s.  Was %d, now %d." % (name, len(self.parameters), len(parameters)))
 
-               if not entry_points:
-                       raise RuntimeError('%s has no entry point after filtering' % self.name)
+            for j in range(0, len(parameters)):
+                p1 = parameters[j]
+                p2 = self.parameters[j]
+                if not p1.compatible( p2 ):
+                    raise RuntimeError( 'Parameter type mismatch in %s.  "%s" was "%s", now "%s".' % (name, p2.name, p2.type_expr.original_string, p1.type_expr.original_string))
 
-               self.entry_points = entry_points
-               if self.name not in entry_points:
-                       # use the first remaining entry point
-                       self.name = entry_points[0]
-                       self.parameters = self.entry_point_parameters[entry_points[0]]
 
-       def get_images(self):
-               """Return potentially empty list of input images."""
-               return self.images
+        if true_name == name or not self.initialized:
+            self.return_type = return_type
+            self.parameters = parameters
 
+            for param in self.parameters:
+                if param.is_image():
+                    self.images.append( param )
 
-       def parameterIterator(self):
-               return self.parameters.__iter__();
+        if element.children:
+            self.initialized = 1
+            self.entry_point_parameters[name] = parameters
+        else:
+            self.entry_point_parameters[name] = []
 
+        return
 
-       def get_parameter_string(self, entrypoint = None):
-               if entrypoint:
-                       params = self.entry_point_parameters[ entrypoint ]
-               else:
-                       params = self.parameters
-               
-               return create_parameter_string( params, 1 )
+    def filter_entry_points(self, entry_point_list):
+        """Filter out entry points not in entry_point_list."""
+        if not self.initialized:
+            raise RuntimeError('%s is not initialized yet' % self.name)
 
-       def get_called_parameter_string(self):
-               p_string = ""
-               comma = ""
+        entry_points = []
+        for ent in self.entry_points:
+            if ent not in entry_point_list:
+                if ent in self.static_entry_points:
+                    self.static_entry_points.remove(ent)
+                self.entry_point_parameters.pop(ent)
+            else:
+                entry_points.append(ent)
 
-               for p in self.parameterIterator():
-                       p_string = p_string + comma + p.name
-                       comma = ", "
+        if not entry_points:
+            raise RuntimeError('%s has no entry point after filtering' % self.name)
 
-               return p_string
+        self.entry_points = entry_points
+        if self.name not in entry_points:
+            # use the first remaining entry point
+            self.name = entry_points[0]
+            self.parameters = self.entry_point_parameters[entry_points[0]]
 
+    def get_images(self):
+        """Return potentially empty list of input images."""
+        return self.images
 
-       def is_abi(self):
-               return (self.offset >= 0 and not self.assign_offset)
 
-       def is_static_entry_point(self, name):
-               return name in self.static_entry_points
+    def parameterIterator(self):
+        return self.parameters.__iter__();
 
-       def dispatch_name(self):
-               if self.name in self.static_entry_points:
-                       return self.name
-               else:
-                       return "_dispatch_stub_%u" % (self.offset)
 
-       def static_name(self, name):
-               if name in self.static_entry_points:
-                       return name
-               else:
-                       return "_dispatch_stub_%u" % (self.offset)
+    def get_parameter_string(self, entrypoint = None):
+        if entrypoint:
+            params = self.entry_point_parameters[ entrypoint ]
+        else:
+            params = self.parameters
+
+        return create_parameter_string( params, 1 )
+
+    def get_called_parameter_string(self):
+        p_string = ""
+        comma = ""
+
+        for p in self.parameterIterator():
+            p_string = p_string + comma + p.name
+            comma = ", "
+
+        return p_string
+
+
+    def is_abi(self):
+        return (self.offset >= 0 and not self.assign_offset)
+
+    def is_static_entry_point(self, name):
+        return name in self.static_entry_points
+
+    def dispatch_name(self):
+        if self.name in self.static_entry_points:
+            return self.name
+        else:
+            return "_dispatch_stub_%u" % (self.offset)
+
+    def static_name(self, name):
+        if name in self.static_entry_points:
+            return name
+        else:
+            return "_dispatch_stub_%u" % (self.offset)
 
 
 class gl_item_factory:
-       """Factory to create objects derived from gl_item."""
-
-       def create_item(self, item_name, element, context):
-               if item_name == "function":
-                       return gl_function(element, context)
-               if item_name == "type":
-                       return gl_type(element, context)
-               elif item_name == "enum":
-                       return gl_enum(element, context)
-               elif item_name == "parameter":
-                       return gl_parameter(element, context)
-               elif item_name == "api":
-                       return gl_api(self)
-               else:
-                       return None
+    """Factory to create objects derived from gl_item."""
+
+    def create_item(self, item_name, element, context):
+        if item_name == "function":
+            return gl_function(element, context)
+        if item_name == "type":
+            return gl_type(element, context)
+        elif item_name == "enum":
+            return gl_enum(element, context)
+        elif item_name == "parameter":
+            return gl_parameter(element, context)
+        elif item_name == "api":
+            return gl_api(self)
+        else:
+            return None
 
 
 class gl_api:
-       def __init__(self, factory):
-               self.functions_by_name = {}
-               self.enums_by_name = {}
-               self.types_by_name = {}
+    def __init__(self, factory):
+        self.functions_by_name = {}
+        self.enums_by_name = {}
+        self.types_by_name = {}
+
+        self.category_dict = {}
+        self.categories = [{}, {}, {}, {}]
+
+        self.factory = factory
+
+        self.next_offset = 0
+
+        typeexpr.create_initial_types()
+        return
+
+    def filter_functions(self, entry_point_list):
+        """Filter out entry points not in entry_point_list."""
+        functions_by_name = {}
+        for func in self.functions_by_name.itervalues():
+            entry_points = [ent for ent in func.entry_points if ent in entry_point_list]
+            if entry_points:
+                func.filter_entry_points(entry_points)
+                functions_by_name[func.name] = func
 
-               self.category_dict = {}
-               self.categories = [{}, {}, {}, {}]
+        self.functions_by_name = functions_by_name
 
-               self.factory = factory
+    def process_element(self, doc):
+        element = doc.children
+        while element.type != "element" or element.name != "OpenGLAPI":
+            element = element.next
 
-               self.next_offset = 0
+        if element:
+            self.process_OpenGLAPI(element)
+        return
 
-               typeexpr.create_initial_types()
-               return
 
-       def filter_functions(self, entry_point_list):
-               """Filter out entry points not in entry_point_list."""
-               functions_by_name = {}
-               for func in self.functions_by_name.itervalues():
-                       entry_points = [ent for ent in func.entry_points if ent in entry_point_list]
-                       if entry_points:
-                               func.filter_entry_points(entry_points)
-                               functions_by_name[func.name] = func
+    def process_OpenGLAPI(self, element):
+        child = element.children
+        while child:
+            if child.type == "element":
+                if child.name == "category":
+                    self.process_category( child )
+                elif child.name == "OpenGLAPI":
+                    self.process_OpenGLAPI( child )
 
-               self.functions_by_name = functions_by_name
+            child = child.next
 
-       def process_element(self, doc):
-               element = doc.children
-               while element.type != "element" or element.name != "OpenGLAPI":
-                       element = element.next
+        return
 
-               if element:
-                       self.process_OpenGLAPI(element)
-               return
 
+    def process_category(self, cat):
+        cat_name = cat.nsProp( "name", None )
+        cat_number = cat.nsProp( "number", None )
 
-       def process_OpenGLAPI(self, element):
-               child = element.children
-               while child:
-                       if child.type == "element":
-                               if child.name == "category":
-                                       self.process_category( child )
-                               elif child.name == "OpenGLAPI":
-                                       self.process_OpenGLAPI( child )
+        [cat_type, key] = classify_category(cat_name, cat_number)
+        self.categories[cat_type][key] = [cat_name, cat_number]
 
-                       child = child.next
+        child = cat.children
+        while child:
+            if child.type == "element":
+                if child.name == "function":
+                    func_name = real_function_name( child )
 
-               return
+                    temp_name = child.nsProp( "name", None )
+                    self.category_dict[ temp_name ] = [cat_name, cat_number]
 
+                    if self.functions_by_name.has_key( func_name ):
+                        func = self.functions_by_name[ func_name ]
+                        func.process_element( child )
+                    else:
+                        func = self.factory.create_item( "function", child, self )
+                        self.functions_by_name[ func_name ] = func
 
-       def process_category(self, cat):
-               cat_name = cat.nsProp( "name", None )
-               cat_number = cat.nsProp( "number", None )
+                    if func.offset >= self.next_offset:
+                        self.next_offset = func.offset + 1
 
-               [cat_type, key] = classify_category(cat_name, cat_number)
-               self.categories[cat_type][key] = [cat_name, cat_number]
 
-               child = cat.children
-               while child:
-                       if child.type == "element":
-                               if child.name == "function":
-                                       func_name = real_function_name( child )
+                elif child.name == "enum":
+                    enum = self.factory.create_item( "enum", child, self )
+                    self.enums_by_name[ enum.name ] = enum
+                elif child.name == "type":
+                    t = self.factory.create_item( "type", child, self )
+                    self.types_by_name[ "GL" + t.name ] = t
 
-                                       temp_name = child.nsProp( "name", None )
-                                       self.category_dict[ temp_name ] = [cat_name, cat_number]
 
-                                       if self.functions_by_name.has_key( func_name ):
-                                               func = self.functions_by_name[ func_name ]
-                                               func.process_element( child )
-                                       else:
-                                               func = self.factory.create_item( "function", child, self )
-                                               self.functions_by_name[ func_name ] = func
+            child = child.next
 
-                                       if func.offset >= self.next_offset:
-                                               self.next_offset = func.offset + 1
+        return
 
 
-                               elif child.name == "enum":
-                                       enum = self.factory.create_item( "enum", child, self )
-                                       self.enums_by_name[ enum.name ] = enum
-                               elif child.name == "type":
-                                       t = self.factory.create_item( "type", child, self )
-                                       self.types_by_name[ "GL" + t.name ] = t
+    def functionIterateByCategory(self, cat = None):
+        """Iterate over functions by category.
 
+        If cat is None, all known functions are iterated in category
+        order.  See classify_category for details of the ordering.
+        Within a category, functions are sorted by name.  If cat is
+        not None, then only functions in that category are iterated.
+        """
+        lists = [{}, {}, {}, {}]
 
-                       child = child.next
+        for func in self.functionIterateAll():
+            [cat_name, cat_number] = self.category_dict[func.name]
 
-               return
+            if (cat == None) or (cat == cat_name):
+                [func_cat_type, key] = classify_category(cat_name, cat_number)
 
+                if not lists[func_cat_type].has_key(key):
+                    lists[func_cat_type][key] = {}
 
-       def functionIterateByCategory(self, cat = None):
-               """Iterate over functions by category.
-               
-               If cat is None, all known functions are iterated in category
-               order.  See classify_category for details of the ordering.
-               Within a category, functions are sorted by name.  If cat is
-               not None, then only functions in that category are iterated.
-               """
-               lists = [{}, {}, {}, {}]
+                lists[func_cat_type][key][func.name] = func
 
-               for func in self.functionIterateAll():
-                       [cat_name, cat_number] = self.category_dict[func.name]
 
-                       if (cat == None) or (cat == cat_name):
-                               [func_cat_type, key] = classify_category(cat_name, cat_number)
+        functions = []
+        for func_cat_type in range(0,4):
+            keys = lists[func_cat_type].keys()
+            keys.sort()
 
-                               if not lists[func_cat_type].has_key(key):
-                                       lists[func_cat_type][key] = {}
+            for key in keys:
+                names = lists[func_cat_type][key].keys()
+                names.sort()
 
-                               lists[func_cat_type][key][func.name] = func
+                for name in names:
+                    functions.append(lists[func_cat_type][key][name])
 
+        return functions.__iter__()
 
-               functions = []
-               for func_cat_type in range(0,4):
-                       keys = lists[func_cat_type].keys()
-                       keys.sort()
 
-                       for key in keys:
-                               names = lists[func_cat_type][key].keys()
-                               names.sort()
+    def functionIterateByOffset(self):
+        max_offset = -1
+        for func in self.functions_by_name.itervalues():
+            if func.offset > max_offset:
+                max_offset = func.offset
 
-                               for name in names:
-                                       functions.append(lists[func_cat_type][key][name])
 
-               return functions.__iter__()
+        temp = [None for i in range(0, max_offset + 1)]
+        for func in self.functions_by_name.itervalues():
+            if func.offset != -1:
+                temp[ func.offset ] = func
 
 
-       def functionIterateByOffset(self):
-               max_offset = -1
-               for func in self.functions_by_name.itervalues():
-                       if func.offset > max_offset:
-                               max_offset = func.offset
+        list = []
+        for i in range(0, max_offset + 1):
+            if temp[i]:
+                list.append(temp[i])
 
+        return list.__iter__();
 
-               temp = [None for i in range(0, max_offset + 1)]
-               for func in self.functions_by_name.itervalues():
-                       if func.offset != -1:
-                               temp[ func.offset ] = func
 
+    def functionIterateAll(self):
+        return self.functions_by_name.itervalues()
 
-               list = []
-               for i in range(0, max_offset + 1):
-                       if temp[i]:
-                               list.append(temp[i])
 
-               return list.__iter__();
+    def enumIterateByName(self):
+        keys = self.enums_by_name.keys()
+        keys.sort()
 
+        list = []
+        for enum in keys:
+            list.append( self.enums_by_name[ enum ] )
 
-       def functionIterateAll(self):
-               return self.functions_by_name.itervalues()
+        return list.__iter__()
 
 
-       def enumIterateByName(self):
-               keys = self.enums_by_name.keys()
-               keys.sort()
-               
-               list = []
-               for enum in keys:
-                       list.append( self.enums_by_name[ enum ] )
+    def categoryIterate(self):
+        """Iterate over categories.
 
-               return list.__iter__()
+        Iterate over all known categories in the order specified by
+        classify_category.  Each iterated value is a tuple of the
+        name and number (which may be None) of the category.
+        """
 
+        list = []
+        for cat_type in range(0,4):
+            keys = self.categories[cat_type].keys()
+            keys.sort()
 
-       def categoryIterate(self):
-               """Iterate over categories.
-               
-               Iterate over all known categories in the order specified by
-               classify_category.  Each iterated value is a tuple of the
-               name and number (which may be None) of the category.
-               """
+            for key in keys:
+                list.append(self.categories[cat_type][key])
 
-               list = []
-               for cat_type in range(0,4):
-                       keys = self.categories[cat_type].keys()
-                       keys.sort()
-                       
-                       for key in keys:
-                               list.append(self.categories[cat_type][key])
-                               
-               return list.__iter__()
+        return list.__iter__()
 
 
-       def get_category_for_name( self, name ):
-               if self.category_dict.has_key(name):
-                       return self.category_dict[name]
-               else:
-                       return ["<unknown category>", None]
+    def get_category_for_name( self, name ):
+        if self.category_dict.has_key(name):
+            return self.category_dict[name]
+        else:
+            return ["<unknown category>", None]
 
 
-       def typeIterate(self):
-               return self.types_by_name.itervalues()
+    def typeIterate(self):
+        return self.types_by_name.itervalues()
 
 
-       def find_type( self, type_name ):
-               if type_name in self.types_by_name:
-                       return self.types_by_name[ type_name ].type_expr
-               else:
-                       print "Unable to find base type matching \"%s\"." % (type_name)
-                       return None
+    def find_type( self, type_name ):
+        if type_name in self.types_by_name:
+            return self.types_by_name[ type_name ].type_expr
+        else:
+            print "Unable to find base type matching \"%s\"." % (type_name)
+            return None
index 72c2e46c37ec11a2f63ab2ee24b7ab3712129550..c9a6e29372d8ed43007c0e03c20f2c2948bd88db 100644 (file)
@@ -30,94 +30,94 @@ import license
 import sys, getopt
 
 class PrintGlOffsets(gl_XML.gl_print_base):
-       def __init__(self, es=False):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, es=False):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "gl_apitemp.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "gl_apitemp.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
 
-               self.es = es
-
-               self.undef_list.append( "KEYWORD1" )
-               self.undef_list.append( "KEYWORD1_ALT" )
-               self.undef_list.append( "KEYWORD2" )
-               self.undef_list.append( "NAME" )
-               self.undef_list.append( "DISPATCH" )
-               self.undef_list.append( "RETURN_DISPATCH" )
-               self.undef_list.append( "DISPATCH_TABLE_NAME" )
-               self.undef_list.append( "UNUSED_TABLE_NAME" )
-               self.undef_list.append( "TABLE_ENTRY" )
-
-
-       def printFunction(self, f, name):
-               p_string = ""
-               o_string = ""
-               t_string = ""
-               comma = ""
-
-               if f.is_static_entry_point(name):
-                       keyword = "KEYWORD1"
-               else:
-                       keyword = "KEYWORD1_ALT"
-
-               n = f.static_name(name)
-
-               silence = ''
-               space = ''
-               for p in f.parameterIterator():
-                       if p.is_padding:
-                               continue
-
-                       if p.is_pointer():
-                               cast = "(const void *) "
-                       else:
-                               cast = ""
-
-                       t_string = t_string + comma + p.format_string()
-                       p_string = p_string + comma + p.name
-                       o_string = o_string + comma + cast + p.name
-                       comma = ", "
-
-                       silence += "%s(void) %s;" % (space, p.name);
-                       space = ' '
-
-
-               if f.return_type != 'void':
-                       dispatch = "RETURN_DISPATCH"
-               else:
-                       dispatch = "DISPATCH"
-
-               need_proto = False
-               if not f.is_static_entry_point(name):
-                       need_proto = True
-               elif self.es:
-                       cat, num = api.get_category_for_name(name)
-                       if (cat.startswith("es") or cat.startswith("GL_OES")):
-                               need_proto = True
-               if need_proto:
-                       print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name))
-                       print ''
-
-               print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name))
-               print '{'
-               if silence:
-                       print '    %s' % (silence)
-               if p_string == "":
-                       print '   %s(%s, (), (F, "gl%s();\\n"));' \
-                               % (dispatch, f.name, name)
-               else:
-                       print '   %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
-                               % (dispatch, f.name, p_string, name, t_string, o_string)
-               print '}'
-               print ''
-               return
-
-       def printRealHeader(self):
-               print ''
-               self.printVisibility( "HIDDEN", "hidden" )
-               print """
+        self.es = es
+
+        self.undef_list.append( "KEYWORD1" )
+        self.undef_list.append( "KEYWORD1_ALT" )
+        self.undef_list.append( "KEYWORD2" )
+        self.undef_list.append( "NAME" )
+        self.undef_list.append( "DISPATCH" )
+        self.undef_list.append( "RETURN_DISPATCH" )
+        self.undef_list.append( "DISPATCH_TABLE_NAME" )
+        self.undef_list.append( "UNUSED_TABLE_NAME" )
+        self.undef_list.append( "TABLE_ENTRY" )
+
+
+    def printFunction(self, f, name):
+        p_string = ""
+        o_string = ""
+        t_string = ""
+        comma = ""
+
+        if f.is_static_entry_point(name):
+            keyword = "KEYWORD1"
+        else:
+            keyword = "KEYWORD1_ALT"
+
+        n = f.static_name(name)
+
+        silence = ''
+        space = ''
+        for p in f.parameterIterator():
+            if p.is_padding:
+                continue
+
+            if p.is_pointer():
+                cast = "(const void *) "
+            else:
+                cast = ""
+
+            t_string = t_string + comma + p.format_string()
+            p_string = p_string + comma + p.name
+            o_string = o_string + comma + cast + p.name
+            comma = ", "
+
+            silence += "%s(void) %s;" % (space, p.name);
+            space = ' '
+
+
+        if f.return_type != 'void':
+            dispatch = "RETURN_DISPATCH"
+        else:
+            dispatch = "DISPATCH"
+
+        need_proto = False
+        if not f.is_static_entry_point(name):
+            need_proto = True
+        elif self.es:
+            cat, num = api.get_category_for_name(name)
+            if (cat.startswith("es") or cat.startswith("GL_OES")):
+                need_proto = True
+        if need_proto:
+            print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name))
+            print ''
+
+        print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name))
+        print '{'
+        if silence:
+            print '    %s' % (silence)
+        if p_string == "":
+            print '   %s(%s, (), (F, "gl%s();\\n"));' \
+                    % (dispatch, f.name, name)
+        else:
+            print '   %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
+                    % (dispatch, f.name, p_string, name, t_string, o_string)
+        print '}'
+        print ''
+        return
+
+    def printRealHeader(self):
+        print ''
+        self.printVisibility( "HIDDEN", "hidden" )
+        print """
 /*
  * This file is a template which generates the OpenGL API entry point
  * functions.  It should be included by a .c file which first defines
@@ -165,12 +165,12 @@ class PrintGlOffsets(gl_XML.gl_print_base):
 #endif
 
 """
-               return
+        return
 
-    
 
-       def printInitDispatch(self, api):
-               print """
+
+    def printInitDispatch(self, api):
+        print """
 #endif /* defined( NAME ) */
 
 /*
@@ -188,24 +188,24 @@ class PrintGlOffsets(gl_XML.gl_print_base):
 #endif
 
 _glapi_proc DISPATCH_TABLE_NAME[] = {"""
-               for f in api.functionIterateByOffset():
-                       print '   TABLE_ENTRY(%s),' % (f.dispatch_name())
+        for f in api.functionIterateByOffset():
+            print '   TABLE_ENTRY(%s),' % (f.dispatch_name())
 
-               print '   /* A whole bunch of no-op functions.  These might be called'
-               print '    * when someone tries to call a dynamically-registered'
-               print '    * extension function without a current rendering context.'
-               print '    */'
-               for i in range(1, 100):
-                       print '   TABLE_ENTRY(Unused),'
+        print '   /* A whole bunch of no-op functions.  These might be called'
+        print '    * when someone tries to call a dynamically-registered'
+        print '    * extension function without a current rendering context.'
+        print '    */'
+        for i in range(1, 100):
+            print '   TABLE_ENTRY(Unused),'
 
-               print '};'
-               print '#endif /* DISPATCH_TABLE_NAME */'
-               print ''
-               return
+        print '};'
+        print '#endif /* DISPATCH_TABLE_NAME */'
+        print ''
+        return
 
 
-       def printAliasedTable(self, api):
-               print """
+    def printAliasedTable(self, api):
+        print """
 /*
  * This is just used to silence compiler warnings.
  * We list the functions which are not otherwise used.
@@ -213,115 +213,115 @@ _glapi_proc DISPATCH_TABLE_NAME[] = {"""
 #ifdef UNUSED_TABLE_NAME
 _glapi_proc UNUSED_TABLE_NAME[] = {"""
 
-               normal_entries = []
-               proto_entries = []
-               for f in api.functionIterateByOffset():
-                       normal_ents, proto_ents = self.classifyEntryPoints(f)
-
-                       # exclude f.name
-                       if f.name in normal_ents:
-                               normal_ents.remove(f.name)
-                       elif f.name in proto_ents:
-                               proto_ents.remove(f.name)
-
-                       normal_ents = [f.static_name(ent) for ent in normal_ents]
-                       proto_ents = [f.static_name(ent) for ent in proto_ents]
-
-                       normal_entries.extend(normal_ents)
-                       proto_entries.extend(proto_ents)
-
-               print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
-               for ent in normal_entries:
-                       print '   TABLE_ENTRY(%s),' % (ent)
-               print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
-               print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
-               for ent in proto_entries:
-                       print '   TABLE_ENTRY(%s),' % (ent)
-               print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
-
-               print '};'
-               print '#endif /*UNUSED_TABLE_NAME*/'
-               print ''
-               return
-
-
-       def classifyEntryPoints(self, func):
-               normal_names = []
-               normal_stubs = []
-               proto_names = []
-               proto_stubs = []
-               # classify the entry points
-               for name in func.entry_points:
-                       if func.has_different_protocol(name):
-                               if func.is_static_entry_point(name):
-                                       proto_names.append(name)
-                               else:
-                                       proto_stubs.append(name)
-                       else:
-                               if func.is_static_entry_point(name):
-                                       normal_names.append(name)
-                               else:
-                                       normal_stubs.append(name)
-               # there can be at most one stub for a function
-               if normal_stubs:
-                       normal_names.append(normal_stubs[0])
-               elif proto_stubs:
-                       proto_names.append(proto_stubs[0])
-
-               return (normal_names, proto_names)
-
-       def printBody(self, api):
-               normal_entry_points = []
-               proto_entry_points = []
-               for func in api.functionIterateByOffset():
-                       normal_ents, proto_ents = self.classifyEntryPoints(func)
-                       normal_entry_points.append((func, normal_ents))
-                       proto_entry_points.append((func, proto_ents))
-
-               print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
-               print ''
-               for func, ents in normal_entry_points:
-                       for ent in ents:
-                               self.printFunction(func, ent)
-               print ''
-               print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
-               print ''
-               print '/* these entry points might require different protocols */'
-               print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
-               print ''
-               for func, ents in proto_entry_points:
-                       for ent in ents:
-                               self.printFunction(func, ent)
-               print ''
-               print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
-               print ''
-
-               self.printInitDispatch(api)
-               self.printAliasedTable(api)
-               return
+        normal_entries = []
+        proto_entries = []
+        for f in api.functionIterateByOffset():
+            normal_ents, proto_ents = self.classifyEntryPoints(f)
+
+            # exclude f.name
+            if f.name in normal_ents:
+                normal_ents.remove(f.name)
+            elif f.name in proto_ents:
+                proto_ents.remove(f.name)
+
+            normal_ents = [f.static_name(ent) for ent in normal_ents]
+            proto_ents = [f.static_name(ent) for ent in proto_ents]
+
+            normal_entries.extend(normal_ents)
+            proto_entries.extend(proto_ents)
+
+        print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
+        for ent in normal_entries:
+            print '   TABLE_ENTRY(%s),' % (ent)
+        print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
+        print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
+        for ent in proto_entries:
+            print '   TABLE_ENTRY(%s),' % (ent)
+        print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
+
+        print '};'
+        print '#endif /*UNUSED_TABLE_NAME*/'
+        print ''
+        return
+
+
+    def classifyEntryPoints(self, func):
+        normal_names = []
+        normal_stubs = []
+        proto_names = []
+        proto_stubs = []
+        # classify the entry points
+        for name in func.entry_points:
+            if func.has_different_protocol(name):
+                if func.is_static_entry_point(name):
+                    proto_names.append(name)
+                else:
+                    proto_stubs.append(name)
+            else:
+                if func.is_static_entry_point(name):
+                    normal_names.append(name)
+                else:
+                    normal_stubs.append(name)
+        # there can be at most one stub for a function
+        if normal_stubs:
+            normal_names.append(normal_stubs[0])
+        elif proto_stubs:
+            proto_names.append(proto_stubs[0])
+
+        return (normal_names, proto_names)
+
+    def printBody(self, api):
+        normal_entry_points = []
+        proto_entry_points = []
+        for func in api.functionIterateByOffset():
+            normal_ents, proto_ents = self.classifyEntryPoints(func)
+            normal_entry_points.append((func, normal_ents))
+            proto_entry_points.append((func, proto_ents))
+
+        print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
+        print ''
+        for func, ents in normal_entry_points:
+            for ent in ents:
+                self.printFunction(func, ent)
+        print ''
+        print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
+        print ''
+        print '/* these entry points might require different protocols */'
+        print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
+        print ''
+        for func, ents in proto_entry_points:
+            for ent in ents:
+                self.printFunction(func, ent)
+        print ''
+        print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
+        print ''
+
+        self.printInitDispatch(api)
+        self.printAliasedTable(api)
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0]
-       print "-c          Enable compatibility with OpenGL ES."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0]
+    print "-c          Enable compatibility with OpenGL ES."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-    
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:c")
-       except Exception,e:
-               show_usage()
-
-       es = False
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-c":
-                       es = True
-
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-
-       printer = PrintGlOffsets(es)
-       printer.Print(api)
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:c")
+    except Exception,e:
+        show_usage()
+
+    es = False
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-c":
+            es = True
+
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+
+    printer = PrintGlOffsets(es)
+    printer.Print(api)
index d51b74a4a7cbcfc0b3f0e1da99bc198190a5f973..0bf8b0a9c61e6b4d255870c133872f76a70f4398 100644 (file)
@@ -32,31 +32,31 @@ import sys, getopt
 
 class PrintGlEnums(gl_XML.gl_print_base):
 
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "gl_enums.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "gl_enums.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2005 Brian Paul All Rights Reserved.""", "BRIAN PAUL")
-               self.enum_table = {}
-
-
-       def printRealHeader(self):
-               print '#include "main/glheader.h"'
-               print '#include "main/mfeatures.h"'
-               print '#include "main/enums.h"'
-               print '#include "main/imports.h"'
-               print '#include "main/mtypes.h"'
-               print ''
-               print 'typedef struct {'
-               print '   size_t offset;'
-               print '   int n;'
-               print '} enum_elt;'
-               print ''
-               return
-
-       def print_code(self):
-               print """
+        self.enum_table = {}
+
+
+    def printRealHeader(self):
+        print '#include "main/glheader.h"'
+        print '#include "main/mfeatures.h"'
+        print '#include "main/enums.h"'
+        print '#include "main/imports.h"'
+        print '#include "main/mtypes.h"'
+        print ''
+        print 'typedef struct {'
+        print '   size_t offset;'
+        print '   int n;'
+        print '} enum_elt;'
+        print ''
+        return
+
+    def print_code(self):
+        print """
 typedef int (*cfunc)(const void *, const void *);
 
 /**
@@ -160,100 +160,100 @@ int _mesa_lookup_enum_by_name( const char *symbol )
 }
 
 """
-               return
+        return
 
 
-       def printBody(self, api_list):
-               self.enum_table = {}
-               for api in api_list:
-                       self.process_enums( api )
+    def printBody(self, api_list):
+        self.enum_table = {}
+        for api in api_list:
+            self.process_enums( api )
 
-               keys = self.enum_table.keys()
-               keys.sort()
+        keys = self.enum_table.keys()
+        keys.sort()
 
-               name_table = []
-               enum_table = {}
+        name_table = []
+        enum_table = {}
 
-               for enum in keys:
-                       low_pri = 9
-                       for [name, pri] in self.enum_table[ enum ]:
-                               name_table.append( [name, enum] )
+        for enum in keys:
+            low_pri = 9
+            for [name, pri] in self.enum_table[ enum ]:
+                name_table.append( [name, enum] )
 
-                               if pri < low_pri:
-                                       low_pri = pri
-                                       enum_table[enum] = name
-                                               
+                if pri < low_pri:
+                    low_pri = pri
+                    enum_table[enum] = name
 
-               name_table.sort()
 
-               string_offsets = {}
-               i = 0;
-               print 'LONGSTRING static const char enum_string_table[] = '
-               for [name, enum] in name_table:
-                       print '   "%s\\0"' % (name)
-                       string_offsets[ name ] = i
-                       i += len(name) + 1
+        name_table.sort()
 
-               print '   ;'
-               print ''
+        string_offsets = {}
+        i = 0;
+        print 'LONGSTRING static const char enum_string_table[] = '
+        for [name, enum] in name_table:
+            print '   "%s\\0"' % (name)
+            string_offsets[ name ] = i
+            i += len(name) + 1
 
+        print '   ;'
+        print ''
 
-               print 'static const enum_elt all_enums[%u] =' % (len(name_table))
-               print '{'
-               for [name, enum] in name_table:
-                       print '   { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name)
-               print '};'
-               print ''
 
-               print 'static const unsigned reduced_enums[%u] =' % (len(keys))
-               print '{'
-               for enum in keys:
-                       name = enum_table[ enum ]
-                       if [name, enum] not in name_table:
-                               print '      /* Error! %s, 0x%04x */ 0,' % (name, enum)
-                       else:
-                               i = name_table.index( [name, enum] )
+        print 'static const enum_elt all_enums[%u] =' % (len(name_table))
+        print '{'
+        for [name, enum] in name_table:
+            print '   { %5u, 0x%08X }, /* %s */' % (string_offsets[name], enum, name)
+        print '};'
+        print ''
 
-                               print '      %4u, /* %s */' % (i, name)
-               print '};'
+        print 'static const unsigned reduced_enums[%u] =' % (len(keys))
+        print '{'
+        for enum in keys:
+            name = enum_table[ enum ]
+            if [name, enum] not in name_table:
+                print '      /* Error! %s, 0x%04x */ 0,' % (name, enum)
+            else:
+                i = name_table.index( [name, enum] )
 
+                print '      %4u, /* %s */' % (i, name)
+        print '};'
 
-               self.print_code()
-               return
 
+        self.print_code()
+        return
 
-       def process_enums(self, api):
-               for obj in api.enumIterateByName():
-                       if obj.value not in self.enum_table:
-                               self.enum_table[ obj.value ] = []
 
+    def process_enums(self, api):
+        for obj in api.enumIterateByName():
+            if obj.value not in self.enum_table:
+                self.enum_table[ obj.value ] = []
 
-                       enum = self.enum_table[ obj.value ]
-                       name = "GL_" + obj.name
-                       priority = obj.priority()
-                       already_in = False;
-                       for n, p in enum:
-                               if n == name:
-                                       already_in = True
-                       if not already_in:
-                               enum.append( [name, priority] )
+
+            enum = self.enum_table[ obj.value ]
+            name = "GL_" + obj.name
+            priority = obj.priority()
+            already_in = False;
+            for n, p in enum:
+                if n == name:
+                    already_in = True
+            if not already_in:
+                enum.append( [name, priority] )
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name]" % sys.argv[0]
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name]" % sys.argv[0]
+    sys.exit(1)
 
 if __name__ == '__main__':
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:")
-       except Exception,e:
-               show_usage()
-
-       api_list = []
-       for (arg,val) in args:
-               if arg == "-f":
-                       api = gl_XML.parse_GL_API( val )
-                       api_list.append(api);
-
-       printer = PrintGlEnums()
-       printer.Print( api_list )
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:")
+    except Exception,e:
+        show_usage()
+
+    api_list = []
+    for (arg,val) in args:
+        if arg == "-f":
+            api = gl_XML.parse_GL_API( val )
+            api_list.append(api);
+
+    printer = PrintGlEnums()
+    printer.Print( api_list )
index edaabdbacecaf122afd78c0220fea0e51e4417f8..b0901323245cf73c0f7c03168b4a1fb33d57a45d 100644 (file)
@@ -138,65 +138,65 @@ body_template = """
 
 class PrintCode(gl_XML.gl_print_base):
 
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "gl_gen_table.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "gl_gen_table.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004, 2005
 (C) Copyright Apple Inc 2011""", "BRIAN PAUL, IBM")
 
-               return
+        return
 
 
-       def get_stack_size(self, f):
-               size = 0
-               for p in f.parameterIterator():
-                       if p.is_padding:
-                               continue
+    def get_stack_size(self, f):
+        size = 0
+        for p in f.parameterIterator():
+            if p.is_padding:
+                continue
 
-                       size += p.get_stack_size()
+            size += p.get_stack_size()
 
-               return size
+        return size
 
 
-       def printRealHeader(self):
-               print header
-               return
+    def printRealHeader(self):
+        print header
+        return
 
 
-       def printRealFooter(self):
-               print footer
-               return
+    def printRealFooter(self):
+        print footer
+        return
 
 
-       def printBody(self, api):
-               for f in api.functionIterateByOffset():
-                       for entry_point in f.entry_points:
-                               vars = { 'entry_point' : entry_point,
-                                        'name' : f.name }
+    def printBody(self, api):
+        for f in api.functionIterateByOffset():
+            for entry_point in f.entry_points:
+                vars = { 'entry_point' : entry_point,
+                         'name' : f.name }
 
-                               print body_template % vars
-               return
+                print body_template % vars
+        return
 
 def show_usage():
-       print "Usage: %s [-f input_file_name]" % sys.argv[0]
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name]" % sys.argv[0]
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
+    file_name = "gl_API.xml"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
+    except Exception,e:
+        show_usage()
 
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
 
-       printer = PrintCode()
+    printer = PrintCode()
 
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-       printer.Print(api)
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+    printer.Print(api)
index 54867b346348d62d18fd0e9bf148bdb89d3645be..897ac18ae714351710dc4270b78e4ee4739dafd7 100644 (file)
@@ -30,91 +30,91 @@ import license
 import sys, getopt
 
 class PrintGlOffsets(gl_XML.gl_print_base):
-       def __init__(self, es=False):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, es=False):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.es = es
-               self.name = "gl_offsets.py (from Mesa)"
-               self.header_tag = '_GLAPI_OFFSETS_H_'
-               self.license = license.bsd_license_template % ( \
+        self.es = es
+        self.name = "gl_offsets.py (from Mesa)"
+        self.header_tag = '_GLAPI_OFFSETS_H_'
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
-               return
+        return
 
-       def printBody(self, api):
-               print '/* this file should not be included directly in mesa */'
-               print ''
+    def printBody(self, api):
+        print '/* this file should not be included directly in mesa */'
+        print ''
 
-               functions = []
-               abi_functions = []
-               alias_functions = []
-               count = 0
-               for f in api.functionIterateByOffset():
-                       if not f.is_abi():
-                               functions.append( [f, count] )
-                               count += 1
-                       else:
-                               abi_functions.append( f )
+        functions = []
+        abi_functions = []
+        alias_functions = []
+        count = 0
+        for f in api.functionIterateByOffset():
+            if not f.is_abi():
+                functions.append( [f, count] )
+                count += 1
+            else:
+                abi_functions.append( f )
 
-                       if self.es:
-                               # remember functions with aliases
-                               if len(f.entry_points) > 1:
-                                       alias_functions.append(f)
+            if self.es:
+                # remember functions with aliases
+                if len(f.entry_points) > 1:
+                    alias_functions.append(f)
 
-               for f in abi_functions:
-                       print '#define _gloffset_%s %d' % (f.name, f.offset)
-                       last_static = f.offset
+        for f in abi_functions:
+            print '#define _gloffset_%s %d' % (f.name, f.offset)
+            last_static = f.offset
 
-               print ''
-               print '#if !defined(_GLAPI_USE_REMAP_TABLE)'
-               print ''
+        print ''
+        print '#if !defined(_GLAPI_USE_REMAP_TABLE)'
+        print ''
 
-               for [f, index] in functions:
-                       print '#define _gloffset_%s %d' % (f.name, f.offset)
+        for [f, index] in functions:
+            print '#define _gloffset_%s %d' % (f.name, f.offset)
 
-               print '#define _gloffset_FIRST_DYNAMIC %d' % (api.next_offset)
+        print '#define _gloffset_FIRST_DYNAMIC %d' % (api.next_offset)
 
-               print ''
-               print '#else'
-               print ''
+        print ''
+        print '#else'
+        print ''
 
-               for [f, index] in functions:
-                       print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name)
+        for [f, index] in functions:
+            print '#define _gloffset_%s driDispatchRemapTable[%s_remap_index]' % (f.name, f.name)
 
-               print ''
-               print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */'
+        print ''
+        print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */'
 
-               if alias_functions:
-                       print ''
-                       print '/* define aliases for compatibility */'
-                       for f in alias_functions:
-                               for name in f.entry_points:
-                                       if name != f.name:
-                                               print '#define _gloffset_%s _gloffset_%s' % (name, f.name)
-               return
+        if alias_functions:
+            print ''
+            print '/* define aliases for compatibility */'
+            for f in alias_functions:
+                for name in f.entry_points:
+                    if name != f.name:
+                        print '#define _gloffset_%s _gloffset_%s' % (name, f.name)
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0]
-       print "    -c        Enable compatibility with OpenGL ES."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0]
+    print "    -c        Enable compatibility with OpenGL ES."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-    
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:c")
-       except Exception,e:
-               show_usage()
-
-       es = False
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-c":
-                       es = True
-
-       api = gl_XML.parse_GL_API( file_name )
-
-       printer = PrintGlOffsets(es)
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:c")
+    except Exception,e:
+        show_usage()
+
+    es = False
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-c":
+            es = True
+
+    api = gl_XML.parse_GL_API( file_name )
+
+    printer = PrintGlOffsets(es)
+    printer.Print( api )
index a9ba48297a194e66d0f25829da52c6474cc18924..f139c58ea6f2d3a577d51401711288b77923778e 100644 (file)
@@ -30,19 +30,19 @@ import gl_XML, glX_XML
 import sys, getopt
 
 class PrintGlProcs(gl_XML.gl_print_base):
-       def __init__(self, long_strings, es=False):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, long_strings, es=False):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.es = es
-               self.long_strings = long_strings
-               self.name = "gl_procs.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.es = es
+        self.long_strings = long_strings
+        self.name = "gl_procs.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM")
 
 
-       def printRealHeader(self):
-               print """
+    def printRealHeader(self):
+        print """
 /* This file is only included by glapi.c and is used for
  * the GetProcAddress() function
  */
@@ -66,150 +66,150 @@ typedef struct {
 #endif
 
 """
-               return
-
-       def printRealFooter(self):
-               print ''
-               print '#undef NAME_FUNC_OFFSET'
-               return
-
-       def printFunctionString(self, name):
-               if self.long_strings:
-                       print '    "gl%s\\0"' % (name)
-               else:
-                       print "    'g','l',",
-                       for c in name:
-                               print "'%s'," % (c),
-                       
-                       print "'\\0',"
-
-
-       def printBody(self, api):
-               print ''
-               if self.long_strings:
-                       print 'static const char gl_string_table[] ='
-               else:
-                       print 'static const char gl_string_table[] = {'
-
-               base_offset = 0
-               table = []
-               for func in api.functionIterateByOffset():
-                       name = func.dispatch_name()
-                       self.printFunctionString(func.name)
-                       table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
-
-                       # The length of the function's name, plus 2 for "gl",
-                       # plus 1 for the NUL.
-
-                       base_offset += len(func.name) + 3
-
-
-               for func in api.functionIterateByOffset():
-                       for n in func.entry_points:
-                               if n != func.name:
-                                       name = func.dispatch_name()
-                                       self.printFunctionString( n )
-                                       
-                                       if func.has_different_protocol(n):
-                                               alt_name = "gl" + func.static_glx_name(n)
-                                               table.append((base_offset, "gl" + name, alt_name, alt_name, func.offset))
-                                       else:
-                                               table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
-
-                                       base_offset += len(n) + 3
-
-
-               if self.long_strings:
-                       print '    ;'
-               else:
-                       print '};'
-
-               print ''
-               print ''
-               print "#ifdef USE_MGL_NAMESPACE"
-               for func in api.functionIterateByOffset():
-                       for n in func.entry_points:
-                               if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
-                                       print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset)
-                                       break
-               print "#endif /* USE_MGL_NAMESPACE */"
-               print ''
-               print ''
-               print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)'
-               for func in api.functionIterateByOffset():
-                       for n in func.entry_points:
-                               if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
-                                       print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string())
-                                       break
-
-               if self.es:
-                       categories = {}
-                       for func in api.functionIterateByOffset():
-                               for n in func.entry_points:
-                                       cat, num = api.get_category_for_name(n)
-                                       if (cat.startswith("es") or cat.startswith("GL_OES")):
-                                               if not categories.has_key(cat):
-                                                       categories[cat] = []
-                                               proto = 'GLAPI %s GLAPIENTRY %s(%s);' \
-                                                               % (func.return_type, "gl" + n, func.get_parameter_string(n))
-                                               categories[cat].append(proto)
-                       if categories:
-                               print ''
-                               print '/* OpenGL ES specific prototypes */'
-                               print ''
-                               keys = categories.keys()
-                               keys.sort()
-                               for key in keys:
-                                       print '/* category %s */' % key
-                                       print "\n".join(categories[key])
-                               print ''
-
-               print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */'
-
-               print ''
-               print 'static const glprocs_table_t static_functions[] = {'
-
-               for info in table:
-                       print '    NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info
-
-               print '    NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)'
-               print '};'
-               return
+        return
+
+    def printRealFooter(self):
+        print ''
+        print '#undef NAME_FUNC_OFFSET'
+        return
+
+    def printFunctionString(self, name):
+        if self.long_strings:
+            print '    "gl%s\\0"' % (name)
+        else:
+            print "    'g','l',",
+            for c in name:
+                print "'%s'," % (c),
+
+            print "'\\0',"
+
+
+    def printBody(self, api):
+        print ''
+        if self.long_strings:
+            print 'static const char gl_string_table[] ='
+        else:
+            print 'static const char gl_string_table[] = {'
+
+        base_offset = 0
+        table = []
+        for func in api.functionIterateByOffset():
+            name = func.dispatch_name()
+            self.printFunctionString(func.name)
+            table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
+
+            # The length of the function's name, plus 2 for "gl",
+            # plus 1 for the NUL.
+
+            base_offset += len(func.name) + 3
+
+
+        for func in api.functionIterateByOffset():
+            for n in func.entry_points:
+                if n != func.name:
+                    name = func.dispatch_name()
+                    self.printFunctionString( n )
+
+                    if func.has_different_protocol(n):
+                        alt_name = "gl" + func.static_glx_name(n)
+                        table.append((base_offset, "gl" + name, alt_name, alt_name, func.offset))
+                    else:
+                        table.append((base_offset, "gl" + name, "gl" + name, "NULL", func.offset))
+
+                    base_offset += len(n) + 3
+
+
+        if self.long_strings:
+            print '    ;'
+        else:
+            print '};'
+
+        print ''
+        print ''
+        print "#ifdef USE_MGL_NAMESPACE"
+        for func in api.functionIterateByOffset():
+            for n in func.entry_points:
+                if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
+                    print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func.offset, func.offset)
+                    break
+        print "#endif /* USE_MGL_NAMESPACE */"
+        print ''
+        print ''
+        print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)'
+        for func in api.functionIterateByOffset():
+            for n in func.entry_points:
+                if (not func.is_static_entry_point(func.name)) or (func.has_different_protocol(n) and not func.is_static_entry_point(n)):
+                    print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string())
+                    break
+
+        if self.es:
+            categories = {}
+            for func in api.functionIterateByOffset():
+                for n in func.entry_points:
+                    cat, num = api.get_category_for_name(n)
+                    if (cat.startswith("es") or cat.startswith("GL_OES")):
+                        if not categories.has_key(cat):
+                            categories[cat] = []
+                        proto = 'GLAPI %s GLAPIENTRY %s(%s);' \
+                                        % (func.return_type, "gl" + n, func.get_parameter_string(n))
+                        categories[cat].append(proto)
+            if categories:
+                print ''
+                print '/* OpenGL ES specific prototypes */'
+                print ''
+                keys = categories.keys()
+                keys.sort()
+                for key in keys:
+                    print '/* category %s */' % key
+                    print "\n".join(categories[key])
+                print ''
+
+        print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */'
+
+        print ''
+        print 'static const glprocs_table_t static_functions[] = {'
+
+        for info in table:
+            print '    NAME_FUNC_OFFSET(%5u, %s, %s, %s, %d),' % info
+
+        print '    NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)'
+        print '};'
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0]
-       print "-c          Enable compatibility with OpenGL ES."
-       print "-m mode     mode can be one of:"
-       print "    long  - Create code for compilers that can handle very"
-       print "            long string constants. (default)"
-       print "    short - Create code for compilers that can only handle"
-       print "            ANSI C89 string constants."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0]
+    print "-c          Enable compatibility with OpenGL ES."
+    print "-m mode     mode can be one of:"
+    print "    long  - Create code for compilers that can handle very"
+    print "            long string constants. (default)"
+    print "    short - Create code for compilers that can only handle"
+    print "            ANSI C89 string constants."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c")
-       except Exception,e:
-               show_usage()
-
-       long_string = 1
-       es = False
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       if val == "short":
-                               long_string = 0
-                       elif val == "long":
-                               long_string = 1
-                       else:
-                               show_usage()
-               elif arg == "-c":
-                   es = True
-
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-       printer = PrintGlProcs(long_string, es)
-       printer.Print(api)
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c")
+    except Exception,e:
+        show_usage()
+
+    long_string = 1
+    es = False
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            if val == "short":
+                long_string = 0
+            elif val == "long":
+                long_string = 1
+            else:
+                show_usage()
+        elif arg == "-c":
+            es = True
+
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+    printer = PrintGlProcs(long_string, es)
+    printer.Print(api)
index a0ae4c39af468bfb27f20d7aee9c1f0e94c59d01..856aedb4fcff163d6e54cb925793e2dc0f2ae2c3 100644 (file)
@@ -30,63 +30,63 @@ import license
 import sys, getopt
 
 class PrintGlTable(gl_XML.gl_print_base):
-       def __init__(self, es=False):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, es=False):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.es = es
-               self.header_tag = '_GLAPI_TABLE_H_'
-               self.name = "gl_table.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.es = es
+        self.header_tag = '_GLAPI_TABLE_H_'
+        self.name = "gl_table.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
-               self.ifdef_emitted = False;
-               return
+        self.ifdef_emitted = False;
+        return
 
 
-       def printBody(self, api):
-               for f in api.functionIterateByOffset():
-                       if not f.is_abi() and not self.ifdef_emitted:
-                               print '#if !defined HAVE_SHARED_GLAPI'
-                               self.ifdef_emitted = True
-                       arg_string = f.get_parameter_string()
-                       print '   %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset)
+    def printBody(self, api):
+        for f in api.functionIterateByOffset():
+            if not f.is_abi() and not self.ifdef_emitted:
+                print '#if !defined HAVE_SHARED_GLAPI'
+                self.ifdef_emitted = True
+            arg_string = f.get_parameter_string()
+            print '   %s (GLAPIENTRYP %s)(%s); /* %d */' % (f.return_type, f.name, arg_string, f.offset)
 
-               print '#endif /* !defined HAVE_SHARED_GLAPI */'
+        print '#endif /* !defined HAVE_SHARED_GLAPI */'
 
 
-       def printRealHeader(self):
-               print '#ifndef GLAPIENTRYP'
-               print '# ifndef GLAPIENTRY'
-               print '#  define GLAPIENTRY'
-               print '# endif'
-               print ''
-               print '# define GLAPIENTRYP GLAPIENTRY *'
-               print '#endif'
-               print ''
-               print ''
-               print 'struct _glapi_table'
-               print '{'
-               return
+    def printRealHeader(self):
+        print '#ifndef GLAPIENTRYP'
+        print '# ifndef GLAPIENTRY'
+        print '#  define GLAPIENTRY'
+        print '# endif'
+        print ''
+        print '# define GLAPIENTRYP GLAPIENTRY *'
+        print '#endif'
+        print ''
+        print ''
+        print 'struct _glapi_table'
+        print '{'
+        return
 
 
-       def printRealFooter(self):
-               print '};'
-               return
+    def printRealFooter(self):
+        print '};'
+        return
 
 
 class PrintRemapTable(gl_XML.gl_print_base):
-       def __init__(self, es=False):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self, es=False):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.es = es
-               self.header_tag = '_DISPATCH_H_'
-               self.name = "gl_table.py (from Mesa)"
-               self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
-               return
+        self.es = es
+        self.header_tag = '_DISPATCH_H_'
+        self.name = "gl_table.py (from Mesa)"
+        self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
+        return
 
 
-       def printRealHeader(self):
-               print """
+    def printRealHeader(self):
+        print """
 /**
  * \\file main/dispatch.h
  * Macros for handling GL dispatch tables.
@@ -104,163 +104,163 @@ class PrintRemapTable(gl_XML.gl_print_base):
 #include "main/mfeatures.h"
 #endif
 """
-               return
-
-       def printBody(self, api):
-               print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
-               print '    (*(cast (GET_by_offset(disp, offset)))) parameters'
-               print '#define GET_by_offset(disp, offset) \\'
-               print '    (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
-               print '#define SET_by_offset(disp, offset, fn) \\'
-               print '    do { \\'
-               print '        if ( (offset) < 0 ) { \\'
-               print '            /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
-               print '            /*         __func__, __LINE__, disp, offset, # fn); */ \\'
-               print '            /* abort(); */ \\'
-               print '        } \\'
-               print '        else { \\'
-               print '            ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\'
-               print '        } \\'
-               print '    } while(0)'
-               print ''
-
-               functions = []
-               abi_functions = []
-               alias_functions = []
-               count = 0
-               for f in api.functionIterateByOffset():
-                       if not f.is_abi():
-                               functions.append( [f, count] )
-                               count += 1
-                       else:
-                               abi_functions.append( [f, -1] )
-
-                       if self.es:
-                               # remember functions with aliases
-                               if len(f.entry_points) > 1:
-                                       alias_functions.append(f)
-
-               print '/* total number of offsets below */'
-               print '#define _gloffset_COUNT %d' % (len(abi_functions + functions))
-               print ''
-
-               for f, index in abi_functions:
-                       print '#define _gloffset_%s %d' % (f.name, f.offset)
-
-               print ''
-               print '#if !FEATURE_remap_table'
-               print ''
-
-               for f, index in functions:
-                       print '#define _gloffset_%s %d' % (f.name, f.offset)
-
-               print ''
-               print '#else /* !FEATURE_remap_table */'
-               print ''
-
-               if self.es:
-                       remap_table = "esLocalRemapTable"
-
-                       print '#define %s_size %u' % (remap_table, count)
-                       print 'static int %s[ %s_size ];' % (remap_table, remap_table)
-                       print ''
-               else:
-                       remap_table = "driDispatchRemapTable"
-
-                       print '#define %s_size %u' % (remap_table, count)
-                       print 'extern int %s[ %s_size ];' % (remap_table, remap_table)
-                       print ''
-
-               for f, index in functions:
-                       print '#define %s_remap_index %u' % (f.name, index)
-
-               print ''
-
-               for f, index in functions:
-                       print '#define _gloffset_%s %s[%s_remap_index]' % (f.name, remap_table, f.name)
-
-               print ''
-               print '#endif /* !FEATURE_remap_table */'
-               print ''
-
-               for f, index in abi_functions + functions:
-                       arg_string = gl_XML.create_parameter_string( f.parameters, 0 )
-
-                       print 'typedef %s (GLAPIENTRYP _glptr_%s)(%s);' % (f.return_type, f.name, arg_string)
-                       print '#define CALL_%s(disp, parameters) \\' % (f.name)
-                       print '    (* GET_%s(disp)) parameters' % (f.name)
-                       print 'static inline _glptr_%s GET_%s(struct _glapi_table *disp) {' % (f.name, f.name)
-                       print '   return (_glptr_%s) (GET_by_offset(disp, _gloffset_%s));' % (f.name, f.name)
-                       print '}'
-                       print
-                       print 'static inline void SET_%s(struct _glapi_table *disp, %s (GLAPIENTRYP fn)(%s)) {' % (f.name, f.return_type, arg_string)
-                       print '   SET_by_offset(disp, _gloffset_%s, fn);' % (f.name)
-                       print '}'
-                       print
-
-               if alias_functions:
-                       print ''
-                       print '/* define aliases for compatibility */'
-                       for f in alias_functions:
-                               for name in f.entry_points:
-                                       if name != f.name:
-                                               print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name)
-                                               print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name)
-                                               print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name)
-                       print ''
-
-                       print '#if FEATURE_remap_table'
-                       for f in alias_functions:
-                               for name in f.entry_points:
-                                       if name != f.name:
-                                               print '#define %s_remap_index %s_remap_index' % (name, f.name)
-                       print '#endif /* FEATURE_remap_table */'
-                       print ''
-
-               return
+        return
+
+    def printBody(self, api):
+        print '#define CALL_by_offset(disp, cast, offset, parameters) \\'
+        print '    (*(cast (GET_by_offset(disp, offset)))) parameters'
+        print '#define GET_by_offset(disp, offset) \\'
+        print '    (offset >= 0) ? (((_glapi_proc *)(disp))[offset]) : NULL'
+        print '#define SET_by_offset(disp, offset, fn) \\'
+        print '    do { \\'
+        print '        if ( (offset) < 0 ) { \\'
+        print '            /* fprintf( stderr, "[%s:%u] SET_by_offset(%p, %d, %s)!\\n", */ \\'
+        print '            /*         __func__, __LINE__, disp, offset, # fn); */ \\'
+        print '            /* abort(); */ \\'
+        print '        } \\'
+        print '        else { \\'
+        print '            ( (_glapi_proc *) (disp) )[offset] = (_glapi_proc) fn; \\'
+        print '        } \\'
+        print '    } while(0)'
+        print ''
+
+        functions = []
+        abi_functions = []
+        alias_functions = []
+        count = 0
+        for f in api.functionIterateByOffset():
+            if not f.is_abi():
+                functions.append( [f, count] )
+                count += 1
+            else:
+                abi_functions.append( [f, -1] )
+
+            if self.es:
+                # remember functions with aliases
+                if len(f.entry_points) > 1:
+                    alias_functions.append(f)
+
+        print '/* total number of offsets below */'
+        print '#define _gloffset_COUNT %d' % (len(abi_functions + functions))
+        print ''
+
+        for f, index in abi_functions:
+            print '#define _gloffset_%s %d' % (f.name, f.offset)
+
+        print ''
+        print '#if !FEATURE_remap_table'
+        print ''
+
+        for f, index in functions:
+            print '#define _gloffset_%s %d' % (f.name, f.offset)
+
+        print ''
+        print '#else /* !FEATURE_remap_table */'
+        print ''
+
+        if self.es:
+            remap_table = "esLocalRemapTable"
+
+            print '#define %s_size %u' % (remap_table, count)
+            print 'static int %s[ %s_size ];' % (remap_table, remap_table)
+            print ''
+        else:
+            remap_table = "driDispatchRemapTable"
+
+            print '#define %s_size %u' % (remap_table, count)
+            print 'extern int %s[ %s_size ];' % (remap_table, remap_table)
+            print ''
+
+        for f, index in functions:
+            print '#define %s_remap_index %u' % (f.name, index)
+
+        print ''
+
+        for f, index in functions:
+            print '#define _gloffset_%s %s[%s_remap_index]' % (f.name, remap_table, f.name)
+
+        print ''
+        print '#endif /* !FEATURE_remap_table */'
+        print ''
+
+        for f, index in abi_functions + functions:
+            arg_string = gl_XML.create_parameter_string( f.parameters, 0 )
+
+            print 'typedef %s (GLAPIENTRYP _glptr_%s)(%s);' % (f.return_type, f.name, arg_string)
+            print '#define CALL_%s(disp, parameters) \\' % (f.name)
+            print '    (* GET_%s(disp)) parameters' % (f.name)
+            print 'static inline _glptr_%s GET_%s(struct _glapi_table *disp) {' % (f.name, f.name)
+            print '   return (_glptr_%s) (GET_by_offset(disp, _gloffset_%s));' % (f.name, f.name)
+            print '}'
+            print
+            print 'static inline void SET_%s(struct _glapi_table *disp, %s (GLAPIENTRYP fn)(%s)) {' % (f.name, f.return_type, arg_string)
+            print '   SET_by_offset(disp, _gloffset_%s, fn);' % (f.name)
+            print '}'
+            print
+
+        if alias_functions:
+            print ''
+            print '/* define aliases for compatibility */'
+            for f in alias_functions:
+                for name in f.entry_points:
+                    if name != f.name:
+                        print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name)
+                        print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name)
+                        print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name)
+            print ''
+
+            print '#if FEATURE_remap_table'
+            for f in alias_functions:
+                for name in f.entry_points:
+                    if name != f.name:
+                        print '#define %s_remap_index %s_remap_index' % (name, f.name)
+            print '#endif /* FEATURE_remap_table */'
+            print ''
+
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m mode] [-c ver]" % sys.argv[0]
-       print "    -m mode   Mode can be 'table' or 'remap_table'."
-       print "    -c ver    Version can be 'es1' or 'es2'."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m mode] [-c ver]" % sys.argv[0]
+    print "    -m mode   Mode can be 'table' or 'remap_table'."
+    print "    -c ver    Version can be 'es1' or 'es2'."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-    
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c:")
-       except Exception,e:
-               show_usage()
-
-       mode = "table"
-       es = None
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-m":
-                       mode = val
-               elif arg == "-c":
-                       es = val
-
-       if mode == "table":
-               printer = PrintGlTable(es)
-       elif mode == "remap_table":
-               printer = PrintRemapTable(es)
-       else:
-               show_usage()
-
-       api = gl_XML.parse_GL_API( file_name )
-
-       if es is not None:
-               import gles_api
-
-               api_map = {
-                       'es1': gles_api.es1_api,
-                       'es2': gles_api.es2_api,
-               }
-
-               api.filter_functions(api_map[es])
-
-       printer.Print( api )
+    file_name = "gl_API.xml"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c:")
+    except Exception,e:
+        show_usage()
+
+    mode = "table"
+    es = None
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-m":
+            mode = val
+        elif arg == "-c":
+            es = val
+
+    if mode == "table":
+        printer = PrintGlTable(es)
+    elif mode == "remap_table":
+        printer = PrintRemapTable(es)
+    else:
+        show_usage()
+
+    api = gl_XML.parse_GL_API( file_name )
+
+    if es is not None:
+        import gles_api
+
+        api_map = {
+                'es1': gles_api.es1_api,
+                'es2': gles_api.es2_api,
+        }
+
+        api.filter_functions(api_map[es])
+
+    printer.Print( api )
index 9a085eaec5ba561a2646107f3ba76ac295d84a50..a3548c2951e0ba9a0025bb8f8dae8a7ff1c68d75 100644 (file)
@@ -30,306 +30,306 @@ import gl_XML, glX_XML
 import sys, getopt, copy
 
 def should_use_push(registers):
-       for [reg, offset] in registers:
-               if reg[1:4] == "xmm":
-                       return 0
+    for [reg, offset] in registers:
+        if reg[1:4] == "xmm":
+            return 0
 
-       N = len(registers)
-       return (N & 1) != 0
+    N = len(registers)
+    return (N & 1) != 0
 
 
 def local_size(registers):
-       # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of
-       # 16 when control is transfered to the function entry point."  This
-       # means that the local stack usage must be (16*N)+8 for some value
-       # of N.  (16*N)+8 = (8*(2N))+8 = 8*(2N+1).  As long as N is odd, we
-       # meet this requirement.
+    # The x86-64 ABI says "the value (%rsp - 8) is always a multiple of
+    # 16 when control is transfered to the function entry point."  This
+    # means that the local stack usage must be (16*N)+8 for some value
+    # of N.  (16*N)+8 = (8*(2N))+8 = 8*(2N+1).  As long as N is odd, we
+    # meet this requirement.
 
-       N = (len(registers) | 1)
-       return 8*N
+    N = (len(registers) | 1)
+    return 8*N
 
 
 def save_all_regs(registers):
-       adjust_stack = 0
-       if not should_use_push(registers):
-               adjust_stack = local_size(registers)
-               print '\tsubq\t$%u, %%rsp' % (adjust_stack)
+    adjust_stack = 0
+    if not should_use_push(registers):
+        adjust_stack = local_size(registers)
+        print '\tsubq\t$%u, %%rsp' % (adjust_stack)
 
-       for [reg, stack_offset] in registers:
-               save_reg( reg, stack_offset, adjust_stack )
-       return
+    for [reg, stack_offset] in registers:
+        save_reg( reg, stack_offset, adjust_stack )
+    return
 
 
 def restore_all_regs(registers):
-       adjust_stack = 0
-       if not should_use_push(registers):
-               adjust_stack = local_size(registers)
+    adjust_stack = 0
+    if not should_use_push(registers):
+        adjust_stack = local_size(registers)
 
-       temp = copy.deepcopy(registers)
-       while len(temp):
-               [reg, stack_offset] = temp.pop()
-               restore_reg(reg, stack_offset, adjust_stack)
+    temp = copy.deepcopy(registers)
+    while len(temp):
+        [reg, stack_offset] = temp.pop()
+        restore_reg(reg, stack_offset, adjust_stack)
 
-       if adjust_stack:
-               print '\taddq\t$%u, %%rsp' % (adjust_stack)
-       return
+    if adjust_stack:
+        print '\taddq\t$%u, %%rsp' % (adjust_stack)
+    return
 
 
 def save_reg(reg, offset, use_move):
-       if use_move:
-               if offset == 0:
-                       print '\tmovq\t%s, (%%rsp)' % (reg)
-               else:
-                       print '\tmovq\t%s, %u(%%rsp)' % (reg, offset)
-       else:
-               print '\tpushq\t%s' % (reg)
+    if use_move:
+        if offset == 0:
+            print '\tmovq\t%s, (%%rsp)' % (reg)
+        else:
+            print '\tmovq\t%s, %u(%%rsp)' % (reg, offset)
+    else:
+        print '\tpushq\t%s' % (reg)
 
-       return
+    return
 
 
 def restore_reg(reg, offset, use_move):
-       if use_move:
-               if offset == 0:
-                       print '\tmovq\t(%%rsp), %s' % (reg)
-               else:
-                       print '\tmovq\t%u(%%rsp), %s' % (offset, reg)
-       else:
-               print '\tpopq\t%s' % (reg)
+    if use_move:
+        if offset == 0:
+            print '\tmovq\t(%%rsp), %s' % (reg)
+        else:
+            print '\tmovq\t%u(%%rsp), %s' % (offset, reg)
+    else:
+        print '\tpopq\t%s' % (reg)
 
-       return
+    return
 
 
 class PrintGenericStubs(gl_XML.gl_print_base):
 
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
-
-               self.name = "gl_x86-64_asm.py (from Mesa)"
-               self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
-               return
-
-
-       def get_stack_size(self, f):
-               size = 0
-               for p in f.parameterIterator():
-                       size += p.get_stack_size()
-
-               return size
-
-
-       def printRealHeader(self):
-               print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change"
-               print " * the symbol visibility mode to 'default'."
-               print ' */'
-               print ''
-               print '#include "x86/assyntax.h"'
-               print ''
-               print '#ifdef __GNUC__'
-               print '#  pragma GCC visibility push(default)'
-               print '#  define HIDDEN(x) .hidden x'
-               print '#else'
-               print '#  define HIDDEN(x)'
-               print '#endif'
-               print ''
-               print '# if defined(USE_MGL_NAMESPACE)'
-               print '#  define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))'
-               print '#  define _glapi_Dispatch _mglapi_Dispatch'
-               print '# else'
-               print '#  define GL_PREFIX(n) GLNAME(CONCAT(gl,n))'
-               print '# endif'
-               print ''
-               print '#if defined(HAVE_PTHREAD) || defined(_WIN32)'
-               print '#  define THREADS'
-               print '#endif'
-               print ''
-               print '\t.text'
-               print ''
-               print '#ifdef GLX_USE_TLS'
-               print ''
-               print '\t.globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch)'
-               print '_x86_64_get_get_dispatch:'
-               print '\tlea\t_x86_64_get_dispatch(%rip), %rax'
-               print '\tret'
-               print ''
-               print '\t.p2align\t4,,15'
-               print '_x86_64_get_dispatch:'
-               print '\tmovq\t_glapi_tls_Dispatch@GOTTPOFF(%rip), %rax'
-               print '\tmovq\t%fs:(%rax), %rax'
-               print '\tret'
-               print '\t.size\t_x86_64_get_dispatch, .-_x86_64_get_dispatch'
-               print ''
-               print '#elif defined(HAVE_PTHREAD)'
-               print ''
-               print '\t.extern\t_glapi_Dispatch'
-               print '\t.extern\t_gl_DispatchTSD'
-               print '\t.extern\tpthread_getspecific'
-               print ''
-               print '\t.p2align\t4,,15'
-               print '_x86_64_get_dispatch:'
-               print '\tmovq\t_gl_DispatchTSD@GOTPCREL(%rip), %rax'
-               print '\tmovl\t(%rax), %edi'
-               print '\tjmp\tpthread_getspecific@PLT'
-               print ''
-               print '#elif defined(THREADS)'
-               print ''
-               print '\t.extern\t_glapi_get_dispatch'
-               print ''
-               print '#endif'
-               print ''
-               return
-
-
-       def printRealFooter(self):
-               print ''
-               print '#if defined(GLX_USE_TLS) && defined(__linux__)'
-               print ' .section ".note.ABI-tag", "a"'
-               print ' .p2align 2'
-               print ' .long   1f - 0f   /* name length */'
-               print ' .long   3f - 2f   /* data length */'
-               print ' .long   1         /* note length */'
-               print '0:       .asciz "GNU"      /* vendor name */'
-               print '1:       .p2align 2'
-               print '2:       .long   0         /* note data: the ABI tag */'
-               print ' .long   2,4,20    /* Minimum kernel version w/TLS */'
-               print '3:       .p2align 2        /* pad out section */'
-               print '#endif /* GLX_USE_TLS */'
-               print ''
-               print '#if defined (__ELF__) && defined (__linux__)'
-               print ' .section .note.GNU-stack,"",%progbits'
-               print '#endif'
-               return
-
-
-       def printFunction(self, f):
-               
-               # The x86-64 ABI divides function parameters into a couple
-               # classes.  For the OpenGL interface, the only ones that are
-               # relevent are INTEGER and SSE.  Basically, the first 8
-               # GLfloat or GLdouble parameters are placed in %xmm0 - %xmm7,
-               # the first 6 non-GLfloat / non-GLdouble parameters are placed
-               # in registers listed in int_parameters.
-               #
-               # If more parameters than that are required, they are passed
-               # on the stack.  Therefore, we just have to make sure that
-               # %esp hasn't changed when we jump to the actual function.
-               # Since we're jumping to the function (and not calling it), we
-               # have to make sure of that anyway!
-
-               int_parameters = ["%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9"]
-
-               int_class = 0
-               sse_class = 0
-               stack_offset = 0
-               registers = []
-               for p in f.parameterIterator():
-                       type_name = p.get_base_type_string()
-
-                       if p.is_pointer() or (type_name != "GLfloat" and type_name != "GLdouble"):
-                               if int_class < 6:
-                                       registers.append( [int_parameters[int_class], stack_offset] )
-                                       int_class += 1
-                                       stack_offset += 8
-                       else:
-                               if sse_class < 8:
-                                       registers.append( ["%%xmm%u" % (sse_class), stack_offset] )
-                                       sse_class += 1
-                                       stack_offset += 8
-
-               if ((int_class & 1) == 0) and (sse_class == 0):
-                       registers.append( ["%rbp", 0] )
-
-
-               name = f.dispatch_name()
-
-               print '\t.p2align\t4,,15'
-               print '\t.globl\tGL_PREFIX(%s)' % (name)
-               print '\t.type\tGL_PREFIX(%s), @function' % (name)
-               if not f.is_static_entry_point(f.name):
-                       print '\tHIDDEN(GL_PREFIX(%s))' % (name)
-               print 'GL_PREFIX(%s):' % (name)
-               print '#if defined(GLX_USE_TLS)'
-               print '\tcall\t_x86_64_get_dispatch@PLT'
-               print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
-               print '\tjmp\t*%r11'
-               print '#elif defined(HAVE_PTHREAD)'
-               
-               save_all_regs(registers)
-               print '\tcall\t_x86_64_get_dispatch@PLT'
-               restore_all_regs(registers)
-
-               if f.offset == 0:
-                       print '\tmovq\t(%rax), %r11'
-               else:
-                       print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
-
-               print '\tjmp\t*%r11'
-
-               print '#else'
-               print '\tmovq\t_glapi_Dispatch(%rip), %rax'
-               print '\ttestq\t%rax, %rax'
-               print '\tje\t1f'
-               print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
-               print '\tjmp\t*%r11'
-               print '1:'
-
-               save_all_regs(registers)
-               print '\tcall\t_glapi_get_dispatch'
-               restore_all_regs(registers)
-
-               print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
-               print '\tjmp\t*%r11'
-               print '#endif /* defined(GLX_USE_TLS) */'
-
-               print '\t.size\tGL_PREFIX(%s), .-GL_PREFIX(%s)' % (name, name)
-               print ''
-               return
-
-
-       def printBody(self, api):
-               for f in api.functionIterateByOffset():
-                       self.printFunction(f)
-
-
-               for f in api.functionIterateByOffset():
-                       dispatch = f.dispatch_name()
-                       for n in f.entry_points:
-                               if n != f.name:
-                                       if f.is_static_entry_point(n):
-                                               text = '\t.globl GL_PREFIX(%s) ; .set GL_PREFIX(%s), GL_PREFIX(%s)' % (n, n, dispatch)
-
-                                               if f.has_different_protocol(n):
-                                                       print '#ifndef GLX_INDIRECT_RENDERING'
-                                                       print text
-                                                       print '#endif'
-                                               else:
-                                                       print text
-
-               return
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+
+        self.name = "gl_x86-64_asm.py (from Mesa)"
+        self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
+        return
+
+
+    def get_stack_size(self, f):
+        size = 0
+        for p in f.parameterIterator():
+            size += p.get_stack_size()
+
+        return size
+
+
+    def printRealHeader(self):
+        print "/* If we build with gcc's -fvisibility=hidden flag, we'll need to change"
+        print " * the symbol visibility mode to 'default'."
+        print ' */'
+        print ''
+        print '#include "x86/assyntax.h"'
+        print ''
+        print '#ifdef __GNUC__'
+        print '#  pragma GCC visibility push(default)'
+        print '#  define HIDDEN(x) .hidden x'
+        print '#else'
+        print '#  define HIDDEN(x)'
+        print '#endif'
+        print ''
+        print '# if defined(USE_MGL_NAMESPACE)'
+        print '#  define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))'
+        print '#  define _glapi_Dispatch _mglapi_Dispatch'
+        print '# else'
+        print '#  define GL_PREFIX(n) GLNAME(CONCAT(gl,n))'
+        print '# endif'
+        print ''
+        print '#if defined(HAVE_PTHREAD) || defined(_WIN32)'
+        print '#  define THREADS'
+        print '#endif'
+        print ''
+        print '\t.text'
+        print ''
+        print '#ifdef GLX_USE_TLS'
+        print ''
+        print '\t.globl _x86_64_get_get_dispatch; HIDDEN(_x86_64_get_get_dispatch)'
+        print '_x86_64_get_get_dispatch:'
+        print '\tlea\t_x86_64_get_dispatch(%rip), %rax'
+        print '\tret'
+        print ''
+        print '\t.p2align\t4,,15'
+        print '_x86_64_get_dispatch:'
+        print '\tmovq\t_glapi_tls_Dispatch@GOTTPOFF(%rip), %rax'
+        print '\tmovq\t%fs:(%rax), %rax'
+        print '\tret'
+        print '\t.size\t_x86_64_get_dispatch, .-_x86_64_get_dispatch'
+        print ''
+        print '#elif defined(HAVE_PTHREAD)'
+        print ''
+        print '\t.extern\t_glapi_Dispatch'
+        print '\t.extern\t_gl_DispatchTSD'
+        print '\t.extern\tpthread_getspecific'
+        print ''
+        print '\t.p2align\t4,,15'
+        print '_x86_64_get_dispatch:'
+        print '\tmovq\t_gl_DispatchTSD@GOTPCREL(%rip), %rax'
+        print '\tmovl\t(%rax), %edi'
+        print '\tjmp\tpthread_getspecific@PLT'
+        print ''
+        print '#elif defined(THREADS)'
+        print ''
+        print '\t.extern\t_glapi_get_dispatch'
+        print ''
+        print '#endif'
+        print ''
+        return
+
+
+    def printRealFooter(self):
+        print ''
+        print '#if defined(GLX_USE_TLS) && defined(__linux__)'
+        print '        .section ".note.ABI-tag", "a"'
+        print '        .p2align 2'
+        print '        .long   1f - 0f   /* name length */'
+        print '        .long   3f - 2f   /* data length */'
+        print '        .long   1         /* note length */'
+        print '0:      .asciz "GNU"      /* vendor name */'
+        print '1:      .p2align 2'
+        print '2:      .long   0         /* note data: the ABI tag */'
+        print '        .long   2,4,20    /* Minimum kernel version w/TLS */'
+        print '3:      .p2align 2        /* pad out section */'
+        print '#endif /* GLX_USE_TLS */'
+        print ''
+        print '#if defined (__ELF__) && defined (__linux__)'
+        print '        .section .note.GNU-stack,"",%progbits'
+        print '#endif'
+        return
+
+
+    def printFunction(self, f):
+
+        # The x86-64 ABI divides function parameters into a couple
+        # classes.  For the OpenGL interface, the only ones that are
+        # relevent are INTEGER and SSE.  Basically, the first 8
+        # GLfloat or GLdouble parameters are placed in %xmm0 - %xmm7,
+        # the first 6 non-GLfloat / non-GLdouble parameters are placed
+        # in registers listed in int_parameters.
+        #
+        # If more parameters than that are required, they are passed
+        # on the stack.  Therefore, we just have to make sure that
+        # %esp hasn't changed when we jump to the actual function.
+        # Since we're jumping to the function (and not calling it), we
+        # have to make sure of that anyway!
+
+        int_parameters = ["%rdi", "%rsi", "%rdx", "%rcx", "%r8", "%r9"]
+
+        int_class = 0
+        sse_class = 0
+        stack_offset = 0
+        registers = []
+        for p in f.parameterIterator():
+            type_name = p.get_base_type_string()
+
+            if p.is_pointer() or (type_name != "GLfloat" and type_name != "GLdouble"):
+                if int_class < 6:
+                    registers.append( [int_parameters[int_class], stack_offset] )
+                    int_class += 1
+                    stack_offset += 8
+            else:
+                if sse_class < 8:
+                    registers.append( ["%%xmm%u" % (sse_class), stack_offset] )
+                    sse_class += 1
+                    stack_offset += 8
+
+        if ((int_class & 1) == 0) and (sse_class == 0):
+            registers.append( ["%rbp", 0] )
+
+
+        name = f.dispatch_name()
+
+        print '\t.p2align\t4,,15'
+        print '\t.globl\tGL_PREFIX(%s)' % (name)
+        print '\t.type\tGL_PREFIX(%s), @function' % (name)
+        if not f.is_static_entry_point(f.name):
+            print '\tHIDDEN(GL_PREFIX(%s))' % (name)
+        print 'GL_PREFIX(%s):' % (name)
+        print '#if defined(GLX_USE_TLS)'
+        print '\tcall\t_x86_64_get_dispatch@PLT'
+        print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
+        print '\tjmp\t*%r11'
+        print '#elif defined(HAVE_PTHREAD)'
+
+        save_all_regs(registers)
+        print '\tcall\t_x86_64_get_dispatch@PLT'
+        restore_all_regs(registers)
+
+        if f.offset == 0:
+            print '\tmovq\t(%rax), %r11'
+        else:
+            print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
+
+        print '\tjmp\t*%r11'
+
+        print '#else'
+        print '\tmovq\t_glapi_Dispatch(%rip), %rax'
+        print '\ttestq\t%rax, %rax'
+        print '\tje\t1f'
+        print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
+        print '\tjmp\t*%r11'
+        print '1:'
+
+        save_all_regs(registers)
+        print '\tcall\t_glapi_get_dispatch'
+        restore_all_regs(registers)
+
+        print '\tmovq\t%u(%%rax), %%r11' % (f.offset * 8)
+        print '\tjmp\t*%r11'
+        print '#endif /* defined(GLX_USE_TLS) */'
+
+        print '\t.size\tGL_PREFIX(%s), .-GL_PREFIX(%s)' % (name, name)
+        print ''
+        return
+
+
+    def printBody(self, api):
+        for f in api.functionIterateByOffset():
+            self.printFunction(f)
+
+
+        for f in api.functionIterateByOffset():
+            dispatch = f.dispatch_name()
+            for n in f.entry_points:
+                if n != f.name:
+                    if f.is_static_entry_point(n):
+                        text = '\t.globl GL_PREFIX(%s) ; .set GL_PREFIX(%s), GL_PREFIX(%s)' % (n, n, dispatch)
+
+                        if f.has_different_protocol(n):
+                            print '#ifndef GLX_INDIRECT_RENDERING'
+                            print text
+                            print '#endif'
+                        else:
+                            print text
+
+        return
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-       mode = "generic"
-
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
-       except Exception,e:
-               show_usage()
-
-       for (arg,val) in args:
-               if arg == '-m':
-                       mode = val
-               elif arg == "-f":
-                       file_name = val
-
-       if mode == "generic":
-               printer = PrintGenericStubs()
-       else:
-               print "ERROR: Invalid mode \"%s\" specified." % mode
-               show_usage()
-
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-       printer.Print(api)
+    file_name = "gl_API.xml"
+    mode = "generic"
+
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
+    except Exception,e:
+        show_usage()
+
+    for (arg,val) in args:
+        if arg == '-m':
+            mode = val
+        elif arg == "-f":
+            file_name = val
+
+    if mode == "generic":
+        printer = PrintGenericStubs()
+    else:
+        print "ERROR: Invalid mode \"%s\" specified." % mode
+        show_usage()
+
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+    printer.Print(api)
index 5eaa340f78a94f7975ba3f159c8822da3c510402..8b0f6ee2409ff82b2436fe741fa64cf8b85ed103 100644 (file)
@@ -31,239 +31,239 @@ import sys, getopt
 
 class PrintGenericStubs(gl_XML.gl_print_base):
 
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
 
-               self.name = "gl_x86_asm.py (from Mesa)"
-               self.license = license.bsd_license_template % ( \
+        self.name = "gl_x86_asm.py (from Mesa)"
+        self.license = license.bsd_license_template % ( \
 """Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 (C) Copyright IBM Corporation 2004, 2005""", "BRIAN PAUL, IBM")
-               return
+        return
 
 
-       def get_stack_size(self, f):
-               size = 0
-               for p in f.parameterIterator():
-                       if p.is_padding:
-                               continue
+    def get_stack_size(self, f):
+        size = 0
+        for p in f.parameterIterator():
+            if p.is_padding:
+                continue
 
-                       size += p.get_stack_size()
+            size += p.get_stack_size()
 
-               return size
+        return size
 
 
-       def printRealHeader(self):
-               print '#include "x86/assyntax.h"'
-               print ''
-               print '#if defined(STDCALL_API)'
-               print '# if defined(USE_MGL_NAMESPACE)'
-               print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
-               print '# else'
-               print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
-               print '# endif'
-               print '#else'
-               print '# if defined(USE_MGL_NAMESPACE)'
-               print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
-               print '#  define _glapi_Dispatch _mglapi_Dispatch'
-               print '# else'
-               print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
-               print '# endif'
-               print '#endif'
-               print ''
-               print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
-               print ''
-               print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__)'
-               print '#define GLOBL_FN(x) GLOBL x ; .type x, @function'
-               print '#else'
-               print '#define GLOBL_FN(x) GLOBL x'
-               print '#endif'
-               print ''
-               print '#if defined(HAVE_PTHREAD) || defined(_WIN32)'
-               print '#  define THREADS'
-               print '#endif'
-               print ''
-               print '#ifdef GLX_USE_TLS'
-               print ''
-               print '#ifdef GLX_X86_READONLY_TEXT'
-               print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)'
-               print '#else'
-               print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */'
-               print '#endif'
-               print ''
-               print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
-               print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
-               print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
-               print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
-               print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
-               print '\tCTX_INSNS ;                                    \\'
-               print '\tJMP(GL_OFFSET(off))'
-               print ''
-               print '#elif defined(HAVE_PTHREAD)'
-               print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
-               print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
-               print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
-               print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
-               print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
-               print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
-               print '\tJE(1f) ;\t\t\t\t\t\\'
-               print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
-               print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
-               print '\tJMP(GL_OFFSET(off))'
-               print '#elif defined(THREADS)'
-               print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
-               print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
-               print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
-               print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
-               print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
-               print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
-               print '\tJE(1f) ;\t\t\t\t\t\\'
-               print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
-               print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
-               print '\tJMP(GL_OFFSET(off))'
-               print '#else /* Non-threaded version. */'
-               print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
-               print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
-               print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
-               print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
-               print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
-               print '\tJMP(GL_OFFSET(off))'
-               print '#endif'
-               print ''
-               print '#ifdef HAVE_ALIAS'
-               print '#  define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
-               print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
-               print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
-               print '#else'
-               print '#  define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
-               print '    GL_STUB(fn, off, fn_alt)'
-               print '#endif'
-               print ''
-               print 'SEG_TEXT'
-               print ''
-               print '#ifdef GLX_USE_TLS'
-               print ''
-               print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
-               print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
-               print 'ALIGNTEXT16'
-               print 'GLNAME(_x86_get_dispatch):'
-               print '\tcall   1f'
-               print '1:\tpopl %eax'
-               print '\taddl   $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
-               print '\tmovl   _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax'
-               print '\tret'
-               print ''
-               print '#elif defined(HAVE_PTHREAD)'
-               print 'EXTERN GLNAME(_glapi_Dispatch)'
-               print 'EXTERN GLNAME(_gl_DispatchTSD)'
-               print 'EXTERN GLNAME(pthread_getspecific)'
-               print ''
-               print 'ALIGNTEXT16'
-               print 'GLNAME(_x86_get_dispatch):'
-               print '\tSUB_L(CONST(24), ESP)'
-               print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
-               print '\tCALL(GLNAME(pthread_getspecific))'
-               print '\tADD_L(CONST(28), ESP)'
-               print '\tRET'
-               print '#elif defined(THREADS)'
-               print 'EXTERN GLNAME(_glapi_get_dispatch)'
-               print '#endif'
-               print ''
+    def printRealHeader(self):
+        print '#include "x86/assyntax.h"'
+        print ''
+        print '#if defined(STDCALL_API)'
+        print '# if defined(USE_MGL_NAMESPACE)'
+        print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n2))'
+        print '# else'
+        print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
+        print '# endif'
+        print '#else'
+        print '# if defined(USE_MGL_NAMESPACE)'
+        print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
+        print '#  define _glapi_Dispatch _mglapi_Dispatch'
+        print '# else'
+        print '#  define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
+        print '# endif'
+        print '#endif'
+        print ''
+        print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
+        print ''
+        print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__) && !defined(__APPLE__)'
+        print '#define GLOBL_FN(x) GLOBL x ; .type x, @function'
+        print '#else'
+        print '#define GLOBL_FN(x) GLOBL x'
+        print '#endif'
+        print ''
+        print '#if defined(HAVE_PTHREAD) || defined(_WIN32)'
+        print '#  define THREADS'
+        print '#endif'
+        print ''
+        print '#ifdef GLX_USE_TLS'
+        print ''
+        print '#ifdef GLX_X86_READONLY_TEXT'
+        print '# define CTX_INSNS MOV_L(GS:(EAX), EAX)'
+        print '#else'
+        print '# define CTX_INSNS NOP /* Pad for init_glapi_relocs() */'
+        print '#endif'
+        print ''
+        print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
+        print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
+        print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
+        print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
+        print '\tCALL(_x86_get_dispatch) ;\t\t\t\\'
+        print '\tCTX_INSNS ;                                   \\'
+        print '\tJMP(GL_OFFSET(off))'
+        print ''
+        print '#elif defined(HAVE_PTHREAD)'
+        print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
+        print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
+        print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
+        print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
+        print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
+        print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
+        print '\tJE(1f) ;\t\t\t\t\t\\'
+        print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
+        print '1:\tCALL(_x86_get_dispatch) ;\t\t\t\\'
+        print '\tJMP(GL_OFFSET(off))'
+        print '#elif defined(THREADS)'
+        print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
+        print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
+        print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
+        print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
+        print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
+        print '\tTEST_L(EAX, EAX) ;\t\t\t\t\\'
+        print '\tJE(1f) ;\t\t\t\t\t\\'
+        print '\tJMP(GL_OFFSET(off)) ;\t\t\t\t\\'
+        print '1:\tCALL(_glapi_get_dispatch) ;\t\t\t\\'
+        print '\tJMP(GL_OFFSET(off))'
+        print '#else /* Non-threaded version. */'
+        print '#  define GL_STUB(fn,off,fn_alt)\t\t\t\\'
+        print 'ALIGNTEXT16;\t\t\t\t\t\t\\'
+        print 'GLOBL_FN(GL_PREFIX(fn, fn_alt));\t\t\t\\'
+        print 'GL_PREFIX(fn, fn_alt):\t\t\t\t\t\\'
+        print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX) ;\t\\'
+        print '\tJMP(GL_OFFSET(off))'
+        print '#endif'
+        print ''
+        print '#ifdef HAVE_ALIAS'
+        print '#  define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
+        print '\t.globl\tGL_PREFIX(fn, fn_alt) ;\t\t\t\\'
+        print '\t.set\tGL_PREFIX(fn, fn_alt), GL_PREFIX(alias, alias_alt)'
+        print '#else'
+        print '#  define GL_STUB_ALIAS(fn,off,fn_alt,alias,alias_alt)\t\\'
+        print '    GL_STUB(fn, off, fn_alt)'
+        print '#endif'
+        print ''
+        print 'SEG_TEXT'
+        print ''
+        print '#ifdef GLX_USE_TLS'
+        print ''
+        print '\tGLOBL\tGLNAME(_x86_get_dispatch)'
+        print '\tHIDDEN(GLNAME(_x86_get_dispatch))'
+        print 'ALIGNTEXT16'
+        print 'GLNAME(_x86_get_dispatch):'
+        print '\tcall  1f'
+        print '1:\tpopl        %eax'
+        print '\taddl  $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax'
+        print '\tmovl  _glapi_tls_Dispatch@GOTNTPOFF(%eax), %eax'
+        print '\tret'
+        print ''
+        print '#elif defined(HAVE_PTHREAD)'
+        print 'EXTERN GLNAME(_glapi_Dispatch)'
+        print 'EXTERN GLNAME(_gl_DispatchTSD)'
+        print 'EXTERN GLNAME(pthread_getspecific)'
+        print ''
+        print 'ALIGNTEXT16'
+        print 'GLNAME(_x86_get_dispatch):'
+        print '\tSUB_L(CONST(24), ESP)'
+        print '\tPUSH_L(GLNAME(_gl_DispatchTSD))'
+        print '\tCALL(GLNAME(pthread_getspecific))'
+        print '\tADD_L(CONST(28), ESP)'
+        print '\tRET'
+        print '#elif defined(THREADS)'
+        print 'EXTERN GLNAME(_glapi_get_dispatch)'
+        print '#endif'
+        print ''
 
-               print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )'
-               print '\t\t.section\twtext, "awx", @progbits'
-               print '#endif /* defined( GLX_USE_TLS ) */'
+        print '#if defined( GLX_USE_TLS ) && !defined( GLX_X86_READONLY_TEXT )'
+        print '\t\t.section\twtext, "awx", @progbits'
+        print '#endif /* defined( GLX_USE_TLS ) */'
 
-               print ''
-               print '\t\tALIGNTEXT16'
-               print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
-               print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
-               print 'GLNAME(gl_dispatch_functions_start):'
-               print ''
-               return
+        print ''
+        print '\t\tALIGNTEXT16'
+        print '\t\tGLOBL GLNAME(gl_dispatch_functions_start)'
+        print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_start))'
+        print 'GLNAME(gl_dispatch_functions_start):'
+        print ''
+        return
 
 
-       def printRealFooter(self):
-               print ''
-               print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
-               print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
-               print '\t\tALIGNTEXT16'
-               print 'GLNAME(gl_dispatch_functions_end):'
-               print ''
-               print '#if defined(GLX_USE_TLS) && defined(__linux__)'
-               print ' .section ".note.ABI-tag", "a"'
-               print ' .p2align 2'
-               print ' .long   1f - 0f   /* name length */'
-               print ' .long   3f - 2f   /* data length */'
-               print ' .long   1         /* note length */'
-               print '0:       .asciz "GNU"      /* vendor name */'
-               print '1:       .p2align 2'
-               print '2:       .long   0         /* note data: the ABI tag */'
-               print ' .long   2,4,20    /* Minimum kernel version w/TLS */'
-               print '3:       .p2align 2        /* pad out section */'
-               print '#endif /* GLX_USE_TLS */'
-               print ''
-               print '#if defined (__ELF__) && defined (__linux__)'
-               print ' .section .note.GNU-stack,"",%progbits'
-               print '#endif'
-               return
+    def printRealFooter(self):
+        print ''
+        print '\t\tGLOBL\tGLNAME(gl_dispatch_functions_end)'
+        print '\t\tHIDDEN(GLNAME(gl_dispatch_functions_end))'
+        print '\t\tALIGNTEXT16'
+        print 'GLNAME(gl_dispatch_functions_end):'
+        print ''
+        print '#if defined(GLX_USE_TLS) && defined(__linux__)'
+        print '        .section ".note.ABI-tag", "a"'
+        print '        .p2align 2'
+        print '        .long   1f - 0f   /* name length */'
+        print '        .long   3f - 2f   /* data length */'
+        print '        .long   1         /* note length */'
+        print '0:      .asciz "GNU"      /* vendor name */'
+        print '1:      .p2align 2'
+        print '2:      .long   0         /* note data: the ABI tag */'
+        print '        .long   2,4,20    /* Minimum kernel version w/TLS */'
+        print '3:      .p2align 2        /* pad out section */'
+        print '#endif /* GLX_USE_TLS */'
+        print ''
+        print '#if defined (__ELF__) && defined (__linux__)'
+        print '        .section .note.GNU-stack,"",%progbits'
+        print '#endif'
+        return
 
 
-       def printBody(self, api):
-               for f in api.functionIterateByOffset():
-                       name = f.dispatch_name()
-                       stack = self.get_stack_size(f)
-                       alt = "%s@%u" % (name, stack)
+    def printBody(self, api):
+        for f in api.functionIterateByOffset():
+            name = f.dispatch_name()
+            stack = self.get_stack_size(f)
+            alt = "%s@%u" % (name, stack)
 
-                       print '\tGL_STUB(%s, %d, %s)' % (name, f.offset, alt)
+            print '\tGL_STUB(%s, %d, %s)' % (name, f.offset, alt)
 
-                       if not f.is_static_entry_point(f.name):
-                               print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt)
+            if not f.is_static_entry_point(f.name):
+                print '\tHIDDEN(GL_PREFIX(%s, %s))' % (name, alt)
 
 
-               for f in api.functionIterateByOffset():
-                       name = f.dispatch_name()
-                       stack = self.get_stack_size(f)
-                       alt = "%s@%u" % (name, stack)
+        for f in api.functionIterateByOffset():
+            name = f.dispatch_name()
+            stack = self.get_stack_size(f)
+            alt = "%s@%u" % (name, stack)
 
-                       for n in f.entry_points:
-                               if f.is_static_entry_point(n):
-                                       if n != f.name:
-                                               alt2 = "%s@%u" % (n, stack)
-                                               text = '\tGL_STUB_ALIAS(%s, %d, %s, %s, %s)' % (n, f.offset, alt2, name, alt)
+            for n in f.entry_points:
+                if f.is_static_entry_point(n):
+                    if n != f.name:
+                        alt2 = "%s@%u" % (n, stack)
+                        text = '\tGL_STUB_ALIAS(%s, %d, %s, %s, %s)' % (n, f.offset, alt2, name, alt)
 
-                                               if f.has_different_protocol(n):
-                                                       print '#ifndef GLX_INDIRECT_RENDERING'
-                                                       print text
-                                                       print '#endif'
-                                               else:
-                                                       print text
+                        if f.has_different_protocol(n):
+                            print '#ifndef GLX_INDIRECT_RENDERING'
+                            print text
+                            print '#endif'
+                        else:
+                            print text
 
-               return
+        return
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
-       mode = "generic"
+    file_name = "gl_API.xml"
+    mode = "generic"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "m:f:")
+    except Exception,e:
+        show_usage()
 
-       for (arg,val) in args:
-               if arg == '-m':
-                       mode = val
-               elif arg == "-f":
-                       file_name = val
+    for (arg,val) in args:
+        if arg == '-m':
+            mode = val
+        elif arg == "-f":
+            file_name = val
 
-       if mode == "generic":
-               printer = PrintGenericStubs()
-       else:
-               print "ERROR: Invalid mode \"%s\" specified." % mode
-               show_usage()
+    if mode == "generic":
+        printer = PrintGenericStubs()
+    else:
+        print "ERROR: Invalid mode \"%s\" specified." % mode
+        show_usage()
 
-       api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
-       printer.Print(api)
+    api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+    printer.Print(api)
index 38b0246ba5b51776ae2932c9af605da3976ede62..473baaee5c6897de919ee16c26dccf61333227cb 100644 (file)
@@ -40,173 +40,173 @@ import string
 
 
 def PrintHead():
-       print '; DO NOT EDIT - This file generated automatically by mesadef.py script'
-       print 'DESCRIPTION \'Mesa (OpenGL work-alike) for Win32\''
-       print 'VERSION 6.0'
-       print ';'
-       print '; Module definition file for Mesa (OPENGL32.DLL)'
-       print ';'
-       print '; Note: The OpenGL functions use the STDCALL'
-       print '; function calling convention.  Microsoft\'s'
-       print '; OPENGL32 uses this convention and so must the'
-       print '; Mesa OPENGL32 so that the Mesa DLL can be used'
-       print '; as a drop-in replacement.'
-       print ';'
-       print '; The linker exports STDCALL entry points with'
-       print '; \'decorated\' names; e.g., _glBegin@0, where the'
-       print '; trailing number is the number of bytes of '
-       print '; parameter data pushed onto the stack.  The'
-       print '; callee is responsible for popping this data'
-       print '; off the stack, usually via a RETF n instruction.'
-       print ';'
-       print '; However, the Microsoft OPENGL32.DLL does not export'
-       print '; the decorated names, even though the calling convention'
-       print '; is STDCALL.  So, this module definition file is'
-       print '; needed to force the Mesa OPENGL32.DLL to export the'
-       print '; symbols in the same manner as the Microsoft DLL.'
-       print '; Were it not for this problem, this file would not'
-       print '; be needed (for the gl* functions) since the entry'
-       print '; points are compiled with dllexport declspec.'
-       print ';'
-       print '; However, this file is still needed to export "internal"'
-       print '; Mesa symbols for the benefit of the OSMESA32.DLL.'
-       print ';'
-       print 'EXPORTS'
-       return
+    print '; DO NOT EDIT - This file generated automatically by mesadef.py script'
+    print 'DESCRIPTION \'Mesa (OpenGL work-alike) for Win32\''
+    print 'VERSION 6.0'
+    print ';'
+    print '; Module definition file for Mesa (OPENGL32.DLL)'
+    print ';'
+    print '; Note: The OpenGL functions use the STDCALL'
+    print '; function calling convention.  Microsoft\'s'
+    print '; OPENGL32 uses this convention and so must the'
+    print '; Mesa OPENGL32 so that the Mesa DLL can be used'
+    print '; as a drop-in replacement.'
+    print ';'
+    print '; The linker exports STDCALL entry points with'
+    print '; \'decorated\' names; e.g., _glBegin@0, where the'
+    print '; trailing number is the number of bytes of '
+    print '; parameter data pushed onto the stack.  The'
+    print '; callee is responsible for popping this data'
+    print '; off the stack, usually via a RETF n instruction.'
+    print ';'
+    print '; However, the Microsoft OPENGL32.DLL does not export'
+    print '; the decorated names, even though the calling convention'
+    print '; is STDCALL.  So, this module definition file is'
+    print '; needed to force the Mesa OPENGL32.DLL to export the'
+    print '; symbols in the same manner as the Microsoft DLL.'
+    print '; Were it not for this problem, this file would not'
+    print '; be needed (for the gl* functions) since the entry'
+    print '; points are compiled with dllexport declspec.'
+    print ';'
+    print '; However, this file is still needed to export "internal"'
+    print '; Mesa symbols for the benefit of the OSMESA32.DLL.'
+    print ';'
+    print 'EXPORTS'
+    return
 #enddef
 
 
 def PrintTail():
-       print ';'
-       print '; WGL API'
-       print '\twglChoosePixelFormat'
-       print '\twglCopyContext'
-       print '\twglCreateContext'
-       print '\twglCreateLayerContext'
-       print '\twglDeleteContext'
-       print '\twglDescribeLayerPlane'
-       print '\twglDescribePixelFormat'
-       print '\twglGetCurrentContext'
-       print '\twglGetCurrentDC'
-       print '\twglGetExtensionsStringARB'
-       print '\twglGetLayerPaletteEntries'
-       print '\twglGetPixelFormat'
-       print '\twglGetProcAddress'
-       print '\twglMakeCurrent'
-       print '\twglRealizeLayerPalette'
-       print '\twglSetLayerPaletteEntries'
-       print '\twglSetPixelFormat'
-       print '\twglShareLists'
-       print '\twglSwapBuffers'
-       print '\twglSwapLayerBuffers'
-       print '\twglUseFontBitmapsA'
-       print '\twglUseFontBitmapsW'
-       print '\twglUseFontOutlinesA'
-       print '\twglUseFontOutlinesW'
-       print ';'
-       print '; Mesa internals - mostly for OSMESA'
-       print '\t_ac_CreateContext'
-       print '\t_ac_DestroyContext'
-       print '\t_ac_InvalidateState'
-       print '\t_glapi_get_context'
-       print '\t_glapi_get_proc_address'
-       print '\t_mesa_buffer_data'
-       print '\t_mesa_buffer_map'
-       print '\t_mesa_buffer_subdata'
-       print '\t_mesa_choose_tex_format'
-       print '\t_mesa_compressed_texture_size'
-       print '\t_mesa_create_framebuffer'
-       print '\t_mesa_create_visual'
-       print '\t_mesa_delete_buffer_object'
-       print '\t_mesa_delete_texture_object'
-       print '\t_mesa_destroy_framebuffer'
-       print '\t_mesa_destroy_visual'
-       print '\t_mesa_enable_1_3_extensions'
-       print '\t_mesa_enable_1_4_extensions'
-       print '\t_mesa_enable_1_5_extensions'
-       print '\t_mesa_enable_sw_extensions'
-       print '\t_mesa_error'
-       print '\t_mesa_free_context_data'
-       print '\t_mesa_get_current_context'
-       print '\t_mesa_init_default_imports'
-       print '\t_mesa_initialize_context'
-       print '\t_mesa_make_current'
-       print '\t_mesa_new_buffer_object'
-       print '\t_mesa_new_texture_object'
-       print '\t_mesa_problem'
-       print '\t_mesa_ResizeBuffersMESA'
-       print '\t_mesa_store_compressed_teximage1d'
-       print '\t_mesa_store_compressed_teximage2d'
-       print '\t_mesa_store_compressed_teximage3d'
-       print '\t_mesa_store_compressed_texsubimage1d'
-       print '\t_mesa_store_compressed_texsubimage2d'
-       print '\t_mesa_store_compressed_texsubimage3d'
-       print '\t_mesa_store_teximage1d'
-       print '\t_mesa_store_teximage2d'
-       print '\t_mesa_store_teximage3d'
-       print '\t_mesa_store_texsubimage1d'
-       print '\t_mesa_store_texsubimage2d'
-       print '\t_mesa_store_texsubimage3d'
-       print '\t_mesa_test_proxy_teximage'
-       print '\t_mesa_Viewport'
-       print '\t_mesa_meta_CopyColorSubTable'
-       print '\t_mesa_meta_CopyColorTable'
-       print '\t_mesa_meta_CopyConvolutionFilter1D'
-       print '\t_mesa_meta_CopyConvolutionFilter2D'
-       print '\t_mesa_meta_CopyTexImage1D'
-       print '\t_mesa_meta_CopyTexImage2D'
-       print '\t_mesa_meta_CopyTexSubImage1D'
-       print '\t_mesa_meta_CopyTexSubImage2D'
-       print '\t_mesa_meta_CopyTexSubImage3D'
-       print '\t_swrast_Accum'
-       print '\t_swrast_alloc_buffers'
-       print '\t_swrast_Bitmap'
-       print '\t_swrast_CopyPixels'
-       print '\t_swrast_DrawPixels'
-       print '\t_swrast_GetDeviceDriverReference'
-       print '\t_swrast_Clear'
-       print '\t_swrast_choose_line'
-       print '\t_swrast_choose_triangle'
-       print '\t_swrast_CreateContext'
-       print '\t_swrast_DestroyContext'
-       print '\t_swrast_InvalidateState'
-       print '\t_swrast_ReadPixels'
-       print '\t_swrast_zbuffer_address'
-       print '\t_swsetup_Wakeup'
-       print '\t_swsetup_CreateContext'
-       print '\t_swsetup_DestroyContext'
-       print '\t_swsetup_InvalidateState'
-       print '\t_tnl_CreateContext'
-       print '\t_tnl_DestroyContext'
-       print '\t_tnl_InvalidateState'
-       print '\t_tnl_MakeCurrent'
-       print '\t_tnl_run_pipeline'
+    print ';'
+    print '; WGL API'
+    print '\twglChoosePixelFormat'
+    print '\twglCopyContext'
+    print '\twglCreateContext'
+    print '\twglCreateLayerContext'
+    print '\twglDeleteContext'
+    print '\twglDescribeLayerPlane'
+    print '\twglDescribePixelFormat'
+    print '\twglGetCurrentContext'
+    print '\twglGetCurrentDC'
+    print '\twglGetExtensionsStringARB'
+    print '\twglGetLayerPaletteEntries'
+    print '\twglGetPixelFormat'
+    print '\twglGetProcAddress'
+    print '\twglMakeCurrent'
+    print '\twglRealizeLayerPalette'
+    print '\twglSetLayerPaletteEntries'
+    print '\twglSetPixelFormat'
+    print '\twglShareLists'
+    print '\twglSwapBuffers'
+    print '\twglSwapLayerBuffers'
+    print '\twglUseFontBitmapsA'
+    print '\twglUseFontBitmapsW'
+    print '\twglUseFontOutlinesA'
+    print '\twglUseFontOutlinesW'
+    print ';'
+    print '; Mesa internals - mostly for OSMESA'
+    print '\t_ac_CreateContext'
+    print '\t_ac_DestroyContext'
+    print '\t_ac_InvalidateState'
+    print '\t_glapi_get_context'
+    print '\t_glapi_get_proc_address'
+    print '\t_mesa_buffer_data'
+    print '\t_mesa_buffer_map'
+    print '\t_mesa_buffer_subdata'
+    print '\t_mesa_choose_tex_format'
+    print '\t_mesa_compressed_texture_size'
+    print '\t_mesa_create_framebuffer'
+    print '\t_mesa_create_visual'
+    print '\t_mesa_delete_buffer_object'
+    print '\t_mesa_delete_texture_object'
+    print '\t_mesa_destroy_framebuffer'
+    print '\t_mesa_destroy_visual'
+    print '\t_mesa_enable_1_3_extensions'
+    print '\t_mesa_enable_1_4_extensions'
+    print '\t_mesa_enable_1_5_extensions'
+    print '\t_mesa_enable_sw_extensions'
+    print '\t_mesa_error'
+    print '\t_mesa_free_context_data'
+    print '\t_mesa_get_current_context'
+    print '\t_mesa_init_default_imports'
+    print '\t_mesa_initialize_context'
+    print '\t_mesa_make_current'
+    print '\t_mesa_new_buffer_object'
+    print '\t_mesa_new_texture_object'
+    print '\t_mesa_problem'
+    print '\t_mesa_ResizeBuffersMESA'
+    print '\t_mesa_store_compressed_teximage1d'
+    print '\t_mesa_store_compressed_teximage2d'
+    print '\t_mesa_store_compressed_teximage3d'
+    print '\t_mesa_store_compressed_texsubimage1d'
+    print '\t_mesa_store_compressed_texsubimage2d'
+    print '\t_mesa_store_compressed_texsubimage3d'
+    print '\t_mesa_store_teximage1d'
+    print '\t_mesa_store_teximage2d'
+    print '\t_mesa_store_teximage3d'
+    print '\t_mesa_store_texsubimage1d'
+    print '\t_mesa_store_texsubimage2d'
+    print '\t_mesa_store_texsubimage3d'
+    print '\t_mesa_test_proxy_teximage'
+    print '\t_mesa_Viewport'
+    print '\t_mesa_meta_CopyColorSubTable'
+    print '\t_mesa_meta_CopyColorTable'
+    print '\t_mesa_meta_CopyConvolutionFilter1D'
+    print '\t_mesa_meta_CopyConvolutionFilter2D'
+    print '\t_mesa_meta_CopyTexImage1D'
+    print '\t_mesa_meta_CopyTexImage2D'
+    print '\t_mesa_meta_CopyTexSubImage1D'
+    print '\t_mesa_meta_CopyTexSubImage2D'
+    print '\t_mesa_meta_CopyTexSubImage3D'
+    print '\t_swrast_Accum'
+    print '\t_swrast_alloc_buffers'
+    print '\t_swrast_Bitmap'
+    print '\t_swrast_CopyPixels'
+    print '\t_swrast_DrawPixels'
+    print '\t_swrast_GetDeviceDriverReference'
+    print '\t_swrast_Clear'
+    print '\t_swrast_choose_line'
+    print '\t_swrast_choose_triangle'
+    print '\t_swrast_CreateContext'
+    print '\t_swrast_DestroyContext'
+    print '\t_swrast_InvalidateState'
+    print '\t_swrast_ReadPixels'
+    print '\t_swrast_zbuffer_address'
+    print '\t_swsetup_Wakeup'
+    print '\t_swsetup_CreateContext'
+    print '\t_swsetup_DestroyContext'
+    print '\t_swsetup_InvalidateState'
+    print '\t_tnl_CreateContext'
+    print '\t_tnl_DestroyContext'
+    print '\t_tnl_InvalidateState'
+    print '\t_tnl_MakeCurrent'
+    print '\t_tnl_run_pipeline'
 #enddef
 
 
 records = []
 
 def FindOffset(funcName):
-       for (name, alias, offset) in records:
-               if name == funcName:
-                       return offset
-               #endif
-       #endfor
-       return -1
+    for (name, alias, offset) in records:
+        if name == funcName:
+            return offset
+        #endif
+    #endfor
+    return -1
 #enddef
 
 
 def EmitEntry(name, returnType, argTypeList, argNameList, alias, offset):
-       if alias == '':
-               dispatchName = name
-       else:
-               dispatchName = alias
-       if offset < 0:
-               offset = FindOffset(dispatchName)
-       if offset >= 0 and string.find(name, "unused") == -1:
-               print '\tgl%s' % (name)
-               # save this info in case we need to look up an alias later
-               records.append((name, dispatchName, offset))
+    if alias == '':
+        dispatchName = name
+    else:
+        dispatchName = alias
+    if offset < 0:
+        offset = FindOffset(dispatchName)
+    if offset >= 0 and string.find(name, "unused") == -1:
+        print '\tgl%s' % (name)
+        # save this info in case we need to look up an alias later
+        records.append((name, dispatchName, offset))
 
 #enddef
 
index 0008634ff2e5f4662a8e3d0badd979672017c0f9..eae1cf3e5ea2e15531551344651df2c621c50c88 100644 (file)
@@ -29,171 +29,171 @@ import license
 import sys, getopt, string
 
 def get_function_spec(func):
-       sig = ""
-       # derive parameter signature
-       for p in func.parameterIterator():
-               if p.is_padding:
-                       continue
-               # FIXME: This is a *really* ugly hack. :(
-               tn = p.type_expr.get_base_type_node()
-               if p.is_pointer():
-                       sig += 'p'
-               elif tn.integer:
-                       sig += 'i'
-               elif tn.size == 4:
-                       sig += 'f'
-               else:
-                       sig += 'd'
-
-       spec = [sig]
-       for ent in func.entry_points:
-               spec.append("gl" + ent)
-
-       # spec is terminated by an empty string
-       spec.append('')
-
-       return spec
+    sig = ""
+    # derive parameter signature
+    for p in func.parameterIterator():
+        if p.is_padding:
+            continue
+        # FIXME: This is a *really* ugly hack. :(
+        tn = p.type_expr.get_base_type_node()
+        if p.is_pointer():
+            sig += 'p'
+        elif tn.integer:
+            sig += 'i'
+        elif tn.size == 4:
+            sig += 'f'
+        else:
+            sig += 'd'
+
+    spec = [sig]
+    for ent in func.entry_points:
+        spec.append("gl" + ent)
+
+    # spec is terminated by an empty string
+    spec.append('')
+
+    return spec
 
 class PrintGlRemap(gl_XML.gl_print_base):
-       def __init__(self):
-               gl_XML.gl_print_base.__init__(self)
-
-               self.name = "remap_helper.py (from Mesa)"
-               self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
-               return
-
-
-       def printRealHeader(self):
-               print '#include "main/dispatch.h"'
-               print '#include "main/remap.h"'
-               print ''
-               return
-
-
-       def printBody(self, api):
-               pool_indices = {}
-
-               print '/* this is internal to remap.c */'
-               print '#ifndef need_MESA_remap_table'
-               print '#error Only remap.c should include this file!'
-               print '#endif /* need_MESA_remap_table */'
-               print ''
-
-               print ''
-               print 'static const char _mesa_function_pool[] ='
-
-               # output string pool
-               index = 0;
-               for f in api.functionIterateAll():
-                       pool_indices[f] = index
-
-                       spec = get_function_spec(f)
-
-                       # a function has either assigned offset, fixed offset,
-                       # or no offset
-                       if f.assign_offset:
-                               comments = "will be remapped"
-                       elif f.offset > 0:
-                               comments = "offset %d" % f.offset
-                       else:
-                               comments = "dynamic"
-
-                       print '   /* _mesa_function_pool[%d]: %s (%s) */' \
-                                       % (index, f.name, comments)
-                       for line in spec:
-                               print '   "%s\\0"' % line
-                               index += len(line) + 1
-               print '   ;'
-               print ''
-
-               print '/* these functions need to be remapped */'
-               print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {'
-               # output all functions that need to be remapped
-               # iterate by offsets so that they are sorted by remap indices
-               for f in api.functionIterateByOffset():
-                       if not f.assign_offset:
-                               continue
-                       print '   { %5d, %s_remap_index },' \
-                                       % (pool_indices[f], f.name)
-               print '   {    -1, -1 }'
-               print '};'
-               print ''
-
-               # collect functions by versions/extensions
-               extension_functions = {}
-               abi_extensions = []
-               for f in api.functionIterateAll():
-                       for n in f.entry_points:
-                               category, num = api.get_category_for_name(n)
-                               # consider only GL_VERSION_X_Y or extensions
-                               c = gl_XML.real_category_name(category)
-                               if c.startswith("GL_"):
-                                       if not extension_functions.has_key(c):
-                                               extension_functions[c] = []
-                                       extension_functions[c].append(f)
-                                       # remember the ext names of the ABI
-                                       if (f.is_abi() and n == f.name and
-                                               c not in abi_extensions):
-                                               abi_extensions.append(c)
-               # ignore the ABI itself
-               for ext in abi_extensions:
-                       extension_functions.pop(ext)
-
-               extensions = extension_functions.keys()
-               extensions.sort()
-
-               # output ABI functions that have alternative names (with ext suffix)
-               print '/* these functions are in the ABI, but have alternative names */'
-               print 'static const struct gl_function_remap MESA_alt_functions[] = {'
-               for ext in extensions:
-                       funcs = []
-                       for f in extension_functions[ext]:
-                               # test if the function is in the ABI and has alt names
-                               if f.is_abi() and len(f.entry_points) > 1:
-                                       funcs.append(f)
-                       if not funcs:
-                               continue
-                       print '   /* from %s */' % ext
-                       for f in funcs:
-                               print '   { %5d, _gloffset_%s },' \
-                                               % (pool_indices[f], f.name)
-               print '   {    -1, -1 }'
-               print '};'
-               print ''
-               return
+    def __init__(self):
+        gl_XML.gl_print_base.__init__(self)
+
+        self.name = "remap_helper.py (from Mesa)"
+        self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
+        return
+
+
+    def printRealHeader(self):
+        print '#include "main/dispatch.h"'
+        print '#include "main/remap.h"'
+        print ''
+        return
+
+
+    def printBody(self, api):
+        pool_indices = {}
+
+        print '/* this is internal to remap.c */'
+        print '#ifndef need_MESA_remap_table'
+        print '#error Only remap.c should include this file!'
+        print '#endif /* need_MESA_remap_table */'
+        print ''
+
+        print ''
+        print 'static const char _mesa_function_pool[] ='
+
+        # output string pool
+        index = 0;
+        for f in api.functionIterateAll():
+            pool_indices[f] = index
+
+            spec = get_function_spec(f)
+
+            # a function has either assigned offset, fixed offset,
+            # or no offset
+            if f.assign_offset:
+                comments = "will be remapped"
+            elif f.offset > 0:
+                comments = "offset %d" % f.offset
+            else:
+                comments = "dynamic"
+
+            print '   /* _mesa_function_pool[%d]: %s (%s) */' \
+                            % (index, f.name, comments)
+            for line in spec:
+                print '   "%s\\0"' % line
+                index += len(line) + 1
+        print '   ;'
+        print ''
+
+        print '/* these functions need to be remapped */'
+        print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {'
+        # output all functions that need to be remapped
+        # iterate by offsets so that they are sorted by remap indices
+        for f in api.functionIterateByOffset():
+            if not f.assign_offset:
+                continue
+            print '   { %5d, %s_remap_index },' \
+                            % (pool_indices[f], f.name)
+        print '   {    -1, -1 }'
+        print '};'
+        print ''
+
+        # collect functions by versions/extensions
+        extension_functions = {}
+        abi_extensions = []
+        for f in api.functionIterateAll():
+            for n in f.entry_points:
+                category, num = api.get_category_for_name(n)
+                # consider only GL_VERSION_X_Y or extensions
+                c = gl_XML.real_category_name(category)
+                if c.startswith("GL_"):
+                    if not extension_functions.has_key(c):
+                        extension_functions[c] = []
+                    extension_functions[c].append(f)
+                    # remember the ext names of the ABI
+                    if (f.is_abi() and n == f.name and
+                            c not in abi_extensions):
+                        abi_extensions.append(c)
+        # ignore the ABI itself
+        for ext in abi_extensions:
+            extension_functions.pop(ext)
+
+        extensions = extension_functions.keys()
+        extensions.sort()
+
+        # output ABI functions that have alternative names (with ext suffix)
+        print '/* these functions are in the ABI, but have alternative names */'
+        print 'static const struct gl_function_remap MESA_alt_functions[] = {'
+        for ext in extensions:
+            funcs = []
+            for f in extension_functions[ext]:
+                # test if the function is in the ABI and has alt names
+                if f.is_abi() and len(f.entry_points) > 1:
+                    funcs.append(f)
+            if not funcs:
+                continue
+            print '   /* from %s */' % ext
+            for f in funcs:
+                print '   { %5d, _gloffset_%s },' \
+                                % (pool_indices[f], f.name)
+        print '   {    -1, -1 }'
+        print '};'
+        print ''
+        return
 
 
 def show_usage():
-       print "Usage: %s [-f input_file_name] [-c ver]" % sys.argv[0]
-       print "    -c ver    Version can be 'es1' or 'es2'."
-       sys.exit(1)
+    print "Usage: %s [-f input_file_name] [-c ver]" % sys.argv[0]
+    print "    -c ver    Version can be 'es1' or 'es2'."
+    sys.exit(1)
 
 if __name__ == '__main__':
-       file_name = "gl_API.xml"
+    file_name = "gl_API.xml"
 
-       try:
-               (args, trail) = getopt.getopt(sys.argv[1:], "f:c:")
-       except Exception,e:
-               show_usage()
+    try:
+        (args, trail) = getopt.getopt(sys.argv[1:], "f:c:")
+    except Exception,e:
+        show_usage()
 
-       es = None
-       for (arg,val) in args:
-               if arg == "-f":
-                       file_name = val
-               elif arg == "-c":
-                       es = val
+    es = None
+    for (arg,val) in args:
+        if arg == "-f":
+            file_name = val
+        elif arg == "-c":
+            es = val
 
-       api = gl_XML.parse_GL_API( file_name )
+    api = gl_XML.parse_GL_API( file_name )
 
-       if es is not None:
-               import gles_api
+    if es is not None:
+        import gles_api
 
-               api_map = {
-                       'es1': gles_api.es1_api,
-                       'es2': gles_api.es2_api,
-               }
+        api_map = {
+                'es1': gles_api.es1_api,
+                'es2': gles_api.es2_api,
+        }
 
-               api.filter_functions(api_map[es])
+        api.filter_functions(api_map[es])
 
-       printer = PrintGlRemap()
-       printer.Print( api )
+    printer = PrintGlRemap()
+    printer.Print( api )
index 7836b2739aa55378bbf91a867e88adfc23b183b7..6cc71cbf91f921483e2b2c82b970a2ac02cdc284 100644 (file)
 import string, copy
 
 class type_node:
-       def __init__(self):
-               self.pointer = 0  # bool
-               self.const = 0    # bool
-               self.signed = 1   # bool
-               self.integer = 1  # bool
+    def __init__(self):
+        self.pointer = 0  # bool
+        self.const = 0    # bool
+        self.signed = 1   # bool
+        self.integer = 1  # bool
 
-               # If elements is set to non-zero, then field is an array.
-               self.elements = 0
+        # If elements is set to non-zero, then field is an array.
+        self.elements = 0
 
-               self.name = None
-               self.size = 0     # type's size in bytes
-               return
+        self.name = None
+        self.size = 0     # type's size in bytes
+        return
 
 
-       def string(self):
-               """Return string representation of this type_node."""
-               s = ""
-               
-               if self.pointer:
-                       s = "* "
+    def string(self):
+        """Return string representation of this type_node."""
+        s = ""
 
-               if self.const:
-                       s += "const "
+        if self.pointer:
+            s = "* "
 
-               if not self.pointer:
-                       if self.integer:
-                               if self.signed:
-                                       s += "signed "
-                               else:
-                                       s += "unsigned "
+        if self.const:
+            s += "const "
 
-                       if self.name:
-                               s += "%s " % (self.name)
+        if not self.pointer:
+            if self.integer:
+                if self.signed:
+                    s += "signed "
+                else:
+                    s += "unsigned "
 
-               return s
+            if self.name:
+                s += "%s " % (self.name)
+
+        return s
 
 
 class type_table:
-       def __init__(self):
-               self.types_by_name = {}
-               return
+    def __init__(self):
+        self.types_by_name = {}
+        return
 
 
-       def add_type(self, type_expr):
-               self.types_by_name[ type_expr.get_base_name() ] = type_expr
-               return
+    def add_type(self, type_expr):
+        self.types_by_name[ type_expr.get_base_name() ] = type_expr
+        return
 
 
-       def find_type(self, name):
-               if name in self.types_by_name:
-                       return self.types_by_name[ name ]
-               else:
-                       return None
+    def find_type(self, name):
+        if name in self.types_by_name:
+            return self.types_by_name[ name ]
+        else:
+            return None
 
 
 def create_initial_types():
-       tt = type_table()
-
-       basic_types = [
-               ("char",   1, 1),
-               ("short",  2, 1),
-               ("int",    4, 1),
-               ("long",   4, 1),
-               ("float",  4, 0),
-               ("double", 8, 0),
-               ("enum",   4, 1)
-       ]
-
-       for (type_name, type_size, integer) in basic_types:
-               te = type_expression(None)
-               tn = type_node()
-               tn.name = type_name
-               tn.size = type_size
-               tn.integer = integer
-               te.expr.append(tn)
-               tt.add_type( te )
-
-       type_expression.built_in_types = tt
-       return
+    tt = type_table()
+
+    basic_types = [
+            ("char",   1, 1),
+            ("short",  2, 1),
+            ("int",    4, 1),
+            ("long",   4, 1),
+            ("float",  4, 0),
+            ("double", 8, 0),
+            ("enum",   4, 1)
+    ]
+
+    for (type_name, type_size, integer) in basic_types:
+        te = type_expression(None)
+        tn = type_node()
+        tn.name = type_name
+        tn.size = type_size
+        tn.integer = integer
+        te.expr.append(tn)
+        tt.add_type( te )
+
+    type_expression.built_in_types = tt
+    return
 
 
 class type_expression:
-       built_in_types = None
+    built_in_types = None
+
+    def __init__(self, type_string, extra_types = None):
+        self.expr = []
 
-       def __init__(self, type_string, extra_types = None):
-               self.expr = []
+        if not type_string:
+            return
 
-               if not type_string:
-                       return
+        self.original_string = type_string
 
-               self.original_string = type_string
+        if not type_expression.built_in_types:
+            raise RuntimeError("create_initial_types must be called before creating type_expression objects.")
 
-               if not type_expression.built_in_types:
-                       raise RuntimeError("create_initial_types must be called before creating type_expression objects.")
+        # Replace '*' with ' * ' in type_string.  Then, split the string
+        # into tokens, separated by spaces.
+        tokens = string.split( string.replace( type_string, "*", " * " ) )
 
-               # Replace '*' with ' * ' in type_string.  Then, split the string
-               # into tokens, separated by spaces.
-               tokens = string.split( string.replace( type_string, "*", " * " ) )
+        const = 0
+        t = None
+        signed = 0
+        unsigned = 0
 
-               const = 0
-               t = None
-               signed = 0
-               unsigned = 0
+        for i in tokens:
+            if i == "const":
+                if t and t.pointer:
+                    t.const = 1
+                else:
+                    const = 1
+            elif i == "signed":
+                signed = 1
+            elif i == "unsigned":
+                unsigned = 1
+            elif i == "*":
+                # This is a quirky special-case because of the
+                # way the C works for types.  If 'unsigned' is
+                # specified all by itself, it is treated the
+                # same as "unsigned int".
 
-               for i in tokens:
-                       if i == "const":
-                               if t and t.pointer:
-                                       t.const = 1
-                               else:
-                                       const = 1
-                       elif i == "signed":
-                               signed = 1
-                       elif i == "unsigned":
-                               unsigned = 1
-                       elif i == "*":
-                               # This is a quirky special-case because of the
-                               # way the C works for types.  If 'unsigned' is
-                               # specified all by itself, it is treated the
-                               # same as "unsigned int".
+                if unsigned:
+                    self.set_base_type( "int", signed, unsigned, const, extra_types )
+                    const = 0
+                    signed = 0
+                    unsigned = 0
 
-                               if unsigned:
-                                       self.set_base_type( "int", signed, unsigned, const, extra_types )
-                                       const = 0
-                                       signed = 0
-                                       unsigned = 0
+                if not self.expr:
+                    raise RuntimeError("Invalid type expression (dangling pointer)")
 
-                               if not self.expr:
-                                       raise RuntimeError("Invalid type expression (dangling pointer)")
+                if signed:
+                    raise RuntimeError("Invalid type expression (signed / unsigned applied to pointer)")
 
-                               if signed:
-                                       raise RuntimeError("Invalid type expression (signed / unsigned applied to pointer)")
+                t = type_node()
+                t.pointer = 1
+                self.expr.append( t )
+            else:
+                if self.expr:
+                    raise RuntimeError('Invalid type expression (garbage after pointer qualifier -> "%s")' % (self.original_string))
 
-                               t = type_node()
-                               t.pointer = 1
-                               self.expr.append( t )
-                       else:
-                               if self.expr:
-                                       raise RuntimeError('Invalid type expression (garbage after pointer qualifier -> "%s")' % (self.original_string))
+                self.set_base_type( i, signed, unsigned, const, extra_types )
+                const = 0
+                signed = 0
+                unsigned = 0
 
-                               self.set_base_type( i, signed, unsigned, const, extra_types )
-                               const = 0
-                               signed = 0
-                               unsigned = 0
+            if signed and unsigned:
+                raise RuntimeError("Invalid type expression (both signed and unsigned specified)")
 
-                       if signed and unsigned:
-                               raise RuntimeError("Invalid type expression (both signed and unsigned specified)")
-                               
 
-               if const:
-                       raise RuntimeError("Invalid type expression (dangling const)")
+        if const:
+            raise RuntimeError("Invalid type expression (dangling const)")
 
-               if unsigned:
-                       raise RuntimeError("Invalid type expression (dangling signed)")
+        if unsigned:
+            raise RuntimeError("Invalid type expression (dangling signed)")
 
-               if signed:
-                       raise RuntimeError("Invalid type expression (dangling unsigned)")
+        if signed:
+            raise RuntimeError("Invalid type expression (dangling unsigned)")
 
-               return
+        return
 
 
-       def set_base_type(self, type_name, signed, unsigned, const, extra_types):
-               te = type_expression.built_in_types.find_type( type_name )
-               if not te:
-                       te = extra_types.find_type( type_name )
+    def set_base_type(self, type_name, signed, unsigned, const, extra_types):
+        te = type_expression.built_in_types.find_type( type_name )
+        if not te:
+            te = extra_types.find_type( type_name )
 
-               if not te:
-                       raise RuntimeError('Unknown base type "%s".' % (type_name))
+        if not te:
+            raise RuntimeError('Unknown base type "%s".' % (type_name))
 
-               self.expr = copy.deepcopy(te.expr)
+        self.expr = copy.deepcopy(te.expr)
 
-               t = self.expr[ len(self.expr) - 1 ]
-               t.const = const
-               if signed:
-                       t.signed = 1
-               elif unsigned:
-                       t.signed = 0
+        t = self.expr[ len(self.expr) - 1 ]
+        t.const = const
+        if signed:
+            t.signed = 1
+        elif unsigned:
+            t.signed = 0
 
 
-       def set_base_type_node(self, tn):
-               self.expr = [tn]
-               return
+    def set_base_type_node(self, tn):
+        self.expr = [tn]
+        return
 
 
-       def set_elements(self, count):
-               tn = self.expr[0]
+    def set_elements(self, count):
+        tn = self.expr[0]
 
-               tn.elements = count
-               return
+        tn.elements = count
+        return
 
 
-       def string(self):
-               s = ""
-               for t in self.expr:
-                       s += t.string()
+    def string(self):
+        s = ""
+        for t in self.expr:
+            s += t.string()
 
-               return s
+        return s
 
 
-       def get_base_type_node(self):
-               return self.expr[0]
+    def get_base_type_node(self):
+        return self.expr[0]
 
 
-       def get_base_name(self):
-               if len(self.expr):
-                       return self.expr[0].name
-               else:
-                       return None
+    def get_base_name(self):
+        if len(self.expr):
+            return self.expr[0].name
+        else:
+            return None
 
 
-       def get_element_size(self):
-               tn = self.expr[0]
+    def get_element_size(self):
+        tn = self.expr[0]
 
-               if tn.elements:
-                       return tn.elements * tn.size
-               else:
-                       return tn.size
+        if tn.elements:
+            return tn.elements * tn.size
+        else:
+            return tn.size
 
 
-       def get_element_count(self):
-               tn = self.expr[0]
-               return tn.elements
+    def get_element_count(self):
+        tn = self.expr[0]
+        return tn.elements
 
 
-       def get_stack_size(self):
-               tn = self.expr[ -1 ]
+    def get_stack_size(self):
+        tn = self.expr[ -1 ]
 
-               if tn.elements or tn.pointer:
-                       return 4
-               elif not tn.integer:
-                       return tn.size
-               else:
-                       return 4
+        if tn.elements or tn.pointer:
+            return 4
+        elif not tn.integer:
+            return tn.size
+        else:
+            return 4
 
 
-       def is_pointer(self):
-               tn = self.expr[ -1 ]
-               return tn.pointer
+    def is_pointer(self):
+        tn = self.expr[ -1 ]
+        return tn.pointer
 
 
-       def format_string(self):
-               tn = self.expr[ -1 ]
-               if tn.pointer:
-                       return "%p"
-               elif not tn.integer:
-                       return "%f"
-               else:
-                       return "%d"
+    def format_string(self):
+        tn = self.expr[ -1 ]
+        if tn.pointer:
+            return "%p"
+        elif not tn.integer:
+            return "%f"
+        else:
+            return "%d"
 
 
 
 if __name__ == '__main__':
-       
-       types_to_try = [ "int", "int *", "const int *", "int * const", "const int * const", \
-                        "unsigned * const *", \
-                        "float", "const double", "double * const"]
 
-       create_initial_types()
+    types_to_try = [ "int", "int *", "const int *", "int * const", "const int * const", \
+                     "unsigned * const *", \
+                     "float", "const double", "double * const"]
+
+    create_initial_types()
 
-       for t in types_to_try:
-               print 'Trying "%s"...' % (t)
-               te = type_expression( t )
-               print 'Got "%s" (%u, %u).' % (te.string(), te.get_stack_size(), te.get_element_size())
+    for t in types_to_try:
+        print 'Trying "%s"...' % (t)
+        te = type_expression( t )
+        print 'Got "%s" (%u, %u).' % (te.string(), te.get_stack_size(), te.get_element_size())