2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / repinfo.ads
blob39d037a15d9c2c3af3e8a8d7ad99ba6e25539976
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R E P I N F O --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1999-2007, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- This package contains the routines to handle back annotation of the
35 -- tree to fill in representation information, and also the routine used
36 -- by -gnatR to print this information. This unit is used both in the
37 -- compiler and in ASIS (it is used in ASIS as part of the implementation
38 -- of the data decomposition annex).
40 with Types; use Types;
41 with Uintp; use Uintp;
43 package Repinfo is
45 --------------------------------
46 -- Representation Information --
47 --------------------------------
49 -- The representation information of interest here is size and
50 -- component information for arrays and records. For primitive
51 -- types, the front end computes the Esize and RM_Size fields of
52 -- the corresponding entities as constant non-negative integers,
53 -- and the Uint values are stored directly in these fields.
55 -- For composite types, there are three cases:
57 -- 1. In some cases the front end knows the values statically,
58 -- for example in the case where representation clauses or
59 -- pragmas specify the values.
61 -- 2. If Backend_Layout is True, then the backend is responsible
62 -- for layout of all types and objects not laid out by the
63 -- front end. This includes all dynamic values, and also
64 -- static values (e.g. record sizes) when not set by the
65 -- front end.
67 -- 3. If Backend_Layout is False, then the front end lays out
68 -- all data, according to target dependent size and alignment
69 -- information, creating dynamic inlinable functions where
70 -- needed in the case of sizes not known till runtime.
72 -----------------------------
73 -- Back-Annotation by Gigi --
74 -----------------------------
76 -- The following interface is used by gigi if Backend_Layout is True
78 -- As part of the processing in gigi, the types are laid out and
79 -- appropriate values computed for the sizes and component positions
80 -- and sizes of records and arrays.
82 -- The back-annotation circuit in gigi is responsible for updating the
83 -- relevant fields in the tree to reflect these computations, as follows:
85 -- For E_Array_Type entities, the Component_Size field
87 -- For all record and array types and subtypes, the Esize field,
88 -- which contains the Size (more accurately the Object_SIze) value
89 -- for the type or subtype.
91 -- For E_Component and E_Discriminant entities, the Esize (size
92 -- of component) and Component_Bit_Offset fields. Note that gigi
93 -- does not (yet ???) back annotate Normalized_Position/First_Bit.
95 -- There are three cases to consider:
97 -- 1. The value is constant. In this case, the back annotation works
98 -- by simply storing the non-negative universal integer value in
99 -- the appropriate field corresponding to this constant size.
101 -- 2. The value depends on variables other than discriminants of the
102 -- current record. In this case, the value is not known, even if
103 -- the complete data of the record is available, and gigi marks
104 -- this situation by storing the special value No_Uint.
106 -- 3. The value depends on the discriminant values for the current
107 -- record. In this case, gigi back annotates the field with a
108 -- representation of the expression for computing the value in
109 -- terms of the discriminants. A negative Uint value is used to
110 -- represent the value of such an expression, as explained in
111 -- the following section.
113 -- GCC expressions are represented with a Uint value that is negative.
114 -- See the body of this package for details on the representation used.
116 -- One other case in which gigi back annotates GCC expressions is in
117 -- the Present_Expr field of an N_Variant node. This expression which
118 -- will always depend on discriminants, and hence always be represented
119 -- as a negative Uint value, provides an expression which, when evaluated
120 -- with a given set of discriminant values, indicates whether the variant
121 -- is present for that set of values (result is True, i.e. non-zero) or
122 -- not present (result is False, i.e. zero).
124 subtype Node_Ref is Uint;
125 -- Subtype used for negative Uint values used to represent nodes
127 subtype Node_Ref_Or_Val is Uint;
128 -- Subtype used for values that can either be a Node_Ref (negative)
129 -- or a value (non-negative)
131 type TCode is range 0 .. 28;
132 -- Type used on Ada side to represent DEFTREECODE values defined in
133 -- tree.def. Only a subset of these tree codes can actually appear.
134 -- The names are the names from tree.def in Ada casing.
136 -- name code description operands
138 Cond_Expr : constant TCode := 1; -- conditional 3
139 Plus_Expr : constant TCode := 2; -- addition 2
140 Minus_Expr : constant TCode := 3; -- subtraction 2
141 Mult_Expr : constant TCode := 4; -- multiplication 2
142 Trunc_Div_Expr : constant TCode := 5; -- truncating division 2
143 Ceil_Div_Expr : constant TCode := 6; -- division rounding up 2
144 Floor_Div_Expr : constant TCode := 7; -- division rounding down 2
145 Trunc_Mod_Expr : constant TCode := 8; -- mod for trunc_div 2
146 Ceil_Mod_Expr : constant TCode := 9; -- mod for ceil_div 2
147 Floor_Mod_Expr : constant TCode := 10; -- mod for floor_div 2
148 Exact_Div_Expr : constant TCode := 11; -- exact div 2
149 Negate_Expr : constant TCode := 12; -- negation 1
150 Min_Expr : constant TCode := 13; -- minimum 2
151 Max_Expr : constant TCode := 14; -- maximum 2
152 Abs_Expr : constant TCode := 15; -- absolute value 1
153 Truth_Andif_Expr : constant TCode := 16; -- Boolean and then 2
154 Truth_Orif_Expr : constant TCode := 17; -- Boolean or else 2
155 Truth_And_Expr : constant TCode := 18; -- Boolean and 2
156 Truth_Or_Expr : constant TCode := 19; -- Boolean or 2
157 Truth_Xor_Expr : constant TCode := 20; -- Boolean xor 2
158 Truth_Not_Expr : constant TCode := 21; -- Boolean not 1
159 Lt_Expr : constant TCode := 22; -- comparison < 2
160 Le_Expr : constant TCode := 23; -- comparison <= 2
161 Gt_Expr : constant TCode := 24; -- comparison > 2
162 Ge_Expr : constant TCode := 25; -- comparison >= 2
163 Eq_Expr : constant TCode := 26; -- comparison = 2
164 Ne_Expr : constant TCode := 27; -- comparison /= 2
165 Bit_And_Expr : constant TCode := 28; -- Binary and 2
167 -- The following entry is used to represent a discriminant value in
168 -- the tree. It has a special tree code that does not correspond
169 -- directly to a gcc node. The single operand is the number of the
170 -- discriminant in the record (1 = first discriminant).
172 Discrim_Val : constant TCode := 0; -- discriminant value 1
174 ------------------------
175 -- The gigi Interface --
176 ------------------------
178 -- The following declarations are for use by gigi for back annotation
180 function Create_Node
181 (Expr : TCode;
182 Op1 : Node_Ref_Or_Val;
183 Op2 : Node_Ref_Or_Val := No_Uint;
184 Op3 : Node_Ref_Or_Val := No_Uint) return Node_Ref;
185 -- Creates a node using the tree code defined by Expr and from one to three
186 -- operands as required (unused operands set as shown to No_Uint) Note that
187 -- this call can be used to create a discriminant reference by using (Expr
188 -- => Discrim_Val, Op1 => discriminant_number).
190 function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref;
191 -- Creates a reference to the discriminant whose entity is Discr
193 --------------------------------------------------------
194 -- Front-End Interface for Dynamic Size/Offset Values --
195 --------------------------------------------------------
197 -- If Backend_Layout is False, then the front-end deals with all
198 -- dynamic size and offset fields. There are two cases:
200 -- 1. The value can be computed at the time of type freezing, and
201 -- is stored in a run-time constant. In this case, the field
202 -- contains a reference to this entity. In the case of sizes
203 -- the value stored is the size in storage units, since dynamic
204 -- sizes are always a multiple of storage units.
206 -- 2. The size/offset depends on the value of discriminants at
207 -- run-time. In this case, the front end builds a function to
208 -- compute the value. This function has a single parameter
209 -- which is the discriminated record object in question. Any
210 -- references to discriminant values are simply references to
211 -- the appropriate discriminant in this single argument, and
212 -- to compute the required size/offset value at run time, the
213 -- code generator simply constructs a call to the function
214 -- with the appropriate argument. The size/offset field in
215 -- this case contains a reference to the function entity.
216 -- Note that as for case 1, if such a function is used to
217 -- return a size, then the size in storage units is returned,
218 -- not the size in bits.
220 -- The interface here allows these created entities to be referenced
221 -- using negative Unit values, so that they can be stored in the
222 -- appropriate size and offset fields in the tree.
224 -- In the case of components, if the location of the component is static,
225 -- then all four fields (Component_Bit_Offset, Normalized_Position, Esize,
226 -- and Normalized_First_Bit) are set to appropriate values. In the case of
227 -- a non-static component location, Component_Bit_Offset is not used and
228 -- is left set to Unknown. Normalized_Position and Normalized_First_Bit
229 -- are set appropriately.
231 subtype SO_Ref is Uint;
232 -- Type used to represent a Uint value that represents a static or
233 -- dynamic size/offset value (non-negative if static, negative if
234 -- the size value is dynamic).
236 subtype Dynamic_SO_Ref is Uint;
237 -- Type used to represent a negative Uint value used to store
238 -- a dynamic size/offset value.
240 function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean;
241 pragma Inline (Is_Dynamic_SO_Ref);
242 -- Given a SO_Ref (Uint) value, returns True iff the SO_Ref value
243 -- represents a dynamic Size/Offset value (i.e. it is negative).
245 function Is_Static_SO_Ref (U : SO_Ref) return Boolean;
246 pragma Inline (Is_Static_SO_Ref);
247 -- Given a SO_Ref (Uint) value, returns True iff the SO_Ref value
248 -- represents a static Size/Offset value (i.e. it is non-negative).
250 function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref;
251 -- Given the Entity_Id for a constant (case 1), the Node_Id for an
252 -- expression (case 2), or the Entity_Id for a function (case 3),
253 -- this function returns a (negative) Uint value that can be used
254 -- to retrieve the entity or expression for later use.
256 function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id;
257 -- Retrieve the Node_Id or Entity_Id stored by a previous call to
258 -- Create_Dynamic_SO_Ref. The approach is that the front end makes
259 -- the necessary Create_Dynamic_SO_Ref calls to associate the node
260 -- and entity id values and the back end makes Get_Dynamic_SO_Ref
261 -- calls to retrieve them.
263 --------------------
264 -- ASIS_Interface --
265 --------------------
267 type Discrim_List is array (Pos range <>) of Uint;
268 -- Type used to represent list of discriminant values
270 function Rep_Value
271 (Val : Node_Ref_Or_Val;
272 D : Discrim_List) return Uint;
273 -- Given the contents of a First_Bit_Position or Esize field containing
274 -- a node reference (i.e. a negative Uint value) and D, the list of
275 -- discriminant values, returns the interpreted value of this field.
276 -- For convenience, Rep_Value will take a non-negative Uint value
277 -- as an argument value, and return it unmodified. A No_Uint value is
278 -- also returned unmodified.
280 procedure Tree_Read;
281 -- Initializes internal tables from current tree file using the relevant
282 -- Table.Tree_Read routines.
284 ------------------------
285 -- Compiler Interface --
286 ------------------------
288 procedure List_Rep_Info;
289 -- Procedure to list representation information
291 procedure Tree_Write;
292 -- Writes out internal tables to current tree file using the relevant
293 -- Table.Tree_Write routines.
295 --------------------------
296 -- Debugging Procedures --
297 --------------------------
299 procedure List_GCC_Expression (U : Node_Ref_Or_Val);
300 -- Prints out given expression in symbolic form. Constants are listed
301 -- in decimal numeric form, Discriminants are listed with a # followed
302 -- by the discriminant number, and operators are output in appropriate
303 -- symbolic form No_Uint displays as two question marks. The output is
304 -- on a single line but has no line return after it. This procedure is
305 -- useful only if operating in backend layout mode.
307 procedure lgx (U : Node_Ref_Or_Val);
308 -- In backend layout mode, this is like List_GCC_Expression, but
309 -- includes a line return at the end. If operating in front end
310 -- layout mode, then the name of the entity for the size (either
311 -- a function of a variable) is listed followed by a line return.
313 end Repinfo;