def condition_for_function(f, abi, all_not_in_ABI): """Create a C-preprocessor condition for the function. There are two modes of operation. If all_not_in_ABI is set, a condition is only created is all of the entry-point names for f are not in the selected ABI. If all_not_in_ABI is not set, a condition is created if any entryp-point name is not in the selected ABI. """ condition = [] for n in f.entry_points: [category, num] = api.get_category_for_name( n ) if category not in abi: condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) ) elif all_not_in_ABI: return [] return condition
def condition_for_function(f, abi, all_not_in_ABI): """Create a C-preprocessor condition for the function. There are two modes of operation. If all_not_in_ABI is set, a condition is only created is all of the entry-point names for f are not in the selected ABI. If all_not_in_ABI is not set, a condition is created if any entryp-point name is not in the selected ABI. """ condition = [] for n in f.entry_points: [category, num] = api.get_category_for_name(n) if category not in abi: condition.append('defined(need_%s)' % (gl_XML.real_category_name(category))) elif all_not_in_ABI: return [] return condition
def printBody(self, api): abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] category_list = {} print '#ifndef NULL' print '# define NULL 0' print '#endif' print '' for f in api.functionIterateAll(): condition = condition_for_function(f, abi, 0) if len(condition): print '#if %s' % (string.join(condition, " || ")) print 'static const char %s_names[] = ' % (f.name) parameter_signature = '' for p in f.parameterIterator(): # FIXME: This is a *really* ugly hack. :( tn = p.type_expr.get_base_type_node() if p.is_pointer(): parameter_signature += 'p' elif tn.integer: parameter_signature += 'i' elif tn.size == 4: parameter_signature += 'f' else: parameter_signature += 'd' print ' "%s\\0" /* Parameter signature */' % (parameter_signature) for n in f.entry_points: print ' "gl%s\\0"' % (n) [category, num] = api.get_category_for_name( n ) if category not in abi: c = gl_XML.real_category_name(category) if not category_list.has_key(c): category_list[ c ] = [] category_list[ c ].append( f ) print ' "";' print '#endif' print '' keys = category_list.keys() keys.sort() for category in keys: print '#if defined(need_%s)' % (category) print 'static const struct dri_extension_function %s_functions[] = {' % (category) for f in category_list[ category ]: # A function either has an offset that is # assigned by the ABI, or it has a remap # index. if any_entrypoints_in_abi(f, abi, api): index_name = "-1" offset = f.offset else: index_name = "%s_remap_index" % (f.name) offset = -1 print ' { %s_names, %s, %d },' % (f.name, index_name, offset) print ' { NULL, 0, 0 }' print '};' print '#endif' 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 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 printBody(self, api): abi = ["1.0", "1.1", "1.2", "GL_ARB_multitexture"] category_list = {} print '#ifndef NULL' print '# define NULL 0' print '#endif' print '' for f in api.functionIterateAll(): condition = condition_for_function(f, abi, 0) if len(condition): print '#if %s' % (string.join(condition, " || ")) print 'static const char %s_names[] =' % (f.name) parameter_signature = '' for p in f.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(): parameter_signature += 'p' elif tn.integer: parameter_signature += 'i' elif tn.size == 4: parameter_signature += 'f' else: parameter_signature += 'd' print ' "%s\\0" /* Parameter signature */' % ( parameter_signature) for n in f.entry_points: print ' "gl%s\\0"' % (n) [category, num] = api.get_category_for_name(n) if category not in abi: c = gl_XML.real_category_name(category) if not category_list.has_key(c): category_list[c] = [] category_list[c].append(f) print ' "";' print '#endif' print '' keys = category_list.keys() keys.sort() for category in keys: print '#if defined(need_%s)' % (category) print 'static const struct dri_extension_function %s_functions[] = {' % ( category) for f in category_list[category]: # A function either has an offset that is # assigned by the ABI, or it has a remap # index. if any_entrypoints_in_abi(f, abi, api): index_name = "-1" offset = f.offset else: index_name = "%s_remap_index" % (f.name) offset = -1 print ' { %s_names, %s, %d },' % (f.name, index_name, offset) print ' { NULL, 0, 0 }' print '};' print '#endif' print '' return
def printBody(self, api): print 'struct gl_function_remap {' print ' GLint func_index;' print ' GLint dispatch_offset; /* for sanity check */' print '};' print '' pool_indices = {} print '/* this is internal to remap.c */' print '#ifdef need_MESA_remap_table' 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 {' print ' GLint pool_index;' print ' GLint remap_index;' print '} 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 '' abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ] extension_functions = {} # collect non-ABI functions for f in api.functionIterateAll(): for n in f.entry_points: category, num = api.get_category_for_name(n) if category not in abi: c = gl_XML.real_category_name(category) if not extension_functions.has_key(c): extension_functions[c] = [] extension_functions[c].append(f) 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 if not f.assign_offset and f.offset >= 0: 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 '' print '#endif /* need_MESA_remap_table */' print '' # output remap helpers for DRI drivers for ext in extensions: funcs = [] remapped = [] for f in extension_functions[ext]: if f.assign_offset: # these are handled above remapped.append(f) else: # these functions are either in the # abi, or have offset -1 funcs.append(f) print '#if defined(need_%s)' % (ext) if remapped: print '/* functions defined in MESA_remap_table_functions are excluded */' # output extension functions that need to be mapped print 'static const struct gl_function_remap %s_functions[] = {' % (ext) for f in funcs: if f.offset >= 0: print ' { %5d, _gloffset_%s },' \ % (pool_indices[f], f.name) else: print ' { %5d, -1 }, /* %s */' % \ (pool_indices[f], f.name) print ' { -1, -1 }' print '};' print '#endif' print '' return