1 // Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef FORTRAN_COMMON_DEFAULT_KINDS_H_ 16 #define FORTRAN_COMMON_DEFAULT_KINDS_H_ 17 18 #include "Fortran.h" 19 #include <cstdint> 20 21 namespace Fortran::common { 22 23 // All address calculations in generated code are 64-bit safe. 24 // Compile-time folding of bounds, subscripts, and lengths 25 // consequently uses 64-bit signed integers. The name reflects 26 // this usage as a subscript into a constant array. 27 using ConstantSubscript = std::int64_t; 28 29 // Represent the default values of the kind parameters of the 30 // various intrinsic types. Most of these can be configured by 31 // means of the compiler command line; subscriptIntegerKind, 32 // however, is fixed at 8 because all address calculations are 33 // 64-bit safe. 34 class IntrinsicTypeDefaultKinds { 35 public: 36 IntrinsicTypeDefaultKinds(); subscriptIntegerKind()37 static constexpr int subscriptIntegerKind() { return 8; } doublePrecisionKind()38 int doublePrecisionKind() const { return doublePrecisionKind_; } quadPrecisionKind()39 int quadPrecisionKind() const { return quadPrecisionKind_; } 40 41 IntrinsicTypeDefaultKinds &set_defaultIntegerKind(int); 42 IntrinsicTypeDefaultKinds &set_defaultRealKind(int); 43 IntrinsicTypeDefaultKinds &set_doublePrecisionKind(int); 44 IntrinsicTypeDefaultKinds &set_quadPrecisionKind(int); 45 IntrinsicTypeDefaultKinds &set_defaultCharacterKind(int); 46 IntrinsicTypeDefaultKinds &set_defaultLogicalKind(int); 47 48 int GetDefaultKind(TypeCategory) const; 49 50 private: 51 // Default REAL just simply has to be IEEE-754 single precision today. 52 // It occupies one numeric storage unit by definition. The default INTEGER 53 // and default LOGICAL intrinsic types also have to occupy one numeric 54 // storage unit, so their kinds are also forced. Default COMPLEX must always 55 // comprise two default REAL components. 56 int defaultIntegerKind_{4}; 57 int defaultRealKind_{defaultIntegerKind_}; 58 int doublePrecisionKind_{2 * defaultRealKind_}; 59 int quadPrecisionKind_{2 * doublePrecisionKind_}; 60 int defaultCharacterKind_{1}; 61 int defaultLogicalKind_{defaultIntegerKind_}; 62 }; 63 } 64 #endif // FORTRAN_COMMON_DEFAULT_KINDS_H_ 65