|
|
@ -136,16 +136,30 @@ def generateFilterNames(fns): |
|
|
|
print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) |
|
|
|
print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) |
|
|
|
print '#total %d' % len(fns) |
|
|
|
print '#total %d' % len(fns) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getTypeWithParam(t, p): |
|
|
|
|
|
|
|
if callback_check.match(t): |
|
|
|
|
|
|
|
return callback_check.sub(r'\1 *' + p + r'\3', t) |
|
|
|
|
|
|
|
return t + ' ' + p |
|
|
|
|
|
|
|
|
|
|
|
@outputToString |
|
|
|
@outputToString |
|
|
|
def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'): |
|
|
|
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]) |
|
|
|
first = True |
|
|
|
first = True |
|
|
|
for fn in fns: |
|
|
|
for fn in fns: |
|
|
|
commentStr = '' if fn.has_key('enabled') else '//' |
|
|
|
commentStr = '' if fn.has_key('enabled') else '//' |
|
|
|
print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s%d<%s_%s, %s%s>::switch_fn;' % \ |
|
|
|
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)' % \ |
|
|
|
|
|
|
|
(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['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), |
|
|
|
((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), |
|
|
|
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ |
|
|
|
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ |
|
|
|
commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], ' '.join(fn['ret']), ('' if len(fn['params']) == 0 else ', ' + ', '.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 + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])) |
|
|
|
print |
|
|
|
print |
|
|
|
first = False |
|
|
|
first = False |
|
|
@ -200,22 +214,12 @@ def generateFnDeclaration(fns): |
|
|
|
def generateTemplates(sz, lprefix, switch_name, calling_convention=''): |
|
|
|
def generateTemplates(sz, 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(sz): |
|
|
|
for sz in range(sz): |
|
|
|
template_params = ['int ID', 'typename _R'] |
|
|
|
template_params = ['ID', '_R', 'decl_args'] |
|
|
|
types = [] |
|
|
|
params = ['p%d' % (i + 1) for i in range(0, sz)] |
|
|
|
types_with_params = [] |
|
|
|
print '#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)) |
|
|
|
params = [] |
|
|
|
print ' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention) |
|
|
|
for i in range(1, sz + 1): |
|
|
|
print ' static _R %s ID##_switch_fn decl_args \\' % (calling_convention) |
|
|
|
template_params.append('typename _T%d' % i) |
|
|
|
print ' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)) |
|
|
|
types.append('_T%d' % i) |
|
|
|
|
|
|
|
types_with_params.append('_T%d p%d' % (i, i)) |
|
|
|
|
|
|
|
params.append('p%d' % i) |
|
|
|
|
|
|
|
print 'template <%s>' % ', '.join(template_params) |
|
|
|
|
|
|
|
print 'struct %s%d' % (lprefix, sz) |
|
|
|
|
|
|
|
print '{' |
|
|
|
|
|
|
|
print ' typedef _R (%s *FN)(%s);' % (calling_convention, ', '.join(types)) |
|
|
|
|
|
|
|
print ' static _R %s switch_fn(%s)' % (calling_convention, ', '.join(types_with_params)) |
|
|
|
|
|
|
|
print ' { return ((FN)%s(ID))(%s); }' % (switch_name, ', '.join(params)) |
|
|
|
|
|
|
|
print '};' |
|
|
|
|
|
|
|
print '' |
|
|
|
print '' |
|
|
|
|
|
|
|
|
|
|
|
@outputToString |
|
|
|
@outputToString |
|
|
|