# loki.transformations.transpile.fortran_iso_c_wrapper module

c_intrinsic_kind(_type, scope)

  Determine the intrinsic C-type for a given symbol table entry.

  Parameters:

    - _type (`SymbolAttr`) – The symbols type attribute to determine type and kind

    - scope (`Scope`) – The containing scope in which to clone the type symbol

iso_c_intrinsic_import(scope, use_c_ptr=False)

  Create `Import` object for the intrinsic C base types.

  Parameters:

    - scope (`Scope`) – The scope in which to create the import node and type symbols.

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

iso_c_intrinsic_kind(_type, scope, is_array=False, use_c_ptr=False)

  Determine the intrinsic ISO-C type for a given symbol table entry.

  Parameters:

    - _type (`SymbolAttr`) – The symbols type attribute to determine type and kind

    - is_array (bool) – Flag indicating if the passed type belongs to an array symbol.

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

c_struct_typedef(derived, use_c_ptr=False)

  Create the `TypeDef` for the C-wrapped struct definition.

  Parameters:

    use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

generate_iso_c_interface(routine, bind_name, c_structs, scope, use_c_ptr=False, language='c')

  Generate the ISO-C subroutine `Interface` object for a given `Subroutine`.

  Parameters:

    - routine (`Subroutine`) – The subroutine for which to generate the interface

    - bind_name (str) – Name of the C-function to which this interface corresponds.

    - c_structs (dict of str to str) – Map from Fortran derived type name to C-struct type name

    - scope (`Scope`) – Parent scope in which to create the `Interface`

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

    - language (string) – C-style language to generate; if this is `'c'`, we resolve non-C imports.

generate_iso_c_wrapper_routine(routine, c_structs, bind_name=None, use_c_ptr=False, language='c')

  Generate Fortran ISO-C wrapper `Subroutine` that corresponds to a transpiled C method.

  The new wrapper subroutine will have the suffix `'_fc'` appended to the name original subroutine name and bind to a C function with the suffix `'_c'`.

  This method will call `generate_iso_c_interface()` to generate the ISO-C compatible interface for the C function and generate a wrapper `Subroutine` that converts the native Fortran arguments to a call to the C function with ISO-C compatible arguments.

  Parameters:

    - routine (`Subroutine`) – The subroutine for which to generate the interface

    - c_structs (dict of str to str) – Map from Fortran derived type name to C-struct type name

    - bind_name (str) – Name of the C-function to which this interface corresponds.

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

    - language (string) – C-style language to generate; if this is `'c'`, we resolve non-C imports.

generate_iso_c_wrapper_module(module, use_c_ptr=False, language='c')

  Generate the ISO-C wrapper module for a raw Fortran module.

  The new wrapper module will have the suffix `'_fc'` appended to the name and contain ISO-C function interfaces for contained `Subroutine` objects. This method will call `generate_iso_c_routine()` to generate the ISO-C compatible procedure interfaces.

  Note

  If the module contains global variables, we generate templated getter functions here, as global Fortran variables are not accessible via ISO-C interfaces.

  Parameters:

    - module (`Module`) – The module for which to generate the interface module

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

    - language (string) – C-style language to generate; if this is `'c'`, we resolve non-C imports.

generate_c_header(module)

  Re-generate the C header as a module with all pertinent nodes, but not Fortran-specific intrinsics (eg. implicit none or save).

  The new header module will have the suffix `'_c'` appended to the original module name.

  Parameters:

    module (`Module`) – The module for which to generate the C header

class FortranISOCWrapperTransformation(use_c_ptr=False, language='c')

  Bases: `Transformation`

  Wrapper transformation that generates ISO-C Fortran wrappers and C headers for translated kernels or additional header modules.

  In addition to `Subroutine` objects with the role `'kernel'`, this transformation will process `Module` objects with the role `'header'`. This will generate ISO-C wrappers for derived types and the corresponding C-compatible structs in C header files.

  Parameters:

    - use_c_ptr (bool, optional) – Use `c_ptr` for array declarations and `c_loc(...)` to pass the corresponding argument. Default is `False`.

    - language (string) – Actual C-style language to generate; must be on of `'c'`, `'cpp'` or `'cuda'` for C, C++ and CUDA respectively.

  item_filter = (<class 'loki.batch.item.ProcedureItem'>, <class 'loki.batch.item.ModuleItem'>)
  transform_module(module, **kwargs)

    Defines the transformation to apply to `Module` items.

    For transformations that modify `Module` objects, this method should be implemented. It gets called via the dispatch method `apply()`.

    Parameters:

      - module (`Module`) – The module to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.

  transform_subroutine(routine, **kwargs)

    Defines the transformation to apply to `Subroutine` items.

    For transformations that modify `Subroutine` objects, this method should be implemented. It gets called via the dispatch method `apply()`.

    Parameters:

      - routine (`Subroutine`) – The subroutine to be transformed.

      - **kwargs (optional) – Keyword arguments for the transformation.