Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- include/flang/Common/Fortran.h --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef FORTRAN_COMMON_FORTRAN_H_
10#define FORTRAN_COMMON_FORTRAN_H_
11
12// Fortran language concepts that are used in many phases are defined
13// once here to avoid redundancy and needless translation.
14
15#include "enum-set.h"
16#include "idioms.h"
17#include <cinttypes>
18#include <optional>
19#include <string>
20
21namespace Fortran::common {
22
23// Fortran has five kinds of intrinsic data types, plus the derived types.
24ENUM_CLASS(TypeCategory, Integer, Real, Complex, Character, Logical, Derived)
25ENUM_CLASS(VectorElementCategory, Integer, Unsigned, Real)
26
27constexpr bool IsNumericTypeCategory(TypeCategory category) {
28 return category == TypeCategory::Integer || category == TypeCategory::Real ||
29 category == TypeCategory::Complex;
30}
31
32// Kinds of IMPORT statements. Default means IMPORT or IMPORT :: names.
33ENUM_CLASS(ImportKind, Default, Only, None, All)
34
35// The attribute on a type parameter can be KIND or LEN.
36ENUM_CLASS(TypeParamAttr, Kind, Len)
37
38ENUM_CLASS(NumericOperator, Power, Multiply, Divide, Add, Subtract)
39const char *AsFortran(NumericOperator);
40
41ENUM_CLASS(LogicalOperator, And, Or, Eqv, Neqv, Not)
42const char *AsFortran(LogicalOperator);
43
44ENUM_CLASS(RelationalOperator, LT, LE, EQ, NE, GE, GT)
45const char *AsFortran(RelationalOperator);
46
47ENUM_CLASS(Intent, Default, In, Out, InOut)
48
49ENUM_CLASS(IoStmtKind, None, Backspace, Close, Endfile, Flush, Inquire, Open,
50 Print, Read, Rewind, Wait, Write)
51
52// Union of specifiers for all I/O statements.
53ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal,
54 Delim, Direct, Encoding, End, Eor, Err, Exist, File, Fmt, Form, Formatted,
55 Id, Iomsg, Iostat, Name, Named, Newunit, Nextrec, Nml, Number, Opened, Pad,
56 Pending, Pos, Position, Read, Readwrite, Rec, Recl, Round, Sequential, Sign,
57 Size, Status, Stream, Unformatted, Unit, Write,
58 Carriagecontrol, // nonstandard
59 Convert, // nonstandard
60 Dispose, // nonstandard
61)
62
63// Defined I/O variants
64ENUM_CLASS(
65 DefinedIo, ReadFormatted, ReadUnformatted, WriteFormatted, WriteUnformatted)
66const char *AsFortran(DefinedIo);
67
68// Floating-point rounding modes; these are packed into a byte to save
69// room in the runtime's format processing context structure.
70enum class RoundingMode : std::uint8_t {
71 TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding
72 ToZero, // ROUND=ZERO, RZ - truncation
73 Down, // ROUND=DOWN, RD
74 Up, // ROUND=UP, RU
75 TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero
76};
77
78// Fortran label. Must be in [1..99999].
79using Label = std::uint64_t;
80
81// Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6).
82static constexpr int maxRank{15};
83
84// CUDA subprogram attribute combinations
85ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, Global, Grid_Global)
86
87// CUDA data attributes; mutually exclusive
88ENUM_CLASS(
89 CUDADataAttr, Constant, Device, Managed, Pinned, Shared, Texture, Unified)
90
91// OpenACC device types
92ENUM_CLASS(
93 OpenACCDeviceType, Star, Default, Nvidia, Radeon, Host, Multicore, None)
94
95// OpenMP atomic_default_mem_order clause allowed values
96ENUM_CLASS(OmpAtomicDefaultMemOrderType, SeqCst, AcqRel, Relaxed)
97
98// Fortran names may have up to 63 characters (See Fortran 2018 C601).
99static constexpr int maxNameLen{63};
100
101// !DIR$ IGNORE_TKR [[(letters) name] ... letters
102// "A" expands to all of TKRDM
103ENUM_CLASS(IgnoreTKR,
104 Type, // T - don't check type category
105 Kind, // K - don't check kind
106 Rank, // R - don't check ranks
107 Device, // D - don't check host/device residence
108 Managed, // M - don't check managed storage
109 Contiguous) // C - don't check for storage sequence association with a
110 // potentially non-contiguous object
111using IgnoreTKRSet = EnumSet<IgnoreTKR, 8>;
112// IGNORE_TKR(A) = IGNORE_TKR(TKRDM)
113static constexpr IgnoreTKRSet ignoreTKRAll{IgnoreTKR::Type, IgnoreTKR::Kind,
114 IgnoreTKR::Rank, IgnoreTKR::Device, IgnoreTKR::Managed};
115std::string AsFortran(IgnoreTKRSet);
116
117bool AreCompatibleCUDADataAttrs(
118 std::optional<CUDADataAttr>, std::optional<CUDADataAttr>, IgnoreTKRSet);
119
120static constexpr char blankCommonObjectName[] = "__BLNK__";
121
122// Get the assembly name for a non BIND(C) external symbol other than the blank
123// common block.
124inline std::string GetExternalAssemblyName(
125 std::string symbolName, bool underscoring) {
126 return underscoring ? std::move(symbolName) + "_" : std::move(symbolName);
127}
128
129} // namespace Fortran::common
130#endif // FORTRAN_COMMON_FORTRAN_H_
131

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of flang/include/flang/Common/Fortran.h