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-2014, 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.c). 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
39with Einfo; use Einfo;
40with Types; use Types;
41
42package 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_Size             : Pos; -- Standard.Long_Long_Integer'Size
74   Long_Size                  : Pos; -- Standard.Long_Integer'Size
75   Maximum_Alignment          : Pos; -- Maximum permitted alignment
76   Max_Unaligned_Field        : Pos; -- Maximum size for unaligned bit field
77   Pointer_Size               : Pos; -- System.Address'Size
78   Short_Enums                : Nat; -- Foreign enums use short size?
79   Short_Size                 : Pos; -- Standard.Short_Integer'Size
80   Strict_Alignment           : Nat; -- Strict alignment?
81   System_Allocator_Alignment : Nat; -- Alignment for malloc calls
82   Wchar_T_Size               : Pos; -- Interfaces.C.wchar_t'Size
83   Words_BE                   : Nat; -- Words stored big-endian?
84
85   -------------------------------------
86   -- Registered Floating-Point Types --
87   -------------------------------------
88
89   --  This table contains the list of modes supported by the back-end as
90   --  provided by the back end routine enumerate_modes in misc.c. Note that
91   --  we only store floating-point modes (see Register_Float_Type).
92
93   type FPT_Mode_Entry is record
94      NAME      : String_Ptr;     -- Name of mode (no null character at end)
95      DIGS      : Natural;        -- Digits for floating-point type
96      FLOAT_REP : Float_Rep_Kind; -- Float representation
97      PRECISION : Natural;        -- Precision in bits
98      SIZE      : Natural;        -- Size in bits
99      ALIGNMENT : Natural;        -- Alignment in bits
100   end record;
101
102   FPT_Mode_Table : array (1 .. 1000) of FPT_Mode_Entry;
103   Num_FPT_Modes  : Natural := 0;
104   --  Table containing the supported modes and number of entries
105
106   -----------------
107   -- Subprograms --
108   -----------------
109
110   procedure Write_Target_Dependent_Values;
111   --  This routine writes the file target.atp in the current directory with
112   --  the values of the global target parameters as listed above, and as set
113   --  by prior calls to Initialize/Read_Target_Dependent_Values. The format
114   --  of the target.atp file is as follows
115   --
116   --    First come the values of the variables defined in this spec:
117   --
118   --      One line per value
119   --
120   --        name  value
121   --
122   --      where name is the name of the parameter, spelled out in full,
123   --      and cased as in the above list, and value is an unsigned decimal
124   --      integer. Two or more blanks separates the name from the value.
125   --
126   --      All the variables must be present, in alphabetical order (i.e. the
127   --      same order as the declarations in this spec).
128   --
129   --   Then there is a blank line to separate the two parts of the file. Then
130   --   come the lines showing the floating-point types to be registered.
131   --
132   --     One line per registered mode
133   --
134   --       name  digs float_rep precision alignment
135   --
136   --     where name is the string name of the type (which can have single
137   --     spaces embedded in the name (e.g. long double). The name is followed
138   --     by at least two blanks. The following fields are as described above
139   --     for a Mode_Entry (where float_rep is I/V/A for IEEE-754-Binary,
140   --     Vax_Native, AAMP), fields are separated by at least one blank, and
141   --     a LF character immediately follows the alignment field.
142   --
143   --     ??? We do not write the size for backward compatibility reasons,
144   --     which means that target.atp will not be a complete description for
145   --     the very peculiar cases where the size cannot be computed from the
146   --     precision and the alignment by the formula:
147   --
148   --       size := (precision + alignment - 1) / alignment * alignment
149
150end Set_Targ;
151