+from __future__ import print_function
import sys, os, re
#
try:
f = open(fileName, "r")
except:
- print "ERROR: Can't open filter file: %s" % fileName
+ print("ERROR: Can't open filter file: %s" % fileName)
return 0
count = 0
@outputToString
def generateFilterNames(fns):
for fn in fns:
- print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name'])
- print '#total %d' % len(fns)
+ print('%s%s' % ('' if 'enabled' in fn else '//', fn['name']))
+ print('#total %d' % len(fns))
callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))')
@outputToString
def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- commentStr = '' if fn.has_key('enabled') else '//'
+ commentStr = '' if 'enabled' in fn else '//'
decl_args = []
for (i, t) in enumerate(fn['params']):
decl_args.append(getTypeWithParam(t, 'p%d' % (i+1)))
decl_args_str = '(' + (', '.join(decl_args)) + ')'
- print '%s%s%d(%s_%s, %s, %s)' % \
+ print('%s%s%d(%s_%s, %s, %s)' % \
(commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], \
- ' '.join(fn['ret']), decl_args_str)
- print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \
+ ' '.join(fn['ret']), decl_args_str))
+ print(commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \
((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''),
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \
- commentStr, enumprefix, fn['name']))
- print commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name']))
- print
+ commentStr, enumprefix, fn['name'])))
+ print(commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])))
+ print()
@outputToString
def generateStaticDefinitions(fns):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- commentStr = '' if fn.has_key('enabled') else '//'
+ commentStr = '' if 'enabled' in fn else '//'
decl_args = []
for (i, t) in enumerate(fn['params']):
decl_args.append(getTypeWithParam(t, 'p%d' % (i+1)))
decl_args_str = '(' + (', '.join(decl_args)) + ')'
- print commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \
+ print(commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \
((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''),
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \
- fn['name']))
+ fn['name'])))
@outputToString
def generateListOfDefinitions(fns, name='opencl_fn_list'):
- print '// generated by %s' % os.path.basename(sys.argv[0])
- print 'static const struct DynamicFnEntry* %s[] = {' % (name)
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
+ print('static const struct DynamicFnEntry* %s[] = {' % (name))
for fn in fns:
- commentStr = '' if fn.has_key('enabled') else '//'
- if fn.has_key('enabled'):
- print ' &%s_definition,' % (fn['name'])
+ commentStr = '' if 'enabled' in fn else '//'
+ if 'enabled' in fn:
+ print(' &%s_definition,' % (fn['name']))
else:
- print ' NULL/*&%s_definition*/,' % (fn['name'])
+ print(' NULL/*&%s_definition*/,' % (fn['name']))
first = False
- print '};'
+ print('};')
@outputToString
def generateEnums(fns, prefix='OPENCL_FN'):
- print '// generated by %s' % os.path.basename(sys.argv[0])
- print 'enum %s_ID {' % prefix
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
+ print('enum %s_ID {' % prefix)
for (i, fn) in enumerate(fns):
- commentStr = '' if fn.has_key('enabled') else '//'
- print commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i))
- print '};'
+ commentStr = '' if 'enabled' in fn else '//'
+ print(commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i)))
+ print('};')
@outputToString
def generateRemapOrigin(fns):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- print '#define %s %s_' % (fn['name'], fn['name'])
+ print('#define %s %s_' % (fn['name'], fn['name']))
@outputToString
def generateRemapDynamic(fns):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- print '#undef %s' % (fn['name'])
- commentStr = '' if fn.has_key('enabled') else '//'
- print commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name']))
+ print('#undef %s' % (fn['name']))
+ commentStr = '' if 'enabled' in fn else '//'
+ print(commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name'])))
@outputToString
def generateFnDeclaration(fns):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- commentStr = '' if fn.has_key('enabled') else '//'
- print commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']),
- fn['name'], ', '.join(fn['params'] if not fn.has_key('params_full') else fn['params_full'])))
+ commentStr = '' if 'enabled' in fn else '//'
+ print(commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']),
+ fn['name'], ', '.join(fn['params'] if 'params_full' not in fn else fn['params_full']))))
@outputToString
def generateTemplates(total, lprefix, switch_name, calling_convention=''):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for sz in range(total):
template_params = ['ID', '_R', 'decl_args']
params = ['p%d' % (i + 1) for i in range(0, sz)]
- print '#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params))
- print ' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention)
- print ' static _R %s ID##_switch_fn decl_args \\' % (calling_convention)
- print ' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params))
- print ''
+ print('#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)))
+ print(' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention))
+ print(' static _R %s ID##_switch_fn decl_args \\' % (calling_convention))
+ print(' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)))
+ print('')
@outputToString
def generateInlineWrappers(fns):
- print '// generated by %s' % os.path.basename(sys.argv[0])
+ print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns:
- commentStr = '' if fn.has_key('enabled') else '//'
- print '#undef %s' % (fn['name'])
- print commentStr + ('#define %s %s_fn' % (fn['name'], fn['name']))
+ commentStr = '' if 'enabled' in fn else '//'
+ print('#undef %s' % (fn['name']))
+ print(commentStr + ('#define %s %s_fn' % (fn['name'], fn['name'])))
params = []
call_params = []
for i in range(0, len(fn['params'])):
call_params.append('p%d' % (i))
if len(fn['ret']) == 1 and fn['ret'][0] == 'void':
- print commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \
- % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params)))
+ print(commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \
+ % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))
else:
- print commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \
- % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params)))
+ print(commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \
+ % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))
def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\n//'):
f = open(inputFile, "r")
if noteLine:
- print noteLine
+ print(noteLine)
for line in f:
if line.startswith('@'):
assert line[-1] == '\n'
line = line[:-1] # remove '\n'
assert line[-1] == '@'
name = line[1:-1]
- assert ctx.has_key(name), name
+ assert name in ctx, name
line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '')
sys.stdout.write(line)
f.close()