loki.transformations.transpile.fortran_iso_c_wrapper
Functions
|
Determine the intrinsic C-type for a given symbol table entry. |
|
Create the |
|
Re-generate the C header as a module with all pertinent nodes, but not Fortran-specific intrinsics (eg. |
|
Generate the ISO-C subroutine |
|
Generate the ISO-C wrapper module for a raw Fortran module. |
|
Generate Fortran ISO-C wrapper |
|
Create |
|
Determine the intrinsic ISO-C type for a given symbol table entry. |
Classes
Wrapper transformation that generates ISO-C Fortran wrappers and C headers for translated kernels or additional header modules. |
- 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 kindscope (
Scope) – The containing scope in which to clone the type symbol
- iso_c_intrinsic_import(scope, use_c_ptr=False)
Create
Importobject for the intrinsic C base types.
- 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.
- c_struct_typedef(derived, use_c_ptr=False)
Create the
TypeDeffor the C-wrapped struct definition.- Parameters:
use_c_ptr (bool, optional) – Use
c_ptrfor array declarations andc_loc(...)to pass the corresponding argument. Default isFalse.
- generate_iso_c_interface(routine, bind_name, c_structs, scope, use_c_ptr=False, language='c')
Generate the ISO-C subroutine
Interfaceobject for a givenSubroutine.- Parameters:
routine (
Subroutine) – The subroutine for which to generate the interfacebind_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 theInterfaceuse_c_ptr (bool, optional) – Use
c_ptrfor array declarations andc_loc(...)to pass the corresponding argument. Default isFalse.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
Subroutinethat 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 wrapperSubroutinethat 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 interfacec_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_ptrfor array declarations andc_loc(...)to pass the corresponding argument. Default isFalse.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 containedSubroutineobjects. This method will callgenerate_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:
- 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:
TransformationWrapper transformation that generates ISO-C Fortran wrappers and C headers for translated kernels or additional header modules.
In addition to
Subroutineobjects with the role'kernel', this transformation will processModuleobjects 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_ptrfor array declarations andc_loc(...)to pass the corresponding argument. Default isFalse.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
Moduleitems.For transformations that modify
Moduleobjects, this method should be implemented. It gets called via the dispatch methodapply().- 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
Subroutineitems.For transformations that modify
Subroutineobjects, this method should be implemented. It gets called via the dispatch methodapply().- Parameters:
routine (
Subroutine) – The subroutine to be transformed.**kwargs (optional) – Keyword arguments for the transformation.