Reference Guide
2.5.0
|
Public Member Functions | |
def | __init__ (self, api="", invoke_name="invoke", kernel_paths=None, line_length=False) |
def | parse (self, alg_filename) |
def | invoke_info (self, alg_parse_tree) |
def | create_invoke_call (self, statement) |
def | create_kernel_call (self, argument) |
def | create_builtin_kernel_call (self, kernel_name, args) |
def | create_coded_kernel_call (self, kernel_name, args) |
def | update_arg_to_module_map (self, statement) |
def | check_invoke_label (self, argument) |
Supports the parsing of PSyclone conformant algorithm code within a file and extraction of relevant information for any 'invoke' calls contained within the code. :param str api: the PSyclone API to use when parsing the code. :param str invoke_name: the expected name of the invocation calls in the \ algorithm code. :param kernel_paths: the paths to search for kernel source files \ (if different from the location of the algorithm source). \ Defaults to None. :type kernel_paths: list of str or NoneType :param bool line_length: a logical flag specifying whether we care \ about line lengths being longer than 132 characters. If so, \ the input (algorithm and kernel) code is checked to make sure \ that it conforms and an error raised if not. The default is \ False. For example: >>> from psyclone.parse.algorithm import Parser >>> parser = Parser(api="gocean1.0") >>> ast, info = parser.parse(SOURCE_FILE)
Definition at line 114 of file algorithm.py.
def psyclone.parse.algorithm.Parser.check_invoke_label | ( | self, | |
argument | |||
) |
Takes the parse tree of an invoke argument containing an invoke label. Raises an exception if this label has already been used by another invoke in the same algorithm code. If all is well it returns the label as a string. :param argument: Parse tree of an invoke argument. This \ should contain a "name=xxx" argument. :type argument: :py:class:`fparser.two.Actual_Arg_Spec` :returns: the label as a string. :rtype: str :raises ParseError: if this label has already been used by \ another invoke in this algorithm code.
Definition at line 497 of file algorithm.py.
References psyclone.parse.algorithm.Parser._alg_filename, and psyclone.parse.algorithm.Parser._unique_invoke_labels.
def psyclone.parse.algorithm.Parser.create_builtin_kernel_call | ( | self, | |
kernel_name, | |||
args | |||
) |
Takes the builtin kernel name and a list of Arg objects which capture information about the builtin call arguments and returns a BuiltinCall instance with content specific to the particular API (as specified in self._api). :param str kernel_name: the name of the builtin kernel being \ called :param args: a list of 'Arg' instances containing the required \ information for the arguments being passed from the algorithm \ layer. The list order is the same as the argument order. :type arg: list of :py:class:`psyclone.parse.algorithm.Arg` :returns: a BuiltInCall instance with information specific to \ the API. :rtype: :py:class:`psyclone.parse.algorithm.BuiltInCall` :raises ParseError: if the builtin is specified in a use \ statement in the algorithm layer
Definition at line 401 of file algorithm.py.
References psyclone.configuration.Config._api, psyclone.parse.algorithm.Parser._api, psyclone.parse.algorithm.Parser._arg_name_to_module_name, and psyclone.parse.algorithm.Parser._builtin_defs_file.
def psyclone.parse.algorithm.Parser.create_coded_kernel_call | ( | self, | |
kernel_name, | |||
args | |||
) |
Takes a coded kernel name and a list of Arg objects which capture information about the coded call arguments and returns a KernelCall instance with content specific to the particular API (as specified in self._api). :param str kernel_name: the name of the coded kernel being \ called :param args: a list of 'Arg' instances containing the required \ information for the arguments being passed from the algorithm \ layer. The list order is the same as the argument order. :type arg: list of :py:class:`psyclone.parse.algorithm.Arg` :returns: a KernelCall instance with information specific to \ the API. :rtype: :py:class:`psyclone.parse.algorithm.KernelCall` :raises ParseError: if the kernel is not specified in a use \ statement in the algorithm layer
Definition at line 431 of file algorithm.py.
References psyclone.parse.algorithm.Parser._alg_filename, psyclone.configuration.Config._api, psyclone.parse.algorithm.Parser._api, psyclone.parse.algorithm.Parser._arg_name_to_module_name, psyclone.parse.algorithm.Parser._kernel_paths, psyclone.line_length.FortLineLength._line_length, and psyclone.parse.algorithm.Parser._line_length.
def psyclone.parse.algorithm.Parser.create_invoke_call | ( | self, | |
statement | |||
) |
Takes the part of a parse tree containing an invoke call and returns an InvokeCall object which captures the required information about the invoke. :param statement: Parse tree of the invoke call. :type statement: :py:class:`fparser.two.Fortran2003.Call_Stmt` :returns: An InvokeCall object which contains relevant \ information about the invoke call. :rtype: :py:class:`psyclone.parse.algorithm.InvokeCall` :raises ParseError: if more than one invoke argument contains \ 'name=xxx'. :raises ParseError: if an unknown or unsupported invoke \ argument is found.
Definition at line 323 of file algorithm.py.
References psyclone.parse.algorithm.Parser.check_invoke_label(), and psyclone.parse.algorithm.Parser.create_kernel_call().
def psyclone.parse.algorithm.Parser.create_kernel_call | ( | self, | |
argument | |||
) |
Takes the parse tree of an invoke argument containing a reference to a kernel or a builtin and returns the kernel or builtin object respectively which contains the required information. :param argument: Parse tree of an invoke argument. This \ should contain a kernel name and associated arguments. :type argument: :py:class:`fparser.two.Fortran2003.Part_Ref` or \ :py:class:`fparser.two.Fortran2003.Structure_Constructor` :returns: A builtin or coded kernel call object which contains \ relevant information about the Kernel. :rtype: :py:class:`psyclone.parse.algorithm.KernelCall` or \ :py:class:`psyclone.parse.algorithm.BuiltInCall`
Definition at line 372 of file algorithm.py.
References psyclone.parse.algorithm.Parser._alg_filename, psyclone.parse.algorithm.Parser._arg_type_defns, psyclone.parse.algorithm.Parser.create_builtin_kernel_call(), and psyclone.parse.algorithm.Parser.create_coded_kernel_call().
def psyclone.parse.algorithm.Parser.invoke_info | ( | self, | |
alg_parse_tree | |||
) |
Takes an fparser2 representation of a PSyclone-conformant algorithm code as input and returns an object containing information about the 'invoke' calls in the algorithm file and any associated kernels within the invoke calls. Also captures the type and precision of every variable declaration within the parse tree. :param alg_parse_tree: the fparser2 representation of the \ algorithm code. :type: :py:class:`fparser.two.Fortran2003.Program` :returns: an object holding details of the algorithm \ code and the invokes found within it. :rtype: :py:class:`psyclone.parse.FileInfo` :raises ParseError: if a program, module, subroutine or \ function is not found in the fparser2 tree. :raises InternalError: if the fparser2 tree representing the \ type declaration statements is not in the expected form. :raises NotImplementedError: if the algorithm code contains \ two different datatypes with the same name.
Definition at line 207 of file algorithm.py.
References psyclone.parse.algorithm.Parser._arg_name_to_module_name, psyclone.parse.algorithm.Parser._arg_type_defns, psyclone.alg_gen.Alg._invoke_name, psyclone.parse.algorithm.Parser._invoke_name, psyclone.parse.algorithm.Parser._unique_invoke_labels, psyclone.parse.algorithm.Parser.create_invoke_call(), and psyclone.parse.algorithm.Parser.update_arg_to_module_map().
def psyclone.parse.algorithm.Parser.parse | ( | self, | |
alg_filename | |||
) |
Takes a PSyclone conformant algorithm file as input and outputs a parse tree of the code contained therein and an object containing information about the 'invoke' calls in the algorithm file and any associated kernels within the invoke calls. If the NEMO API is being used then the parsed code is returned without any additional information about the code. :param str alg_filename: The file containing the algorithm code. :returns: 2-tuple consisting of the fparser2 parse tree of the \ algorithm code and an object holding details of the \ algorithm code and the invokes found within it, unless it \ is the NEMO API, where the first entry of the tuple is \ None and the second is the fparser2 parse tree of the \ code. :rtype: (:py:class:`fparser.two.Fortran2003.Program`, \ :py:class:`psyclone.parse.FileInfo`) or (NoneType, \ :py:class:`fparser.two.Fortran2003.Program`)
Definition at line 173 of file algorithm.py.
References psyclone.parse.algorithm.Parser._alg_filename, psyclone.configuration.Config._api, psyclone.parse.algorithm.Parser._api, psyclone.line_length.FortLineLength._line_length, psyclone.parse.algorithm.Parser._line_length, and psyclone.parse.algorithm.Parser.invoke_info().
def psyclone.parse.algorithm.Parser.update_arg_to_module_map | ( | self, | |
statement | |||
) |
Takes a use statement and adds its contents to the internal arg_name_to_module_name map. This map associates names specified in the 'only' list with the corresponding use name. :param statement: A use statement :type statement: :py:class:`fparser.two.Fortran2003.Use_Stmt` :raises InternalError: if the statement being passed is not an \ fparser use statement.
Definition at line 468 of file algorithm.py.
References psyclone.parse.algorithm.Parser._arg_name_to_module_name.