1 2# Copyright (C) 2012 Intel Corporation 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 23# marshal_XML.py: factory for interpreting XML for the purpose of 24# building thread marshalling code. 25 26import gl_XML 27 28 29class marshal_item_factory(gl_XML.gl_item_factory): 30 """Factory to create objects derived from gl_item containing 31 information necessary to generate thread marshalling code.""" 32 33 def create_function(self, element, context): 34 return marshal_function(element, context) 35 36 37class marshal_function(gl_XML.gl_function): 38 def process_element(self, element): 39 # Do normal processing. 40 super(marshal_function, self).process_element(element) 41 42 # Only do further processing when we see the canonical 43 # function name. 44 if element.get('name') != self.name: 45 return 46 47 # Classify fixed and variable parameters. 48 self.fixed_params = [] 49 self.variable_params = [] 50 for p in self.parameters: 51 if p.is_padding: 52 continue 53 if p.is_variable_length(): 54 self.variable_params.append(p) 55 else: 56 self.fixed_params.append(p) 57 58 # Store the "marshal" attribute, if present. 59 self.marshal = element.get('marshal') 60 self.marshal_sync = element.get('marshal_sync') 61 self.marshal_call_before = element.get('marshal_call_before') 62 self.marshal_call_after = element.get('marshal_call_after') 63 64 def marshal_flavor(self): 65 """Find out how this function should be marshalled between 66 client and server threads.""" 67 # If a "marshal" attribute was present, that overrides any 68 # determination that would otherwise be made by this function. 69 if self.marshal is not None: 70 return self.marshal 71 72 if self.exec_flavor == 'skip': 73 # Functions marked exec="skip" are not yet implemented in 74 # Mesa, so don't bother trying to marshal them. 75 return 'skip' 76 77 if self.return_type != 'void': 78 return 'sync' 79 for p in self.parameters: 80 if p.is_output: 81 return 'sync' 82 if (p.is_pointer() and not (p.count or p.counter or p.marshal_count)): 83 return 'sync' 84 if p.count_parameter_list and not p.marshal_count: 85 # Parameter size is determined by enums; haven't 86 # written logic to handle this yet. TODO: fix. 87 return 'sync' 88 return 'async' 89