psyclone.psyir.frontend.fparser2

This module provides the fparser2 to PSyIR front-end, it follows a Visitor Pattern to traverse relevant fparser2 nodes and contains the logic to transform each node into the equivalent PSyIR representation.

Classes

  • Fparser2Reader: Class to encapsulate the functionality for processing the fparser2 AST and

class psyclone.psyir.frontend.fparser2.Fparser2Reader

Class to encapsulate the functionality for processing the fparser2 AST and convert the nodes to PSyIR.

Inheritance

Inheritance diagram of Fparser2Reader
generate_container(module_ast)

Create a Container from the supplied fparser2 module AST.

Parameters:

module_ast (fparser.two.Fortran2003.Program) – fparser2 AST of the full module.

Returns:

PSyIR container representing the given module_ast or None if there’s no module in the parse tree.

Return type:

psyclone.psyir.nodes.Container

Raises:

GenerationError – unable to generate a Container from the provided fpaser2 parse tree.

generate_psyir(parse_tree)

Translate the supplied fparser2 parse_tree into PSyIR.

Parameters:

parse_tree (fparser.two.Fortran2003.Program) – the supplied fparser2 parse tree.

Returns:

PSyIR representation of the supplied fparser2 parse_tree.

Return type:

psyclone.psyir.nodes.Container or psyclone.psyir.nodes.Routine

Raises:

GenerationError – if the root of the supplied fparser2 parse tree is not a Program.

get_routine_schedules(name, module_ast)

Create one or more schedules for routines corresponding to the supplied name in the supplied fparser2 AST. (There can be more than one routine if the supplied name corresponds to an interface block in the AST.)

Parameters:
  • name (str) – name of the subroutine represented by the kernel.

  • module_ast (fparser.two.Fortran2003.Program) – fparser2 AST of the full module where the kernel code is located.

Returns:

PSyIR schedules representing the matching subroutine(s).

Return type:

List[psyclone.psyir.nodes.KernelSchedule]

Raises:
  • GenerationError – if supplied parse tree contains more than one module.

  • GenerationError – unable to generate a kernel schedule from the provided fpaser2 parse tree.

static nodes_to_code_block(parent, fp2_nodes, message=None)

Create a CodeBlock for the supplied list of fparser2 nodes and then wipe the list. A CodeBlock is a node in the PSyIR (Schedule) that represents a sequence of one or more Fortran statements and/or expressions which PSyclone does not attempt to handle.

Parameters:
  • parent (psyclone.psyir.nodes.Node) – Node in the PSyclone AST to which to add this CodeBlock.

  • fp2_nodes (list of fparser.two.utils.Base) – list of fparser2 AST nodes constituting the CodeBlock.

  • message (Optional[str]) – Include a preceeding comment attached to the CodeBlock.

Returns:

a CodeBlock instance.

Return type:

psyclone.CodeBlock

static process_access_statements(nodes)

Search the supplied list of fparser2 nodes (which must represent a complete Specification Part) for any accessibility statements (e.g. “PUBLIC :: my_var”) to determine the default visibility of symbols as well as identifying those that are explicitly declared as public or private.

Parameters:

nodes (list of fparser.two.utils.Base) – nodes in the fparser2 parse tree describing a Specification Part that will be searched.

Returns:

default visibility of symbols within the current scoping unit and dict of symbol names with explicit visibilities.

Return type:

2-tuple of (psyclone.symbols.Symbol.Visibility, dict)

Raises:
  • InternalError – if an accessibility attribute which is not ‘public’ or ‘private’ is encountered.

  • GenerationError – if the parse tree is found to contain more than one bare accessibility statement (i.e. ‘PUBLIC’ or ‘PRIVATE’)

  • GenerationError – if a symbol is explicitly declared as being both public and private.

process_declarations(parent, nodes, arg_list, visibility_map=None)

Transform the variable declarations in the fparser2 parse tree into symbols in the symbol table of the PSyIR parent node. The default visibility of any new symbol is taken from the symbol table associated with the parent node if necessary. The visibility_map provides information on any explicit symbol visibilities that are specified for the declarations.

Parameters:
  • parent (psyclone.psyir.nodes.KernelSchedule) – PSyIR node in which to insert the symbols found.

  • nodes (List[fparser.two.utils.Base]) – fparser2 AST nodes containing declaration statements.

  • arg_list (fparser.Fortran2003.Dummy_Arg_List) – fparser2 AST node containing the argument list.

  • visibility_map (dict[ str, psyclone.psyir.symbols.Symbol.Visibility]) – mapping of symbol names to explicit visibilities.

Raises:
  • GenerationError – if an INCLUDE statement is encountered.

  • NotImplementedError – the provided declarations contain attributes which are not supported yet.

  • GenerationError – if the parse tree for a USE statement does not have the expected structure.

  • SymbolError – if a declaration is found for a Symbol that is already in the symbol table with a defined interface.

  • InternalError – if the provided declaration is an unexpected or invalid fparser or Fortran expression.

process_nodes(parent, nodes)

Create the PSyIR of the supplied list of nodes in the fparser2 AST.

Parameters:
  • parent (psyclone.psyir.nodes.Node) – Parent node in the PSyIR we are constructing.

  • nodes (list[fparser.two.utils.Base]) – List of sibling nodes in fparser2 AST.