psyclone.psyir.transformations.datanode_to_temp_trans#

This module contains the DataNodeToTempTrans class.

Classes#

class psyclone.psyir.transformations.datanode_to_temp_trans.DataNodeToTempTrans[source]#

Provides a generic transformation for moving a datanode from a statement into a new standalone statement. For example:

>>> from psyclone.psyir.frontend.fortran import FortranReader
>>> from psyclone.psyir.backend.fortran import FortranWriter
>>> from psyclone.psyir.nodes import Assignment
>>> from psyclone.psyir.transformations import DataNodeToTempTrans
>>>
>>> psyir = FortranReader().psyir_from_source('''
...     subroutine my_subroutine()
...         integer :: i
...         integer :: j
...         i = j * 2
...     end subroutine
...     ''')
>>> assign = psyir.walk(Assignment)[0]
>>> DataNodeToTempTrans().apply(assign.rhs, storage_name="temp")
>>> print(FortranWriter()(psyir))
subroutine my_subroutine()
  integer, dimension(10,10) :: a
  integer :: i
  integer :: j
  integer :: temp

    temp = j * 2
    i = temp

end subroutine my_subroutine

Inheritance

Inheritance diagram of DataNodeToTempTrans
apply(node, storage_name='', verbose=False, **kwargs)[source]#

Applies the DataNodeToTempTrans to the input arguments.

Parameters:
  • node (DataNode) – The datanode to extract.

  • storage_name (str) – The base name of the temporary variable to store the result of the input node in. The default is tmp(_…) based on the rules defined in the SymbolTable class.

  • verbose (bool) – Whether to add comments to the input node if the transformation fails.

validate(node, **kwargs)[source]#

Validity checks for input arguments

Parameters:
  • node (DataNode) – The DataNode to be extracted.

  • storage_name (str) – The base name of the temporary variable to store the result of the input node in. The default is tmp(_…) based on the rules defined in the SymbolTable class.

  • verbose (bool) – Whether to add comments to the input node if the transformation fails.

Raises:
  • TypeError – if the input arguments are the wrong types.

  • TransformationError – if the input node’s datatype can’t be resolved.

  • TransformationError – if the input node’s datatype is an array but any of the array’s dimensions are unknown.

  • TransformationError – if the input node doesn’t have an ancestor statement.

  • TransformationError – if the input node contains a call that isn’t guaranteed to be pure.