1 //===-- lib/Common/default-kinds.cpp --------------------------------------===//
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 #include "flang/Common/default-kinds.h"
10 #include "flang/Common/idioms.h"
11 
12 namespace Fortran::common {
13 
IntrinsicTypeDefaultKinds()14 IntrinsicTypeDefaultKinds::IntrinsicTypeDefaultKinds() {
15 #if __x86_64__
16   quadPrecisionKind_ = 10;
17 #endif
18 }
19 
set_defaultIntegerKind(int k)20 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_defaultIntegerKind(
21     int k) {
22   defaultIntegerKind_ = k;
23   return *this;
24 }
25 
set_subscriptIntegerKind(int k)26 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_subscriptIntegerKind(
27     int k) {
28   subscriptIntegerKind_ = k;
29   return *this;
30 }
31 
set_sizeIntegerKind(int k)32 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_sizeIntegerKind(
33     int k) {
34   sizeIntegerKind_ = k;
35   return *this;
36 }
37 
set_defaultRealKind(int k)38 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_defaultRealKind(
39     int k) {
40   defaultRealKind_ = k;
41   return *this;
42 }
43 
set_doublePrecisionKind(int k)44 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_doublePrecisionKind(
45     int k) {
46   doublePrecisionKind_ = k;
47   return *this;
48 }
49 
set_quadPrecisionKind(int k)50 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_quadPrecisionKind(
51     int k) {
52   quadPrecisionKind_ = k;
53   return *this;
54 }
55 
set_defaultCharacterKind(int k)56 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_defaultCharacterKind(
57     int k) {
58   defaultCharacterKind_ = k;
59   return *this;
60 }
61 
set_defaultLogicalKind(int k)62 IntrinsicTypeDefaultKinds &IntrinsicTypeDefaultKinds::set_defaultLogicalKind(
63     int k) {
64   defaultLogicalKind_ = k;
65   return *this;
66 }
67 
GetDefaultKind(TypeCategory category) const68 int IntrinsicTypeDefaultKinds::GetDefaultKind(TypeCategory category) const {
69   switch (category) {
70   case TypeCategory::Integer:
71     return defaultIntegerKind_;
72   case TypeCategory::Real:
73   case TypeCategory::Complex:
74     return defaultRealKind_;
75   case TypeCategory::Character:
76     return defaultCharacterKind_;
77   case TypeCategory::Logical:
78     return defaultLogicalKind_;
79   default:
80     CRASH_NO_CASE;
81     return 0;
82   }
83 }
84 } // namespace Fortran::common
85