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 TypeCode::TypeCode(TypeCategory f
, int kind
) {
15 case TypeCategory::Integer
:
18 raw_
= CFI_type_int8_t
;
21 raw_
= CFI_type_int16_t
;
24 raw_
= CFI_type_int32_t
;
27 raw_
= CFI_type_int64_t
;
30 raw_
= CFI_type_int128_t
;
34 case TypeCategory::Real
:
37 raw_
= CFI_type_half_float
;
40 raw_
= CFI_type_bfloat
;
43 raw_
= CFI_type_float
;
46 raw_
= CFI_type_double
;
49 raw_
= CFI_type_extended_double
;
52 raw_
= CFI_type_float128
;
56 case TypeCategory::Complex
:
59 raw_
= CFI_type_half_float_Complex
;
62 raw_
= CFI_type_bfloat_Complex
;
65 raw_
= CFI_type_float_Complex
;
68 raw_
= CFI_type_double_Complex
;
71 raw_
= CFI_type_extended_double_Complex
;
74 raw_
= CFI_type_long_double_Complex
;
78 case TypeCategory::Character
:
84 raw_
= CFI_type_char16_t
;
87 raw_
= CFI_type_char32_t
;
91 case TypeCategory::Logical
:
97 raw_
= CFI_type_int_least16_t
;
100 raw_
= CFI_type_int_least32_t
;
103 raw_
= CFI_type_int_least64_t
;
107 case TypeCategory::Derived
:
108 raw_
= CFI_type_struct
;
113 std::optional
<std::pair
<TypeCategory
, int>>
114 TypeCode::GetCategoryAndKind() const {
116 case CFI_type_signed_char
:
117 return std::make_pair(TypeCategory::Character
, sizeof(signed char));
119 return std::make_pair(TypeCategory::Integer
, sizeof(short));
121 return std::make_pair(TypeCategory::Integer
, sizeof(int));
123 return std::make_pair(TypeCategory::Integer
, sizeof(long));
124 case CFI_type_long_long
:
125 return std::make_pair(TypeCategory::Integer
, sizeof(long long));
126 case CFI_type_size_t
:
127 return std::make_pair(TypeCategory::Integer
, sizeof(std::size_t));
128 case CFI_type_int8_t
:
129 return std::make_pair(TypeCategory::Integer
, 1);
130 case CFI_type_int16_t
:
131 return std::make_pair(TypeCategory::Integer
, 2);
132 case CFI_type_int32_t
:
133 return std::make_pair(TypeCategory::Integer
, 4);
134 case CFI_type_int64_t
:
135 return std::make_pair(TypeCategory::Integer
, 8);
136 case CFI_type_int128_t
:
137 return std::make_pair(TypeCategory::Integer
, 16);
138 case CFI_type_int_least8_t
:
139 return std::make_pair(TypeCategory::Logical
, 1);
140 case CFI_type_int_least16_t
:
141 return std::make_pair(TypeCategory::Logical
, 2);
142 case CFI_type_int_least32_t
:
143 return std::make_pair(TypeCategory::Logical
, 4);
144 case CFI_type_int_least64_t
:
145 return std::make_pair(TypeCategory::Logical
, 8);
146 case CFI_type_int_least128_t
:
147 return std::make_pair(TypeCategory::Integer
, 16);
148 case CFI_type_int_fast8_t
:
149 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast8_t));
150 case CFI_type_int_fast16_t
:
151 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast16_t));
152 case CFI_type_int_fast32_t
:
153 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast32_t));
154 case CFI_type_int_fast64_t
:
155 return std::make_pair(TypeCategory::Integer
, sizeof(std::int_fast64_t));
156 case CFI_type_int_fast128_t
:
157 return std::make_pair(TypeCategory::Integer
, 16);
158 case CFI_type_intmax_t
:
159 return std::make_pair(TypeCategory::Integer
, sizeof(std::intmax_t));
160 case CFI_type_intptr_t
:
161 return std::make_pair(TypeCategory::Integer
, sizeof(std::intptr_t));
162 case CFI_type_ptrdiff_t
:
163 return std::make_pair(TypeCategory::Integer
, sizeof(std::ptrdiff_t));
164 case CFI_type_half_float
:
165 return std::make_pair(TypeCategory::Real
, 2);
166 case CFI_type_bfloat
:
167 return std::make_pair(TypeCategory::Real
, 3);
169 return std::make_pair(TypeCategory::Real
, 4);
170 case CFI_type_double
:
171 return std::make_pair(TypeCategory::Real
, 8);
172 case CFI_type_extended_double
:
173 return std::make_pair(TypeCategory::Real
, 10);
174 case CFI_type_long_double
:
175 return std::make_pair(TypeCategory::Real
, 16);
176 case CFI_type_float128
:
177 return std::make_pair(TypeCategory::Real
, 16);
178 case CFI_type_half_float_Complex
:
179 return std::make_pair(TypeCategory::Complex
, 2);
180 case CFI_type_bfloat_Complex
:
181 return std::make_pair(TypeCategory::Complex
, 3);
182 case CFI_type_float_Complex
:
183 return std::make_pair(TypeCategory::Complex
, 4);
184 case CFI_type_double_Complex
:
185 return std::make_pair(TypeCategory::Complex
, 8);
186 case CFI_type_extended_double_Complex
:
187 return std::make_pair(TypeCategory::Complex
, 10);
188 case CFI_type_long_double_Complex
:
189 return std::make_pair(TypeCategory::Complex
, 16);
190 case CFI_type_float128_Complex
:
191 return std::make_pair(TypeCategory::Complex
, 16);
193 return std::make_pair(TypeCategory::Logical
, 1);
195 return std::make_pair(TypeCategory::Character
, 1);
197 return std::make_pair(TypeCategory::Integer
, sizeof(void *));
198 case CFI_type_struct
:
199 return std::make_pair(TypeCategory::Derived
, 0);
200 case CFI_type_char16_t
:
201 return std::make_pair(TypeCategory::Character
, 2);
202 case CFI_type_char32_t
:
203 return std::make_pair(TypeCategory::Character
, 4);
208 } // namespace Fortran::runtime