-#!/usr/bin/env python
# Copyright (C) 2012 Intel Corporation
#
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+from __future__ import print_function
+
import contextlib
import getopt
import gl_XML
#include "dispatch.h"
#include "glthread.h"
#include "marshal.h"
-#include "marshal_generated.h"
"""
def out(str):
if str:
- print ' '*current_indent + str
+ print(' '*current_indent + str)
else:
- print ''
+ print('')
@contextlib.contextmanager
'Copyright (C) 2012 Intel Corporation', 'INTEL CORPORATION')
def printRealHeader(self):
- print header
- print '#ifdef HAVE_PTHREAD'
- print
- print 'static inline int safe_mul(int a, int b)'
- print '{'
- print ' if (a < 0 || b < 0) return -1;'
- print ' if (a == 0 || b == 0) return 0;'
- print ' if (a > INT_MAX / b) return -1;'
- print ' return a * b;'
- print '}'
- print
+ print(header)
+ print('static inline int safe_mul(int a, int b)')
+ print('{')
+ print(' if (a < 0 || b < 0) return -1;')
+ print(' if (a == 0 || b == 0) return 0;')
+ print(' if (a > INT_MAX / b) return -1;')
+ print(' return a * b;')
+ print('}')
+ print()
def printRealFooter(self):
- print
- print '#endif'
+ pass
def print_sync_call(self, func):
call = 'CALL_{0}(ctx->CurrentServerDispatch, ({1}))'.format(
out('return {0};'.format(call))
def print_sync_dispatch(self, func):
- out('_mesa_glthread_finish(ctx);')
out('debug_print_sync_fallback("{0}");'.format(func.name))
self.print_sync_call(func)
with indent():
for p in func.fixed_params:
if p.count:
- out('const {0} * {1} = cmd->{1};'.format(
- p.get_base_type_string(), p.name))
+ p_decl = '{0} * {1} = cmd->{1};'.format(
+ p.get_base_type_string(), p.name)
else:
- out('const {0} {1} = cmd->{1};'.format(
- p.type_string(), p.name))
+ p_decl = '{0} {1} = cmd->{1};'.format(
+ p.type_string(), p.name)
+
+ if not p_decl.startswith('const '):
+ # Declare all local function variables as const, even if
+ # the original parameter is not const.
+ p_decl = 'const ' + p_decl
+
+ out(p_decl)
+
if func.variable_params:
for p in func.variable_params:
- out('const {0} * {1};'.format(
+ out('{0} * {1};'.format(
p.get_base_type_string(), p.name))
out('const char *variable_data = (const char *) (cmd + 1);')
for p in func.variable_params:
- out('{0} = (const {1} *) variable_data;'.format(
+ out('{0} = ({1} *) variable_data;'.format(
p.name, p.get_base_type_string()))
if p.img_null_flag:
if p.img_null_flag:
size = '({0} ? {1} : 0)'.format(p.name, size)
size_terms.append(size)
- out('size_t cmd_size = {0};'.format(' + '.join(size_terms)))
+ out('int cmd_size = {0};'.format(' + '.join(size_terms)))
out('{0} *cmd;'.format(struct))
out('debug_print_marshal("{0}");'.format(func.name))
out('if ({0}) {{'.format(func.marshal_fail))
with indent():
out('_mesa_glthread_finish(ctx);')
- out('_mesa_glthread_restore_dispatch(ctx);')
+ out('_mesa_glthread_restore_dispatch(ctx, __func__);')
self.print_sync_dispatch(func)
out('return;')
out('}')
- out('if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {')
+ if len(func.variable_params) > 0:
+ with indent():
+ out('if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {')
+ with indent():
+ self.print_async_dispatch(func)
+ out('return;')
+ out('}')
+ out('')
+ if need_fallback_sync:
+ out('fallback_to_sync:')
+ with indent():
+ out('_mesa_glthread_finish(ctx);')
+ self.print_sync_dispatch(func)
+ else:
with indent():
self.print_async_dispatch(func)
- out('return;')
- out('}')
-
- out('')
- if need_fallback_sync:
- out('fallback_to_sync:')
- with indent():
- self.print_sync_dispatch(func)
-
+ assert not need_fallback_sync
out('}')
def print_async_body(self, func):
out('')
def print_unmarshal_dispatch_cmd(self, api):
- out('size_t')
- out('_mesa_unmarshal_dispatch_cmd(struct gl_context *ctx, '
- 'const void *cmd)')
- out('{')
+ out('const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD] = {')
with indent():
- out('const struct marshal_cmd_base *cmd_base = cmd;')
- out('switch (cmd_base->cmd_id) {')
for func in api.functionIterateAll():
flavor = func.marshal_flavor()
if flavor in ('skip', 'sync'):
continue
- out('case DISPATCH_CMD_{0}:'.format(func.name))
- with indent():
- out('debug_print_unmarshal("{0}");'.format(func.name))
- out(('_mesa_unmarshal_{0}(ctx, (const struct marshal_cmd_{0} *)'
- ' cmd);').format(func.name))
- out('break;')
- out('default:')
- with indent():
- out('assert(!"Unrecognized command ID");')
- out('break;')
- out('}')
- out('')
- out('return cmd_base->cmd_size;')
- out('}')
+ out('[DISPATCH_CMD_{0}] = (_mesa_unmarshal_func)_mesa_unmarshal_{0},'.format(func.name))
+ out('};')
out('')
out('')
def show_usage():
- print 'Usage: %s [-f input_file_name]' % sys.argv[0]
+ print('Usage: %s [-f input_file_name]' % sys.argv[0])
sys.exit(1)
try:
(args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
- except Exception,e:
+ except Exception:
show_usage()
for (arg,val) in args: