X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=genwrap.py;h=1ee97cef332853da9e6c8ffb0d5033e7ae980b7f;hb=ee7f1e3a5912789664648ac5be85127e62c1cda5;hp=81c4e33f8a285bba41d5d65b2cf8979962aacce0;hpb=49f8063ce156a50d4b3b8c77a1508a21ea2bfe90;p=gldbg.git diff --git a/genwrap.py b/genwrap.py index 81c4e33..1ee97ce 100755 --- a/genwrap.py +++ b/genwrap.py @@ -66,11 +66,13 @@ class Typemap: return a==b def __getitem__(self, key): - return self.map[(key[0], "*", "*")] - 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 + 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) @@ -113,16 +115,21 @@ class Function: self.size = size def derive_ctype(self): - self.ctype = typemap[(self.type, self.direction, self.kind)][0] + 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:] - self.io = iomap[self.base_ctype] 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: @@ -131,8 +138,8 @@ class Function: 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=="" and (self.type=="charARB" or self.type=="Char"): - self.csize = "strlen" + 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")) and s.kind=="value": @@ -180,7 +187,7 @@ class Function: have_type = True elif cn.endswith("Format"): res += "formatsize(%s)"%param.name - elif cn.endswith(("Parameter", "ParameterPName", "ParameterName")) or cn=="GetPName": + elif param.name=="pname" or cn.endswith("Parameter"): res += "paramsize(%s)"%param.name elif cn=="MapTarget": res += "mapsize(%s)"%param.name @@ -190,7 +197,7 @@ class Function: 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)"%param.ctype + res += "*sizeof(%s)"%btype return res def finalize(self): @@ -204,6 +211,7 @@ class Function: class Template: def __init__(self, fn): self.sections = [] + self.handcode = [] literal = True text = "" @@ -214,6 +222,10 @@ class Template: 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) @@ -241,6 +253,8 @@ class Template: print sect else: for func in functions: + if func.name in self.handcode: + continue globals = { "w": self.write, "wl": self.writeln, @@ -255,7 +269,7 @@ class Files: def __init__(self, fn): self.typemap = None self.iomap = None - self.spec = None + self.specs = [] self.prefix = None self.ignore_categs = [] self.ignore_funcs = [] @@ -267,7 +281,7 @@ class Files: elif parts[0]=="iomap": self.iomap = parts[1] elif parts[0]=="spec": - self.spec = parts[1] + self.specs.append(parts[1]) elif parts[0]=="prefix": self.prefix = parts[1] elif parts[0]=="ignore": @@ -316,14 +330,18 @@ def read_spec(fn, prefix): 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) - functions = read_spec(files.spec, files.prefix) - functions = [f for f in functions if f.name not in files.ignore_funcs and f.category not in files.ignore_categs] - for f in functions: - f.finalize() - - template.process(functions) + 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)