1 //===-- runtime/type-code.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Runtime/type-code.h"
11 namespace Fortran::runtime
{
13 RT_OFFLOAD_API_GROUP_BEGIN
15 RT_API_ATTRS
TypeCode::TypeCode(TypeCategory f
, int kind
) {
17 case TypeCategory::Integer
:
20 raw_
= CFI_type_int8_t
;
23 raw_
= CFI_type_int16_t
;
26 raw_
= CFI_type_int32_t
;
29 raw_
= CFI_type_int64_t
;
32 raw_
= CFI_type_int128_t
;
36 case TypeCategory::Real
:
39 raw_
= CFI_type_half_float
;
42 raw_
= CFI_type_bfloat
;
45 raw_
= CFI_type_float
;
48 raw_
= CFI_type_double
;
51 raw_
= CFI_type_extended_double
;
54 raw_
= CFI_type_float128
;
58 case TypeCategory::Complex
:
61 raw_
= CFI_type_half_float_Complex
;
64 raw_
= CFI_type_bfloat_Complex
;
67 raw_
= CFI_type_float_Complex
;
70 raw_
= CFI_type_double_Complex
;
73 raw_
= CFI_type_extended_double_Complex
;
76 raw_
= CFI_type_long_double_Complex
;
80 case TypeCategory::Character
:
86 raw_
= CFI_type_char16_t
;
89 raw_
= CFI_type_char32_t
;
93 case TypeCategory::Logical
:
99 raw_
= CFI_type_int_least16_t
;
102 raw_
= CFI_type_int_least32_t
;
105 raw_
= CFI_type_int_least64_t
;
109 case TypeCategory::Derived
:
110 raw_
= CFI_type_struct
;
115 RT_API_ATTRS
Fortran::common::optional
<std::pair
<TypeCategory
, int>>
116 TypeCode::GetCategoryAndKind() const {
118 case CFI_type_signed_char
:
119 return std::make_pair(TypeCategory::Character
, sizeof(signed char));
121 return std::make_pair(TypeCategory::Integer
, sizeof(short));
123 return std::make_pair(TypeCategory::Integer
, sizeof(int));
125 return std::make_pair(TypeCategory::Integer
, sizeof(long));
126 case CFI_type_long_long
:
127 return std::make_pair(TypeCategory::Integer
, sizeof(long long));
128 case CFI_type_size_t
:
129 return std::make_pair(TypeCategory::Integer
, sizeof(std::size_t));
130 case CFI_type_int8_t
:
131 return std::make_pair(TypeCategory::Integer
, 1);
132 case CFI_type_int16_t
:
133 return std::make_pair(TypeCategory::Integer
, 2);
134 case CFI_type_int32_t
:
135 return std::make_pair(TypeCategory::Integer
, 4);
136 case CFI_type_int64_t
:
137 return std::make_pair(TypeCategory::Integer
, 8);
138 case CFI_type_int128_t
:
139 return std::make_pair(TypeCategory::Integer
, 16);
140 case CFI_type_int_least8_t
:
141 return std::make_pair(TypeCategory::Logical
, 1);
142 case CFI_type_int_least16_t
:
143 return std::make_pair(TypeCategory::Logical
, 2);
144 case CFI_type_int_least32_t
:
145 return std::make_pair(TypeCategory::Logical
, 4);
146 case CFI_type_int_least64_t
:
147 return std::make_pair(TypeCategory::Logical
, 8);
148 case CFI_type_int_least128_t
:
149 return std::make_pair(TypeCategory::Integer
, 16);
150 case CFI_type_int_fast8_t
:
151 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast8_t));
152 case CFI_type_int_fast16_t
:
153 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast16_t));
154 case CFI_type_int_fast32_t
:
155 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast32_t));
156 case CFI_type_int_fast64_t
:
157 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast64_t));
158 case CFI_type_int_fast128_t
:
159 return std::make_pair(TypeCategory::Integer
, 16);
160 case CFI_type_intmax_t
:
161 return std::make_pair(TypeCategory::Integer
, sizeof(std::intmax_t));
162 case CFI_type_intptr_t
:
163 return std::make_pair(TypeCategory::Integer
, sizeof(std::intptr_t));
164 case CFI_type_ptrdiff_t
:
165 return std::make_pair(TypeCategory::Integer
, sizeof(std::ptrdiff_t));
166 case CFI_type_half_float
:
167 return std::make_pair(TypeCategory::Real
, 2);
168 case CFI_type_bfloat
:
169 return std::make_pair(TypeCategory::Real
, 3);
171 return std::make_pair(TypeCategory::Real
, 4);
172 case CFI_type_double
:
173 return std::make_pair(TypeCategory::Real
, 8);
174 case CFI_type_extended_double
:
175 return std::make_pair(TypeCategory::Real
, 10);
176 case CFI_type_long_double
:
177 return std::make_pair(TypeCategory::Real
, 16);
178 case CFI_type_float128
:
179 return std::make_pair(TypeCategory::Real
, 16);
180 case CFI_type_half_float_Complex
:
181 return std::make_pair(TypeCategory::Complex
, 2);
182 case CFI_type_bfloat_Complex
:
183 return std::make_pair(TypeCategory::Complex
, 3);
184 case CFI_type_float_Complex
:
185 return std::make_pair(TypeCategory::Complex
, 4);
186 case CFI_type_double_Complex
:
187 return std::make_pair(TypeCategory::Complex
, 8);
188 case CFI_type_extended_double_Complex
:
189 return std::make_pair(TypeCategory::Complex
, 10);
190 case CFI_type_long_double_Complex
:
191 return std::make_pair(TypeCategory::Complex
, 16);
192 case CFI_type_float128_Complex
:
193 return std::make_pair(TypeCategory::Complex
, 16);
195 return std::make_pair(TypeCategory::Logical
, 1);
197 return std::make_pair(TypeCategory::Character
, 1);
199 return std::make_pair(TypeCategory::Integer
, sizeof(void *));
200 case CFI_type_struct
:
201 return std::make_pair(TypeCategory::Derived
, 0);
202 case CFI_type_char16_t
:
203 return std::make_pair(TypeCategory::Character
, 2);
204 case CFI_type_char32_t
:
205 return std::make_pair(TypeCategory::Character
, 4);
207 return Fortran::common::nullopt
;
211 RT_OFFLOAD_API_GROUP_END
213 } // namespace Fortran::runtime