Debian Codegraph @

gcc/ada/gcc-interface/targtyps.cc

raw
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * T A R G T Y P S *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2025, Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING3. If not see *
19 * <http://www.gnu.org/licenses/>. *
20 * *
21 * GNAT was originally developed by the GNAT team at New York University. *
22 * Extensive contributions were provided by Ada Core Technologies Inc. *
23 * *
24 ****************************************************************************/
25
26 /* Functions for retrieving target types. See Ada package Get_Targ. */
27
28 #include "config.h"
29 #include "system.h"
30 #include "coretypes.h"
31 #include "tm.h"
32 #include "target.h"
33 #include "tree.h"
34
35 #include "ada.h"
36 #include "types.h"
37 #include "sinfo.h"
38 #include "ada-tree.h"
39 #include "gigi.h"
40
41 /* If we don't have a specific size for Ada's equivalent of `long', use that
42 of C. */
43 #ifndef ADA_LONG_TYPE_SIZE
44 #define ADA_LONG_TYPE_SIZE LONG_TYPE_SIZE
45 #endif
46
47 /* The following provide a functional interface for the front end Ada code
48 to determine the sizes that are used for various C types. */
49
50 Pos
51 get_target_bits_per_unit (void)
52 {
53 return BITS_PER_UNIT;
54 }
55
56 Pos
57 get_target_bits_per_word (void)
58 {
59 return BITS_PER_WORD;
60 }
61
62 Pos
63 get_target_char_size (void)
64 {
65 return CHAR_TYPE_SIZE;
66 }
67
68 Pos
69 get_target_wchar_t_size (void)
70 {
71 /* We never want wide characters less than "short" in Ada. */
72 return MAX (SHORT_TYPE_SIZE, WCHAR_TYPE_SIZE);
73 }
74
75 Pos
76 get_target_short_size (void)
77 {
78 return SHORT_TYPE_SIZE;
79 }
80
81 Pos
82 get_target_int_size (void)
83 {
84 return INT_TYPE_SIZE;
85 }
86
87 Pos
88 get_target_long_size (void)
89 {
90 return ADA_LONG_TYPE_SIZE;
91 }
92
93 Pos
94 get_target_long_long_size (void)
95 {
96 return LONG_LONG_TYPE_SIZE;
97 }
98
99 Pos
100 get_target_long_long_long_size (void)
101 {
102 if (targetm.scalar_mode_supported_p (TImode))
103 return GET_MODE_BITSIZE (TImode);
104 else
105 return LONG_LONG_TYPE_SIZE;
106 }
107
108 Pos
109 get_target_pointer_size (void)
110 {
111 return POINTER_SIZE;
112 }
113
114 /* Alignment related values, mapped to attributes for functional and
115 documentation purposes. */
116
117 /* Standard'Maximum_Default_Alignment. Maximum alignment that the compiler
118 might choose by default for a type or object.
119
120 Stricter alignment requests trigger gigi's aligning_type circuitry for
121 stack objects or objects allocated by the default allocator. */
122
123 Pos
124 get_target_maximum_default_alignment (void)
125 {
126 return BIGGEST_ALIGNMENT / BITS_PER_UNIT;
127 }
128
129 /* Standard'System_Allocator_Alignment. Alignment guaranteed to be honored
130 by the default allocator (System.Memory.Alloc or malloc if we have no
131 run-time library at hand).
132
133 Stricter alignment requests trigger gigi's aligning_type circuitry for
134 objects allocated by the default allocator. */
135
136 /* ??? Need a way to get info about __gnat_malloc from here (whether it is
137 handy and what alignment it honors). In the meantime, resort to malloc
138 considerations only. */
139
140 /* Account for MALLOC_OBSERVABLE_ALIGNMENTs here. Use this or the ABI
141 guaranteed alignment if greater. */
142
143 #ifdef MALLOC_OBSERVABLE_ALIGNMENT
144 #define MALLOC_ALIGNMENT MALLOC_OBSERVABLE_ALIGNMENT
145 #else
146 #define MALLOC_OBSERVABLE_ALIGNMENT (2 * POINTER_SIZE)
147 #define MALLOC_ALIGNMENT \
148 MAX (MALLOC_ABI_ALIGNMENT, MALLOC_OBSERVABLE_ALIGNMENT)
149 #endif
150
151 Pos
152 get_target_system_allocator_alignment (void)
153 {
154 return MALLOC_ALIGNMENT / BITS_PER_UNIT;
155 }
156
157 /* Standard'Maximum_Allowed_Alignment. Maximum alignment that we may
158 accept for any type or object. */
159
160 #ifndef MAX_OFILE_ALIGNMENT
161 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
162 #endif
163
164 Pos
165 get_target_maximum_allowed_alignment (void)
166 {
167 return MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
168 }
169
170 /* Standard'Maximum_Alignment. The single attribute initially made
171 available, now a synonym of Standard'Maximum_Default_Alignment. */
172
173 Pos
174 get_target_maximum_alignment (void)
175 {
176 return get_target_maximum_default_alignment ();
177 }
178
179 #ifndef FLOAT_WORDS_BIG_ENDIAN
180 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
181 #endif
182
183 Nat
184 get_target_float_words_be (void)
185 {
186 return FLOAT_WORDS_BIG_ENDIAN;
187 }
188
189 Nat
190 get_target_words_be (void)
191 {
192 return WORDS_BIG_ENDIAN;
193 }
194
195 Nat
196 get_target_bytes_be (void)
197 {
198 return BYTES_BIG_ENDIAN;
199 }
200
201 Nat
202 get_target_bits_be (void)
203 {
204 return BITS_BIG_ENDIAN;
205 }
206
207 Nat
208 get_target_strict_alignment (void)
209 {
210 return STRICT_ALIGNMENT;
211 }
212
213 Nat
214 get_target_double_float_alignment (void)
215 {
216 #ifdef TARGET_ALIGN_NATURAL
217 /* This macro is only defined by the rs6000 port. */
218 if (!TARGET_ALIGN_NATURAL
219 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
220 return 32 / BITS_PER_UNIT;
221 #endif
222 return 0;
223 }
224
225 Nat
226 get_target_double_scalar_alignment (void)
227 {
228 #ifdef TARGET_ALIGN_DOUBLE
229 /* This macro is only defined by the i386 and sh ports. */
230 if (!TARGET_ALIGN_DOUBLE
231 #ifdef TARGET_64BIT
232 && !TARGET_64BIT
233 #endif
234 )
235 return 32 / BITS_PER_UNIT;
236 #endif
237 return 0;
238 }