FLANG

default-kinds.h
1 //===-- include/flang/Common/default-kinds.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_DEFAULT_KINDS_H_
10 #define FORTRAN_COMMON_DEFAULT_KINDS_H_
11
12 #include "flang/Common/Fortran.h"
13 #include <cstdint>
14
15 namespace Fortran::common {
16
17 // All address calculations in generated code are 64-bit safe.
18 // Compile-time folding of bounds, subscripts, and lengths
19 // consequently uses 64-bit signed integers. The name reflects
20 // this usage as a subscript into a constant array.
21 using ConstantSubscript = std::int64_t;
22
23 // Represent the default values of the kind parameters of the
24 // various intrinsic types. Most of these can be configured by
25 // means of the compiler command line.
26 class IntrinsicTypeDefaultKinds {
27 public:
28 IntrinsicTypeDefaultKinds();
29 int subscriptIntegerKind() const { return subscriptIntegerKind_; }
30 int sizeIntegerKind() const { return sizeIntegerKind_; }
31 int doublePrecisionKind() const { return doublePrecisionKind_; }
32 int quadPrecisionKind() const { return quadPrecisionKind_; }
33
34 IntrinsicTypeDefaultKinds &set_defaultIntegerKind(int);
35 IntrinsicTypeDefaultKinds &set_subscriptIntegerKind(int);
36 IntrinsicTypeDefaultKinds &set_sizeIntegerKind(int);
37 IntrinsicTypeDefaultKinds &set_defaultRealKind(int);
38 IntrinsicTypeDefaultKinds &set_doublePrecisionKind(int);
39 IntrinsicTypeDefaultKinds &set_quadPrecisionKind(int);
40 IntrinsicTypeDefaultKinds &set_defaultCharacterKind(int);
41 IntrinsicTypeDefaultKinds &set_defaultLogicalKind(int);
42
43 int GetDefaultKind(TypeCategory) const;
44
45 private:
46 // Default REAL just simply has to be IEEE-754 single precision today.
47 // It occupies one numeric storage unit by definition. The default INTEGER
48 // and default LOGICAL intrinsic types also have to occupy one numeric
49 // storage unit, so their kinds are also forced. Default COMPLEX must always
50 // comprise two default REAL components.
51 int defaultIntegerKind_{4};
52 int subscriptIntegerKind_{8};
53 int sizeIntegerKind_{4}; // SIZE(), UBOUND(), &c. default KIND=
54 int defaultRealKind_{defaultIntegerKind_};
55 int doublePrecisionKind_{2 * defaultRealKind_};
56 int quadPrecisionKind_{2 * doublePrecisionKind_};
57 int defaultCharacterKind_{1};
58 int defaultLogicalKind_{defaultIntegerKind_};
59 };
60 } // namespace Fortran::common
61 #endif // FORTRAN_COMMON_DEFAULT_KINDS_H_
Fortran::common::IntrinsicTypeDefaultKinds
Definition: default-kinds.h:26