]> git.tdb.fi Git - gldbg.git/commitdiff
Consolidate genwrap.py and genenum.py into generate.py
authorMikko Rasa <tdb@tdb.fi>
Tue, 15 Jun 2010 08:50:33 +0000 (08:50 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 15 Jun 2010 08:50:33 +0000 (08:50 +0000)
Add the temp directory to svn:ignore

Makefile
genenum.py [deleted file]
generate.py [new file with mode: 0755]
genwrap.py [deleted file]
gl.api [new file with mode: 0644]
gl.files [deleted file]
glx.api [new file with mode: 0644]
glx.files [deleted file]
source/enums.table.t [new file with mode: 0644]

index 41d812d7423f16a78d57300bf191571a4df85436..c1860bd4edd7b8b88e6a4534fc96b3b645a41149 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -73,11 +73,8 @@ temp/.created:
        mkdir -p temp
        touch $@
 
-gensrc/%: source/%.t gensrc/.created genwrap.py gl.files gl.tm gl.io gl.spec glx.files glx.tm glx.io glx.spec glxext.spec
-       python ./genwrap.py $< gl.files glx.files >$@
-
-gensrc/enums.table: gensrc/.created enum.spec glxenum.spec genenum.py
-       python ./genenum.py enum.spec=GL_ glxenum.spec=GLX_ >$@
+gensrc/%: source/%.t gensrc/.created generate.py gl.api gl.tm gl.io gl.spec glx.api glx.tm glx.io glx.spec glxext.spec
+       python ./generate.py $< gl.api glx.api >$@
 
 gensrc/.created:
        mkdir -p gensrc
diff --git a/genenum.py b/genenum.py
deleted file mode 100755 (executable)
index c41d37a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-# $Id$
-
-import sys
-
-enums = []
-
-cur_categ = None
-for fn in sys.argv[1:]:
-       prefix = "GL_"
-       if '=' in fn:
-               fn, prefix = fn.split('=', 1)
-       for line in open(fn):
-               line = line.strip()
-               if not line or line[0]=='#':
-                       continue
-               elif line[-1]==':':
-                       parts = line[:-1].split()
-                       if parts[1]=="enum":
-                               cur_categ = parts[0]
-               elif cur_categ:
-                       parts = line.split()
-                       if parts[0]=="use":
-                               enums.append([None, cur_categ, prefix+parts[2]])
-                       elif parts[1]=="=":
-                               try:
-                                       enums.append([int(parts[2], 0), cur_categ, prefix+parts[0]])
-                               except ValueError, e:
-                                       sys.stderr.write("Syntax error in %s: %s\n"%(fn, e))
-
-for e in enums:
-       if e[0] is None:
-               for n in enums:
-                       if n[2]==e[2] and n[0] is not None:
-                               e[0] = n[0]
-               if e[0] is None:
-                       sys.stderr.write("Could not find value for enum reference %s in category %s\n"%(e[2], e[1]))
-
-enums.sort(lambda x, y: cmp(x[0], y[0])*2+cmp(x[1], y[1]))
-
-'''categs = set([e[2] for e in enums])
-for c in categs:
-       print c, reduce(lambda x, y: x^y, [ord(c[i])*(1<<i) for i in range(len(c))])'''
-
-print "EnumInfo enums[] ="
-print "{"
-for e in enums:
-       if e[0] is not None:
-               print "\t{ 0x%X, \"%s\", \"%s\" },"%(e[0], e[1], e[2])
-print "\t{ 0, 0, 0 }"
-print "};"
-print "unsigned enum_count = %d;"%len(enums)
diff --git a/generate.py b/generate.py
new file mode 100755 (executable)
index 0000000..e30f6d1
--- /dev/null
@@ -0,0 +1,431 @@
+#!/usr/bin/python
+# $Id$
+
+import sys
+import os
+
+class InputFile:
+       def __init__(self, fn):
+               self.file = open(fn)
+
+       def __iter__(self):
+               for l in self.file:
+                       h = l.find("#")
+                       if h==0 or (h>0 and l[h-1].isspace()):
+                               l = l[:h]
+
+                       l = l.rstrip()
+                       if not l:
+                               continue
+
+                       yield l
+               
+
+def strip_name(name):
+       """Strips any vendor suffix and GL prefix from a name (but not GLX prefix)"""
+
+       suffix = ""
+       if name.endswith(" *"):
+               suffix = " *"
+               name = name[:-2]
+       elif name.endswith("Pointer"):
+               suffix = "Pointer"
+               name = name[:-7]
+
+       prefix = ""
+       if name.startswith("const "):
+               prefix = "const "
+               name = name[6:]
+
+       if name.startswith("GL") and not name.startswith("GLX"):
+               name = name[2:]
+       if name.endswith(("EXT", "ARB", "SGI", "IBM", "ATI")):
+               return prefix+name[:-3]+suffix
+       elif name.endswith("SGIX"):
+               return prefix+name[:-4]+suffix
+       elif name.endswith(("NV", "HP")):
+               return prefix+name[:-2]+suffix
+       else:
+               return prefix+name+suffix
+
+
+class Typemap:
+       def __init__(self, fn):
+               self.map = {}
+               for line in InputFile(fn):
+                       parts = [p.strip() for p in line.split(',')]
+                       if parts[3]=="*":
+                               parts[3] = parts[0]
+                       elif parts[3][-1]=='*' and parts[3][-2]!=' ':
+                               parts[3] = parts[3][:-1]+" *"
+                       self.map[tuple(parts[0:3])] = tuple(parts[3:6])
+
+       def wildcard_match(self, a, b):
+               if a=="*" or b=="*":
+                       return True
+               return a==b
+
+       def __getitem__(self, key):
+               try:
+                       return self.map[(key[0], "*", "*")]
+               except KeyError:
+                       for k, v in self.map.iteritems():
+                               if strip_name(k[0])==strip_name(key[0]) and self.wildcard_match(k[1], key[1]) and self.wildcard_match(k[2], key[2]):
+                                       return v
+                       raise KeyError, key
+
+       def update(self, other):
+               self.map.update(other.map)
+
+
+class IOmap:
+       def __init__(self, fn):
+               self.map = {}
+               self.map["void"] = None
+               for line in InputFile(fn):
+                       parts = [p.strip() for p in line.split(',')]
+                       self.map[parts[0]] = tuple(parts[1:])
+
+       def __getitem__(self, key):
+               return self.map[strip_name(key)]
+
+
+class Function:
+       class Parameter:
+               def __init__(self, func, name):
+                       self.func = func
+                       self.name = name
+                       self.type = None
+                       self.direction = "in"
+                       self.kind = "value"
+                       self.size = None
+                       self.ctype = None
+                       self.csize = None
+                       self.io = None
+
+               def set_type(self, type, dir, kind):
+                       self.type = type
+                       self.direction = dir
+                       self.kind = kind
+
+               def set_size(self, size):
+                       if type(size)==str and size.isdigit():
+                               self.size = int(size)
+                       else:
+                               self.size = size
+
+               def derive_ctype(self, typemap, iomap):
+                       m = typemap[(self.type, self.direction, self.kind)]
+                       self.ctype = m[0]
+                       if m[1]!="*":
+                               self.direction = m[1]
+                       if m[2]!="*":
+                               self.kind = m[2]
+                       self.base_ctype = self.ctype
+                       if self.kind=="value":
+                               if self.base_ctype.startswith("const "):
+                                       self.base_ctype = self.base_ctype[6:]
+                       else:
+                               if self.direction=="in":
+                                       self.ctype = "const "+self.ctype
+                               self.ctype = self.ctype+" *"
+                       self.io = iomap[self.base_ctype]
+
+               def derive_csize(self):
+                       if self.kind=="array" and self.size is not None:
+                               self.csize = None
+                               if type(self.size)==int:
+                                       self.csize = "%d*sizeof(%s)"%(self.size, self.base_ctype)
+                               elif self.size.startswith("COMPSIZE("):
+                                       self.csize = self.func.compsize(self.size[9:-1], self.base_ctype)
+                               elif self.size=="pname":
+                                       self.csize = "paramsize(pname)*sizeof(%s)"%self.base_ctype
+                               else:
+                                       s = self.func.get_param(self.size.split('*')[0])
+                                       if (s.type=="SizeI" or s.type.endswith("Int32") or s.type.startswith("BufferSize")):
+                                               if s.kind=="value":
+                                                       self.csize = "%s"%self.size
+                                                       if self.func.name.startswith("glUniformMatrix") and self.func.name[16]!='x':
+                                                               self.csize += "*%d"%(int(self.func.name[15])**2)
+                                                       elif self.func.name.startswith("glUniform") and self.func.name[9].isdigit():
+                                                               self.csize += "*%s"%self.func.name[9]
+                                                       if strip_name(self.base_ctype)!="void":
+                                                               self.csize += "*sizeof(%s)"%self.base_ctype
+                                               elif s.kind=="array" and s.size==1:
+                                                       self.csize = "*%s"%s.name
+                                       if not self.csize:
+                                               sys.stderr.write("Could not determine size for array parameter '%s[%s]' of function '%s'\n"%(self.name, self.size, self.func.name))
+                       elif self.kind=="reference":
+                               self.csize = "sizeof(%s)"%self.base_ctype
+
+       def __init__(self, name, pnames):
+               self.name = name
+               self.ret = Function.Parameter(self, "ret")
+               self.params = [Function.Parameter(self, n) for n in pnames]
+               self.category = None
+
+       def get_param(self, pname):
+               for p in self.params:
+                       if p.name==pname:
+                               return p
+               raise KeyError, pname
+
+       def set_category(self, cat):
+               self.category = cat
+
+       def compsize(self, size, btype):
+               if not size:
+                       return
+
+               res = ""
+               have_type = False
+               for c in size.replace(',', '/').split('/'):
+                       param = self.get_param(c)
+                       if not param:
+                               sys.stderr.write("Compsize '%s' for function '%s' failed: No parameter '%s'\n"%(size, self.name, c))
+                               return
+
+                       if res:
+                               res += "*"
+
+                       cn = strip_name(param.type)
+                       if cn.endswith("Type"):
+                               res += "typesize(%s)"%param.name
+                               have_type = True
+                       elif cn.endswith("Format"):
+                               res += "formatsize(%s)"%param.name
+                       elif param.name=="pname" or cn.endswith("Parameter") or (param.name=="target" and cn=="enum"):
+                               res += "paramsize(%s)"%param.name
+                       elif param.name=="buffer" and cn=="enum":
+                               res += "buffersize(%s)"%param.name
+                       elif (cn=="SizeI" or cn.endswith("Int32")) and not param.size:
+                               res += param.name
+                       else:
+                               sys.stderr.write("Compsize '%s' for function '%s' failed: Parameter '%s' has unknown type '%s'\n"%(size, self.name, param.name, param.type))
+                               return
+               if not have_type:
+                       res += "*sizeof(%s)"%btype
+               return res
+
+       def finalize(self, typemap, iomap):
+               self.ret.derive_ctype(typemap, iomap)
+               for p in self.params:
+                       p.derive_ctype(typemap, iomap)
+               for p in self.params:
+                       p.derive_csize()
+
+
+class Enum:
+       def __init__(self, name, category, value):
+               self.name = name
+               self.category = category
+               self.value = value
+
+
+class Template:
+       def __init__(self, fn):
+               self.mode = "functions"
+               self.sections = []
+               self.handcode = []
+
+               literal = True
+               text = ""
+               for line in InputFile(fn):
+                       if line[0]==':':
+                               if not literal and text:
+                                       self.add_section(text, literal)
+                                       text = ""
+                               text += line[1:]+"\n"
+                               literal = True
+                       elif line[0]=='!':
+                               parts = line[1:].split()
+                               if parts[0]=="handcode":
+                                       self.handcode.append(parts[1])
+                               elif parts[0]=="mode":
+                                       self.mode = parts[1]
+                               else:
+                                       sys.stderr.write("Unknown keyword '%s'\n"%parts[0])
+                       else:
+                               if literal and text:
+                                       self.add_section(text, literal)
+                                       text = ""
+                               text += line+"\n"
+                               literal = False
+               if text:
+                       self.add_section(text, literal)
+
+       def add_section(self, text, literal):
+               if literal:
+                       self.sections.append(text)
+               else:
+                       self.sections.append(compile(text, "-", "exec"))
+
+       def write(self, str, *args):
+               sys.stdout.write(str%args)
+
+       def writeln(self, str, *args):
+               sys.stdout.write(str%args+"\n")
+
+       def process_function(self, code, func):
+               if func.name in self.handcode:
+                       return
+
+               globals = {
+                       "w": self.write,
+                       "wl": self.writeln,
+                       "func": func,
+                       "ret": func.ret,
+                       "params": func.params
+               }
+               eval(code, globals)
+
+       def process_enum(self, code, enum):
+               if enum.value is None:
+                       return
+
+               globals = {
+                       "w": self.write,
+                       "wl": self.writeln,
+                       "enum": enum
+               }
+               eval(code, globals)
+
+       def process_sections(self, objects, handler):
+               for sect in self.sections:
+                       if type(sect)==str:
+                               print sect
+                       else:
+                               for obj in objects:
+                                       handler(sect, obj)
+
+       def process(self, apis):
+               if self.mode=="functions":
+                       functions = []
+                       for api in apis:
+                               typemap = Typemap(api.typemap)
+                               iomap = IOmap(api.iomap)
+                               for spec in api.specs:
+                                       funcs = read_spec(spec, api.prefix)
+                                       funcs = [f for f in funcs if f.name not in api.ignore_funcs and f.category not in api.ignore_categs]
+                                       for func in funcs:
+                                               func.finalize(typemap, iomap)
+                                       names = [f.name for f in funcs]
+                                       functions = [f for f in functions if f.name not in names]+funcs
+                       self.process_sections(functions, self.process_function)
+               elif self.mode=="enums":
+                       enums = []
+                       for api in apis:
+                               for spec in api.enumspecs:
+                                       ens = read_enums(spec, api.enumprefix)
+                                       enums += ens
+                       enums.sort(lambda x, y: cmp(x.value, y.value)*2+cmp(x.category, y.category))
+                       self.process_sections(enums, self.process_enum)
+
+
+class Api:
+       def __init__(self, fn):
+               self.typemap = None
+               self.iomap = None
+               self.specs = []
+               self.prefix = None
+               self.enumspecs = []
+               self.enumprefix = None
+               self.ignore_categs = []
+               self.ignore_funcs = []
+
+               for line in InputFile(fn):
+                       parts = line.split()
+                       if parts[0]=="typemap":
+                               self.typemap = parts[1]
+                       elif parts[0]=="iomap":
+                               self.iomap = parts[1]
+                       elif parts[0]=="spec":
+                               self.specs.append(parts[1])
+                       elif parts[0]=="prefix":
+                               self.prefix = parts[1]
+                       elif parts[0]=="enumspec":
+                               self.enumspecs.append(parts[1])
+                       elif parts[0]=="enumprefix":
+                               self.enumprefix = parts[1]
+                       elif parts[0]=="ignore":
+                               if parts[1]=="category":
+                                       self.ignore_categs.append(parts[2])
+                               elif parts[1]=="function":
+                                       self.ignore_funcs.append(parts[2])
+                       else:
+                               sys.stderr.write("Unknown keyword '%s'\n", parts[0])
+
+
+def read_spec(fn, prefix):
+       funcs = []
+       cur_func = None
+
+       for line in InputFile(fn):
+               if line.find(':')>=0:
+                       continue
+               elif line[0]=='\t' and cur_func:
+                       parts = line.split()
+                       if parts[0]=="return":
+                               cur_func.ret.set_type(parts[1], "out", "value")
+                       elif parts[0]=="param":
+                               bracket = parts[4].find('[')
+                               if bracket>=0:
+                                       parts.insert(5, parts[4][bracket:])
+                                       parts[4] = parts[4][:bracket]
+
+                               param = cur_func.get_param(parts[1])
+                               param.set_type(parts[2], parts[3], parts[4])
+                               if len(parts)==6 or (len(parts)>6 and parts[6]!="retained"):
+                                       param.set_size(parts[5][1:-1])
+                       elif parts[0]=="category":
+                               cur_func.set_category(parts[1])
+                       elif parts[0]=="glxvendorglx" and cur_func.category=="glx":
+                               cur_func.set_category("glxext")
+               else:
+                       paren = line.find('(')
+                       if paren>0:
+                               cparen = line.rfind(')')
+                               if cparen>paren+1:
+                                       pnames = [n.strip() for n in line[paren+1:cparen].split(",")]
+                               else:
+                                       pnames = []
+                               cur_func = Function(prefix+line[:paren], pnames)
+                               funcs.append(cur_func)
+
+       return funcs
+
+def read_enums(fn, prefix):
+       enums = []
+       cur_categ = []
+
+       for line in InputFile(fn):
+               if ':' in line:
+                       parts = line[:line.find(':')].split()
+                       if len(parts)==2 and parts[1]=="enum":
+                               cur_categ = parts[0]
+               elif cur_categ:
+                       parts = line.split()
+                       if parts[0]=="use":
+                               enums.append(Enum(prefix+parts[2], cur_categ, None))
+                       elif parts[1]=="=":
+                               try:
+                                       enums.append(Enum(prefix+parts[0], cur_categ, int(parts[2], 0)))
+                               except ValueError, e:
+                                       sys.stderr.write("Syntax error in %s: %s\n"%(fn, e))
+
+       for e in enums:
+               if e.value is None:
+                       for n in enums:
+                               if n.name==e.name and n.value is not None:
+                                       e.value = n.value
+                       if e.value is None:
+                               sys.stderr.write("Could not find value for enum reference %s in category %s\n"%(e.name, e.category))
+
+       return enums
+
+template = Template(sys.argv[1])
+apis = []
+for i in sys.argv[2:]:
+       apis.append(Api(i))
+
+template.process(apis)
diff --git a/genwrap.py b/genwrap.py
deleted file mode 100755 (executable)
index 07dd914..0000000
+++ /dev/null
@@ -1,354 +0,0 @@
-#!/usr/bin/python
-# $Id$
-
-import sys
-import os
-
-class InputFile:
-       def __init__(self, fn):
-               self.file = open(fn)
-
-       def __iter__(self):
-               for l in self.file:
-                       h = l.find("#")
-                       if h==0 or (h>0 and l[h-1].isspace()):
-                               l = l[:h]
-
-                       l = l.rstrip()
-                       if not l:
-                               continue
-
-                       yield l
-               
-
-def strip_name(name):
-       """Strips any vendor suffix and GL prefix from a name (but not GLX prefix)"""
-
-       suffix = ""
-       if name.endswith(" *"):
-               suffix = " *"
-               name = name[:-2]
-       elif name.endswith("Pointer"):
-               suffix = "Pointer"
-               name = name[:-7]
-
-       prefix = ""
-       if name.startswith("const "):
-               prefix = "const "
-               name = name[6:]
-
-       if name.startswith("GL") and not name.startswith("GLX"):
-               name = name[2:]
-       if name.endswith(("EXT", "ARB", "SGI", "IBM", "ATI")):
-               return prefix+name[:-3]+suffix
-       elif name.endswith("SGIX"):
-               return prefix+name[:-4]+suffix
-       elif name.endswith(("NV", "HP")):
-               return prefix+name[:-2]+suffix
-       else:
-               return prefix+name+suffix
-
-
-class Typemap:
-       def __init__(self, fn):
-               self.map = {}
-               for line in InputFile(fn):
-                       parts = [p.strip() for p in line.split(',')]
-                       if parts[3]=="*":
-                               parts[3] = parts[0]
-                       elif parts[3][-1]=='*' and parts[3][-2]!=' ':
-                               parts[3] = parts[3][:-1]+" *"
-                       self.map[tuple(parts[0:3])] = tuple(parts[3:6])
-
-       def wildcard_match(self, a, b):
-               if a=="*" or b=="*":
-                       return True
-               return a==b
-
-       def __getitem__(self, key):
-               try:
-                       return self.map[(key[0], "*", "*")]
-               except KeyError:
-                       for k, v in self.map.iteritems():
-                               if strip_name(k[0])==strip_name(key[0]) and self.wildcard_match(k[1], key[1]) and self.wildcard_match(k[2], key[2]):
-                                       return v
-                       raise KeyError, key
-
-       def update(self, other):
-               self.map.update(other.map)
-
-
-class IOmap:
-       def __init__(self, fn):
-               self.map = {}
-               self.map["void"] = None
-               for line in InputFile(fn):
-                       parts = [p.strip() for p in line.split(',')]
-                       self.map[parts[0]] = tuple(parts[1:])
-
-       def __getitem__(self, key):
-               return self.map[strip_name(key)]
-
-
-class Function:
-       class Parameter:
-               def __init__(self, func, name):
-                       self.func = func
-                       self.name = name
-                       self.type = None
-                       self.direction = "in"
-                       self.kind = "value"
-                       self.size = None
-                       self.ctype = None
-                       self.csize = None
-                       self.io = None
-
-               def set_type(self, type, dir, kind):
-                       self.type = type
-                       self.direction = dir
-                       self.kind = kind
-
-               def set_size(self, size):
-                       if type(size)==str and size.isdigit():
-                               self.size = int(size)
-                       else:
-                               self.size = size
-
-               def derive_ctype(self):
-                       m = typemap[(self.type, self.direction, self.kind)]
-                       self.ctype = m[0]
-                       if m[1]!="*":
-                               self.direction = m[1]
-                       if m[2]!="*":
-                               self.kind = m[2]
-                       self.base_ctype = self.ctype
-                       if self.kind=="value":
-                               if self.base_ctype.startswith("const "):
-                                       self.base_ctype = self.base_ctype[6:]
-                       else:
-                               if self.direction=="in":
-                                       self.ctype = "const "+self.ctype
-                               self.ctype = self.ctype+" *"
-                       self.io = iomap[self.base_ctype]
-
-               def derive_csize(self):
-                       if self.kind=="array" and self.size is not None:
-                               self.csize = None
-                               if type(self.size)==int:
-                                       self.csize = "%d*sizeof(%s)"%(self.size, self.base_ctype)
-                               elif self.size.startswith("COMPSIZE("):
-                                       self.csize = self.func.compsize(self.size[9:-1], self.base_ctype)
-                               elif self.size=="pname":
-                                       self.csize = "paramsize(pname)*sizeof(%s)"%self.base_ctype
-                               else:
-                                       s = self.func.get_param(self.size.split('*')[0])
-                                       if (s.type=="SizeI" or s.type.endswith("Int32") or s.type.startswith("BufferSize")):
-                                               if s.kind=="value":
-                                                       self.csize = "%s"%self.size
-                                                       if self.func.name.startswith("glUniformMatrix") and self.func.name[16]!='x':
-                                                               self.csize += "*%d"%(int(self.func.name[15])**2)
-                                                       elif self.func.name.startswith("glUniform") and self.func.name[9].isdigit():
-                                                               self.csize += "*%s"%self.func.name[9]
-                                                       if strip_name(self.base_ctype)!="void":
-                                                               self.csize += "*sizeof(%s)"%self.base_ctype
-                                               elif s.kind=="array" and s.size==1:
-                                                       self.csize = "*%s"%s.name
-                                       if not self.csize:
-                                               sys.stderr.write("Could not determine size for array parameter '%s[%s]' of function '%s'\n"%(self.name, self.size, self.func.name))
-                       elif self.kind=="reference":
-                               self.csize = "sizeof(%s)"%self.base_ctype
-
-       def __init__(self, name, pnames):
-               self.name = name
-               self.ret = Function.Parameter(self, "ret")
-               self.params = [Function.Parameter(self, n) for n in pnames]
-               self.category = None
-
-       def get_param(self, pname):
-               for p in self.params:
-                       if p.name==pname:
-                               return p
-               raise KeyError, pname
-
-       def set_category(self, cat):
-               self.category = cat
-
-       def compsize(self, size, btype):
-               if not size:
-                       return
-
-               res = ""
-               have_type = False
-               for c in size.replace(',', '/').split('/'):
-                       param = self.get_param(c)
-                       if not param:
-                               sys.stderr.write("Compsize '%s' for function '%s' failed: No parameter '%s'\n"%(size, self.name, c))
-                               return
-
-                       if res:
-                               res += "*"
-
-                       cn = strip_name(param.type)
-                       if cn.endswith("Type"):
-                               res += "typesize(%s)"%param.name
-                               have_type = True
-                       elif cn.endswith("Format"):
-                               res += "formatsize(%s)"%param.name
-                       elif param.name=="pname" or cn.endswith("Parameter") or (param.name=="target" and cn=="enum"):
-                               res += "paramsize(%s)"%param.name
-                       elif param.name=="buffer" and cn=="enum":
-                               res += "buffersize(%s)"%param.name
-                       elif (cn=="SizeI" or cn.endswith("Int32")) and not param.size:
-                               res += param.name
-                       else:
-                               sys.stderr.write("Compsize '%s' for function '%s' failed: Parameter '%s' has unknown type '%s'\n"%(size, self.name, param.name, param.type))
-                               return
-               if not have_type:
-                       res += "*sizeof(%s)"%btype
-               return res
-
-       def finalize(self):
-               self.ret.derive_ctype()
-               for p in self.params:
-                       p.derive_ctype()
-               for p in self.params:
-                       p.derive_csize()
-
-
-class Template:
-       def __init__(self, fn):
-               self.sections = []
-               self.handcode = []
-
-               literal = True
-               text = ""
-               for line in InputFile(fn):
-                       if line[0]==':':
-                               if not literal and text:
-                                       self.add_section(text, literal)
-                                       text = ""
-                               text += line[1:]+"\n"
-                               literal = True
-                       elif line[0]=='!':
-                               parts = line[1:].split()
-                               if parts[0]=="handcode":
-                                       self.handcode.append(parts[1])
-                       else:
-                               if literal and text:
-                                       self.add_section(text, literal)
-                                       text = ""
-                               text += line+"\n"
-                               literal = False
-               if text:
-                       self.add_section(text, literal)
-
-       def add_section(self, text, literal):
-               if literal:
-                       self.sections.append(text)
-               else:
-                       self.sections.append(compile(text, "-", "exec"))
-
-       def write(self, str, *args):
-               sys.stdout.write(str%args)
-
-       def writeln(self, str, *args):
-               sys.stdout.write(str%args+"\n")
-
-       def process(self, functions):
-               for sect in self.sections:
-                       if type(sect)==str:
-                               print sect
-                       else:
-                               for func in functions:
-                                       if func.name in self.handcode:
-                                               continue
-                                       globals = {
-                                               "w": self.write,
-                                               "wl": self.writeln,
-                                               "func": func,
-                                               "ret": func.ret,
-                                               "params": func.params
-                                       }
-                                       eval(sect, globals)
-
-
-class Files:
-       def __init__(self, fn):
-               self.typemap = None
-               self.iomap = None
-               self.specs = []
-               self.prefix = None
-               self.ignore_categs = []
-               self.ignore_funcs = []
-
-               for line in InputFile(fn):
-                       parts = line.split()
-                       if parts[0]=="typemap":
-                               self.typemap = parts[1]
-                       elif parts[0]=="iomap":
-                               self.iomap = parts[1]
-                       elif parts[0]=="spec":
-                               self.specs.append(parts[1])
-                       elif parts[0]=="prefix":
-                               self.prefix = parts[1]
-                       elif parts[0]=="ignore":
-                               if parts[1]=="category":
-                                       self.ignore_categs.append(parts[2])
-                               elif parts[1]=="function":
-                                       self.ignore_funcs.append(parts[2])
-                       else:
-                               sys.stderr.write("Unknown keyword '%s'\n", parts[0])
-
-
-def read_spec(fn, prefix):
-       funcs = []
-       cur_func = None
-       for line in InputFile(fn):
-               if line.find(':')>=0:
-                       continue
-               elif line[0]=='\t' and cur_func:
-                       parts = line.split()
-                       if parts[0]=="return":
-                               cur_func.ret.set_type(parts[1], "out", "value")
-                       elif parts[0]=="param":
-                               bracket = parts[4].find('[')
-                               if bracket>=0:
-                                       parts.insert(5, parts[4][bracket:])
-                                       parts[4] = parts[4][:bracket]
-
-                               param = cur_func.get_param(parts[1])
-                               param.set_type(parts[2], parts[3], parts[4])
-                               if len(parts)==6 or (len(parts)>6 and parts[6]!="retained"):
-                                       param.set_size(parts[5][1:-1])
-                       elif parts[0]=="category":
-                               cur_func.set_category(parts[1])
-                       elif parts[0]=="glxvendorglx" and cur_func.category=="glx":
-                               cur_func.set_category("glxext")
-               else:
-                       paren = line.find('(')
-                       if paren>0:
-                               cparen = line.rfind(')')
-                               if cparen>paren+1:
-                                       pnames = [n.strip() for n in line[paren+1:cparen].split(",")]
-                               else:
-                                       pnames = []
-                               cur_func = Function(prefix+line[:paren], pnames)
-                               funcs.append(cur_func)
-       return funcs
-
-template = Template(sys.argv[1])
-functions = []
-for i in sys.argv[2:]:
-       files = Files(i)
-
-       typemap = Typemap(files.typemap)
-       iomap = IOmap(files.iomap)
-       for s in files.specs:
-               funcs = read_spec(s, files.prefix)
-               funcs = [f for f in funcs if f.name not in files.ignore_funcs and f.category not in files.ignore_categs]
-               for f in funcs:
-                       f.finalize()
-               names = [f.name for f in funcs]
-               functions = [f for f in functions if f.name not in names]+funcs
-
-template.process(functions)
diff --git a/gl.api b/gl.api
new file mode 100644 (file)
index 0000000..40b44c7
--- /dev/null
+++ b/gl.api
@@ -0,0 +1,8 @@
+typemap gl.tm
+iomap gl.io
+spec gl.spec
+prefix gl
+enumspec enum.spec
+enumprefix GL_
+ignore category VERSION_3_2
+ignore category ARB_sync
diff --git a/gl.files b/gl.files
deleted file mode 100644 (file)
index 8be2a33..0000000
--- a/gl.files
+++ /dev/null
@@ -1,6 +0,0 @@
-typemap gl.tm
-iomap gl.io
-spec gl.spec
-prefix gl
-ignore category VERSION_3_2
-ignore category ARB_sync
diff --git a/glx.api b/glx.api
new file mode 100644 (file)
index 0000000..f19df53
--- /dev/null
+++ b/glx.api
@@ -0,0 +1,13 @@
+typemap glx.tm
+iomap glx.io
+spec glx.spec
+spec glxext.spec
+prefix glX
+enumspec glxenum.spec
+enumprefix GLX_
+ignore category glxext
+ignore category SGIX_video_source
+ignore category SGIX_dmbuffer
+ignore category SGIX_hyperpipe
+ignore category NV_video_output
+ignore category NV_video_capture
diff --git a/glx.files b/glx.files
deleted file mode 100644 (file)
index bfac81e..0000000
--- a/glx.files
+++ /dev/null
@@ -1,11 +0,0 @@
-typemap glx.tm
-iomap glx.io
-spec glx.spec
-spec glxext.spec
-prefix glX
-ignore category glxext
-ignore category SGIX_video_source
-ignore category SGIX_dmbuffer
-ignore category SGIX_hyperpipe
-ignore category NV_video_output
-ignore category NV_video_capture
diff --git a/source/enums.table.t b/source/enums.table.t
new file mode 100644 (file)
index 0000000..f90c851
--- /dev/null
@@ -0,0 +1,8 @@
+# $Id$
+!mode enums
+:EnumInfo enums[] =
+:{
+wl('   { 0x%X, "%s", "%s" },'%(enum.value, enum.category, enum.name))
+:      { 0, 0, 0 }
+:};
+:const unsigned enum_count = sizeof(enums)/sizeof(EnumInfo);