annotate gcc/ada/sem_mech.ads @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ M E C H --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
kono
parents:
diff changeset
9 -- Copyright (C) 1996-2014, Free Software Foundation, Inc. --
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package contains the routine used to establish calling mechanisms
kono
parents:
diff changeset
27 -- The reason we separate this off into its own package is that it is
kono
parents:
diff changeset
28 -- entirely possible that it may need some target specific specialization.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 with Types; use Types;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 package Sem_Mech is
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -------------------------------------------------
kono
parents:
diff changeset
35 -- Definitions for Parameter Mechanism Control --
kono
parents:
diff changeset
36 -------------------------------------------------
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -- For parameters passed to subprograms, and for function return values,
kono
parents:
diff changeset
39 -- a passing mechanism is defined. The entity attribute Mechanism returns
kono
parents:
diff changeset
40 -- an indication of the mechanism, and Set_Mechanism can be used to set
kono
parents:
diff changeset
41 -- the mechanism. At the program level, there are three ways to explicitly
kono
parents:
diff changeset
42 -- set the mechanism:
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -- An Import_xxx or Export_xxx pragma (where xxx is Function, Procedure,
kono
parents:
diff changeset
45 -- or Valued_Procedure) can explicitly set the mechanism for either a
kono
parents:
diff changeset
46 -- parameter or a function return value. A mechanism explicitly set by
kono
parents:
diff changeset
47 -- such a pragma overrides the effect of C_Pass_By_Copy described below.
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 -- If convention C_Pass_By_Copy is set for a record, and the record type
kono
parents:
diff changeset
50 -- is used as the formal type of a subprogram with a foreign convention,
kono
parents:
diff changeset
51 -- then the mechanism is set to By_Copy.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 -- If a pragma C_Pass_By_Copy applies, and a record type has Convention
kono
parents:
diff changeset
54 -- C, and the record type is used as the formal type of a subprogram
kono
parents:
diff changeset
55 -- with a foreign convention, then the mechanism is set to use By_Copy
kono
parents:
diff changeset
56 -- if the size of the record is sufficiently small (as determined by
kono
parents:
diff changeset
57 -- the value of the parameter to pragma C_Pass_By_Copy).
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 -- The subtype Mechanism_Type (declared in Types) is used to describe
kono
parents:
diff changeset
60 -- the mechanism to be used. The following special values of this type
kono
parents:
diff changeset
61 -- specify the mechanism, as follows.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 Default_Mechanism : constant Mechanism_Type := 0;
kono
parents:
diff changeset
64 -- The default setting indicates that the backend will choose the proper
kono
parents:
diff changeset
65 -- default mechanism. This depends on the convention of the subprogram
kono
parents:
diff changeset
66 -- involved, and is generally target dependent. In the compiler, the
kono
parents:
diff changeset
67 -- backend chooses the mechanism in this case in accordance with any
kono
parents:
diff changeset
68 -- requirements imposed by the ABI. Note that Default is never used for
kono
parents:
diff changeset
69 -- record types on foreign convention subprograms, since By_Reference
kono
parents:
diff changeset
70 -- is forced for such types unless one of the above described approaches
kono
parents:
diff changeset
71 -- is used to explicitly force By_Copy.
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 By_Copy : constant Mechanism_Type := -1;
kono
parents:
diff changeset
74 -- Passing by copy is forced. The exact meaning of By_Copy (e.g. whether
kono
parents:
diff changeset
75 -- at a low level the value is passed in registers, or the value is copied
kono
parents:
diff changeset
76 -- and a pointer is passed), is determined by the backend in accordance
kono
parents:
diff changeset
77 -- with requirements imposed by the ABI. Note that in the extended import
kono
parents:
diff changeset
78 -- and export pragma mechanisms, this is called Value, rather than Copy.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 By_Reference : constant Mechanism_Type := -2;
kono
parents:
diff changeset
81 -- Passing by reference is forced. This is always equivalent to passing
kono
parents:
diff changeset
82 -- a simple pointer in the case of subprograms with a foreign convention.
kono
parents:
diff changeset
83 -- For unconstrained arrays passed to foreign convention subprograms, the
kono
parents:
diff changeset
84 -- address of the first element of the array is passed. For convention
kono
parents:
diff changeset
85 -- Ada, the result is logically to pass a reference, but the precise
kono
parents:
diff changeset
86 -- mechanism (e.g. to pass bounds of unconstrained types and other needed
kono
parents:
diff changeset
87 -- special information) is determined by the backend in accordance with
kono
parents:
diff changeset
88 -- requirements imposed by the ABI as interpreted for Ada.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 pragma Assert (Mechanism_Type'First = -2);
kono
parents:
diff changeset
91 -- Check definition in types is right!
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 -- All the above special values are non-positive. Positive values for
kono
parents:
diff changeset
94 -- Mechanism_Type values have a special meaning. They are used only in
kono
parents:
diff changeset
95 -- the case of records, as a result of the use of the C_Pass_By_Copy
kono
parents:
diff changeset
96 -- pragma, and the meaning is that if the size of the record is known
kono
parents:
diff changeset
97 -- at compile time and does not exceed the mechanism type value, then
kono
parents:
diff changeset
98 -- By_Copy passing is forced, otherwise By_Reference is forced.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 ----------------------
kono
parents:
diff changeset
101 -- Global Variables --
kono
parents:
diff changeset
102 ----------------------
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 Default_C_Record_Mechanism : Mechanism_Type := By_Reference;
kono
parents:
diff changeset
105 -- This value is the default mechanism used for C convention records
kono
parents:
diff changeset
106 -- in foreign-convention subprograms if no mechanism is otherwise
kono
parents:
diff changeset
107 -- specified. This value is modified appropriately by the occurrence
kono
parents:
diff changeset
108 -- of a C_Pass_By_Copy configuration pragma.
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 -----------------
kono
parents:
diff changeset
111 -- Subprograms --
kono
parents:
diff changeset
112 -----------------
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 procedure Set_Mechanisms (E : Entity_Id);
kono
parents:
diff changeset
115 -- E is a subprogram or subprogram type that has been frozen, so the
kono
parents:
diff changeset
116 -- convention of the subprogram and all its formal types and result
kono
parents:
diff changeset
117 -- type in the case of a function are established. The function of
kono
parents:
diff changeset
118 -- this call is to set mechanism values for formals and for the
kono
parents:
diff changeset
119 -- function return if they have not already been explicitly set by
kono
parents:
diff changeset
120 -- a use of an extended Import or Export pragma. The idea is to set
kono
parents:
diff changeset
121 -- mechanism values wherever the semantics is dictated by either
kono
parents:
diff changeset
122 -- requirements or implementation advice in the RM, and to leave
kono
parents:
diff changeset
123 -- the mechanism set to Default if there is no requirement, so that
kono
parents:
diff changeset
124 -- the back-end is free to choose the most efficient method.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
kono
parents:
diff changeset
127 -- Mech is a parameter passing mechanism (see Import_Function syntax
kono
parents:
diff changeset
128 -- for MECHANISM_NAME). This routine checks that the mechanism argument
kono
parents:
diff changeset
129 -- has the right form, and if not issues an error message. If the
kono
parents:
diff changeset
130 -- argument has the right form then the Mechanism field of Ent is
kono
parents:
diff changeset
131 -- set appropriately. It also performs some error checks. Note that
kono
parents:
diff changeset
132 -- the mechanism name has not been analyzed (and cannot indeed be
kono
parents:
diff changeset
133 -- analyzed, since it is semantic nonsense), so we get it in the
kono
parents:
diff changeset
134 -- exact form created by the parser.
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 procedure Set_Mechanism_With_Checks
kono
parents:
diff changeset
137 (Ent : Entity_Id;
kono
parents:
diff changeset
138 Mech : Mechanism_Type;
kono
parents:
diff changeset
139 Enod : Node_Id);
kono
parents:
diff changeset
140 -- Sets the mechanism of Ent to the given Mech value, after first checking
kono
parents:
diff changeset
141 -- that the request makes sense. If it does not make sense, a warning is
kono
parents:
diff changeset
142 -- posted on node Enod, and the Mechanism of Ent is unchanged.
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 end Sem_Mech;