From: José Fonseca Date: Sat, 27 Nov 2010 11:26:40 +0000 (+0000) Subject: Better directory name. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=f8b9475d8f62ed7ad2678b14c58b517388d1f980 Better directory name. --- diff --git a/apigen/.gitignore b/apigen/.gitignore new file mode 100644 index 0000000..e784e3f --- /dev/null +++ b/apigen/.gitignore @@ -0,0 +1,4 @@ +*.spec +*.tm +*api.py +glsize.hpp diff --git a/apigen/Makefile b/apigen/Makefile new file mode 100644 index 0000000..485e083 --- /dev/null +++ b/apigen/Makefile @@ -0,0 +1,38 @@ + +all: \ + download \ + glapi.py glxapi.py wglapi.py \ + glsize.hpp + +download: \ + enum.spec \ + enumext.spec \ + gl.spec \ + gl.tm \ + glxenum.spec \ + glxenumext.spec \ + glx.spec \ + glxext.spec \ + glx.tm \ + wglenum.spec \ + wglenumext.spec \ + wgl.spec \ + wglext.spec \ + wgl.tm + +%.spec %.tm: + wget -N http://www.opengl.org/registry/api/$@ + +glapi.py: glspec.py gl.tm gl.spec + python glspec.py gl gl.tm gl.spec > $@ + +glxapi.py: glspec.py glx.tm glx.spec glxext.spec + python glspec.py glX glx.tm glx.spec glxext.spec > $@ + +wglapi.py: glspec.py wgl.tm wgl.spec wglext.spec + python glspec.py wgl wgl.tm wgl.spec wglext.spec > $@ + +glsize.hpp: glsize.py + python glsize.py > $@ + +.PRECIOUS: %.spec %.tm diff --git a/apigen/gl_trace.py b/apigen/gl_trace.py new file mode 100755 index 0000000..182b395 --- /dev/null +++ b/apigen/gl_trace.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +# Copyright 2008 VMware, Inc. +# Copyright 2004 IBM Corporation +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +import getopt +import os.path +import sys + +glapi_path = os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen') +sys.path.insert(0, glapi_path) + +import gl_XML +import license + +type_map = { + 'void': 'Void', + 'int': 'Int', + 'float': 'Float', +} + +def parse_type(tokens, count = 0): + if count: + if tokens[-1] == '**': + return 'Array(Pointer(%s), "%s")' % (parse_type(tokens[:-1]), count) + if tokens[-1] == '*': + return 'Array(%s, "%s")' % (parse_type(tokens[:-1]), count) + else: + if tokens[-1] == '**': + return 'Pointer(Pointer(%s))' % parse_type(tokens[:-1]) + if tokens[-1] == '*': + return 'Pointer(%s)' % parse_type(tokens[:-1]) + if tokens[-1] == 'const': + return 'Const(%s)' % parse_type(tokens[:-1]) + if tokens[0] == 'const': + return 'Const(%s)' % parse_type(tokens[1:]) + assert len(tokens) == 1 + base = tokens[0] + return type_map.get(base, base) + +def get_type(t, count = 0): + tokens = t.split() + + return parse_type(tokens, count) + + +class PrintGlTable(gl_XML.gl_print_base): + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + #self.header_tag = '_GLAPI_TABLE_H_' + self.name = "gl_trace.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") + return + + def printBody(self, api): + abi = [ "1.0", "1.1", "1.2", "1.5", "GL_ARB_multitexture" ] + for pass_ in range(2): + for f in api.functionIterateByOffset(): + for name in f.entry_points: + [category, num] = api.get_category_for_name( name ) + args = [] + for p in f.parameters: + type = get_type(p.type_string(), p.count) + args.append('(%s, "%s")' % (type, p.name)) + arg_string = '[' + ', '.join(args) + ']' + if category in abi: + if pass_ == 0: + print ' GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string) + else: + if pass_ == 1: + print ' GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string) + + def printRealHeader(self): + return + + def printRealFooter(self): + print ']' + + +def show_usage(): + print "Usage: %s [-f input_file_name]" % sys.argv[0] + sys.exit(1) + + +if __name__ == '__main__': + file_name = os.path.join(glapi_path, "gl_API.xml") + + 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 + + printer = PrintGlTable() + + api = gl_XML.parse_GL_API( file_name ) + + printer.Print( api ) diff --git a/apigen/glsize.py b/apigen/glsize.py new file mode 100755 index 0000000..0eb9255 --- /dev/null +++ b/apigen/glsize.py @@ -0,0 +1,289 @@ +#!/usr/bin/env python + +# Copyright 2010 VMware, Inc. +# Copyright 2004, 2005 IBM Corporation +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# Authors: +# Jose Fonseca +# Ian Romanick + +import os.path +import sys + +glapi_path = os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen') +sys.path.insert(0, glapi_path) + +import gl_XML, glX_XML +import license +import getopt, copy, string + + +class glx_enum_function: + 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"}. + + 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). + + 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". + + 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 e.functions.has_key( match_name ): + [count, mode] = e.functions[ match_name ] + + if mode_set and mode != self.mode: + raise RuntimeError("Not all enums for %s have the same mode." % (func_name)) + + 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 ] = [] + + self.enums[ e.value ] = [ e ] + self.count[ count ].append( e.value ) + + + return + + + 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 PrintUsingSwitch(self, name): + """Emit the body of the __gl*_size function using a + switch-statement.""" + + print ' switch (pname) {' + + 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(pname);' % (name) + else: + print ' return %u;' % (c) + + print ' default:' + print ' assert(0);' + print ' return 1;' + print ' }' + + + def Print(self, name): + print 'static inline size_t' + print '__gl%s_size(GLenum pname)' % (name) + print '{' + + 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 signature( self ): + if self.sig == None: + sig = glx_enum_function.signature(self) + + p = self.function.variable_length_parameter() + if p: + sig += "%u" % (p.size()) + + 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 + + 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] ] + + printer.common_emit_one_arg(p, "pc", 0) + fixup.append( p.name ) + + + print ' GLsizei compsize;' + 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_c(gl_XML.gl_print_base): + + def __init__(self): + gl_XML.gl_print_base.__init__(self) + + self.name = "glX_proto_size.py (from Mesa)" + self.license = license.bsd_license_template % ( "Copyright 2010 VMware, Inc.\nCopyright 2004 IBM Corporation", "AUTHORS") + + def printRealHeader(self): + print + print + print '#include ' + print + print '#include "glimports.hpp"' + print + print + + def printBody(self, api): + enum_sigs = {} + + for func in api.functionIterateByOffset(): + ef = glx_enum_function( func.name, api.enums_by_name ) + if len(ef.enums) == 0: + continue + + if True: + sig = ef.signature() + if enum_sigs.has_key( sig ): + alias_name, real_name = func.name, enum_sigs[ sig ] + print '#define __gl%s_size __gl%s_size' % (alias_name, real_name) + print + else: + enum_sigs[ sig ] = func.name + ef.Print( func.name ) + + +def show_usage(): + print "Usage: %s [-f input_file_name] [--only-get | --only-set] [--get-alias-set]" % sys.argv[0] + sys.exit(1) + + +if __name__ == '__main__': + file_name = os.path.join(glapi_path, "gl_API.xml") + + try: + (args, trail) = getopt.getopt(sys.argv[1:], "f:h:", ["header-tag"]) + except Exception,e: + show_usage() + + header_tag = None + + for (arg,val) in args: + if arg == "-f": + file_name = val + elif (arg == '-h') or (arg == "--header-tag"): + header_tag = val + + printer = PrintGlxSizeStubs_c() + + api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) + + + printer.Print( api ) diff --git a/apigen/glspec.py b/apigen/glspec.py new file mode 100755 index 0000000..ec8330c --- /dev/null +++ b/apigen/glspec.py @@ -0,0 +1,283 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2010 VMware, Inc. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +##########################################################################/ + + +import sys +import re +import optparse + + +def stderr(x): + sys.stderr.write(str(x) + '\n') + + +class Parser: + + def __init__(self, stream): + pass + + +class LineParser: + """Base class for parsers that read line-based formats.""" + + def __init__(self, stream): + self._stream = stream + self._line = None + self._eof = False + # read lookahead + self.readline() + + def parse(self): + raise NotImplementedError + + def readline(self): + line = self._stream.readline() + if not line: + self._line = '' + self._eof = True + self._line = line.rstrip('\r\n') + + def lookahead(self): + assert self._line is not None + return self._line + + def consume(self): + assert self._line is not None + line = self._line + self.readline() + return line + + def eof(self): + assert self._line is not None + return self._eof + + def skip_whitespace(self): + while not self.eof() and self.match_whitespace() or self.match_comment(): + self.consume() + + def match_whitespace(self): + line = self.lookahead() + return not line.strip() + + def match_comment(self): + return False + + +class TypemapParser(LineParser): + + def parse(self): + typemap = {} + self.skip_whitespace() + while not self.eof(): + line = self.consume() + fields = [field.strip() for field in line.split(',')] + src = fields[0] + dst = fields[3] + if dst != '*': + typemap[src] = dst + self.skip_whitespace() + return typemap + + def match_comment(self): + line = self.lookahead() + return line.startswith('#') + + +class SpecParser(LineParser): + + property_re = re.compile(r'^\w+:') + prototype_re = re.compile(r'^(\w+)\((.*)\)$') + + def __init__(self, stream, prefix='', typemap = None): + LineParser.__init__(self, stream) + if typemap is None: + self.typemap = {} + else: + self.typemap = typemap + self.prefix = prefix + self.category = None + + def parse(self): + self.skip_whitespace() + while not self.eof(): + line = self.lookahead() + if self.property_re.match(line): + self.parse_property() + elif self.prototype_re.match(line): + self.parse_prototype() + else: + self.consume() + self.skip_whitespace() + + def parse_property(self): + line = self.consume() + name, value = line.split(':', 1) + if name == 'category': + values = value.split() + #self.prefix = values[0] + + get_function_re = re.compile(r'^Get[A-Z]\w+') + + def parse_prototype(self): + line = self.consume() + mo = self.prototype_re.match(line) + function_name, arg_names = mo.groups() + arg_names = [arg_name.strip() for arg_name in arg_names.split(',') if arg_name.strip()] + + extra = '' + if self.get_function_re.match(function_name): + extra += ', sideeffects=False' + function_name = self.prefix + function_name + + ret_type = 'Void' + arg_types = {} + category = None + line = self.lookahead() + while line.startswith('\t'): + fields = line.split(None, 2) + if fields[0] == 'return': + ret_type = self.parse_type(fields[1]) + elif fields[0] == 'param': + arg_name, arg_type = fields[1:3] + arg_types[fields[1]] = self.parse_arg(function_name, arg_name, arg_type) + elif fields[0] == 'category': + category = fields[1] + else: + pass + self.consume() + line = self.lookahead() + self.consume() + args = [arg_types[arg_name] for arg_name in arg_names] + + if category is not None: + if category == self.prefix: + category = self.prefix.upper() + else: + category = self.prefix.upper() + '_' + category + if category != self.category: + if self.category is not None: + print + print ' # %s' % category + self.category = category + + if self.prefix == 'wgl': + constructor = 'StdFunction' + else: + constructor = 'GlFunction' + + print ' %s(%s, "%s", [%s]%s),' % (constructor, ret_type, function_name, ', '.join(args), extra) + + array_re = re.compile(r'^array\s+\[(.*)\]$') + + string_typemap = { + 'GLchar': 'GLstring', + 'GLcharARB': 'GLstringARB', + } + + def parse_arg(self, function_name, arg_name, arg_type): + orig_type, inout, kind = arg_type.split(' ', 2) + + base_type = self.parse_type(orig_type) + + if kind == 'value': + arg_type = base_type + elif kind == 'reference': + arg_type = 'Pointer(%s)' % base_type + if inout == 'in': + arg_type = 'Const(%s)' % arg_type + elif kind.startswith("array"): + arg_type = 'OpaquePointer(%s)' % base_type + + if base_type == 'Void': + constructor = 'Blob' + else: + constructor = 'Array' + + mo = self.array_re.match(kind) + if mo: + length = mo.group(1).strip() + if length == '': + try: + arg_type = self.string_typemap[base_type] + except KeyError: + pass + elif length == '1': + arg_type = 'Pointer(%s)' % base_type + elif length.find("COMPSIZE") == -1: + arg_type = '%s(%s, "%s")' % (constructor, base_type, length) + else: + # XXX: Handle COMPSIZE better + length = length.replace("COMPSIZE", "__%s_size" % function_name) + length = length.replace("/", ", ") + arg_type = '%s(%s, "%s")' % (constructor, base_type, length) + if inout == 'in': + arg_type = 'Const(%s)' % arg_type + else: + assert False + + arg = '(%s, "%s")' % (arg_type, arg_name) + if inout == 'out': + arg = 'Out' + arg + return arg + + semantic_typemap = { + 'String': 'CString', + 'Texture': 'GLtexture', + } + + post_typemap = { + 'void': 'Void', + 'int': 'Int', + 'float': 'Float', + } + + def parse_type(self, type): + try: + return self.semantic_typemap[type] + except KeyError: + pass + type = self.typemap.get(type, type) + type = self.post_typemap.get(type, type) + return type + + def match_comment(self): + line = self.lookahead() + return line.startswith('#') + + +def main(): + prefix = sys.argv[1] + + parser = TypemapParser(open(sys.argv[2], 'rt')) + typemap = parser.parse() + + for arg in sys.argv[3:]: + parser = SpecParser(open(arg, 'rt'), prefix=prefix, typemap=typemap) + parser.parse() + + +if __name__ == '__main__': + main() diff --git a/helpers/.gitignore b/helpers/.gitignore deleted file mode 100644 index e784e3f..0000000 --- a/helpers/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.spec -*.tm -*api.py -glsize.hpp diff --git a/helpers/Makefile b/helpers/Makefile deleted file mode 100644 index 485e083..0000000 --- a/helpers/Makefile +++ /dev/null @@ -1,38 +0,0 @@ - -all: \ - download \ - glapi.py glxapi.py wglapi.py \ - glsize.hpp - -download: \ - enum.spec \ - enumext.spec \ - gl.spec \ - gl.tm \ - glxenum.spec \ - glxenumext.spec \ - glx.spec \ - glxext.spec \ - glx.tm \ - wglenum.spec \ - wglenumext.spec \ - wgl.spec \ - wglext.spec \ - wgl.tm - -%.spec %.tm: - wget -N http://www.opengl.org/registry/api/$@ - -glapi.py: glspec.py gl.tm gl.spec - python glspec.py gl gl.tm gl.spec > $@ - -glxapi.py: glspec.py glx.tm glx.spec glxext.spec - python glspec.py glX glx.tm glx.spec glxext.spec > $@ - -wglapi.py: glspec.py wgl.tm wgl.spec wglext.spec - python glspec.py wgl wgl.tm wgl.spec wglext.spec > $@ - -glsize.hpp: glsize.py - python glsize.py > $@ - -.PRECIOUS: %.spec %.tm diff --git a/helpers/gl_trace.py b/helpers/gl_trace.py deleted file mode 100755 index 182b395..0000000 --- a/helpers/gl_trace.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2008 VMware, Inc. -# Copyright 2004 IBM Corporation -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# on the rights to use, copy, modify, merge, publish, distribute, sub -# license, and/or sell copies of the Software, and to permit persons to whom -# the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice (including the next -# paragraph) shall be included in all copies or substantial portions of the -# Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. - -import getopt -import os.path -import sys - -glapi_path = os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen') -sys.path.insert(0, glapi_path) - -import gl_XML -import license - -type_map = { - 'void': 'Void', - 'int': 'Int', - 'float': 'Float', -} - -def parse_type(tokens, count = 0): - if count: - if tokens[-1] == '**': - return 'Array(Pointer(%s), "%s")' % (parse_type(tokens[:-1]), count) - if tokens[-1] == '*': - return 'Array(%s, "%s")' % (parse_type(tokens[:-1]), count) - else: - if tokens[-1] == '**': - return 'Pointer(Pointer(%s))' % parse_type(tokens[:-1]) - if tokens[-1] == '*': - return 'Pointer(%s)' % parse_type(tokens[:-1]) - if tokens[-1] == 'const': - return 'Const(%s)' % parse_type(tokens[:-1]) - if tokens[0] == 'const': - return 'Const(%s)' % parse_type(tokens[1:]) - assert len(tokens) == 1 - base = tokens[0] - return type_map.get(base, base) - -def get_type(t, count = 0): - tokens = t.split() - - return parse_type(tokens, count) - - -class PrintGlTable(gl_XML.gl_print_base): - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - #self.header_tag = '_GLAPI_TABLE_H_' - self.name = "gl_trace.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") - return - - def printBody(self, api): - abi = [ "1.0", "1.1", "1.2", "1.5", "GL_ARB_multitexture" ] - for pass_ in range(2): - for f in api.functionIterateByOffset(): - for name in f.entry_points: - [category, num] = api.get_category_for_name( name ) - args = [] - for p in f.parameters: - type = get_type(p.type_string(), p.count) - args.append('(%s, "%s")' % (type, p.name)) - arg_string = '[' + ', '.join(args) + ']' - if category in abi: - if pass_ == 0: - print ' GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string) - else: - if pass_ == 1: - print ' GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string) - - def printRealHeader(self): - return - - def printRealFooter(self): - print ']' - - -def show_usage(): - print "Usage: %s [-f input_file_name]" % sys.argv[0] - sys.exit(1) - - -if __name__ == '__main__': - file_name = os.path.join(glapi_path, "gl_API.xml") - - 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 - - printer = PrintGlTable() - - api = gl_XML.parse_GL_API( file_name ) - - printer.Print( api ) diff --git a/helpers/glsize.py b/helpers/glsize.py deleted file mode 100755 index 0eb9255..0000000 --- a/helpers/glsize.py +++ /dev/null @@ -1,289 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2010 VMware, Inc. -# Copyright 2004, 2005 IBM Corporation -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a -# copy of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# on the rights to use, copy, modify, merge, publish, distribute, sub -# license, and/or sell copies of the Software, and to permit persons to whom -# the Software is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice (including the next -# paragraph) shall be included in all copies or substantial portions of the -# Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL -# THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -# -# Authors: -# Jose Fonseca -# Ian Romanick - -import os.path -import sys - -glapi_path = os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen') -sys.path.insert(0, glapi_path) - -import gl_XML, glX_XML -import license -import getopt, copy, string - - -class glx_enum_function: - 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"}. - - 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). - - 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". - - 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 e.functions.has_key( match_name ): - [count, mode] = e.functions[ match_name ] - - if mode_set and mode != self.mode: - raise RuntimeError("Not all enums for %s have the same mode." % (func_name)) - - 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 ] = [] - - self.enums[ e.value ] = [ e ] - self.count[ count ].append( e.value ) - - - return - - - 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 PrintUsingSwitch(self, name): - """Emit the body of the __gl*_size function using a - switch-statement.""" - - print ' switch (pname) {' - - 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(pname);' % (name) - else: - print ' return %u;' % (c) - - print ' default:' - print ' assert(0);' - print ' return 1;' - print ' }' - - - def Print(self, name): - print 'static inline size_t' - print '__gl%s_size(GLenum pname)' % (name) - print '{' - - 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 signature( self ): - if self.sig == None: - sig = glx_enum_function.signature(self) - - p = self.function.variable_length_parameter() - if p: - sig += "%u" % (p.size()) - - 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 - - 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] ] - - printer.common_emit_one_arg(p, "pc", 0) - fixup.append( p.name ) - - - print ' GLsizei compsize;' - 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_c(gl_XML.gl_print_base): - - def __init__(self): - gl_XML.gl_print_base.__init__(self) - - self.name = "glX_proto_size.py (from Mesa)" - self.license = license.bsd_license_template % ( "Copyright 2010 VMware, Inc.\nCopyright 2004 IBM Corporation", "AUTHORS") - - def printRealHeader(self): - print - print - print '#include ' - print - print '#include "glimports.hpp"' - print - print - - def printBody(self, api): - enum_sigs = {} - - for func in api.functionIterateByOffset(): - ef = glx_enum_function( func.name, api.enums_by_name ) - if len(ef.enums) == 0: - continue - - if True: - sig = ef.signature() - if enum_sigs.has_key( sig ): - alias_name, real_name = func.name, enum_sigs[ sig ] - print '#define __gl%s_size __gl%s_size' % (alias_name, real_name) - print - else: - enum_sigs[ sig ] = func.name - ef.Print( func.name ) - - -def show_usage(): - print "Usage: %s [-f input_file_name] [--only-get | --only-set] [--get-alias-set]" % sys.argv[0] - sys.exit(1) - - -if __name__ == '__main__': - file_name = os.path.join(glapi_path, "gl_API.xml") - - try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:h:", ["header-tag"]) - except Exception,e: - show_usage() - - header_tag = None - - for (arg,val) in args: - if arg == "-f": - file_name = val - elif (arg == '-h') or (arg == "--header-tag"): - header_tag = val - - printer = PrintGlxSizeStubs_c() - - api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() ) - - - printer.Print( api ) diff --git a/helpers/glspec.py b/helpers/glspec.py deleted file mode 100755 index ec8330c..0000000 --- a/helpers/glspec.py +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2010 VMware, Inc. -# All Rights Reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -##########################################################################/ - - -import sys -import re -import optparse - - -def stderr(x): - sys.stderr.write(str(x) + '\n') - - -class Parser: - - def __init__(self, stream): - pass - - -class LineParser: - """Base class for parsers that read line-based formats.""" - - def __init__(self, stream): - self._stream = stream - self._line = None - self._eof = False - # read lookahead - self.readline() - - def parse(self): - raise NotImplementedError - - def readline(self): - line = self._stream.readline() - if not line: - self._line = '' - self._eof = True - self._line = line.rstrip('\r\n') - - def lookahead(self): - assert self._line is not None - return self._line - - def consume(self): - assert self._line is not None - line = self._line - self.readline() - return line - - def eof(self): - assert self._line is not None - return self._eof - - def skip_whitespace(self): - while not self.eof() and self.match_whitespace() or self.match_comment(): - self.consume() - - def match_whitespace(self): - line = self.lookahead() - return not line.strip() - - def match_comment(self): - return False - - -class TypemapParser(LineParser): - - def parse(self): - typemap = {} - self.skip_whitespace() - while not self.eof(): - line = self.consume() - fields = [field.strip() for field in line.split(',')] - src = fields[0] - dst = fields[3] - if dst != '*': - typemap[src] = dst - self.skip_whitespace() - return typemap - - def match_comment(self): - line = self.lookahead() - return line.startswith('#') - - -class SpecParser(LineParser): - - property_re = re.compile(r'^\w+:') - prototype_re = re.compile(r'^(\w+)\((.*)\)$') - - def __init__(self, stream, prefix='', typemap = None): - LineParser.__init__(self, stream) - if typemap is None: - self.typemap = {} - else: - self.typemap = typemap - self.prefix = prefix - self.category = None - - def parse(self): - self.skip_whitespace() - while not self.eof(): - line = self.lookahead() - if self.property_re.match(line): - self.parse_property() - elif self.prototype_re.match(line): - self.parse_prototype() - else: - self.consume() - self.skip_whitespace() - - def parse_property(self): - line = self.consume() - name, value = line.split(':', 1) - if name == 'category': - values = value.split() - #self.prefix = values[0] - - get_function_re = re.compile(r'^Get[A-Z]\w+') - - def parse_prototype(self): - line = self.consume() - mo = self.prototype_re.match(line) - function_name, arg_names = mo.groups() - arg_names = [arg_name.strip() for arg_name in arg_names.split(',') if arg_name.strip()] - - extra = '' - if self.get_function_re.match(function_name): - extra += ', sideeffects=False' - function_name = self.prefix + function_name - - ret_type = 'Void' - arg_types = {} - category = None - line = self.lookahead() - while line.startswith('\t'): - fields = line.split(None, 2) - if fields[0] == 'return': - ret_type = self.parse_type(fields[1]) - elif fields[0] == 'param': - arg_name, arg_type = fields[1:3] - arg_types[fields[1]] = self.parse_arg(function_name, arg_name, arg_type) - elif fields[0] == 'category': - category = fields[1] - else: - pass - self.consume() - line = self.lookahead() - self.consume() - args = [arg_types[arg_name] for arg_name in arg_names] - - if category is not None: - if category == self.prefix: - category = self.prefix.upper() - else: - category = self.prefix.upper() + '_' + category - if category != self.category: - if self.category is not None: - print - print ' # %s' % category - self.category = category - - if self.prefix == 'wgl': - constructor = 'StdFunction' - else: - constructor = 'GlFunction' - - print ' %s(%s, "%s", [%s]%s),' % (constructor, ret_type, function_name, ', '.join(args), extra) - - array_re = re.compile(r'^array\s+\[(.*)\]$') - - string_typemap = { - 'GLchar': 'GLstring', - 'GLcharARB': 'GLstringARB', - } - - def parse_arg(self, function_name, arg_name, arg_type): - orig_type, inout, kind = arg_type.split(' ', 2) - - base_type = self.parse_type(orig_type) - - if kind == 'value': - arg_type = base_type - elif kind == 'reference': - arg_type = 'Pointer(%s)' % base_type - if inout == 'in': - arg_type = 'Const(%s)' % arg_type - elif kind.startswith("array"): - arg_type = 'OpaquePointer(%s)' % base_type - - if base_type == 'Void': - constructor = 'Blob' - else: - constructor = 'Array' - - mo = self.array_re.match(kind) - if mo: - length = mo.group(1).strip() - if length == '': - try: - arg_type = self.string_typemap[base_type] - except KeyError: - pass - elif length == '1': - arg_type = 'Pointer(%s)' % base_type - elif length.find("COMPSIZE") == -1: - arg_type = '%s(%s, "%s")' % (constructor, base_type, length) - else: - # XXX: Handle COMPSIZE better - length = length.replace("COMPSIZE", "__%s_size" % function_name) - length = length.replace("/", ", ") - arg_type = '%s(%s, "%s")' % (constructor, base_type, length) - if inout == 'in': - arg_type = 'Const(%s)' % arg_type - else: - assert False - - arg = '(%s, "%s")' % (arg_type, arg_name) - if inout == 'out': - arg = 'Out' + arg - return arg - - semantic_typemap = { - 'String': 'CString', - 'Texture': 'GLtexture', - } - - post_typemap = { - 'void': 'Void', - 'int': 'Int', - 'float': 'Float', - } - - def parse_type(self, type): - try: - return self.semantic_typemap[type] - except KeyError: - pass - type = self.typemap.get(type, type) - type = self.post_typemap.get(type, type) - return type - - def match_comment(self): - line = self.lookahead() - return line.startswith('#') - - -def main(): - prefix = sys.argv[1] - - parser = TypemapParser(open(sys.argv[2], 'rt')) - typemap = parser.parse() - - for arg in sys.argv[3:]: - parser = SpecParser(open(arg, 'rt'), prefix=prefix, typemap=typemap) - parser.parse() - - -if __name__ == '__main__': - main()