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