OSDN Git Service

* doc/install.texi (xtensa-*-elf): New target.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_mech.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ M E C H                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                            $Revision: 1.6 $                              --
10 --                                                                          --
11 --          Copyright (C) 1996-1997 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 --  This package contains the routine used to establish calling mechanisms
30 --  The reason we separate this off into its own package is that it is
31 --  entirely possible that it may need some target specific specialization.
32
33 with Types; use Types;
34
35 package Sem_Mech is
36
37    -------------------------------------------------
38    -- Definitions for Parameter Mechanism Control --
39    -------------------------------------------------
40
41    --  For parameters passed to subprograms, and for function return values,
42    --  as passing mechanism is defined. The entity attribute Mechanism returns
43    --  an indication of the mechanism, and Set_Mechanism can be used to set
44    --  the mechanism. At the program level, there are three ways to explicitly
45    --  set the mechanism:
46
47    --    An Import_xxx or Export_xxx pragma (where xxx is Function, Procedure,
48    --    or Valued_Procedure) can explicitly set the mechanism for either a
49    --    parameter or a function return value. A mechanism explicitly set by
50    --    such a pragma overrides the effect of C_Pass_By_Copy described below.
51
52    --    If convention C_Pass_By_Copy is set for a record, and the record type
53    --    is used as the formal type of a subprogram with a foreign convention,
54    --    then the mechanism is set to By_Copy.
55
56    --    If a pragma C_Pass_By_Copy applies, and a record type has Convention
57    --    C, and the record type is used as the formal type of a subprogram
58    --    with a foreign convention, then the mechanism is set to use By_Copy
59    --    if the size of the record is sufficiently small (as determined by
60    --    the value of the parameter to pragma C_Pass_By_Copy).
61
62    --  The subtype Mechanism_Type (declared in Types) is used to describe
63    --  the mechanism to be used. The following special values of this type
64    --  specify the mechanism, as follows.
65
66    Default_Mechanism : constant Mechanism_Type := 0;
67    --  The default setting indicates that the backend will choose the proper
68    --  default mechanism. This depends on the convention of the subprogram
69    --  involved, and is generally target dependent. In the compiler, the
70    --  backend chooses the mechanism in this case in accordance with any
71    --  requirements imposed by the ABI. Note that Default is never used for
72    --  record types on foreign convention subprograms, since By_Reference
73    --  is forced for such types unless one of the above described approaches
74    --  is used to explicitly force By_Copy.
75
76    By_Copy : constant Mechanism_Type := -1;
77    --  Passing by copy is forced. The exact meaning of By_Copy (e.g. whether
78    --  at a low level the value is passed in registers, or the value is copied
79    --  and a pointer is passed), is determined by the backend in accordance
80    --  with requirements imposed by the ABI. Note that in the extended import
81    --  and export pragma mechanisms, this is called Value, rather than Copy.
82
83    By_Reference : constant Mechanism_Type := -2;
84    --  Passing by reference is forced. This is always equivalent to passing
85    --  a simple pointer in the case of subprograms with a foreign convention.
86    --  For unconstrained arrays passed to foreign convention subprograms, the
87    --  address of the first element of the array is passed. For convention
88    --  Ada, the result is logically to pass a reference, but the precise
89    --  mechanism (e.g. to pass bounds of unconstrained types and other needed
90    --  special information) is determined by the backend in accordance with
91    --  requirements imposed by the ABI as interpreted for Ada.
92
93    By_Descriptor      : constant Mechanism_Type := -3;
94    By_Descriptor_UBS  : constant Mechanism_Type := -4;
95    By_Descriptor_UBSB : constant Mechanism_Type := -5;
96    By_Descriptor_UBA  : constant Mechanism_Type := -6;
97    By_Descriptor_S    : constant Mechanism_Type := -7;
98    By_Descriptor_SB   : constant Mechanism_Type := -8;
99    By_Descriptor_A    : constant Mechanism_Type := -9;
100    By_Descriptor_NCA  : constant Mechanism_Type := -10;
101    --  These values are used only in OpenVMS ports of GNAT. Pass by descriptor
102    --  is forced, as described in the OpenVMS ABI. The suffix indicates the
103    --  descriptor type:
104    --
105    --     UBS    unaligned bit string
106    --     UBSB   aligned bit string with arbitrary bounds
107    --     UBA    unaligned bit array
108    --     S      string, also a scalar or access type parameter
109    --     SB     string with arbitrary bounds
110    --     A      contiguous array
111    --     NCA    non-contiguous array
112    --
113    --  Note: the form with no suffix is used if the Import/Export pragma
114    --  uses the simple form of the mechanism name where no descriptor
115    --  type is supplied. In this case the back end assigns a descriptor
116    --  type based on the Ada type in accordance with the OpenVMS ABI.
117
118    subtype Descriptor_Codes is Mechanism_Type
119      range By_Descriptor_NCA .. By_Descriptor;
120    --  Subtype including all descriptor mechanisms
121
122    --  All the above special values are non-positive. Positive values for
123    --  Mechanism_Type values have a special meaning. They are used only in
124    --  the case of records, as a result of the use of the C_Pass_By_Copy
125    --  pragma, and the meaning is that if the size of the record is known
126    --  at compile time and does not exceed the mechanism type value, then
127    --  By_Copy passing is forced, otherwise By_Reference is forced.
128
129    ----------------------
130    -- Global Variables --
131    ----------------------
132
133    Default_C_Record_Mechanism : Mechanism_Type := By_Reference;
134    --  This value is the default mechanism used for C convention records
135    --  in foreign-convention subprograms if no mechanism is otherwise
136    --  specified. This value is modified appropriately by the occurrence
137    --  of a C_Pass_By_Copy configuration pragma.
138
139    -----------------
140    -- Subprograms --
141    -----------------
142
143    procedure Set_Mechanisms (E : Entity_Id);
144    --  E is a subprogram or subprogram type that has been frozen, so the
145    --  convention of the subprogram and all its formal types and result
146    --  type in the case of a function are established. The function of
147    --  this call is to set mechanism values for formals and for the
148    --  function return if they have not already been explicitly set by
149    --  a use of an extended Import or Export pragma. The idea is to set
150    --  mechanism values whereever the semantics is dictated by either
151    --  requirements or implementation advice in the RM, and to leave
152    --  the mechanism set to Default if there is no requirement, so that
153    --  the back-end is free to choose the most efficient method.
154
155    procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
156    --  Mech is a parameter passing mechanism (see Import_Function syntax
157    --  for MECHANISM_NAME). This routine checks that the mechanism argument
158    --  has the right form, and if not issues an error message. If the
159    --  argument has the right form then the Mechanism field of Ent is
160    --  set appropriately. It also performs some error checks. Note that
161    --  the mechanism name has not been analyzed (and cannot indeed be
162    --  analyzed, since it is semantic nonsense), so we get it in the
163    --  exact form created by the parser.
164
165    procedure Set_Mechanism_With_Checks
166      (Ent  : Entity_Id;
167       Mech : Mechanism_Type;
168       Enod : Node_Id);
169    --  Sets the mechanism of Ent to the given Mech value, after first checking
170    --  that the request makes sense. If it does not make sense, a warning is
171    --  posted on node Enod, and the Mechanism of Ent is unchanged.
172
173 end Sem_Mech;