1# Copyright (C) 2012 Intel Corporation 2# Copyright (C) 2022 Advanced Micro Devices, Inc. 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the "Software"), 6# to deal in the Software without restriction, including without limitation 7# the rights to use, copy, modify, merge, publish, distribute, sublicense, 8# and/or sell copies of the Software, and to permit persons to whom the 9# Software is furnished to do so, subject to the following conditions: 10# 11# The above copyright notice and this permission notice (including the next 12# paragraph) shall be included in all copies or substantial portions of the 13# Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21# IN THE SOFTWARE. 22 23import contextlib 24import gl_XML 25import license 26import marshal_XML 27import sys 28 29header = """#include "glthread_marshal.h" 30""" 31 32current_indent = 0 33 34 35def out(str): 36 if str: 37 print(' '*current_indent + str) 38 else: 39 print('') 40 41 42@contextlib.contextmanager 43def indent(delta=3): 44 global current_indent 45 current_indent += delta 46 yield 47 current_indent -= delta 48 49 50class PrintCode(gl_XML.gl_print_base): 51 def __init__(self): 52 super(PrintCode, self).__init__() 53 54 self.name = 'gl_marshal.py' 55 self.license = license.bsd_license_template % ( 56 'Copyright (C) 2012 Intel Corporation', 'INTEL CORPORATION') 57 58 def printRealHeader(self): 59 print(header) 60 61 def printRealFooter(self): 62 pass 63 64 def printBody(self, api): 65 out('const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD] = {') 66 with indent(): 67 for func in api.functionIterateAll(): 68 if func.marshal_flavor() in ('skip', 'sync'): 69 continue 70 out('[DISPATCH_CMD_{0}] = (_mesa_unmarshal_func)_mesa_unmarshal_{0},'.format(func.name)) 71 if func.packed_fixed_params: 72 out('[DISPATCH_CMD_{0}_packed] = (_mesa_unmarshal_func)_mesa_unmarshal_{0}_packed,'.format(func.name)) 73 out('};') 74 75 # Print the string table of function names. 76 out('') 77 out('const char *_mesa_unmarshal_func_name[NUM_DISPATCH_CMD] = {') 78 with indent(): 79 for func in api.functionIterateAll(): 80 if func.marshal_flavor() in ('skip', 'sync'): 81 continue 82 out('[DISPATCH_CMD_{0}] = "{0}",'.format(func.name)) 83 if func.packed_fixed_params: 84 out('[DISPATCH_CMD_{0}_packed] = "{0}_packed",'.format(func.name)) 85 out('};') 86 87 88def show_usage(): 89 print('Usage: %s [file_name]' % sys.argv[0]) 90 sys.exit(1) 91 92 93if __name__ == '__main__': 94 try: 95 file_name = sys.argv[1] 96 pointer_size = int(sys.argv[2]) 97 except Exception: 98 show_usage() 99 100 printer = PrintCode() 101 102 assert pointer_size != 0 103 api = gl_XML.parse_GL_API(file_name, marshal_XML.marshal_item_factory(), pointer_size) 104 printer.Print(api) 105