cfc45e7fe16fa7abd9345f980ef2ed1513e1bc3b
[platform/upstream/gcc48.git] / gcc / ada / gcc-interface / targtyps.c
1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                            T A R G T Y P S                               *
6  *                                                                          *
7  *                                  Body                                    *
8  *                                                                          *
9  *          Copyright (C) 1992-2012, 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 "tree.h"
32 #include "tm.h"
33 #include "tm_p.h"
34
35 #include "ada.h"
36 #include "types.h"
37 #include "atree.h"
38 #include "elists.h"
39 #include "namet.h"
40 #include "nlists.h"
41 #include "snames.h"
42 #include "stringt.h"
43 #include "uintp.h"
44 #include "urealp.h"
45 #include "fe.h"
46 #include "sinfo.h"
47 #include "einfo.h"
48 #include "ada-tree.h"
49 #include "gigi.h"
50
51 /* If we don't have a specific size for Ada's equivalent of `long', use that
52    of C.  */
53 #ifndef ADA_LONG_TYPE_SIZE
54 #define ADA_LONG_TYPE_SIZE LONG_TYPE_SIZE
55 #endif
56
57 /* If we don't have a target definition of WIDEST_HARDWARE_FP_SIZE, assume
58    DOUBLE_TYPE_SIZE.  We used to default to LONG_DOUBLE_TYPE_SIZE, which now
59    most often maps 128 bits implemented with very inefficient software
60    emulations so is incorrect as a hardware size estimate.  */
61
62 #ifndef WIDEST_HARDWARE_FP_SIZE
63 #define WIDEST_HARDWARE_FP_SIZE DOUBLE_TYPE_SIZE
64 #endif
65
66 /* The following provide a functional interface for the front end Ada code
67    to determine the sizes that are used for various C types. */
68
69 Pos
70 get_target_bits_per_unit (void)
71 {
72   return BITS_PER_UNIT;
73 }
74
75 Pos
76 get_target_bits_per_word (void)
77 {
78   return BITS_PER_WORD;
79 }
80
81 Pos
82 get_target_char_size (void)
83 {
84   return CHAR_TYPE_SIZE;
85 }
86
87 Pos
88 get_target_wchar_t_size (void)
89 {
90   /* We never want wide characters less than "short" in Ada.  */
91   return MAX (SHORT_TYPE_SIZE, WCHAR_TYPE_SIZE);
92 }
93
94 Pos
95 get_target_short_size (void)
96 {
97   return SHORT_TYPE_SIZE;
98 }
99
100 Pos
101 get_target_int_size (void)
102 {
103   return INT_TYPE_SIZE;
104 }
105
106 Pos
107 get_target_long_size (void)
108 {
109   return ADA_LONG_TYPE_SIZE;
110 }
111
112 Pos
113 get_target_long_long_size (void)
114 {
115   return LONG_LONG_TYPE_SIZE;
116 }
117
118 Pos
119 get_target_float_size (void)
120 {
121   return fp_prec_to_size (FLOAT_TYPE_SIZE);
122 }
123
124 Pos
125 get_target_double_size (void)
126 {
127   return fp_prec_to_size (DOUBLE_TYPE_SIZE);
128 }
129
130 Pos
131 get_target_long_double_size (void)
132 {
133   return fp_prec_to_size (WIDEST_HARDWARE_FP_SIZE);
134 }
135
136 Pos
137 get_target_pointer_size (void)
138 {
139   return POINTER_SIZE;
140 }
141
142 /* Alignment related values, mapped to attributes for functional and
143    documentation purposes.  */
144
145 /* Standard'Maximum_Default_Alignment.  Maximum alignment that the compiler
146    might choose by default for a type or object.
147
148    Stricter alignment requests trigger gigi's aligning_type circuitry for
149    stack objects or objects allocated by the default allocator.  */
150
151 Pos
152 get_target_maximum_default_alignment (void)
153 {
154   return BIGGEST_ALIGNMENT / BITS_PER_UNIT;
155 }
156
157 /* Standard'System_Allocator_Alignment.  Alignment guaranteed to be honored
158    by the default allocator (System.Memory.Alloc or malloc if we have no
159    run-time library at hand).
160
161    Stricter alignment requests trigger gigi's aligning_type circuitry for
162    objects allocated by the default allocator.  */
163
164 /* ??? Need a way to get info about __gnat_malloc from here (whether it is
165    handy and what alignment it honors).  In the meantime, resort to malloc
166    considerations only.  */
167
168 /* Account for MALLOC_OBSERVABLE_ALIGNMENTs here.  Use this or the ABI
169    guaranteed alignment if greater.  */
170
171 #ifdef MALLOC_OBSERVABLE_ALIGNMENT
172 #define MALLOC_ALIGNMENT MALLOC_OBSERVABLE_ALIGNMENT
173 #else
174 #define MALLOC_OBSERVABLE_ALIGNMENT (2 * LONG_TYPE_SIZE)
175 #define MALLOC_ALIGNMENT \
176   MAX (MALLOC_ABI_ALIGNMENT, MALLOC_OBSERVABLE_ALIGNMENT)
177 #endif
178
179 Pos
180 get_target_system_allocator_alignment (void)
181 {
182   return MALLOC_ALIGNMENT / BITS_PER_UNIT;
183 }
184
185 /* Standard'Maximum_Allowed_Alignment.  Maximum alignment that we may
186    accept for any type or object.  */
187
188 #ifndef MAX_OFILE_ALIGNMENT
189 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
190 #endif
191
192 Pos
193 get_target_maximum_allowed_alignment (void)
194 {
195   return MAX_OFILE_ALIGNMENT / BITS_PER_UNIT;
196 }
197
198 /* Standard'Maximum_Alignment.  The single attribute initially made
199    available, now a synonym of Standard'Maximum_Default_Alignment.  */
200
201 Pos
202 get_target_maximum_alignment (void)
203 {
204   return get_target_maximum_default_alignment ();
205 }
206
207 #ifndef FLOAT_WORDS_BIG_ENDIAN
208 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
209 #endif
210
211 Nat
212 get_float_words_be (void)
213 {
214   return FLOAT_WORDS_BIG_ENDIAN;
215 }
216
217 Nat
218 get_words_be (void)
219 {
220   return WORDS_BIG_ENDIAN;
221 }
222
223 Nat
224 get_bytes_be (void)
225 {
226   return BYTES_BIG_ENDIAN;
227 }
228
229 Nat
230 get_bits_be (void)
231 {
232   return BITS_BIG_ENDIAN;
233 }
234
235 Nat
236 get_target_strict_alignment (void)
237 {
238   return STRICT_ALIGNMENT;
239 }
240
241 Nat
242 get_target_double_float_alignment (void)
243 {
244 #ifdef TARGET_ALIGN_NATURAL
245   /* This macro is only defined by the rs6000 port.  */
246   if (!TARGET_ALIGN_NATURAL
247       && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
248     return 32 / BITS_PER_UNIT;
249 #endif
250   return 0;
251 }
252
253 Nat
254 get_target_double_scalar_alignment (void)
255 {
256 #ifdef TARGET_ALIGN_DOUBLE
257   /* This macro is only defined by the i386 and sh ports.  */
258   if (!TARGET_ALIGN_DOUBLE
259 #ifdef TARGET_64BIT
260       && !TARGET_64BIT
261 #endif
262      )
263     return 32 / BITS_PER_UNIT;
264 #endif
265   return 0;
266 }