From 9d07cfc18b34c8d840af9b40c3a6da3bd3458b06 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Thu, 9 Jan 2025 12:14:35 +0000 Subject: [PATCH] Transpile: Remove redundant interface generation for module functions --- .../transpile/fortran_iso_c_wrapper.py | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/loki/transformations/transpile/fortran_iso_c_wrapper.py b/loki/transformations/transpile/fortran_iso_c_wrapper.py index 819d919ba..7f77fe8f6 100644 --- a/loki/transformations/transpile/fortran_iso_c_wrapper.py +++ b/loki/transformations/transpile/fortran_iso_c_wrapper.py @@ -426,12 +426,6 @@ def generate_iso_c_wrapper_module(module, use_c_ptr=False, language='c'): modname = f'{module.name}_fc' wrapper_module = Module(name=modname) - # Generate bind(c) intrinsics for module variables - original_import = ir.Import(module=module.name) - isoc_import = iso_c_intrinsic_import(module, use_c_ptr=use_c_ptr) - implicit_none = ir.Intrinsic(text='implicit none') - spec = [original_import, isoc_import, implicit_none] - # Create getter methods for module-level variables (I know... :( ) if language == 'c': wrappers = [] @@ -457,28 +451,6 @@ def generate_iso_c_wrapper_module(module, use_c_ptr=False, language='c'): wrappers += [getter] wrapper_module.contains = ir.Section(body=(ir.Intrinsic('CONTAINS'), *wrappers)) - # Create function interface definitions for module functions - intfs = [] - for fct in module.subroutines: - if fct.is_function: - intf_fct = fct.clone(bind=f'{fct.name.lower()}') - intf_fct.body = ir.Section(body=()) - - intf_args = [] - for arg in intf_fct.arguments: - # Only scalar, intent(in) arguments are pass by value - # Pass by reference for array types - value = isinstance(arg, sym.Scalar) and arg.type.intent and arg.type.intent.lower() == 'in' - kind = iso_c_intrinsic_kind(arg.type, intf_fct, use_c_ptr=use_c_ptr) - ctype = SymbolAttributes(arg.type.dtype, value=value, kind=kind) - dimensions = arg.dimensions if isinstance(arg, sym.Array) else None - var = sym.Variable(name=arg.name, dimensions=dimensions, type=ctype, scope=intf_fct) - intf_args += (var,) - intf_fct.arguments = intf_args - sanitise_imports(intf_fct) - intfs.append(intf_fct) - spec.append(ir.Interface(body=(as_tuple(intfs),))) - # Remove any unused imports sanitise_imports(wrapper_module) return wrapper_module @@ -532,18 +504,6 @@ def generate_c_header(module): header_td._update(body=as_tuple(declarations)) spec += [header_td] - # Generate a header declaration for module routines - for fct in module.subroutines: - if fct.is_function: - fct_type = 'void' - if fct.name in fct.variables: - fct_type = c_intrinsic_kind(fct.variable_map[fct.name.lower()].type, header_module) - - args = [f'{c_intrinsic_kind(a.type, header_module)} {a.name.lower()}' - for a in fct.arguments] - fct_decl = f'{fct_type} {fct.name.lower()}({", ".join(args)});' - spec.append(ir.Intrinsic(text=fct_decl)) - header_module.spec = spec header_module.rescope_symbols() return header_module