1 2# Copyright (C) 2009 Chia-I Wu <[email protected]> 3# All Rights Reserved. 4# 5# This is based on extension_helper.py by Ian Romanick. 6# 7# Permission is hereby granted, free of charge, to any person obtaining a 8# copy of this software and associated documentation files (the "Software"), 9# to deal in the Software without restriction, including without limitation 10# on the rights to use, copy, modify, merge, publish, distribute, sub 11# license, and/or sell copies of the Software, and to permit persons to whom 12# the Software is furnished to do so, subject to the following conditions: 13# 14# The above copyright notice and this permission notice (including the next 15# paragraph) shall be included in all copies or substantial portions of the 16# Software. 17# 18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 24# IN THE SOFTWARE. 25 26import argparse 27 28import license 29import gl_XML 30 31 32class PrintGlRemap(gl_XML.gl_print_base): 33 def __init__(self): 34 gl_XML.gl_print_base.__init__(self) 35 36 self.name = "remap_helper.py (from Mesa)" 37 self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu <[email protected]>", "Chia-I Wu") 38 return 39 40 41 def printRealHeader(self): 42 print('#include "main/dispatch.h"') 43 print('#include "main/remap.h"') 44 print('') 45 return 46 47 48 def printBody(self, api): 49 pool_indices = {} 50 51 print('/* this is internal to remap.c */') 52 print('#ifndef need_MESA_remap_table') 53 print('#error Only remap.c should include this file!') 54 print('#endif /* need_MESA_remap_table */') 55 print('') 56 57 print('') 58 print('static const char _mesa_function_pool[] =') 59 60 # output string pool 61 index = 0; 62 for f in api.functionIterateAll(): 63 pool_indices[f] = index 64 65 # a function has either assigned offset, fixed offset, 66 # or no offset 67 if f.assign_offset: 68 comments = "will be remapped" 69 elif f.offset > 0: 70 comments = "offset %d" % f.offset 71 else: 72 comments = "dynamic" 73 74 print(' /* _mesa_function_pool[%d]: %s (%s) */' \ 75 % (index, f.name, comments)) 76 print(' "gl%s\\0"' % f.entry_points[0]) 77 index += len(f.entry_points[0]) + 3 78 print(' ;') 79 print('') 80 81 print('/* these functions need to be remapped */') 82 print('static const struct gl_function_pool_remap MESA_remap_table_functions[] = {') 83 # output all functions that need to be remapped 84 # iterate by offsets so that they are sorted by remap indices 85 for f in api.functionIterateByOffset(): 86 if not f.assign_offset: 87 continue 88 print(' { %5d, %s_remap_index },' \ 89 % (pool_indices[f], f.name)) 90 print(' { -1, -1 }') 91 print('};') 92 print('') 93 return 94 95 96def _parser(): 97 """Parse input options and return a namsepace.""" 98 parser = argparse.ArgumentParser() 99 parser.add_argument('-f', '--filename', 100 default="gl_API.xml", 101 metavar="input_file_name", 102 dest='file_name', 103 help="An xml description file.") 104 return parser.parse_args() 105 106 107def main(): 108 """Main function.""" 109 args = _parser() 110 111 api = gl_XML.parse_GL_API(args.file_name) 112 113 printer = PrintGlRemap() 114 printer.Print(api) 115 116 117if __name__ == '__main__': 118 main() 119