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-2003 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 2,  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 COPYING.  If not, write --
19-- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20-- MA 02111-1307, USA.                                                      --
21--                                                                          --
22-- GNAT was originally developed  by the GNAT team at  New York University. --
23-- Extensive contributions were provided by Ada Core Technologies Inc.      --
24--                                                                          --
25------------------------------------------------------------------------------
26
27--  This package contains constants describing target properties
28
29with Types;    use Types;
30with Get_Targ; use Get_Targ;
31
32package Ttypes is
33
34   ------------------------------
35   -- Host/Target Dependencies --
36   ------------------------------
37
38   --  It is vital to maintain a clear distinction between properties of
39   --  types on the host and types on the target, since in the general
40   --  case of a cross-compiler these will be different.
41
42   --  This package and its companion Ttypef provide definitions of values
43   --  that describe the properties of the target types. All instances of
44   --  target dependencies, including the definitions of such packages as
45   --  Standard and System depend directly or indirectly on the definitions
46   --  in the Ttypes and Ttypef packages.
47
48   --  In the source of the compiler, references to attributes such as
49   --  Integer'Size will give information regarding the host types (i.e.
50   --  the types within the compiler itself). Such references are therefore
51   --  almost always suspicious (it is hard for example to see that the
52   --  code in the compiler should even be using type Integer very much,
53   --  and certainly this code should not depend on the size of Integer).
54
55   --  On the other hand, it is perfectly reasonable for the compiler to
56   --  require access to the size of type Integer for the target machine,
57   --  e.g. in constructing the internal representation of package Standard.
58   --  For this purpose, instead of referencing the attribute Integer'Size,
59   --  a reference to Ttypes.Standard_Integer_Size will provide the needed
60   --  value for the target type.
61
62   --  Two approaches are used for handling target dependent values in the
63   --  standard library packages. Package Standard is handled specially,
64   --  being constructed internally (by package Stand). Target dependent
65   --  values needed in Stand are obtained by direct reference to Ttypes
66   --  and Ttypef.
67
68   --  For package System, the required constant values are obtained by
69   --  referencing appropriate attributes. Ada 95 already defines most of
70   --  the required attributes, and GNAT specific attributes have been
71   --  defined to cover the remaining cases (such as Storage_Unit). The
72   --  evaluation of these attributes obtains the required target dependent
73   --  values from Ttypes and Ttypef. The additional attributes that have
74   --  been added to GNAT (Address_Size, Storage_Unit, Word_Size, Max_Priority,
75   --  and Max_Interrupt_Priority) are for almost all purposes redundant with
76   --  respect to the corresponding references to System constants. For example
77   --  in a program, System.Address_Size and Standard'Address_Size yield the
78   --  same value. The critical use of the attribute is in writing the System
79   --  declaration of Address_Size which of course cannot refer to itself. By
80   --  this means we achieve complete target independence in the source code
81   --  of package System, i.e. there is only one copy of the source of System
82   --  for all targets.
83
84   --  Note that during compilation there are two versions of package System
85   --  around. The version that is directly WITH'ed by compiler packages
86   --  contains host-dependent definitions, which is what is needed in that
87   --  case (for example, System.Storage_Unit referenced in the source of the
88   --  compiler refers to the storage unit of the host, not the target. This
89   --  means that, like attribute references, any references to constants in
90   --  package System in the compiler code are suspicious, since it is strange
91   --  for the compiler to have such host dependencies. If the compiler needs
92   --  to access the target dependent values of such quantities as Storage_Unit
93   --  then it should reference the constants in this package (Ttypes), rather
94   --  than referencing System.Storage_Unit, or Standard'Storage_Unit, both of
95   --  which would yield the host value.
96
97   ---------------------------------------------------
98   -- Target-Dependent Values for Types in Standard --
99   ---------------------------------------------------
100
101   --  Note: GNAT always supplies all the following integer and float types,
102   --  but depending on the machine, some of the types may be identical. For
103   --  example, on some machines, Short_Float may be the same as Float, and
104   --  Long_Long_Float may be the same as Long_Float.
105
106   Standard_Short_Short_Integer_Size   : constant Pos := Get_Char_Size;
107   Standard_Short_Short_Integer_Width  : constant Pos :=
108                           Width_From_Size (Standard_Short_Short_Integer_Size);
109
110   Standard_Short_Integer_Size         : constant Pos := Get_Short_Size;
111   Standard_Short_Integer_Width        : constant Pos :=
112                           Width_From_Size (Standard_Short_Integer_Size);
113
114   Standard_Integer_Size               : constant Pos := Get_Int_Size;
115   Standard_Integer_Width              : constant Pos :=
116                           Width_From_Size (Standard_Integer_Size);
117
118   Standard_Long_Integer_Size          : constant Pos := Get_Long_Size;
119   Standard_Long_Integer_Width         : constant Pos :=
120                           Width_From_Size (Standard_Long_Integer_Size);
121
122   Standard_Long_Long_Integer_Size     : constant Pos := Get_Long_Long_Size;
123   Standard_Long_Long_Integer_Width    : constant Pos :=
124                           Width_From_Size (Standard_Long_Long_Integer_Size);
125
126   Standard_Short_Float_Size           : constant Pos := Get_Float_Size;
127   Standard_Short_Float_Digits         : constant Pos :=
128                           Digits_From_Size (Standard_Short_Float_Size);
129
130   Standard_Float_Size                 : constant Pos := Get_Float_Size;
131   Standard_Float_Digits               : constant Pos :=
132                           Digits_From_Size (Standard_Float_Size);
133
134   Standard_Long_Float_Size            : constant Pos := Get_Double_Size;
135   Standard_Long_Float_Digits          : constant Pos :=
136                           Digits_From_Size (Standard_Long_Float_Size);
137
138   Standard_Long_Long_Float_Size       : constant Pos := Get_Long_Double_Size;
139   Standard_Long_Long_Float_Digits     : constant Pos :=
140                           Digits_From_Size (Standard_Long_Long_Float_Size);
141
142   Standard_Character_Size             : constant Pos := Get_Char_Size;
143
144   Standard_Wide_Character_Size        : constant Pos := 16;
145   --  The Standard.Wide_Character type is special in the sense that
146   --  it is not defined in terms of its corresponding C type (wchar_t).
147   --  Unfortunately this makes the representation of Wide_Character
148   --  incompatible with the C wchar_t type.
149   --  ??? This is required by the RM or backward compatibility
150
151   --  Note: there is no specific control over the representation of
152   --  enumeration types. The convention used is that if an enumeration
153   --  type has fewer than 2**(Character'Size) elements, then the size
154   --  used is Character'Size, otherwise Integer'Size is used.
155
156   --  Similarly, the size of fixed-point types depends on the size of the
157   --  corresponding integer type, which is the smallest predefined integer
158   --  type capable of representing the required range of values.
159
160   -------------------------------------------------
161   -- Target-Dependent Values for Types in System --
162   -------------------------------------------------
163
164   System_Address_Size : constant Pos := Get_Pointer_Size;
165   --  System.Address'Size (also size of all thin pointers)
166
167   System_Max_Binary_Modulus_Power    : constant Pos :=
168                                          Standard_Long_Long_Integer_Size;
169
170   System_Max_Nonbinary_Modulus_Power : constant Pos :=
171                                          Standard_Integer_Size - 1;
172
173   System_Storage_Unit : constant Pos := Get_Bits_Per_Unit;
174   System_Word_Size    : constant Pos := Get_Bits_Per_Word;
175
176   System_Tick_Nanoseconds : constant Pos := 1_000_000_000;
177   --  Value of System.Tick in nanoseconds. At the moment, this is a fixed
178   --  constant (with value of 1.0 seconds), but later we should add this
179   --  value to the GCC configuration file so that its value can be made
180   --  configuration dependent.
181
182   -----------------------------------------------------
183   -- Target-Dependent Values for Types in Interfaces --
184   -----------------------------------------------------
185
186   Interfaces_Wchar_T_Size : constant Pos := Get_Wchar_T_Size;
187
188   ----------------------------------------
189   -- Other Target-Dependent Definitions --
190   ----------------------------------------
191
192   Maximum_Alignment : constant Pos := Get_Maximum_Alignment;
193   --  The maximum alignment, in storage units, that an object or
194   --  type may require on the target machine.
195
196   Max_Unaligned_Field : constant Pos := Get_Max_Unaligned_Field;
197   --  The maximum supported size in bits for a field that is not aligned
198   --  on a storage unit boundary.
199
200   Bytes_Big_Endian : Boolean := Get_Bytes_BE /= 0;
201   --  Important note: for Ada purposes, the important setting is the bytes
202   --  endianness (Bytes_Big_Endian), not the bits value (Bits_Big_Endian).
203   --  This is because Ada bit addressing must be compatible with the byte
204   --  ordering (otherwise we would end up with non-contiguous fields). It
205   --  is rare for the two to be different, but if they are, Bits_Big_Endian
206   --  is relevant only for the generation of instructions with bit numbers,
207   --  and thus relevant only to the back end. Note that this is a variable
208   --  rather than a constant, since it can be modified (flipped) by -gnatd8.
209
210   Target_Strict_Alignment : Boolean := Get_Strict_Alignment /= 0;
211   --  True if instructions will fail if data is misaligned
212
213end Ttypes;
214