Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ARG1 = DataSymbol(TMP_NAME1, REAL_TYPE, interface=ArgumentInterface(
ArgumentInterface.Access.READWRITE))
SYMBOL_TABLE.add(ARG1)
TMP_NAME2 = SYMBOL_TABLE.new_symbol_name()
TMP_SYMBOL = DataSymbol(TMP_NAME2, REAL_DOUBLE_TYPE)
SYMBOL_TABLE.add(TMP_SYMBOL)
INDEX_NAME = SYMBOL_TABLE.new_symbol_name(root_name="i")
SYMBOL_TABLE.add(DataSymbol(INDEX_NAME, INTEGER4_TYPE))
SYMBOL_TABLE.specify_argument_list([ARG1])
REAL_KIND_NAME = SYMBOL_TABLE.new_symbol_name(root_name="RKIND")
REAL_KIND = DataSymbol(REAL_KIND_NAME, INTEGER_TYPE, constant_value=8)
SYMBOL_TABLE.add(REAL_KIND)
# Array using precision defined by another symbol
ARRAY_NAME = SYMBOL_TABLE.new_symbol_name(root_name="a")
SCALAR_TYPE = ScalarType(ScalarType.Intrinsic.REAL, REAL_KIND)
ARRAY = DataSymbol(ARRAY_NAME, ArrayType(SCALAR_TYPE, [10]))
SYMBOL_TABLE.add(ARRAY)
# Nodes which do not have Nodes as children and (some) predefined
# scalar datatypes
ZERO = Literal("0.0", REAL_TYPE)
ONE = Literal("1.0", REAL4_TYPE)
TWO = Literal("2.0", SCALAR_TYPE)
INT_ZERO = Literal("0", INTEGER_SINGLE_TYPE)
INT_ONE = Literal("1", INTEGER8_TYPE)
TMP1 = Reference(ARG1)
TMP2 = Reference(TMP_SYMBOL)
# Unary Operation
OPER = UnaryOperation.Operator.SIN
UNARYOPERATION = UnaryOperation.create(OPER, TMP2)
from psyclone.psyir.nodes import UnaryOperation, BinaryOperation, \
NaryOperation, Schedule, CodeBlock, IfBlock, Reference, Literal, Loop, \
Container, Assignment, Return, Array, Node, Range
from psyclone.errors import InternalError, GenerationError
from psyclone.psyGen import Directive, KernelSchedule
from psyclone.psyir.symbols import SymbolError, DataSymbol, ContainerSymbol, \
Symbol, GlobalInterface, ArgumentInterface, UnresolvedInterface, \
LocalInterface, ScalarType, ArrayType, DeferredType
# The list of Fortran instrinsic functions that we know about (and can
# therefore distinguish from array accesses). These are taken from
# fparser.
FORTRAN_INTRINSICS = Fortran2003.Intrinsic_Name.function_names
# Mapping from Fortran data types to PSyIR types
TYPE_MAP_FROM_FORTRAN = {"integer": ScalarType.Intrinsic.INTEGER,
"character": ScalarType.Intrinsic.CHARACTER,
"logical": ScalarType.Intrinsic.BOOLEAN,
"real": ScalarType.Intrinsic.REAL,
"double precision": ScalarType.Intrinsic.REAL}
# Mapping from fparser2 Fortran Literal types to PSyIR types
CONSTANT_TYPE_MAP = {
Fortran2003.Real_Literal_Constant: ScalarType.Intrinsic.REAL,
Fortran2003.Logical_Literal_Constant: ScalarType.Intrinsic.BOOLEAN,
Fortran2003.Char_Literal_Constant: ScalarType.Intrinsic.CHARACTER,
Fortran2003.Int_Literal_Constant: ScalarType.Intrinsic.INTEGER}
def _get_symbol_table(node):
'''Find a symbol table associated with an ancestor of Node 'node' (or
the node itself). If there is more than one symbol table, then the
def default_integer_type():
'''Returns the default integer datatype specified by the front end.
:returns: the default integer datatype.
:rtype: :py:class:`psyclone.psyir.symbols.ScalarType`
'''
return ScalarType(ScalarType.Intrinsic.INTEGER,
default_precision(ScalarType.Intrinsic.INTEGER))
"Unsupported literal type '{0}' found in get_literal_precision."
"".format(type(fparser2_node).__name__))
if not isinstance(psyir_literal_parent, Node):
raise InternalError(
"Expecting argument psyir_literal_parent to be a PSyIR Node but "
"found '{0}' in get_literal_precision."
"".format(type(psyir_literal_parent).__name__))
precision_name = fparser2_node.items[1]
if not precision_name:
# Precision may still be specified by the exponent in a real literal
if isinstance(fparser2_node, Fortran2003.Real_Literal_Constant):
precision_value = fparser2_node.items[0]
if "d" in precision_value.lower():
return ScalarType.Precision.DOUBLE
if "e" in precision_value.lower():
return ScalarType.Precision.SINGLE
# Return the default precision
try:
data_name = CONSTANT_TYPE_MAP[type(fparser2_node)]
except KeyError:
raise NotImplementedError(
"Could not process {0}. Only 'real', 'integer', "
"'logical' and 'character' intrinsic types are "
"supported.".format(type(fparser2_node).__name__))
return default_precision(data_name)
try:
# Precision is specified as an integer
return int(precision_name)
except ValueError:
# Precision is not an integer so should be a kind symbol
# PSyIR stores names as lower case.
precision_name = precision_name.lower()
def default_real_type():
'''Returns the default real datatype specified by the front end.
:returns: the default real datatype.
:rtype: :py:class:`psyclone.psyir.symbols.ScalarType`
'''
return ScalarType(ScalarType.Intrinsic.REAL,
default_precision(ScalarType.Intrinsic.REAL))
"Datatype 'real' in symbol '{0}' supports fixed precision of "
"[4, 8, 16] but found '{1}'.".format(symbol.name,
precision))
if fortrantype in ['integer', 'logical'] and precision not in \
[1, 2, 4, 8, 16]:
raise VisitorError(
"Datatype '{0}' in symbol '{1}' supports fixed precision of "
"[1, 2, 4, 8, 16] but found '{2}'."
"".format(fortrantype, symbol.name, precision))
# Precision has an an explicit size. Use the "type*size" Fortran
# extension for simplicity. We could have used
# type(kind=selected_int|real_kind(size)) or, for Fortran 2008,
# ISO_FORTRAN_ENV; type(type64) :: MyType.
return "{0}*{1}".format(fortrantype, precision)
if isinstance(precision, ScalarType.Precision):
# The precision information is not absolute so is either
# machine specific or is specified via the compiler. Fortran
# only distinguishes relative precision for single and double
# precision reals.
if fortrantype.lower() == "real" and \
precision == ScalarType.Precision.DOUBLE:
return "double precision"
# This logging warning can be added when issue #11 is
# addressed.
# import logging
# logging.warning(
# "Fortran does not support relative precision for the '%s' "
# "datatype but '%s' was specified for variable '%s'.",
# datatype, str(symbol.precision), symbol.name)
return fortrantype
sym_name = str(name).lower()
if decln_access_spec is None:
# There was no access-spec on the LHS of the decln
if sym_name in explicit_private_symbols:
visibility = Symbol.Visibility.PRIVATE
elif sym_name in explicit_public_symbols:
visibility = Symbol.Visibility.PUBLIC
else:
visibility = default_visibility
else:
visibility = decln_access_spec
if entity_shape:
# array
datatype = ArrayType(ScalarType(data_name, precision),
entity_shape)
else:
# scalar
datatype = ScalarType(data_name, precision)
if sym_name not in parent.symbol_table:
parent.symbol_table.add(DataSymbol(sym_name, datatype,
visibility=visibility,
constant_value=ct_expr,
interface=interface))
else:
# The symbol table already contains an entry with this name
# so update its interface information.
sym = parent.symbol_table.lookup(sym_name)
if not sym.unresolved_interface:
raise SymbolError(
Range node.
:param object value: entity to check.
:param str name: the name of the quantity for which this value has \
been supplied.
:raises TypeError: if the supplied value is not a sub-class of Node.
:raises TypeError: if the supplied value is a Literal but is not of \
INTEGER type.
'''
if not isinstance(value, Node):
raise TypeError(
"The {0} value of a Range must be a sub-class of "
"Node but got: {1}".format(name, type(value).__name__))
if (isinstance(value, Literal) and
value.datatype.intrinsic != ScalarType.Intrinsic.INTEGER):
raise TypeError(
"If the {0} value of a Range is a Literal then it "
"must be of type INTEGER but got {1}".format(
name, value.datatype))