Skip to content

Commit

Permalink
Transpile: Do not bubber c_structs between invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange05 committed Dec 23, 2024
1 parent 7308e2e commit dd2c558
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions loki/transformations/transpile/fortran_iso_c_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def __init__(self, use_c_ptr=False, language='c'):
raise ValueError(f'language "{self.language}" is not supported!'
f' (supported languages: "{self._supported_languages}")')

# Maps from original type name to ISO-C and C-struct types
self.c_structs = OrderedDict()

def file_suffix(self):
if self.language == 'cpp':
return '.cpp'
Expand All @@ -86,8 +83,9 @@ def transform_module(self, module, **kwargs):

role = kwargs.get('role', 'kernel')

c_structs = {}
for name, td in module.typedef_map.items():
self.c_structs[name.lower()] = c_struct_typedef(td, use_c_ptr=self.use_c_ptr)
c_structs[name.lower()] = c_struct_typedef(td, use_c_ptr=self.use_c_ptr)

if role == 'header':
# Generate Fortran wrapper module
Expand All @@ -112,15 +110,16 @@ def transform_subroutine(self, routine, **kwargs):

role = kwargs.get('role', 'kernel')

c_structs = {}
for arg in routine.arguments:
if isinstance(arg.type.dtype, DerivedType):
self.c_structs[arg.type.dtype.name.lower()] = c_struct_typedef(arg.type, use_c_ptr=self.use_c_ptr)
c_structs[arg.type.dtype.name.lower()] = c_struct_typedef(arg.type, use_c_ptr=self.use_c_ptr)

if role == 'kernel':
# Generate Fortran wrapper module
bind_name = None if self.language in ['c', 'cpp'] else f'{routine.name.lower()}_c_launch'
wrapper = generate_iso_c_wrapper_routine(
routine, self.c_structs, bind_name=bind_name,
routine, c_structs, bind_name=bind_name,
use_c_ptr=self.use_c_ptr, language=self.language
)
contains = ir.Section(body=(ir.Intrinsic('CONTAINS'), wrapper))
Expand Down

0 comments on commit dd2c558

Please sign in to comment.