diff options
author | Paul Berry <[email protected]> | 2012-10-10 07:20:57 -0700 |
---|---|---|
committer | Paul Berry <[email protected]> | 2012-10-10 11:19:14 -0700 |
commit | 99802519b47983be8301a0283f2946a44a9656a5 (patch) | |
tree | 6d1e8bbcbb6c3fbc81eb14a56253b08ae95f61a0 /src/mapi/glapi/gen/remap_helper.py | |
parent | 856464979bb50c9209c19b66147c8f94cdf5be43 (diff) |
glapi: Reformat python code generation scripts to use 4-space indentation.
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 <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/mapi/glapi/gen/remap_helper.py')
-rw-r--r-- | src/mapi/glapi/gen/remap_helper.py | 308 |
1 files changed, 154 insertions, 154 deletions
diff --git a/src/mapi/glapi/gen/remap_helper.py b/src/mapi/glapi/gen/remap_helper.py index 0008634ff2e..eae1cf3e5ea 100644 --- a/src/mapi/glapi/gen/remap_helper.py +++ b/src/mapi/glapi/gen/remap_helper.py @@ -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 <[email protected]>", "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 <[email protected]>", "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 ) |