psyclone.psyir.backend.language_writer
PSyIR visitor layer that provides convenient functions that can be reused for different language-specific visitors.
Classes
LanguageWriter
: A convenience PSyIR visitor intermediate class. It provides
- class psyclone.psyir.backend.language_writer.LanguageWriter(array_parenthesis, structure_character, skip_nodes=False, indent_string=' ', initial_indent_depth=0, check_global_constraints=True)
A convenience PSyIR visitor intermediate class. It provides configuration options and functions that can be shared between different language-specific visitors.
- Parameters:
array_parenthesis (2-tuple of str) – a tuple of two strings that contain the opening and closing parenthesis used for array accesses - e.g.: (“(”, “)”).
structure_symbol (str) – the symbol to be used to address a member of a structure, e.g. “%”.
skip_nodes (bool) – If skip_nodes is False then an exception is raised if a visitor method for a PSyIR node has not been implemented, otherwise the visitor silently continues. This is an optional argument which defaults to False.
indent_string (str) – Specifies what to use for indentation. This is an optional argument that defaults to two spaces.
initial_indent_depth (int) – Specifies how much indentation to start with. This is an optional argument that defaults to 0.
check_global_constraints (bool) – whether or not to validate all global constraints when walking the tree. Defaults to True.
- Raises:
TypeError – if any of the supplied parameters are of the wrong type.
Inheritance
- property array_parenthesis
- Returns:
the array parenthesis to be used in this language.
- Return type:
two element list of str
- arrayofstructuresreference_node(node)
Creates the code for a reference to one or more elements of an array of derived types.
- Parameters:
node (
psyclone.psyir.nodes.ArrayOfStructuresReference
) – an ArrayOfStructuresReference PSyIR node.- Returns:
the code as string.
- Return type:
str
- Raises:
VisitorError – if the supplied node does not have the correct number and type of children.
- arrayreference_node(node)
This method is called when an ArrayReference instance is found in the PSyIR tree.
- Parameters:
node (
psyclone.psyir.nodes.ArrayNode
) – an ArrayNode PSyIR node.- Returns:
the code as a string.
- Return type:
str
- Raises:
VisitorError – if the node does not have any children.
- clause_node(node)
This method is called when a Clause instance is found in the PSyIR tree. It returns the clause and its children as a string.
- Parameters:
node (
psyclone.psyir.nodes.Clause
) – a Clause PSyIR node.- Returns:
the code for this node.
- Return type:
str
- abstract gen_indices(indices, var_name=None)
Given a list of PSyIR nodes representing the dimensions of an array, return a list of strings representing those array dimensions.
- Parameters:
indices (list of
psyclone.psyir.symbols.Node
) – list of PSyIR nodes.var_name (str) – name of the variable for which the dimensions are created. Only used in the C implementation.
- Returns:
the code representation of the dimensions.
- Return type:
list of str
- member_node(node)
Creates the code for an access to a member of a derived type.
- Parameters:
node (
psyclone.psyir.nodes.Member
) – a Member PSyIR node.- Returns:
the code as string
- Return type:
str
- property structure_character
- Returns:
the character use to access a member of a structure in this language.
- Return type:
str
- structurereference_node(node)
Creates the code for an access to a member of a structure type.
- Parameters:
node (
psyclone.psyir.nodes.StructureReference
) – a StructureReference PSyIR node.- Returns:
the code as string.
- Return type:
str
- Raises:
VisitorError – if this node does not have an instance of Member as its only child.