| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E T _ T A R G -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2013-2025, 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 handles setting target dependent parameters. If the -gnatet |
| 27 |
-- switch is not set, then these values are taken from the back end (via the |
| 28 |
-- routines in Get_Targ, and the enumerate_modes routine in misc.cc). If the |
| 29 |
-- switch is set, then the values are read from the target.atp file in the |
| 30 |
-- current directory (usually written with the Write_Target_Dependent_Values |
| 31 |
-- procedure defined in this package). |
| 32 |
|
| 33 |
-- Note that all these values return sizes of C types with corresponding |
| 34 |
-- names. This allows GNAT to define the corresponding Ada types to have |
| 35 |
-- the same representation. There is one exception: the representation |
| 36 |
-- of Wide_Character_Type uses twice the size of a C char, instead of the |
| 37 |
-- size of wchar_t, since this corresponds to expected Ada usage. |
| 38 |
|
| 39 |
with Stand; use Stand; |
| 40 |
with Types; use Types; |
| 41 |
|
| 42 |
package Set_Targ is |
| 43 |
|
| 44 |
----------------------------- |
| 45 |
-- Target-Dependent Values -- |
| 46 |
----------------------------- |
| 47 |
|
| 48 |
-- The following is a table of target dependent values. In normal operation |
| 49 |
-- these values are set by calling the appropriate C backend routines that |
| 50 |
-- interface to back end routines that determine target characteristics. |
| 51 |
|
| 52 |
-- If the -gnateT switch is used, then any values that are read from the |
| 53 |
-- file target.atp in the current directory overwrite values set from the |
| 54 |
-- back end. This is used by tools other than the compiler, e.g. to do |
| 55 |
-- semantic analysis of programs that will run on some other target than |
| 56 |
-- the machine on which the tool is run. |
| 57 |
|
| 58 |
-- Note: fields marked with a question mark are boolean fields, where a |
| 59 |
-- value of 0 is False, and a value of 1 is True. |
| 60 |
|
| 61 |
Bits_BE : Nat; -- Bits stored big-endian? |
| 62 |
Bits_Per_Unit : Pos; -- Bits in a storage unit |
| 63 |
Bits_Per_Word : Pos; -- Bits in a word |
| 64 |
Bytes_BE : Nat; -- Bytes stored big-endian? |
| 65 |
Char_Size : Pos; -- Standard.Character'Size |
| 66 |
Double_Float_Alignment : Nat; -- Alignment of double float |
| 67 |
Double_Scalar_Alignment : Nat; -- Alignment of double length scalar |
| 68 |
Double_Size : Pos; -- Standard.Long_Float'Size |
| 69 |
Float_Size : Pos; -- Standard.Float'Size |
| 70 |
Float_Words_BE : Nat; -- Float words stored big-endian? |
| 71 |
Int_Size : Pos; -- Standard.Integer'Size |
| 72 |
Long_Double_Size : Pos; -- Standard.Long_Long_Float'Size |
| 73 |
Long_Long_Long_Size : Pos; -- Standard.Long_Long_Long_Integer'Size |
| 74 |
Long_Long_Size : Pos; -- Standard.Long_Long_Integer'Size |
| 75 |
Long_Size : Pos; -- Standard.Long_Integer'Size |
| 76 |
Maximum_Alignment : Pos; -- Maximum permitted alignment |
| 77 |
Max_Unaligned_Field : Pos; -- Kept only for backward compatibility |
| 78 |
Pointer_Size : Pos; -- System.Address'Size |
| 79 |
Short_Enums : Nat; -- Foreign enums use short size? |
| 80 |
Short_Size : Pos; -- Standard.Short_Integer'Size |
| 81 |
Strict_Alignment : Nat; -- Strict alignment? |
| 82 |
System_Allocator_Alignment : Nat; -- Alignment for malloc calls |
| 83 |
Wchar_T_Size : Pos; -- Interfaces.C.wchar_t'Size |
| 84 |
Words_BE : Nat; -- Words stored big-endian? |
| 85 |
|
| 86 |
------------------------------------- |
| 87 |
-- Registered Floating-Point Types -- |
| 88 |
------------------------------------- |
| 89 |
|
| 90 |
-- This table contains the list of modes supported by the back-end as |
| 91 |
-- provided by the back end routine enumerate_modes in misc.cc. Note that |
| 92 |
-- we only store floating-point modes (see Register_Float_Type). |
| 93 |
|
| 94 |
type FPT_Mode_Entry is record |
| 95 |
NAME : String_Ptr; -- Name of mode (no null character at end) |
| 96 |
DIGS : Natural; -- Digits for floating-point type |
| 97 |
FLOAT_REP : Float_Rep_Kind; -- Float representation |
| 98 |
PRECISION : Natural; -- Precision in bits |
| 99 |
SIZE : Natural; -- Size in bits |
| 100 |
ALIGNMENT : Natural; -- Alignment in bits |
| 101 |
end record; |
| 102 |
|
| 103 |
FPT_Mode_Table : array (1 .. 1000) of FPT_Mode_Entry; |
| 104 |
Num_FPT_Modes : Natural := 0; |
| 105 |
-- Table containing the supported modes and number of entries |
| 106 |
|
| 107 |
----------------- |
| 108 |
-- Subprograms -- |
| 109 |
----------------- |
| 110 |
|
| 111 |
subtype S_Float_Types is |
| 112 |
Standard_Entity_Type range S_Short_Float .. S_Long_Long_Float; |
| 113 |
|
| 114 |
function C_Type_For (T : S_Float_Types) return String; |
| 115 |
-- Return the name of a C type supported by the back-end and suitable as |
| 116 |
-- a basis to construct the standard Ada floating point type identified by |
| 117 |
-- T. This is used as a common ground to feed both ttypes values and the |
| 118 |
-- GNAT tree nodes for the standard floating point types. |
| 119 |
|
| 120 |
procedure Write_Target_Dependent_Values; |
| 121 |
-- This routine writes the file target.atp in the current directory with |
| 122 |
-- the values of the global target parameters as listed above, and as set |
| 123 |
-- by prior calls to Initialize/Read_Target_Dependent_Values. The format |
| 124 |
-- of the target.atp file is as follows |
| 125 |
-- |
| 126 |
-- First come the values of the variables defined in this spec: |
| 127 |
-- |
| 128 |
-- One line per value |
| 129 |
-- |
| 130 |
-- name value |
| 131 |
-- |
| 132 |
-- where name is the name of the parameter, spelled out in full, |
| 133 |
-- and cased as in the above list, and value is an unsigned decimal |
| 134 |
-- integer. Two or more blanks separates the name from the value. |
| 135 |
-- |
| 136 |
-- All the variables must be present, in alphabetical order (i.e. the |
| 137 |
-- same order as the declarations in this spec). |
| 138 |
-- |
| 139 |
-- Then there is a blank line to separate the two parts of the file. Then |
| 140 |
-- come the lines showing the floating-point types to be registered. |
| 141 |
-- |
| 142 |
-- One line per registered mode |
| 143 |
-- |
| 144 |
-- name digs float_rep precision alignment |
| 145 |
-- |
| 146 |
-- where name is the string name of the type (which can have |
| 147 |
-- single spaces embedded in the name (e.g. long double). The |
| 148 |
-- name is followed by at least two blanks. The following fields |
| 149 |
-- are as described above for a Mode_Entry (where float_rep is |
| 150 |
-- I for IEEE-754-Binary, which is the only Float_Rep_Kind |
| 151 |
-- currently supported), fields are separated by at least one |
| 152 |
-- blank, and a LF character immediately follows the alignment |
| 153 |
-- field. |
| 154 |
-- |
| 155 |
-- ??? We do not write the size for backward compatibility reasons, |
| 156 |
-- which means that target.atp will not be a complete description for |
| 157 |
-- the very peculiar cases where the size cannot be computed from the |
| 158 |
-- precision and the alignment by the formula: |
| 159 |
-- |
| 160 |
-- size := (precision + alignment - 1) / alignment * alignment |
| 161 |
|
| 162 |
end Set_Targ; |