1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                               T T Y P E S                                --
6--                                                                          --
7--                                 S p e c                                  --
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, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license.          --
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--  This package contains constants describing target properties
27
28with Types;    use Types;
29with Get_Targ; use Get_Targ;
30
31package Ttypes is
32
33   ------------------------------
34   -- Host/Target Dependencies --
35   ------------------------------
36
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.
40
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.
45
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).
52
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.
59
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
64   --  and Ttypef.
65
66   --  For package System, the required constant values are obtained by
67   --  referencing appropriate attributes. Ada 95 already defines most of
68   --  the required attributes, and GNAT specific attributes have been
69   --  defined to cover the remaining cases (such as Storage_Unit). The
70   --  evaluation of these attributes obtains the required target dependent
71   --  values from Ttypes and Ttypef. The additional attributes that have
72   --  been added to GNAT (Address_Size, Storage_Unit, Word_Size, Max_Priority,
73   --  and Max_Interrupt_Priority) are for almost all purposes redundant with
74   --  respect to the corresponding references to System constants. For example
75   --  in a program, System.Address_Size and Standard'Address_Size yield the
76   --  same value. The critical use of the attribute is in writing the System
77   --  declaration of Address_Size which of course cannot refer to itself. By
78   --  this means we achieve complete target independence in the source code
79   --  of package System, i.e. there is only one copy of the source of System
80   --  for all targets.
81
82   --  Note that during compilation there are two versions of package System
83   --  around. The version that is directly with'ed by compiler packages
84   --  contains host-dependent definitions, which is what is needed in that
85   --  case (for example, System.Storage_Unit referenced in the source of the
86   --  compiler refers to the storage unit of the host, not the target). This
87   --  means that, like attribute references, any references to constants in
88   --  package System in the compiler code are suspicious, since it is strange
89   --  for the compiler to have such host dependencies. If the compiler needs
90   --  to access the target dependent values of such quantities as Storage_Unit
91   --  then it should reference the constants in this package (Ttypes), rather
92   --  than referencing System.Storage_Unit, or Standard'Storage_Unit, both of
93   --  which would yield the host value.
94
95   ----------------------------------------------
96   -- Target-Dependent Information in ALI File --
97   ----------------------------------------------
98
99   --  If the flag Generate_Target_Dependent_Info is set (e.g. by use of the
100   --  -gnatT switch), then the ALI file contains T lines representing each of
101   --  the constants defined in this package (see Lib-Writ spec for details).
102
103   --  These T lines use a code consisting of four upper case letters to
104   --  identify the constant whose value is output. These four letter codes
105   --  may be found as a comment in the declaration of each constant.
106
107   ---------------------------------------------------
108   -- Target-Dependent Values for Types in Standard --
109   ---------------------------------------------------
110
111   --  Note: GNAT always supplies all the following integer and float types,
112   --  but depending on the machine, some of the types may be identical. For
113   --  example, on some machines, Short_Float may be the same as Float, and
114   --  Long_Long_Float may be the same as Long_Float.
115
116   Standard_Short_Short_Integer_Size  : constant Pos :=               -- SINS
117                                          Get_Char_Size;
118   Standard_Short_Short_Integer_Width : constant Pos :=               -- SINW
119                                          Width_From_Size
120                                           (Standard_Short_Short_Integer_Size);
121
122   Standard_Short_Integer_Size        : constant Pos :=               -- SHIS
123                                          Get_Short_Size;
124   Standard_Short_Integer_Width       : constant Pos :=               -- SHIW
125                                          Width_From_Size
126                                            (Standard_Short_Integer_Size);
127
128   Standard_Integer_Size              : constant Pos :=               -- INTS
129                                          Get_Int_Size;
130   Standard_Integer_Width             : constant Pos :=               -- INTW
131                                          Width_From_Size
132                                            (Standard_Integer_Size);
133
134   Standard_Long_Integer_Size         : constant Pos :=               -- LINS
135                                          Get_Long_Size;
136   Standard_Long_Integer_Width        : constant Pos :=               -- LINW
137                                          Width_From_Size
138                                            (Standard_Long_Integer_Size);
139
140   Standard_Long_Long_Integer_Size    : constant Pos :=               -- LLIS
141                                          Get_Long_Long_Size;
142   Standard_Long_Long_Integer_Width   : constant Pos :=               -- LLIW
143                                          Width_From_Size
144                                            (Standard_Long_Long_Integer_Size);
145
146   Standard_Short_Float_Size          : constant Pos :=               -- SFLS
147                                          Get_Float_Size;
148   Standard_Short_Float_Digits        : constant Pos :=               -- SFLD
149                                          Digits_From_Size
150                                            (Standard_Short_Float_Size);
151
152   Standard_Float_Size                : constant Pos :=               -- FLTS
153                                          Get_Float_Size;
154   Standard_Float_Digits              : constant Pos :=               -- FLTD
155                                          Digits_From_Size
156                                            (Standard_Float_Size);
157
158   Standard_Long_Float_Size           : constant Pos :=               -- LFLS
159                                          Get_Double_Size;
160   Standard_Long_Float_Digits         : constant Pos :=               -- LFLD
161                                          Digits_From_Size
162                                            (Standard_Long_Float_Size);
163
164   Standard_Long_Long_Float_Size      : constant Pos :=               -- LLFS
165                                          Get_Long_Double_Size;
166   Standard_Long_Long_Float_Digits    : constant Pos :=               -- LLFD
167                                          Digits_From_Size
168                                            (Standard_Long_Long_Float_Size);
169
170   Standard_Character_Size            : constant Pos :=               -- CHAS
171                                          Get_Char_Size;
172
173   Standard_Wide_Character_Size       : constant Pos := 16;           -- WCHS
174   Standard_Wide_Wide_Character_Size  : constant Pos := 32;           -- WWCS
175   --  Standard wide character sizes
176
177   --  Note: there is no specific control over the representation of
178   --  enumeration types. The convention used is that if an enumeration
179   --  type has fewer than 2**(Character'Size) elements, then the size
180   --  used is Character'Size, otherwise Integer'Size is used.
181
182   --  Similarly, the size of fixed-point types depends on the size of the
183   --  corresponding integer type, which is the smallest predefined integer
184   --  type capable of representing the required range of values.
185
186   -------------------------------------------------
187   -- Target-Dependent Values for Types in System --
188   -------------------------------------------------
189
190   System_Address_Size : constant Pos := Get_Pointer_Size;            -- ADRS
191   --  System.Address'Size (also size of all thin pointers)
192
193   System_Max_Binary_Modulus_Power : constant Pos :=                  -- MBMP
194                                       Standard_Long_Long_Integer_Size;
195
196   System_Max_Nonbinary_Modulus_Power : constant Pos :=               -- MNMP
197                                          Standard_Integer_Size;
198
199   System_Storage_Unit : constant Pos := Get_Bits_Per_Unit;           -- SUNI
200   System_Word_Size    : constant Pos := Get_Bits_Per_Word;           -- WRDS
201
202   System_Tick_Nanoseconds : constant Pos := 1_000_000_000;           -- TICK
203   --  Value of System.Tick in nanoseconds. At the moment, this is a fixed
204   --  constant (with value of 1.0 seconds), but later we should add this
205   --  value to the GCC configuration file so that its value can be made
206   --  configuration dependent.
207
208   -----------------------------------------------------
209   -- Target-Dependent Values for Types in Interfaces --
210   -----------------------------------------------------
211
212   Interfaces_Wchar_T_Size : constant Pos := Get_Wchar_T_Size;        -- WCTS
213
214   ----------------------------------------
215   -- Other Target-Dependent Definitions --
216   ----------------------------------------
217
218   Maximum_Alignment : constant Pos := Get_Maximum_Alignment;        -- MAXA
219   --  The maximum alignment, in storage units, that an object or type may
220   --  require on the target machine.
221
222   System_Allocator_Alignment : constant Pos :=                      -- ALLA
223                                  Get_System_Allocator_Alignment;
224   --  The alignment in storage units of addresses returned by malloc
225
226   Max_Unaligned_Field : constant Pos := Get_Max_Unaligned_Field;    -- MUNF
227   --  The maximum supported size in bits for a field that is not aligned
228   --  on a storage unit boundary.
229
230   Bytes_Big_Endian : Boolean := Get_Bytes_BE /= 0;                  -- BEND
231   --  Important note: for Ada purposes, the important setting is the bytes
232   --  endianness (Bytes_Big_Endian), not the bits value (Bits_Big_Endian).
233   --  This is because Ada bit addressing must be compatible with the byte
234   --  ordering (otherwise we would end up with non-contiguous fields). It
235   --  is rare for the two to be different, but if they are, Bits_Big_Endian
236   --  is relevant only for the generation of instructions with bit numbers,
237   --  and thus relevant only to the back end. Note that this is a variable
238   --  rather than a constant, since it can be modified (flipped) by -gnatd8.
239
240   Target_Strict_Alignment : Boolean :=                               -- STRA
241                               Get_Strict_Alignment /= 0;
242   --  True if instructions will fail if data is misaligned. Note that this
243   --  is a variable rather than a constant since it can be modified (set to
244   --  True) if the debug flag -gnatd.A is used.
245
246   Target_Double_Float_Alignment : constant Nat :=                    -- DFLA
247                                     Get_Double_Float_Alignment;
248   --  The default alignment of "double" floating-point types, i.e. floating
249   --  point types whose size is equal to 64 bits, or 0 if this alignment is
250   --  not specifically capped.
251
252   Target_Double_Scalar_Alignment : constant Nat :=                   -- DSCA
253                                      Get_Double_Scalar_Alignment;
254   --  The default alignment of "double" or larger scalar types, i.e. scalar
255   --  types whose size is greater or equal to 64 bits, or 0 if this alignment
256   --  is not specifically capped.
257
258end Ttypes;
259