Reference Guide  2.5.0
psyir.py
1 # -----------------------------------------------------------------------------
2 # BSD 3-Clause License
3 #
4 # Copyright (c) 2022-2024, Science and Technology Facilities Council
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright notice, this
11 # list of conditions and the following disclaimer.
12 #
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 #
17 # * Neither the name of the copyright holder nor the names of its
18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33 # -----------------------------------------------------------------------------
34 # Author: R. W. Ford, STFC Daresbury Lab
35 # Modified: S. Siso, STFC Daresbury Lab
36 
37 '''Module containing the LFRic-specific Container class for a Kernel.
38 
39 '''
40 from psyclone.psyir.nodes import Container
41 
42 
43 class LFRicKernelContainer(Container):
44  '''An LFRic-specific Container. This specialises the generic Container
45  node and adds in any domain-specific information.
46 
47  :param str name: the name of the container.
48  :param metadata: the metadata object.
49  :type metadata: \
50  :py:class:`psyclone.domain.lfric.kernel.LFRicKernelMetadata`
51  :param kwargs: additional keyword arguments to pass to parent \
52  constructor.
53  :type kwargs: unwrapped dict
54 
55  '''
56  def __init__(self, name, metadata, **kwargs):
57  super().__init__(name, **kwargs)
58  # The metadata object capturing LFRic kernel metadata.
59  self._metadata_metadata = metadata
60 
61  @classmethod
62  def create(cls, name, metadata, symbol_table, children):
63  '''Create an LFRic Container instance given a name, metadata, a symbol
64  table and a list of child nodes. An LFRic-specific kernel is
65  created with the metadata describing the kernel interface for
66  a single kernel routine within the container.
67 
68  :param str name: the name of the Container.
69  :param metadata: the metadata object.
70  :type metadata: \
71  :py:class:`psyclone.domain.lfric.kernel.LFRicKernelMetadata`
72  :param symbol_table: the symbol table associated with this \
73  Container.
74  :type symbol_table: :py:class:`psyclone.psyir.symbols.SymbolTable`
75  :param children: a list of PSyIR nodes contained in the \
76  Container. These must be Containers or Routines.
77  :type children: List[:py:class:`psyclone.psyir.nodes.Container` \
78  | :py:class:`psyclone.psyir.nodes.Routine`]
79 
80  :returns: an instance of `cls`.
81  :rtype: :py:class:`psyclone.psyir.nodes.Container` or subclass
82  thereof.
83 
84  '''
85  return cls(name, metadata, children=children,
86  symbol_table=symbol_table.detach())
87 
88  @property
89  def metadata(self):
90  '''
91  :returns the LFRic metadata object.
92  :rtype: :py:class:`psyclone.domain.lfric.kernel.psyir.\
93  LFRicKernelMetadata`
94  '''
95  return self._metadata_metadata
96 
98  '''Lower this LFRic-specific container to language level psyir.
99 
100  :returns: the lowered version of this node.
101  :rtype: :py:class:`psyclone.psyir.node.Node`
102 
103  '''
104  # Create metadata symbol and add it to the container symbol
105  # table.
106  data_symbol = self.metadatametadata.lower_to_psyir()
107  self.symbol_table.add(data_symbol)
108 
109  # Replace this LFRic container with a generic container
110  children = self.pop_all_children()
111  generic_container = Container.create(
112  self.name, self.symbol_table.detach(), children)
113  self.replace_with(generic_container)
114  return generic_container
115 
116 
117 __all__ = ["LFRicKernelContainer"]
def create(cls, name, metadata, symbol_table, children)
Definition: psyir.py:62