psyclone.psyir.nodes.routine#
This module contains the Routine node implementation.
Classes#
Routine: A sub-class of a Schedule that represents a subroutine, function or
- class psyclone.psyir.nodes.routine.Routine(symbol, is_program=False, **kwargs)[source]#
A sub-class of a Schedule that represents a subroutine, function or program unit.
- Parameters:
symbol (
psyclone.psyir.symbols.RoutineSymbol) – the Symbol used to represent this Routine in its Container.is_program (Optional[bool]) – whether this Routine represents the entry point into a program (e.g. Fortran Program or C main()). Default is False.
kwargs (unwrapped dict.) – additional keyword arguments provided to the super class.
- Raises:
TypeError – if any of the supplied arguments are of the wrong type.
Inheritance

- check_outer_scope_accesses(call, kern_or_call, permit_unresolved=True, ignore_non_data_accesses=False)[source]#
Check for unresolved symbols or for any declared in the outer scope Container of the target routine.
- Parameters:
call (Union[CodedKern, Call]) – the node representing the call to the routine that is to be inlined.
kern_or_call (
str) – text appropriate to whether we have a PSyKAl Kernel or a generic routine.permit_unresolved (
bool) – whether or not the presence of unresolved symbols will result in an error being raised.ignore_non_data_accesses (
bool) – ignore unresolved symbols if they do not represent data accesses (e.g. provide type information).
- Raises:
SymbolError – if there is an access to an unresolved symbol and permit_unresolved is False.
SymbolError – if there is an access to a symbol that is declared in the parent scope of this routine.
- classmethod create(name, symbol_table=None, children=None, is_program=False, return_symbol_name=None)[source]#
Create an instance of the supplied class given a name, a symbol table and a list of child nodes. This is implemented as a classmethod so that it is able to act as a Factory for subclasses - e.g. it will create a KernelSchedule if called from KernelSchedule.create().
- Parameters:
name (str) – the name of the Routine (or subclass).
symbol_table (Optional[
psyclone.psyGen.SymbolTable]) – the symbol table associated with this Routine.children (Optional[list of
psyclone.psyir.nodes.Node]) – a list of PSyIR nodes contained in the Routine.is_program (Optional[bool]) – whether this Routine represents the entry point into a program (e.g. Fortran Program or C main()). Default is False.
return_symbol_name (str) – name of the symbol that holds the return value of this routine (if any). Must be present in the supplied symbol table.
- Returns:
an instance of cls.
- Return type:
psyclone.psyir.nodes.Routineor subclass- Raises:
TypeError – if the arguments to the create method are not of the expected type.
- property dag_name#
- Returns:
the name of this node in the dag.
- Return type:
str
- property is_program#
- Returns:
whether this Routine represents the entry point into a program (e.g. is a Fortran Program or a C main()).
- Return type:
bool
- property name#
- Returns:
the name of this Routine.
- Return type:
str
- node_str(colour=True)[source]#
Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.
- Parameters:
colour (bool) – whether or not to include colour control codes.
- Returns:
description of this node, possibly coloured.
- Return type:
str
- replace_with(node, keep_name_in_context=True)[source]#
Removes self and its descendants from the PSyIR tree to which it is connected and replaces it with the supplied node (and its descendants).
The node must be a Routine (or subclass) and has the same Symbol as self.
keep_name_in_context is ignored for this replace_with implementation, however we keep the argument to match with the base implementation.
- Parameters:
node (
psyclone.psyir.nodes.Routine) – the node that will replace self in the PSyIR tree.keep_name_in_context (bool) – ignored.
- Raises:
TypeError – if the argument node is not a Routine.
GenerationError – if this node does not have a parent.
GenerationError – if the argument ‘node’ has a parent
GenerationError – if self and node do not have the same Symbol.
- property return_symbol#
- Returns:
the symbol which will hold the return value of this Routine or None if the Routine is not a function.
- Return type:
psyclone.psyir.symbols.DataSymbolor NoneType
- property symbol#
- Returns:
the RoutineSymbol corresponding to this Routine.
- Return type:
psyclone.psyir.symbols.RoutineSymbolor NoneType
- update_parent_symbol_table(new_parent)[source]#
Update the Routine’s new parent’s symbol tables with the corresponding RoutineSymbol.
- Parameters:
new_parent (
psyclone.psyir.nodes.ScopingNode) – The new parent of this node.- Raises:
GenerationError – if a symbol with the same name already exists in the scope.
GenerationError – if a Routine with the same name already exists in the scope.
GenerationError – if a Codeblock representing a routine with the same name already exists in the scope.