37 '''This module implements the PSyclone NEMO API by specialising
38 the required base classes for code generation (PSy, Invokes,
39 Invoke, InvokeSchedule, Loop, CodedKern, Arguments and KernelArgument).
43 from fparser.two.utils
import walk
44 from fparser.two
import Fortran2003
47 from psyclone.psyGen import PSy, Invokes, Invoke, InvokeSchedule, InlinedKern
55 Represents a NEMO 'Invoke' which, since NEMO is existing code, means
56 an existing program unit, e.g. a subroutine.
58 :param sched: PSyIR node representing the program unit.
59 :type sched: :py:class:`psyclone.psyir.nodes.Routine`
60 :param str name: the name of this Invoke (program unit).
61 :param invokes: the Invokes object that holds this Invoke.
62 :type invokes: :py:class:`psyclone.nemo.NemoInvokes`
65 def __init__(self, sched, name, invokes):
75 Class capturing information on all 'Invokes' (program units) within
76 a single NEMO source file.
78 :param psyir: the language-level PSyIR for the whole Fortran source file.
79 :type psyir: :py:class:`psyclone.psyir.nodes.Container`
80 :param psy: the PSy object containing all information for this source file.
81 :type psy: :py:class:`psyclone.nemo.NemoPSy`
84 def __init__(self, psyir, psy):
93 CreateNemoPSyTrans().apply(psyir)
94 routines = psyir.walk(Routine)
97 for subroutine
in routines:
99 my_invoke =
NemoInvoke(subroutine, subroutine.name, self)
106 The NEMO-specific PSy class. This creates a NEMO-specific
107 invokes object (which controls all the required invocation calls).
109 :param ast: the fparser2 AST for this PSy layer (i.e. NEMO routine)
110 :type ast: :py:class:`fparser.two.Fortran2003.Main_Program` or \
111 :py:class:`fparser.two.Fortran2003.Subroutine_Subprogram` or \
112 :py:class:`fparser.two.Fortran2003.Function_Subprogram`.
113 :raises InternalError: if no Fortran2003.Name nodes are found in the \
116 def __init__(self, ast):
118 names = walk(ast.content, Fortran2003.Name)
121 raise InternalError(
"Found no names in supplied Fortran - should "
126 psyir = processor.generate_psyir(ast)
134 Generate the Fortran for the NEMO code represented by this
137 :returns: the Fortran code.
141 enable_checks = Config.get().backend_checks_enabled
142 fwriter =
FortranWriter(check_global_constraints=enable_checks)
148 The NEMO-specific InvokeSchedule sub-class. This is the top-level node in
149 PSyclone's IR of a NEMO program unit (program, subroutine etc).
151 :param str name: the name of this NemoInvokeSchedule (Routine).
152 :param invoke: the Invoke to which this NemoInvokeSchedule belongs.
153 :type invoke: :py:class:`psyclone.nemo.NemoInvoke`
154 :param kwargs: additional keyword arguments provided to the super class.
155 :type kwargs: unwrapped dict.
158 _text_name =
"NemoInvokeSchedule"
160 def __init__(self, name, invoke=None, **kwargs):
161 super().__init__(name,
None,
None, **kwargs)
167 Returns a list of all of the user-supplied kernels (as opposed to
168 builtins) that are beneath this node in the PSyIR. In the NEMO API
169 this means all instances of InlinedKern.
171 :returns: all user-supplied kernel calls below this node.
172 :rtype: list of :py:class:`psyclone.psyGen.CodedKern`
174 return self.walk(InlinedKern)