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-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, 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; 30with Set_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 provides definitions of values that describe the properties 43 -- of the target types. All instances of target dependencies, including the 44 -- definitions of such packages as Standard and System depend directly or 45 -- indirectly on the definitions in the Ttypes packages. 46 47 -- In the source of the compiler, references to attributes such as 48 -- Integer'Size will give information regarding the host types (i.e. 49 -- the types within the compiler itself). Such references are therefore 50 -- almost always suspicious (it is hard for example to see that the 51 -- code in the compiler should even be using type Integer very much, 52 -- and certainly this code should not depend on the size of Integer). 53 54 -- On the other hand, it is perfectly reasonable for the compiler to 55 -- require access to the size of type Integer for the target machine, 56 -- e.g. in constructing the internal representation of package Standard. 57 -- For this purpose, instead of referencing the attribute Integer'Size, 58 -- a reference to Ttypes.Standard_Integer_Size will provide the needed 59 -- value for the target type. 60 61 -- Two approaches are used for handling target dependent values in the 62 -- standard library packages. Package Standard is handled specially, 63 -- being constructed internally (by package Stand). Target dependent 64 -- values needed in Stand are obtained by direct reference to Ttypes 65 -- and Ttypef. 66 67 -- For package System, there is a separate version for each target, with 68 -- explicit declarations of the required, constants. 69 70 -- Historical note: Originally we had in mind dealing with target dependent 71 -- differences by referencing appropriate attributes. Ada 95 already 72 -- defines most of the required attributes, and GNAT specific attributes 73 -- were defined to cover the remaining cases (such as Storage_Unit). 74 -- The additional attributes that have been added to GNAT (Address_Size, 75 -- Storage_Unit, and Word_Size) are redundant with respect to the 76 -- corresponding references to System constants. For example in a program, 77 -- System.Address_Size and Standard'Address_Size yield the same value. 78 -- These attributes have been retained for compatibility purposes, but 79 -- serve no purpose at this stage. 80 81 -- Note that during compilation there are two versions of package System 82 -- around. The version that is directly with'ed by compiler packages 83 -- contains host-dependent definitions, which is what is needed in that 84 -- case (for example, System.Storage_Unit referenced in the source of the 85 -- compiler refers to the storage unit of the host, not the target). This 86 -- means that, like attribute references, any references to constants in 87 -- package System in the compiler code are suspicious, since it is strange 88 -- for the compiler to have such host dependencies. If the compiler needs 89 -- to access the target dependent values of such quantities as Storage_Unit 90 -- then it should reference the constants in this package (Ttypes), rather 91 -- than referencing System.Storage_Unit, or Standard'Storage_Unit, both of 92 -- which would yield the host value. 93 94 --------------------------------------------------- 95 -- Target-Dependent Values for Types in Standard -- 96 --------------------------------------------------- 97 98 -- Note: GNAT always supplies all the following integer and float types, 99 -- but depending on the machine, some of the types may be identical. For 100 -- example, on some machines, Short_Float may be the same as Float, and 101 -- Long_Long_Float may be the same as Long_Float. 102 103 Standard_Short_Short_Integer_Size : constant Pos := 104 Set_Targ.Char_Size; 105 Standard_Short_Short_Integer_Width : constant Pos := 106 Get_Targ.Width_From_Size 107 (Standard_Short_Short_Integer_Size); 108 109 Standard_Short_Integer_Size : constant Pos := 110 Set_Targ.Short_Size; 111 Standard_Short_Integer_Width : constant Pos := 112 Get_Targ.Width_From_Size 113 (Standard_Short_Integer_Size); 114 115 Standard_Integer_Size : constant Pos := 116 Set_Targ.Int_Size; 117 Standard_Integer_Width : constant Pos := 118 Get_Targ.Width_From_Size 119 (Standard_Integer_Size); 120 121 Standard_Long_Integer_Size : constant Pos := 122 Set_Targ.Long_Size; 123 Standard_Long_Integer_Width : constant Pos := 124 Get_Targ.Width_From_Size 125 (Standard_Long_Integer_Size); 126 127 Standard_Long_Long_Integer_Size : constant Pos := 128 Set_Targ.Long_Long_Size; 129 Standard_Long_Long_Integer_Width : constant Pos := 130 Get_Targ.Width_From_Size 131 (Standard_Long_Long_Integer_Size); 132 133 Standard_Short_Float_Size : constant Pos := 134 Set_Targ.Float_Size; 135 Standard_Short_Float_Digits : constant Pos := 136 Get_Targ.Digits_From_Size 137 (Standard_Short_Float_Size); 138 139 Standard_Float_Size : constant Pos := 140 Set_Targ.Float_Size; 141 Standard_Float_Digits : constant Pos := 142 Get_Targ.Digits_From_Size 143 (Standard_Float_Size); 144 145 Standard_Long_Float_Size : constant Pos := 146 Set_Targ.Double_Size; 147 Standard_Long_Float_Digits : constant Pos := 148 Get_Targ.Digits_From_Size 149 (Standard_Long_Float_Size); 150 151 Standard_Long_Long_Float_Size : constant Pos := 152 Set_Targ.Long_Double_Size; 153 Standard_Long_Long_Float_Digits : constant Pos := 154 Get_Targ.Digits_From_Size 155 (Standard_Long_Long_Float_Size); 156 157 Standard_Character_Size : constant Pos := Set_Targ.Char_Size; 158 159 Standard_Wide_Character_Size : constant Pos := 16; 160 Standard_Wide_Wide_Character_Size : constant Pos := 32; 161 -- Standard wide character sizes 162 163 -- Note: there is no specific control over the representation of 164 -- enumeration types. The convention used is that if an enumeration 165 -- type has fewer than 2**(Character'Size) elements, then the size 166 -- used is Character'Size, otherwise Integer'Size is used. 167 168 -- Similarly, the size of fixed-point types depends on the size of the 169 -- corresponding integer type, which is the smallest predefined integer 170 -- type capable of representing the required range of values. 171 172 ------------------------------------------------- 173 -- Target-Dependent Values for Types in System -- 174 ------------------------------------------------- 175 176 System_Address_Size : constant Pos := Set_Targ.Pointer_Size; 177 -- System.Address'Size (also size of all thin pointers) 178 179 System_Max_Binary_Modulus_Power : constant Pos := 180 Standard_Long_Long_Integer_Size; 181 182 System_Max_Nonbinary_Modulus_Power : constant Pos := Standard_Integer_Size; 183 184 System_Storage_Unit : constant Pos := Set_Targ.Bits_Per_Unit; 185 System_Word_Size : constant Pos := Set_Targ.Bits_Per_Word; 186 187 System_Tick_Nanoseconds : constant Pos := 1_000_000_000; 188 -- Value of System.Tick in nanoseconds. At the moment, this is a fixed 189 -- constant (with value of 1.0 seconds), but later we should add this 190 -- value to the GCC configuration file so that its value can be made 191 -- configuration dependent. 192 193 ----------------------------------------------------- 194 -- Target-Dependent Values for Types in Interfaces -- 195 ----------------------------------------------------- 196 197 Interfaces_Wchar_T_Size : constant Pos := Set_Targ.Wchar_T_Size; 198 199 ---------------------------------------- 200 -- Other Target-Dependent Definitions -- 201 ---------------------------------------- 202 203 Maximum_Alignment : constant Pos := Set_Targ.Maximum_Alignment; 204 -- The maximum alignment, in storage units, that an object or type may 205 -- require on the target machine. 206 207 System_Allocator_Alignment : constant Pos := 208 Set_Targ.System_Allocator_Alignment; 209 -- The alignment in storage units of addresses returned by malloc 210 211 Max_Unaligned_Field : constant Pos := Set_Targ.Max_Unaligned_Field; 212 -- The maximum supported size in bits for a field that is not aligned 213 -- on a storage unit boundary. 214 215 Bytes_Big_Endian : Boolean := Set_Targ.Bytes_BE /= 0; 216 -- Important note: for Ada purposes, the important setting is the bytes 217 -- endianness (Bytes_Big_Endian), not the bits value (Bits_Big_Endian). 218 -- This is because Ada bit addressing must be compatible with the byte 219 -- ordering (otherwise we would end up with non-contiguous fields). It 220 -- is rare for the two to be different, but if they are, Bits_Big_Endian 221 -- is relevant only for the generation of instructions with bit numbers, 222 -- and thus relevant only to the back end. Note that this is a variable 223 -- rather than a constant, since it can be modified (flipped) by -gnatd8. 224 225 Target_Short_Enums : constant Boolean := Set_Targ.Short_Enums /= 0; 226 -- True if we are in short enums mode, where foreign convention 227 -- (in particular C and C++) enumeration types will be sized as in Ada, 228 -- using the shortest possibility from 8,16,32 bits, signed or unsigned. 229 -- A zero value means Short_Enums are not in use, and in this case all 230 -- foreign convention enumeration types are given the same size as c int. 231 232 Target_Strict_Alignment : Boolean := 233 Set_Targ.Strict_Alignment /= 0; 234 -- True if instructions will fail if data is misaligned. Note that this 235 -- is a variable rather than a constant since it can be modified (set to 236 -- True) if the debug flag -gnatd.A is used. 237 238 Target_Double_Float_Alignment : constant Nat := 239 Set_Targ.Double_Float_Alignment; 240 -- The default alignment of "double" floating-point types, i.e. floating 241 -- point types whose size is equal to 64 bits, or 0 if this alignment is 242 -- not lower than the largest power of 2 multiple of System.Storage_Unit 243 -- that does not exceed either the object size of the type or the maximum 244 -- allowed alignment. 245 246 Target_Double_Scalar_Alignment : constant Nat := 247 Set_Targ.Double_Scalar_Alignment; 248 -- The default alignment of "double" or larger scalar types, i.e. scalar 249 -- types whose size is greater or equal to 64 bits, or 0 if this alignment 250 -- is not lower than the largest power of 2 multiple of System.Storage_Unit 251 -- that does not exceed either the object size of the type or the maximum 252 -- allowed alignment. 253 254end Ttypes; 255