diff --git a/modules/core/src/opencl/runtime/generator/common.py b/modules/core/src/opencl/runtime/generator/common.py index 5f81e8ee57..d9064fa70f 100644 --- a/modules/core/src/opencl/runtime/generator/common.py +++ b/modules/core/src/opencl/runtime/generator/common.py @@ -136,16 +136,30 @@ def generateFilterNames(fns): print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) 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 def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'): print '// generated by %s' % os.path.basename(sys.argv[0]) first = True for fn in fns: 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['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 first = False @@ -200,22 +214,12 @@ def generateFnDeclaration(fns): def generateTemplates(sz, lprefix, switch_name, calling_convention=''): print '// generated by %s' % os.path.basename(sys.argv[0]) for sz in range(sz): - template_params = ['int ID', 'typename _R'] - types = [] - types_with_params = [] - params = [] - for i in range(1, sz + 1): - template_params.append('typename _T%d' % i) - 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 '};' + 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 '' @outputToString diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in index 251c085eda..5b48f51400 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_clamdblas.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in index 8633580bab..4e8a563517 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_clamdfft.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in index b6c8f05d51..db9eb80d76 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_core.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in index 847e67f3f3..1c2cb6860e 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_core_wrappers.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in index 13a33c7153..d9de9f6efd 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP #error "Invalid usage" #endif diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in index fc03179140..c5b755470b 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in @@ -1,4 +1,4 @@ -#ifndef __OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP__ +#ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP #error "Invalid usage" #endif