summaryrefslogtreecommitdiff
path: root/src/mesa/glapi/glX_proto_size.py
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2005-01-27 01:08:48 +0000
committerIan Romanick <idr@us.ibm.com>2005-01-27 01:08:48 +0000
commit5aa6dc329b983b95071700c3af9353e3b35454d9 (patch)
tree89506c88a9668aca519aa79d1654a1144d724f71 /src/mesa/glapi/glX_proto_size.py
parent5b0dd893704157cb8f9c42ce4a32a9d3e2a7edef (diff)
The 'mode' setting of a function within an 'enum' element is now used.
Parameters to glX_proto_size.py are now used to determine whether to emit either get-type function, set-type functions, or both. When only get-type functions are emitted, they can optionally alias set-type functions. This would be useful if, for example, the two types were in different source files. The real work to implement this is in SizeStubFunctionIterator class. All of the logic for which functions to iterate and in which order is implemented there.
Diffstat (limited to 'src/mesa/glapi/glX_proto_size.py')
-rw-r--r--src/mesa/glapi/glX_proto_size.py137
1 files changed, 109 insertions, 28 deletions
diff --git a/src/mesa/glapi/glX_proto_size.py b/src/mesa/glapi/glX_proto_size.py
index 883f4827e1..ecab65d3f0 100644
--- a/src/mesa/glapi/glX_proto_size.py
+++ b/src/mesa/glapi/glX_proto_size.py
@@ -35,14 +35,89 @@ import license
import sys, getopt, copy
-class PrintGlxSizeStubs_c(glX_XML.GlxProto):
- def __init__(self):
+class SizeStubFunctionIterator:
+ """Iterate over functions that need "size" information.
+
+ Iterate over the functions that have variable sized data. First the
+ "set"-type functions are iterated followed by the "get"-type
+ functions.
+ """
+
+ def __init__(self, context):
+ self.data = []
+ self.index = 0
+
+ set_functions = []
+ get_functions = []
+ extra_data = []
+
+ for f in gl_XML.glFunctionIterator(context):
+ if f.fn_offset < 0: break
+
+ if context.glx_enum_functions.has_key(f.name):
+ ef = context.glx_enum_functions[f.name]
+ if ef.is_set():
+ set_functions.append(f)
+ else:
+ get_functions.append(f)
+
+
+ if (context.which_functions & PrintGlxSizeStubs_c.do_set) != 0:
+ self.data += set_functions
+ elif context.get_alias_set:
+ extra_data = set_functions
+
+ if (context.which_functions & PrintGlxSizeStubs_c.do_get) != 0:
+ self.data += get_functions
+
+
+ for f in extra_data + self.data:
+ sig = context.glx_enum_functions[f.name].signature()
+
+ if not context.glx_enum_sigs.has_key(sig):
+ context.glx_enum_sigs[sig] = f.name;
+
+ return
+
+
+ def __iter__(self):
+ return self
+
+
+ def next(self):
+ if self.index == len(self.data):
+ raise StopIteration
+
+ f = self.data[ self.index ]
+ self.index += 1
+
+ return f
+
+
+class PrintGlxSizeStubs_common(glX_XML.GlxProto):
+ do_get = (1 << 0)
+ do_set = (1 << 1)
+ do_get_alias_set = (1 << 2)
+
+ def __init__(self, which_functions):
glX_XML.GlxProto.__init__(self)
self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
self.aliases = []
self.glx_enum_sigs = {}
self.name = "glX_proto_size.py (from Mesa)"
+ self.which_functions = which_functions
+
+ if (((which_functions & PrintGlxSizeStubs_common.do_set) != 0) and ((which_functions & PrintGlxSizeStubs_common.do_get) != 0)) or ((which_functions & PrintGlxSizeStubs_common.do_get_alias_set) != 0):
+ self.get_alias_set = 1
+ else:
+ self.get_alias_set = 0
+
+ def functionIterator(self):
+ return SizeStubFunctionIterator(self)
+
+
+class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
def printRealHeader(self):
print ''
print '#include <GL/gl.h>'
@@ -71,33 +146,25 @@ class PrintGlxSizeStubs_c(glX_XML.GlxProto):
print ''
print ''
+
def printRealFooter(self):
for a in self.aliases:
print a
+
def printFunction(self, f):
- if self.glx_enum_functions.has_key(f.name):
- ef = self.glx_enum_functions[f.name]
+ ef = self.glx_enum_functions[f.name]
+ n = self.glx_enum_sigs[ ef.signature() ];
- sig = ef.signature();
- if self.glx_enum_sigs.has_key(sig):
- n = self.glx_enum_sigs[sig];
- a = 'ALIAS( %s, %s )' % (f.name, n)
- self.aliases.append(a)
- else:
- ef.Print( f.name )
- self.glx_enum_sigs[sig] = f.name;
+ if n != f.name:
+ a = 'ALIAS( %s, %s )' % (f.name, n)
+ self.aliases.append(a)
+ else:
+ ef.Print( f.name )
-class PrintGlxSizeStubs_h(glX_XML.GlxProto):
- def __init__(self):
- glX_XML.GlxProto.__init__(self)
- self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
- self.aliases = []
- self.glx_enum_sigs = {}
- self.name = "glX_proto_size.py (from Mesa)"
-
+class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
def printRealHeader(self):
print """
/**
@@ -128,13 +195,19 @@ class PrintGlxSizeStubs_h(glX_XML.GlxProto):
def printFunction(self, f):
- if self.glx_enum_functions.has_key(f.name):
- ef = self.glx_enum_functions[f.name]
- print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (f.name)
+ ef = self.glx_enum_functions[f.name]
+ print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (f.name)
def show_usage():
- print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+ 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 " --get-alias-set When only 'get'-type functions are emitted, allow them"
+ print " to be aliases to 'set'-type funcitons."
+ print ""
+ print "By default, both 'get' and 'set'-type functions are emitted."
sys.exit(1)
@@ -142,21 +215,29 @@ if __name__ == '__main__':
file_name = "gl_API.xml"
try:
- (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
+ (args, trail) = getopt.getopt(sys.argv[1:], "f:m:", ["only-get", "only-set", "get-alias-set"])
except Exception,e:
show_usage()
- mode = "proto"
+ mode = 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 == "--get-alias-set":
+ which_functions |= PrintGlxSizeStubs_common.do_get_alias_set
if mode == "size_c":
- dh = PrintGlxSizeStubs_c()
+ dh = PrintGlxSizeStubs_c( which_functions )
elif mode == "size_h":
- dh = PrintGlxSizeStubs_h()
+ dh = PrintGlxSizeStubs_h( which_functions )
else:
show_usage()