| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- L A Y O U T -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2000-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 does front-end layout of types and objects. The result is |
| 27 |
-- to annotate the tree with information on size and alignment of types |
| 28 |
-- and objects. How much layout is performed depends on the setting of the |
| 29 |
-- target dependent parameter Frontend_Layout. |
| 30 |
|
| 31 |
with Types; use Types; |
| 32 |
|
| 33 |
package Layout is |
| 34 |
|
| 35 |
-- The following procedures are called from Freeze, so all entities for |
| 36 |
-- types and objects that get frozen (i.e. all types and objects seen by |
| 37 |
-- the back end) will get laid out by one of these two procedures. |
| 38 |
|
| 39 |
procedure Layout_Type (E : Entity_Id); |
| 40 |
-- This procedure may set or adjust the fields Esize, RM_Size and |
| 41 |
-- Alignment in the non-generic type or subtype entity E. If the |
| 42 |
-- Frontend_Layout switch is True, then it is guaranteed that all |
| 43 |
-- three fields will be properly set on return. Regardless of the |
| 44 |
-- Frontend_Layout value, it is guaranteed that all discrete types |
| 45 |
-- will have both Esize and RM_Size fields set on return (since |
| 46 |
-- these are static values). Note that Layout_Type is not called |
| 47 |
-- for generic types, since these play no part in code generation, |
| 48 |
-- and hence representation aspects are irrelevant. |
| 49 |
|
| 50 |
procedure Layout_Object (E : Entity_Id); |
| 51 |
-- E is either a variable (E_Variable), a constant (E_Constant), |
| 52 |
-- a loop parameter (E_Loop_Parameter), or a formal parameter of |
| 53 |
-- a non-generic subprogram (E_In_Parameter, E_In_Out_Parameter, |
| 54 |
-- or E_Out_Parameter). This procedure may set or adjust the |
| 55 |
-- Esize and Alignment fields of E. If Frontend_Layout is True, |
| 56 |
-- then it is guaranteed that both fields will be properly set |
| 57 |
-- on return. If the Esize is still unknown in the latter case, |
| 58 |
-- it means that the object must be allocated dynamically, since |
| 59 |
-- its length is not known at compile time. |
| 60 |
|
| 61 |
-- The following are utility routines, called from various places |
| 62 |
|
| 63 |
procedure Adjust_Esize_Alignment (E : Entity_Id); |
| 64 |
-- E is the entity for a type or object. This procedure checks that the |
| 65 |
-- size and alignment are compatible, and if not either gives an error |
| 66 |
-- message if they cannot be adjusted or else adjusts them appropriately. |
| 67 |
|
| 68 |
procedure Set_Discrete_RM_Size (Def_Id : Entity_Id); |
| 69 |
-- Set proper RM_Size for discrete size, this is normally the minimum |
| 70 |
-- number of bits to accommodate the range given, except in the case |
| 71 |
-- where the subtype statically matches the first subtype, in which |
| 72 |
-- case the size must be copied from the first subtype. For generic |
| 73 |
-- types, the RM_Size is simply set to zero. This routine also sets |
| 74 |
-- the Is_Constrained flag in Def_Id. |
| 75 |
|
| 76 |
procedure Set_Elem_Alignment (E : Entity_Id; Align : Nat := 0); |
| 77 |
-- The front end always sets alignments for elementary types by calling |
| 78 |
-- this procedure. Note that we have to do this for discrete types (since |
| 79 |
-- the Alignment attribute is static), so we might as well do it for all |
| 80 |
-- elementary types, as the processing is the same. If Align is nonzero, |
| 81 |
-- it is an external alignment setting that we must respect. |
| 82 |
|
| 83 |
end Layout; |