1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
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, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package contains constants describing target properties
28 with Types
; use Types
;
33 ------------------------------
34 -- Host/Target Dependencies --
35 ------------------------------
37 -- It is vital to maintain a clear distinction between properties of
38 -- types on the host and types on the target, since in the general
39 -- case of a cross-compiler these will be different.
41 -- This package provides definitions of values that describe the properties
42 -- of the target types. All instances of target dependencies, including the
43 -- definitions of such packages as Standard and System depend directly or
44 -- indirectly on the definitions in the Ttypes packages.
46 -- In the source of the compiler, references to attributes such as
47 -- Integer'Size will give information regarding the host types (i.e.
48 -- the types within the compiler itself). Such references are therefore
49 -- almost always suspicious (it is hard for example to see that the
50 -- code in the compiler should even be using type Integer very much,
51 -- and certainly this code should not depend on the size of Integer).
53 -- On the other hand, it is perfectly reasonable for the compiler to
54 -- require access to the size of type Integer for the target machine,
55 -- e.g. in constructing the internal representation of package Standard.
56 -- For this purpose, instead of referencing the attribute Integer'Size,
57 -- a reference to Ttypes.Standard_Integer_Size will provide the needed
58 -- value for the target type.
60 -- Two approaches are used for handling target dependent values in the
61 -- standard library packages. Package Standard is handled specially,
62 -- being constructed internally (by package Stand). Target dependent
63 -- values needed in Stand are obtained by direct reference to Ttypes.
65 -- For package System, there is a separate version for each target, with
66 -- explicit declarations of the required constants.
68 -- Historical note: Originally we had in mind dealing with target dependent
69 -- differences by referencing appropriate attributes. Ada 95 already
70 -- defines most of the required attributes, and GNAT specific attributes
71 -- were defined to cover the remaining cases (such as Storage_Unit).
72 -- The additional attributes that have been added to GNAT (Address_Size,
73 -- Storage_Unit, and Word_Size) are redundant with respect to the
74 -- corresponding references to System constants. For example in a program,
75 -- System.Address_Size and Standard'Address_Size yield the same value.
76 -- These attributes have been retained for compatibility purposes, but
77 -- serve no purpose at this stage.
79 -- Note that during compilation there are two versions of package System
80 -- around. The version that is directly with'ed by compiler packages
81 -- contains host-dependent definitions, which is what is needed in that
82 -- case (for example, System.Storage_Unit referenced in the source of the
83 -- compiler refers to the storage unit of the host, not the target). This
84 -- means that, like attribute references, any references to constants in
85 -- package System in the compiler code are suspicious, since it is strange
86 -- for the compiler to have such host dependencies. If the compiler needs
87 -- to access the target dependent values of such quantities as Storage_Unit
88 -- then it should reference the constants in this package (Ttypes), rather
89 -- than referencing System.Storage_Unit, or Standard'Storage_Unit, both of
90 -- which would yield the host value.
92 ---------------------------------------------------
93 -- Target-Dependent Values for Types in Standard --
94 ---------------------------------------------------
96 -- Note: GNAT always supplies all the following integer and float types,
97 -- but depending on the machine, some of the types may be identical. For
98 -- example, on some machines, Short_Float may be the same as Float, and
99 -- Long_Long_Float may be the same as Long_Float.
101 Standard_Short_Short_Integer_Size
: constant Pos
:=
104 Standard_Short_Integer_Size
: constant Pos
:=
107 Standard_Integer_Size
: constant Pos
:=
110 Standard_Long_Integer_Size
: constant Pos
:=
113 Standard_Long_Long_Integer_Size
: constant Pos
:=
114 Set_Targ
.Long_Long_Size
;
116 Standard_Long_Long_Long_Integer_Size
: Pos
:=
117 Set_Targ
.Long_Long_Long_Size
;
119 Standard_Short_Float_Size
: constant Pos
:=
122 Standard_Float_Size
: constant Pos
:=
125 Standard_Long_Float_Size
: constant Pos
:=
126 Set_Targ
.Double_Size
;
128 Standard_Long_Long_Float_Size
: constant Pos
:=
129 Set_Targ
.Long_Double_Size
;
131 Standard_Character_Size
: constant Pos
:= Set_Targ
.Char_Size
;
133 Standard_Wide_Character_Size
: constant Pos
:= 16;
134 Standard_Wide_Wide_Character_Size
: constant Pos
:= 32;
135 -- Standard wide character sizes
137 -- Note: there is no specific control over the representation of
138 -- enumeration types. The convention used is that if an enumeration
139 -- type has fewer than 2**(Character'Size) elements, then the size
140 -- used is Character'Size, otherwise Integer'Size is used.
142 -- Similarly, the size of fixed-point types depends on the size of the
143 -- corresponding integer type, which is the smallest predefined integer
144 -- type capable of representing the required range of values.
146 -------------------------------------------------
147 -- Target-Dependent Values for Types in System --
148 -------------------------------------------------
150 System_Address_Size
: constant Pos
:= Set_Targ
.Pointer_Size
;
151 -- System.Address'Size (also size of all thin pointers)
153 System_Max_Integer_Size
: Pos
:= Standard_Long_Long_Long_Integer_Size
;
155 System_Max_Binary_Modulus_Power
: Pos
:=
156 Standard_Long_Long_Long_Integer_Size
;
158 System_Max_Nonbinary_Modulus_Power
: constant Pos
:= Standard_Integer_Size
;
160 System_Storage_Unit
: constant Pos
:= Set_Targ
.Bits_Per_Unit
;
161 System_Word_Size
: constant Pos
:= Set_Targ
.Bits_Per_Word
;
163 System_Tick_Nanoseconds
: constant Pos
:= 1_000_000_000
;
164 -- Value of System.Tick in nanoseconds. At the moment, this is a fixed
165 -- constant (with value of 1.0 seconds), but later we should add this
166 -- value to the GCC configuration file so that its value can be made
167 -- configuration dependent.
169 -----------------------------------------------------
170 -- Target-Dependent Values for Types in Interfaces --
171 -----------------------------------------------------
173 Interfaces_Wchar_T_Size
: constant Pos
:= Set_Targ
.Wchar_T_Size
;
175 ----------------------------------------
176 -- Other Target-Dependent Definitions --
177 ----------------------------------------
179 Maximum_Alignment
: constant Pos
:= Set_Targ
.Maximum_Alignment
;
180 -- The maximum alignment, in storage units, that an object or type may
181 -- require on the target machine.
183 System_Allocator_Alignment
: constant Pos
:=
184 Set_Targ
.System_Allocator_Alignment
;
185 -- The alignment in storage units of addresses returned by malloc
187 Bytes_Big_Endian
: Boolean := Set_Targ
.Bytes_BE
/= 0;
188 -- Important note: for Ada purposes, the important setting is the bytes
189 -- endianness (Bytes_Big_Endian), not the bits value (Bits_Big_Endian).
190 -- This is because Ada bit addressing must be compatible with the byte
191 -- ordering (otherwise we would end up with non-contiguous fields). It
192 -- is rare for the two to be different, but if they are, Bits_Big_Endian
193 -- is relevant only for the generation of instructions with bit numbers,
194 -- and thus relevant only to the back end. Note that this is a variable
195 -- rather than a constant, since it can be modified (flipped) by -gnatd8.
197 Target_Short_Enums
: constant Boolean := Set_Targ
.Short_Enums
/= 0;
198 -- True if we are in short enums mode, where foreign convention
199 -- (in particular C and C++) enumeration types will be sized as in Ada,
200 -- using the shortest possibility from 8,16,32 bits, signed or unsigned.
201 -- A zero value means Short_Enums are not in use, and in this case all
202 -- foreign convention enumeration types are given the same size as c int.
204 Target_Strict_Alignment
: Boolean :=
205 Set_Targ
.Strict_Alignment
/= 0;
206 -- True if instructions will fail if data is misaligned. Note that this
207 -- is a variable rather than a constant since it can be modified (set to
208 -- True) if the debug flag -gnatd.a is used.
210 Target_Double_Float_Alignment
: constant Nat
:=
211 Set_Targ
.Double_Float_Alignment
;
212 -- The default alignment of "double" floating-point types, i.e. floating
213 -- point types whose size is equal to 64 bits, or 0 if this alignment is
214 -- not lower than the largest power of 2 multiple of System.Storage_Unit
215 -- that does not exceed either the object size of the type or the maximum
216 -- allowed alignment.
218 Target_Double_Scalar_Alignment
: constant Nat
:=
219 Set_Targ
.Double_Scalar_Alignment
;
220 -- The default alignment of "double" or larger scalar types, i.e. scalar
221 -- types whose size is greater or equal to 64 bits, or 0 if this alignment
222 -- is not lower than the largest power of 2 multiple of System.Storage_Unit
223 -- that does not exceed either the object size of the type or the maximum
224 -- allowed alignment.