| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- E X P _ P A K D -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-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 |
-- Expand routines for manipulation of packed arrays |
| 27 |
|
| 28 |
with Rtsfind; use Rtsfind; |
| 29 |
with Types; use Types; |
| 30 |
|
| 31 |
package Exp_Pakd is |
| 32 |
|
| 33 |
------------------------------------- |
| 34 |
-- Implementation of Packed Arrays -- |
| 35 |
------------------------------------- |
| 36 |
|
| 37 |
-- When a packed array (sub)type is frozen, we create a corresponding |
| 38 |
-- type that will be used to hold the bits of the packed value, and store |
| 39 |
-- the entity for this type in the Packed_Array_Impl_Type field of the |
| 40 |
-- E_Array_Type or E_Array_Subtype entity for the packed array. |
| 41 |
|
| 42 |
-- This packed array type has the name xxxPn, where xxx is the name |
| 43 |
-- of the packed type, and n is the component size. The expanded |
| 44 |
-- declaration declares a type that is one of the following (sizes |
| 45 |
-- below are in bytes): |
| 46 |
|
| 47 |
-- For an unconstrained array with component size 1,2,4 or any other |
| 48 |
-- odd component size. These are the cases in which we do not need |
| 49 |
-- to align the underlying array. |
| 50 |
|
| 51 |
-- type xxxPn is new Packed_Bytes1; |
| 52 |
|
| 53 |
-- For an unconstrained array with component size greater than 2, that is |
| 54 |
-- divisible by 2, but not divisible by 4. These are the cases in which |
| 55 |
-- we can generate better code if the underlying array is 2-byte aligned |
| 56 |
-- (see System.Pack_14 in file s-pack14 for example). |
| 57 |
|
| 58 |
-- type xxxPn is new Packed_Bytes2; |
| 59 |
|
| 60 |
-- For an unconstrained array with component size that is divisible |
| 61 |
-- by 4, other than powers of 2 (which either come under the 1,2,4 |
| 62 |
-- exception above, or are not packed at all). These are cases where |
| 63 |
-- we can generate better code if the underlying array is 4-byte |
| 64 |
-- aligned (see System.Pack_20 in file s-pack20 for example). |
| 65 |
|
| 66 |
-- type xxxPn is new Packed_Bytes4; |
| 67 |
|
| 68 |
-- For a constrained array with a static index type where the number |
| 69 |
-- of bits does not exceed the size of Unsigned: |
| 70 |
|
| 71 |
-- type xxxPn is new Unsigned range 0 .. 2 ** nbits - 1; |
| 72 |
|
| 73 |
-- For a constrained array with a static index type where the number |
| 74 |
-- of bits is greater than the size of Unsigned, but does not exceed |
| 75 |
-- the size of Long_Long_Unsigned: |
| 76 |
|
| 77 |
-- type xxxPn is new Long_Long_Unsigned range 0 .. 2 ** nbits - 1; |
| 78 |
|
| 79 |
-- For all other constrained arrays, we use one of |
| 80 |
|
| 81 |
-- type xxxPn is new Packed_Bytes1 (0 .. m); |
| 82 |
-- type xxxPn is new Packed_Bytes2 (0 .. m); |
| 83 |
-- type xxxPn is new Packed_Bytes4 (0 .. m); |
| 84 |
|
| 85 |
-- where m is calculated (from the length of the original packed array) |
| 86 |
-- to hold the required number of bits, and the choice of the particular |
| 87 |
-- Packed_Bytes{1,2,4} type is made on the basis of alignment needs as |
| 88 |
-- described above for the unconstrained case. |
| 89 |
|
| 90 |
-- When the packed array (sub)type is specified to have the reverse scalar |
| 91 |
-- storage order, the Packed_Bytes{1,2,4} references above are replaced |
| 92 |
-- with Rev_Packed_Bytes{1,2,4}. This is necessary because, although the |
| 93 |
-- component type is Packed_Byte and therefore endian neutral, the scalar |
| 94 |
-- storage order of the new type must be compatible with that of an outer |
| 95 |
-- composite type, if this composite type contains a component whose type |
| 96 |
-- is the packed array (sub)type and which does not start or does not end |
| 97 |
-- on a storage unit boundary. |
| 98 |
|
| 99 |
-- When a variable of packed array type is allocated, gigi will allocate |
| 100 |
-- the amount of space indicated by the corresponding packed array type. |
| 101 |
-- However, we do NOT attempt to rewrite the types of any references or |
| 102 |
-- to retype the variable itself, since this would cause all kinds of |
| 103 |
-- semantic problems in the front end (remember that expansion proceeds |
| 104 |
-- at the same time as analysis). |
| 105 |
|
| 106 |
-- For an indexed reference to a packed array, we simply convert the |
| 107 |
-- reference to the appropriate equivalent reference to the object |
| 108 |
-- of the packed array type (using unchecked conversion). |
| 109 |
|
| 110 |
-- In some cases (for internally generated types, and for the subtypes |
| 111 |
-- for record fields that depend on a discriminant), the corresponding |
| 112 |
-- packed type cannot be easily generated in advance. In these cases, |
| 113 |
-- we generate the required subtype on the fly at the reference point. |
| 114 |
|
| 115 |
-- For the modular case, any unused bits are initialized to zero, and |
| 116 |
-- all operations maintain these bits as zero (where necessary all |
| 117 |
-- unchecked conversions from corresponding array values require |
| 118 |
-- these bits to be clear, which is done automatically by gigi). |
| 119 |
|
| 120 |
-- For the array cases, there can be unused bits in the last byte, and |
| 121 |
-- these are neither initialized, nor treated specially in operations |
| 122 |
-- (i.e. it is allowable for these bits to be clobbered, e.g. by not). |
| 123 |
|
| 124 |
--------------------------- |
| 125 |
-- Endian Considerations -- |
| 126 |
--------------------------- |
| 127 |
|
| 128 |
-- The standard does not specify the way in which bits are numbered in |
| 129 |
-- a packed array. There are two reasonable rules for deciding this: |
| 130 |
|
| 131 |
-- Store the first bit at right end (low order) word. This means |
| 132 |
-- that the scaled subscript can be used directly as a left shift |
| 133 |
-- count (if we put bit 0 at the left end, then we need an extra |
| 134 |
-- subtract to compute the shift count). |
| 135 |
|
| 136 |
-- Layout the bits so that if the packed boolean array is overlaid on |
| 137 |
-- a record, using unchecked conversion, then bit 0 of the array is |
| 138 |
-- the same as the bit numbered bit 0 in a record representation |
| 139 |
-- clause applying to the record. For example: |
| 140 |
|
| 141 |
-- type Rec is record |
| 142 |
-- C : Bits4; |
| 143 |
-- D : Bits7; |
| 144 |
-- E : Bits5; |
| 145 |
-- end record; |
| 146 |
|
| 147 |
-- for Rec use record |
| 148 |
-- C at 0 range 0 .. 3; |
| 149 |
-- D at 0 range 4 .. 10; |
| 150 |
-- E at 0 range 11 .. 15; |
| 151 |
-- end record; |
| 152 |
|
| 153 |
-- type P16 is array (0 .. 15) of Boolean; |
| 154 |
-- pragma Pack (P16); |
| 155 |
|
| 156 |
-- Now if we use unchecked conversion to convert a value of the record |
| 157 |
-- type to the packed array type, according to this second criterion, |
| 158 |
-- we would expect field D to occupy bits 4..10 of the Boolean array. |
| 159 |
|
| 160 |
-- Although not required, this correspondence seems a highly desirable |
| 161 |
-- property, and is one that GNAT decides to guarantee. For a little |
| 162 |
-- endian machine, we can also meet the first requirement, but for a |
| 163 |
-- big endian machine, it will be necessary to store the first bit of |
| 164 |
-- a Boolean array in the left end (most significant) bit of the word. |
| 165 |
-- This may cost an extra instruction on some machines, but we consider |
| 166 |
-- that a worthwhile price to pay for the consistency. |
| 167 |
|
| 168 |
-- One more important point arises in the case where we have a constrained |
| 169 |
-- subtype of an unconstrained array. Take the case of 20 bits. For the |
| 170 |
-- unconstrained representation, we would use an array of bytes: |
| 171 |
|
| 172 |
-- Little-endian case |
| 173 |
-- 8-7-6-5-4-3-2-1 16-15-14-13-12-11-10-9 x-x-x-x-20-19-18-17 |
| 174 |
|
| 175 |
-- Big-endian case |
| 176 |
-- 1-2-3-4-5-6-7-8 9-10-11-12-13-14-15-16 17-18-19-20-x-x-x-x |
| 177 |
|
| 178 |
-- For the constrained case, we use a 20-bit modular value, but in |
| 179 |
-- general this value may well be stored in 32 bits. Let's look at |
| 180 |
-- what it looks like: |
| 181 |
|
| 182 |
-- Little-endian case |
| 183 |
|
| 184 |
-- x-x-x-x-x-x-x-x-x-x-x-x-20-19-18-17-...-10-9-8-7-6-5-4-3-2-1 |
| 185 |
|
| 186 |
-- which stored in memory looks like |
| 187 |
|
| 188 |
-- 8-7-...-2-1 16-15-...-10-9 x-x-x-x-20-19-18-17 x-x-x-x-x-x-x |
| 189 |
|
| 190 |
-- An important rule is that the constrained and unconstrained cases |
| 191 |
-- must have the same bit representation in memory, since we will often |
| 192 |
-- convert from one to the other (e.g. when calling a procedure whose |
| 193 |
-- formal is unconstrained). As we see, that criterion is met for the |
| 194 |
-- little-endian case above. Now let's look at the big-endian case: |
| 195 |
|
| 196 |
-- Big-endian case |
| 197 |
|
| 198 |
-- x-x-x-x-x-x-x-x-x-x-x-x-1-2-3-4-5-6-7-8-9-10-...-17-18-19-20 |
| 199 |
|
| 200 |
-- which stored in memory looks like |
| 201 |
|
| 202 |
-- x-x-x-x-x-x-x-x x-x-x-x-1-2-3-4 5-6-...11-12 13-14-...-19-20 |
| 203 |
|
| 204 |
-- That won't do, the representation value in memory is NOT the same in |
| 205 |
-- the constrained and unconstrained case. The solution is to store the |
| 206 |
-- modular value left-justified: |
| 207 |
|
| 208 |
-- 1-2-3-4-5-6-7-8-9-10-...-17-18-19-20-x-x-x-x-x-x-x-x-x-x-x |
| 209 |
|
| 210 |
-- which stored in memory looks like |
| 211 |
|
| 212 |
-- 1-2-...-7-8 9-10-...15-16 17-18-19-20-x-x-x-x x-x-x-x-x-x-x-x |
| 213 |
|
| 214 |
-- and now, we do indeed have the same representation for the memory |
| 215 |
-- version in the constrained and unconstrained cases. |
| 216 |
|
| 217 |
---------------------------------------------- |
| 218 |
-- Entity Tables for Packed Access Routines -- |
| 219 |
---------------------------------------------- |
| 220 |
|
| 221 |
-- For the cases of component size = 3,5-7,9-15,17-31,33-63,65-127 we call |
| 222 |
-- library routines. These tables provide the entity for the right routine. |
| 223 |
-- They are exposed in the spec to allow checking for the presence of the |
| 224 |
-- needed routine when an array is subject to pragma Pack. |
| 225 |
|
| 226 |
type E_Array is array (Int range 1 .. 127) of RE_Id; |
| 227 |
|
| 228 |
-- Array of Bits_nn entities. Note that we do not use library routines |
| 229 |
-- for the 8-bit and 16-bit cases, but we still fill in the table, using |
| 230 |
-- entries from System.Unsigned, because we also use this table for |
| 231 |
-- certain special unchecked conversions in the big-endian case. |
| 232 |
|
| 233 |
Bits_Id : constant E_Array := |
| 234 |
(01 => RE_Bits_1, |
| 235 |
02 => RE_Bits_2, |
| 236 |
03 => RE_Bits_03, |
| 237 |
04 => RE_Bits_4, |
| 238 |
05 => RE_Bits_05, |
| 239 |
06 => RE_Bits_06, |
| 240 |
07 => RE_Bits_07, |
| 241 |
08 => RE_Unsigned_8, |
| 242 |
09 => RE_Bits_09, |
| 243 |
10 => RE_Bits_10, |
| 244 |
11 => RE_Bits_11, |
| 245 |
12 => RE_Bits_12, |
| 246 |
13 => RE_Bits_13, |
| 247 |
14 => RE_Bits_14, |
| 248 |
15 => RE_Bits_15, |
| 249 |
16 => RE_Unsigned_16, |
| 250 |
17 => RE_Bits_17, |
| 251 |
18 => RE_Bits_18, |
| 252 |
19 => RE_Bits_19, |
| 253 |
20 => RE_Bits_20, |
| 254 |
21 => RE_Bits_21, |
| 255 |
22 => RE_Bits_22, |
| 256 |
23 => RE_Bits_23, |
| 257 |
24 => RE_Bits_24, |
| 258 |
25 => RE_Bits_25, |
| 259 |
26 => RE_Bits_26, |
| 260 |
27 => RE_Bits_27, |
| 261 |
28 => RE_Bits_28, |
| 262 |
29 => RE_Bits_29, |
| 263 |
30 => RE_Bits_30, |
| 264 |
31 => RE_Bits_31, |
| 265 |
32 => RE_Unsigned_32, |
| 266 |
33 => RE_Bits_33, |
| 267 |
34 => RE_Bits_34, |
| 268 |
35 => RE_Bits_35, |
| 269 |
36 => RE_Bits_36, |
| 270 |
37 => RE_Bits_37, |
| 271 |
38 => RE_Bits_38, |
| 272 |
39 => RE_Bits_39, |
| 273 |
40 => RE_Bits_40, |
| 274 |
41 => RE_Bits_41, |
| 275 |
42 => RE_Bits_42, |
| 276 |
43 => RE_Bits_43, |
| 277 |
44 => RE_Bits_44, |
| 278 |
45 => RE_Bits_45, |
| 279 |
46 => RE_Bits_46, |
| 280 |
47 => RE_Bits_47, |
| 281 |
48 => RE_Bits_48, |
| 282 |
49 => RE_Bits_49, |
| 283 |
50 => RE_Bits_50, |
| 284 |
51 => RE_Bits_51, |
| 285 |
52 => RE_Bits_52, |
| 286 |
53 => RE_Bits_53, |
| 287 |
54 => RE_Bits_54, |
| 288 |
55 => RE_Bits_55, |
| 289 |
56 => RE_Bits_56, |
| 290 |
57 => RE_Bits_57, |
| 291 |
58 => RE_Bits_58, |
| 292 |
59 => RE_Bits_59, |
| 293 |
60 => RE_Bits_60, |
| 294 |
61 => RE_Bits_61, |
| 295 |
62 => RE_Bits_62, |
| 296 |
63 => RE_Bits_63, |
| 297 |
64 => RE_Unsigned_64, |
| 298 |
65 => RE_Bits_65, |
| 299 |
66 => RE_Bits_66, |
| 300 |
67 => RE_Bits_67, |
| 301 |
68 => RE_Bits_68, |
| 302 |
69 => RE_Bits_69, |
| 303 |
70 => RE_Bits_70, |
| 304 |
71 => RE_Bits_71, |
| 305 |
72 => RE_Bits_72, |
| 306 |
73 => RE_Bits_73, |
| 307 |
74 => RE_Bits_74, |
| 308 |
75 => RE_Bits_75, |
| 309 |
76 => RE_Bits_76, |
| 310 |
77 => RE_Bits_77, |
| 311 |
78 => RE_Bits_78, |
| 312 |
79 => RE_Bits_79, |
| 313 |
80 => RE_Bits_80, |
| 314 |
81 => RE_Bits_81, |
| 315 |
82 => RE_Bits_82, |
| 316 |
83 => RE_Bits_83, |
| 317 |
84 => RE_Bits_84, |
| 318 |
85 => RE_Bits_85, |
| 319 |
86 => RE_Bits_86, |
| 320 |
87 => RE_Bits_87, |
| 321 |
88 => RE_Bits_88, |
| 322 |
89 => RE_Bits_89, |
| 323 |
90 => RE_Bits_90, |
| 324 |
91 => RE_Bits_91, |
| 325 |
92 => RE_Bits_92, |
| 326 |
93 => RE_Bits_93, |
| 327 |
94 => RE_Bits_94, |
| 328 |
95 => RE_Bits_95, |
| 329 |
96 => RE_Bits_96, |
| 330 |
97 => RE_Bits_97, |
| 331 |
98 => RE_Bits_98, |
| 332 |
99 => RE_Bits_99, |
| 333 |
100 => RE_Bits_100, |
| 334 |
101 => RE_Bits_101, |
| 335 |
102 => RE_Bits_102, |
| 336 |
103 => RE_Bits_103, |
| 337 |
104 => RE_Bits_104, |
| 338 |
105 => RE_Bits_105, |
| 339 |
106 => RE_Bits_106, |
| 340 |
107 => RE_Bits_107, |
| 341 |
108 => RE_Bits_108, |
| 342 |
109 => RE_Bits_109, |
| 343 |
110 => RE_Bits_110, |
| 344 |
111 => RE_Bits_111, |
| 345 |
112 => RE_Bits_112, |
| 346 |
113 => RE_Bits_113, |
| 347 |
114 => RE_Bits_114, |
| 348 |
115 => RE_Bits_115, |
| 349 |
116 => RE_Bits_116, |
| 350 |
117 => RE_Bits_117, |
| 351 |
118 => RE_Bits_118, |
| 352 |
119 => RE_Bits_119, |
| 353 |
120 => RE_Bits_120, |
| 354 |
121 => RE_Bits_121, |
| 355 |
122 => RE_Bits_122, |
| 356 |
123 => RE_Bits_123, |
| 357 |
124 => RE_Bits_124, |
| 358 |
125 => RE_Bits_125, |
| 359 |
126 => RE_Bits_126, |
| 360 |
127 => RE_Bits_127); |
| 361 |
|
| 362 |
-- Array of Get routine entities. These are used to obtain an element from |
| 363 |
-- a packed array. The N'th entry is used to obtain elements from a packed |
| 364 |
-- array whose component size is N. RE_Null is used as a null entry, for |
| 365 |
-- the cases where a library routine is not used. |
| 366 |
|
| 367 |
Get_Id : constant E_Array := |
| 368 |
(01 => RE_Null, |
| 369 |
02 => RE_Null, |
| 370 |
03 => RE_Get_03, |
| 371 |
04 => RE_Null, |
| 372 |
05 => RE_Get_05, |
| 373 |
06 => RE_Get_06, |
| 374 |
07 => RE_Get_07, |
| 375 |
08 => RE_Null, |
| 376 |
09 => RE_Get_09, |
| 377 |
10 => RE_Get_10, |
| 378 |
11 => RE_Get_11, |
| 379 |
12 => RE_Get_12, |
| 380 |
13 => RE_Get_13, |
| 381 |
14 => RE_Get_14, |
| 382 |
15 => RE_Get_15, |
| 383 |
16 => RE_Null, |
| 384 |
17 => RE_Get_17, |
| 385 |
18 => RE_Get_18, |
| 386 |
19 => RE_Get_19, |
| 387 |
20 => RE_Get_20, |
| 388 |
21 => RE_Get_21, |
| 389 |
22 => RE_Get_22, |
| 390 |
23 => RE_Get_23, |
| 391 |
24 => RE_Get_24, |
| 392 |
25 => RE_Get_25, |
| 393 |
26 => RE_Get_26, |
| 394 |
27 => RE_Get_27, |
| 395 |
28 => RE_Get_28, |
| 396 |
29 => RE_Get_29, |
| 397 |
30 => RE_Get_30, |
| 398 |
31 => RE_Get_31, |
| 399 |
32 => RE_Null, |
| 400 |
33 => RE_Get_33, |
| 401 |
34 => RE_Get_34, |
| 402 |
35 => RE_Get_35, |
| 403 |
36 => RE_Get_36, |
| 404 |
37 => RE_Get_37, |
| 405 |
38 => RE_Get_38, |
| 406 |
39 => RE_Get_39, |
| 407 |
40 => RE_Get_40, |
| 408 |
41 => RE_Get_41, |
| 409 |
42 => RE_Get_42, |
| 410 |
43 => RE_Get_43, |
| 411 |
44 => RE_Get_44, |
| 412 |
45 => RE_Get_45, |
| 413 |
46 => RE_Get_46, |
| 414 |
47 => RE_Get_47, |
| 415 |
48 => RE_Get_48, |
| 416 |
49 => RE_Get_49, |
| 417 |
50 => RE_Get_50, |
| 418 |
51 => RE_Get_51, |
| 419 |
52 => RE_Get_52, |
| 420 |
53 => RE_Get_53, |
| 421 |
54 => RE_Get_54, |
| 422 |
55 => RE_Get_55, |
| 423 |
56 => RE_Get_56, |
| 424 |
57 => RE_Get_57, |
| 425 |
58 => RE_Get_58, |
| 426 |
59 => RE_Get_59, |
| 427 |
60 => RE_Get_60, |
| 428 |
61 => RE_Get_61, |
| 429 |
62 => RE_Get_62, |
| 430 |
63 => RE_Get_63, |
| 431 |
64 => RE_Null, |
| 432 |
65 => RE_Get_65, |
| 433 |
66 => RE_Get_66, |
| 434 |
67 => RE_Get_67, |
| 435 |
68 => RE_Get_68, |
| 436 |
69 => RE_Get_69, |
| 437 |
70 => RE_Get_70, |
| 438 |
71 => RE_Get_71, |
| 439 |
72 => RE_Get_72, |
| 440 |
73 => RE_Get_73, |
| 441 |
74 => RE_Get_74, |
| 442 |
75 => RE_Get_75, |
| 443 |
76 => RE_Get_76, |
| 444 |
77 => RE_Get_77, |
| 445 |
78 => RE_Get_78, |
| 446 |
79 => RE_Get_79, |
| 447 |
80 => RE_Get_80, |
| 448 |
81 => RE_Get_81, |
| 449 |
82 => RE_Get_82, |
| 450 |
83 => RE_Get_83, |
| 451 |
84 => RE_Get_84, |
| 452 |
85 => RE_Get_85, |
| 453 |
86 => RE_Get_86, |
| 454 |
87 => RE_Get_87, |
| 455 |
88 => RE_Get_88, |
| 456 |
89 => RE_Get_89, |
| 457 |
90 => RE_Get_90, |
| 458 |
91 => RE_Get_91, |
| 459 |
92 => RE_Get_92, |
| 460 |
93 => RE_Get_93, |
| 461 |
94 => RE_Get_94, |
| 462 |
95 => RE_Get_95, |
| 463 |
96 => RE_Get_96, |
| 464 |
97 => RE_Get_97, |
| 465 |
98 => RE_Get_98, |
| 466 |
99 => RE_Get_99, |
| 467 |
100 => RE_Get_100, |
| 468 |
101 => RE_Get_101, |
| 469 |
102 => RE_Get_102, |
| 470 |
103 => RE_Get_103, |
| 471 |
104 => RE_Get_104, |
| 472 |
105 => RE_Get_105, |
| 473 |
106 => RE_Get_106, |
| 474 |
107 => RE_Get_107, |
| 475 |
108 => RE_Get_108, |
| 476 |
109 => RE_Get_109, |
| 477 |
110 => RE_Get_110, |
| 478 |
111 => RE_Get_111, |
| 479 |
112 => RE_Get_112, |
| 480 |
113 => RE_Get_113, |
| 481 |
114 => RE_Get_114, |
| 482 |
115 => RE_Get_115, |
| 483 |
116 => RE_Get_116, |
| 484 |
117 => RE_Get_117, |
| 485 |
118 => RE_Get_118, |
| 486 |
119 => RE_Get_119, |
| 487 |
120 => RE_Get_120, |
| 488 |
121 => RE_Get_121, |
| 489 |
122 => RE_Get_122, |
| 490 |
123 => RE_Get_123, |
| 491 |
124 => RE_Get_124, |
| 492 |
125 => RE_Get_125, |
| 493 |
126 => RE_Get_126, |
| 494 |
127 => RE_Get_127); |
| 495 |
|
| 496 |
-- Array of Get routine entities to be used in the case where the packed |
| 497 |
-- array is itself a component of a packed structure, and therefore may not |
| 498 |
-- be fully aligned. This only affects the even sizes, since for the odd |
| 499 |
-- sizes, we do not get any fixed alignment in any case. |
| 500 |
|
| 501 |
GetU_Id : constant E_Array := |
| 502 |
(01 => RE_Null, |
| 503 |
02 => RE_Null, |
| 504 |
03 => RE_Get_03, |
| 505 |
04 => RE_Null, |
| 506 |
05 => RE_Get_05, |
| 507 |
06 => RE_GetU_06, |
| 508 |
07 => RE_Get_07, |
| 509 |
08 => RE_Null, |
| 510 |
09 => RE_Get_09, |
| 511 |
10 => RE_GetU_10, |
| 512 |
11 => RE_Get_11, |
| 513 |
12 => RE_GetU_12, |
| 514 |
13 => RE_Get_13, |
| 515 |
14 => RE_GetU_14, |
| 516 |
15 => RE_Get_15, |
| 517 |
16 => RE_Null, |
| 518 |
17 => RE_Get_17, |
| 519 |
18 => RE_GetU_18, |
| 520 |
19 => RE_Get_19, |
| 521 |
20 => RE_GetU_20, |
| 522 |
21 => RE_Get_21, |
| 523 |
22 => RE_GetU_22, |
| 524 |
23 => RE_Get_23, |
| 525 |
24 => RE_GetU_24, |
| 526 |
25 => RE_Get_25, |
| 527 |
26 => RE_GetU_26, |
| 528 |
27 => RE_Get_27, |
| 529 |
28 => RE_GetU_28, |
| 530 |
29 => RE_Get_29, |
| 531 |
30 => RE_GetU_30, |
| 532 |
31 => RE_Get_31, |
| 533 |
32 => RE_Null, |
| 534 |
33 => RE_Get_33, |
| 535 |
34 => RE_GetU_34, |
| 536 |
35 => RE_Get_35, |
| 537 |
36 => RE_GetU_36, |
| 538 |
37 => RE_Get_37, |
| 539 |
38 => RE_GetU_38, |
| 540 |
39 => RE_Get_39, |
| 541 |
40 => RE_GetU_40, |
| 542 |
41 => RE_Get_41, |
| 543 |
42 => RE_GetU_42, |
| 544 |
43 => RE_Get_43, |
| 545 |
44 => RE_GetU_44, |
| 546 |
45 => RE_Get_45, |
| 547 |
46 => RE_GetU_46, |
| 548 |
47 => RE_Get_47, |
| 549 |
48 => RE_GetU_48, |
| 550 |
49 => RE_Get_49, |
| 551 |
50 => RE_GetU_50, |
| 552 |
51 => RE_Get_51, |
| 553 |
52 => RE_GetU_52, |
| 554 |
53 => RE_Get_53, |
| 555 |
54 => RE_GetU_54, |
| 556 |
55 => RE_Get_55, |
| 557 |
56 => RE_GetU_56, |
| 558 |
57 => RE_Get_57, |
| 559 |
58 => RE_GetU_58, |
| 560 |
59 => RE_Get_59, |
| 561 |
60 => RE_GetU_60, |
| 562 |
61 => RE_Get_61, |
| 563 |
62 => RE_GetU_62, |
| 564 |
63 => RE_Get_63, |
| 565 |
64 => RE_Null, |
| 566 |
65 => RE_Get_65, |
| 567 |
66 => RE_GetU_66, |
| 568 |
67 => RE_Get_67, |
| 569 |
68 => RE_GetU_68, |
| 570 |
69 => RE_Get_69, |
| 571 |
70 => RE_GetU_70, |
| 572 |
71 => RE_Get_71, |
| 573 |
72 => RE_GetU_72, |
| 574 |
73 => RE_Get_73, |
| 575 |
74 => RE_GetU_74, |
| 576 |
75 => RE_Get_75, |
| 577 |
76 => RE_GetU_76, |
| 578 |
77 => RE_Get_77, |
| 579 |
78 => RE_GetU_78, |
| 580 |
79 => RE_Get_79, |
| 581 |
80 => RE_GetU_80, |
| 582 |
81 => RE_Get_81, |
| 583 |
82 => RE_GetU_82, |
| 584 |
83 => RE_Get_83, |
| 585 |
84 => RE_GetU_84, |
| 586 |
85 => RE_Get_85, |
| 587 |
86 => RE_GetU_86, |
| 588 |
87 => RE_Get_87, |
| 589 |
88 => RE_GetU_88, |
| 590 |
89 => RE_Get_89, |
| 591 |
90 => RE_GetU_90, |
| 592 |
91 => RE_Get_91, |
| 593 |
92 => RE_GetU_92, |
| 594 |
93 => RE_Get_93, |
| 595 |
94 => RE_GetU_94, |
| 596 |
95 => RE_Get_95, |
| 597 |
96 => RE_GetU_96, |
| 598 |
97 => RE_Get_97, |
| 599 |
98 => RE_GetU_98, |
| 600 |
99 => RE_Get_99, |
| 601 |
100 => RE_GetU_100, |
| 602 |
101 => RE_Get_101, |
| 603 |
102 => RE_GetU_102, |
| 604 |
103 => RE_Get_103, |
| 605 |
104 => RE_GetU_104, |
| 606 |
105 => RE_Get_105, |
| 607 |
106 => RE_GetU_106, |
| 608 |
107 => RE_Get_107, |
| 609 |
108 => RE_GetU_108, |
| 610 |
109 => RE_Get_109, |
| 611 |
110 => RE_GetU_110, |
| 612 |
111 => RE_Get_111, |
| 613 |
112 => RE_GetU_112, |
| 614 |
113 => RE_Get_113, |
| 615 |
114 => RE_GetU_114, |
| 616 |
115 => RE_Get_115, |
| 617 |
116 => RE_GetU_116, |
| 618 |
117 => RE_Get_117, |
| 619 |
118 => RE_GetU_118, |
| 620 |
119 => RE_Get_119, |
| 621 |
120 => RE_GetU_120, |
| 622 |
121 => RE_Get_121, |
| 623 |
122 => RE_GetU_122, |
| 624 |
123 => RE_Get_123, |
| 625 |
124 => RE_GetU_124, |
| 626 |
125 => RE_Get_125, |
| 627 |
126 => RE_GetU_126, |
| 628 |
127 => RE_Get_127); |
| 629 |
|
| 630 |
-- Array of Set routine entities. These are used to assign an element of a |
| 631 |
-- packed array. The N'th entry is used to assign elements for a packed |
| 632 |
-- array whose component size is N. RE_Null is used as a null entry, for |
| 633 |
-- the cases where a library routine is not used. |
| 634 |
|
| 635 |
Set_Id : constant E_Array := |
| 636 |
(01 => RE_Null, |
| 637 |
02 => RE_Null, |
| 638 |
03 => RE_Set_03, |
| 639 |
04 => RE_Null, |
| 640 |
05 => RE_Set_05, |
| 641 |
06 => RE_Set_06, |
| 642 |
07 => RE_Set_07, |
| 643 |
08 => RE_Null, |
| 644 |
09 => RE_Set_09, |
| 645 |
10 => RE_Set_10, |
| 646 |
11 => RE_Set_11, |
| 647 |
12 => RE_Set_12, |
| 648 |
13 => RE_Set_13, |
| 649 |
14 => RE_Set_14, |
| 650 |
15 => RE_Set_15, |
| 651 |
16 => RE_Null, |
| 652 |
17 => RE_Set_17, |
| 653 |
18 => RE_Set_18, |
| 654 |
19 => RE_Set_19, |
| 655 |
20 => RE_Set_20, |
| 656 |
21 => RE_Set_21, |
| 657 |
22 => RE_Set_22, |
| 658 |
23 => RE_Set_23, |
| 659 |
24 => RE_Set_24, |
| 660 |
25 => RE_Set_25, |
| 661 |
26 => RE_Set_26, |
| 662 |
27 => RE_Set_27, |
| 663 |
28 => RE_Set_28, |
| 664 |
29 => RE_Set_29, |
| 665 |
30 => RE_Set_30, |
| 666 |
31 => RE_Set_31, |
| 667 |
32 => RE_Null, |
| 668 |
33 => RE_Set_33, |
| 669 |
34 => RE_Set_34, |
| 670 |
35 => RE_Set_35, |
| 671 |
36 => RE_Set_36, |
| 672 |
37 => RE_Set_37, |
| 673 |
38 => RE_Set_38, |
| 674 |
39 => RE_Set_39, |
| 675 |
40 => RE_Set_40, |
| 676 |
41 => RE_Set_41, |
| 677 |
42 => RE_Set_42, |
| 678 |
43 => RE_Set_43, |
| 679 |
44 => RE_Set_44, |
| 680 |
45 => RE_Set_45, |
| 681 |
46 => RE_Set_46, |
| 682 |
47 => RE_Set_47, |
| 683 |
48 => RE_Set_48, |
| 684 |
49 => RE_Set_49, |
| 685 |
50 => RE_Set_50, |
| 686 |
51 => RE_Set_51, |
| 687 |
52 => RE_Set_52, |
| 688 |
53 => RE_Set_53, |
| 689 |
54 => RE_Set_54, |
| 690 |
55 => RE_Set_55, |
| 691 |
56 => RE_Set_56, |
| 692 |
57 => RE_Set_57, |
| 693 |
58 => RE_Set_58, |
| 694 |
59 => RE_Set_59, |
| 695 |
60 => RE_Set_60, |
| 696 |
61 => RE_Set_61, |
| 697 |
62 => RE_Set_62, |
| 698 |
63 => RE_Set_63, |
| 699 |
64 => RE_Null, |
| 700 |
65 => RE_Set_65, |
| 701 |
66 => RE_Set_66, |
| 702 |
67 => RE_Set_67, |
| 703 |
68 => RE_Set_68, |
| 704 |
69 => RE_Set_69, |
| 705 |
70 => RE_Set_70, |
| 706 |
71 => RE_Set_71, |
| 707 |
72 => RE_Set_72, |
| 708 |
73 => RE_Set_73, |
| 709 |
74 => RE_Set_74, |
| 710 |
75 => RE_Set_75, |
| 711 |
76 => RE_Set_76, |
| 712 |
77 => RE_Set_77, |
| 713 |
78 => RE_Set_78, |
| 714 |
79 => RE_Set_79, |
| 715 |
80 => RE_Set_80, |
| 716 |
81 => RE_Set_81, |
| 717 |
82 => RE_Set_82, |
| 718 |
83 => RE_Set_83, |
| 719 |
84 => RE_Set_84, |
| 720 |
85 => RE_Set_85, |
| 721 |
86 => RE_Set_86, |
| 722 |
87 => RE_Set_87, |
| 723 |
88 => RE_Set_88, |
| 724 |
89 => RE_Set_89, |
| 725 |
90 => RE_Set_90, |
| 726 |
91 => RE_Set_91, |
| 727 |
92 => RE_Set_92, |
| 728 |
93 => RE_Set_93, |
| 729 |
94 => RE_Set_94, |
| 730 |
95 => RE_Set_95, |
| 731 |
96 => RE_Set_96, |
| 732 |
97 => RE_Set_97, |
| 733 |
98 => RE_Set_98, |
| 734 |
99 => RE_Set_99, |
| 735 |
100 => RE_Set_100, |
| 736 |
101 => RE_Set_101, |
| 737 |
102 => RE_Set_102, |
| 738 |
103 => RE_Set_103, |
| 739 |
104 => RE_Set_104, |
| 740 |
105 => RE_Set_105, |
| 741 |
106 => RE_Set_106, |
| 742 |
107 => RE_Set_107, |
| 743 |
108 => RE_Set_108, |
| 744 |
109 => RE_Set_109, |
| 745 |
110 => RE_Set_110, |
| 746 |
111 => RE_Set_111, |
| 747 |
112 => RE_Set_112, |
| 748 |
113 => RE_Set_113, |
| 749 |
114 => RE_Set_114, |
| 750 |
115 => RE_Set_115, |
| 751 |
116 => RE_Set_116, |
| 752 |
117 => RE_Set_117, |
| 753 |
118 => RE_Set_118, |
| 754 |
119 => RE_Set_119, |
| 755 |
120 => RE_Set_120, |
| 756 |
121 => RE_Set_121, |
| 757 |
122 => RE_Set_122, |
| 758 |
123 => RE_Set_123, |
| 759 |
124 => RE_Set_124, |
| 760 |
125 => RE_Set_125, |
| 761 |
126 => RE_Set_126, |
| 762 |
127 => RE_Set_127); |
| 763 |
|
| 764 |
-- Array of Set routine entities to be used in the case where the packed |
| 765 |
-- array is itself a component of a packed structure, and therefore may not |
| 766 |
-- be fully aligned. This only affects the even sizes, since for the odd |
| 767 |
-- sizes, we do not get any fixed alignment in any case. |
| 768 |
|
| 769 |
SetU_Id : constant E_Array := |
| 770 |
(01 => RE_Null, |
| 771 |
02 => RE_Null, |
| 772 |
03 => RE_Set_03, |
| 773 |
04 => RE_Null, |
| 774 |
05 => RE_Set_05, |
| 775 |
06 => RE_SetU_06, |
| 776 |
07 => RE_Set_07, |
| 777 |
08 => RE_Null, |
| 778 |
09 => RE_Set_09, |
| 779 |
10 => RE_SetU_10, |
| 780 |
11 => RE_Set_11, |
| 781 |
12 => RE_SetU_12, |
| 782 |
13 => RE_Set_13, |
| 783 |
14 => RE_SetU_14, |
| 784 |
15 => RE_Set_15, |
| 785 |
16 => RE_Null, |
| 786 |
17 => RE_Set_17, |
| 787 |
18 => RE_SetU_18, |
| 788 |
19 => RE_Set_19, |
| 789 |
20 => RE_SetU_20, |
| 790 |
21 => RE_Set_21, |
| 791 |
22 => RE_SetU_22, |
| 792 |
23 => RE_Set_23, |
| 793 |
24 => RE_SetU_24, |
| 794 |
25 => RE_Set_25, |
| 795 |
26 => RE_SetU_26, |
| 796 |
27 => RE_Set_27, |
| 797 |
28 => RE_SetU_28, |
| 798 |
29 => RE_Set_29, |
| 799 |
30 => RE_SetU_30, |
| 800 |
31 => RE_Set_31, |
| 801 |
32 => RE_Null, |
| 802 |
33 => RE_Set_33, |
| 803 |
34 => RE_SetU_34, |
| 804 |
35 => RE_Set_35, |
| 805 |
36 => RE_SetU_36, |
| 806 |
37 => RE_Set_37, |
| 807 |
38 => RE_SetU_38, |
| 808 |
39 => RE_Set_39, |
| 809 |
40 => RE_SetU_40, |
| 810 |
41 => RE_Set_41, |
| 811 |
42 => RE_SetU_42, |
| 812 |
43 => RE_Set_43, |
| 813 |
44 => RE_SetU_44, |
| 814 |
45 => RE_Set_45, |
| 815 |
46 => RE_SetU_46, |
| 816 |
47 => RE_Set_47, |
| 817 |
48 => RE_SetU_48, |
| 818 |
49 => RE_Set_49, |
| 819 |
50 => RE_SetU_50, |
| 820 |
51 => RE_Set_51, |
| 821 |
52 => RE_SetU_52, |
| 822 |
53 => RE_Set_53, |
| 823 |
54 => RE_SetU_54, |
| 824 |
55 => RE_Set_55, |
| 825 |
56 => RE_SetU_56, |
| 826 |
57 => RE_Set_57, |
| 827 |
58 => RE_SetU_58, |
| 828 |
59 => RE_Set_59, |
| 829 |
60 => RE_SetU_60, |
| 830 |
61 => RE_Set_61, |
| 831 |
62 => RE_SetU_62, |
| 832 |
63 => RE_Set_63, |
| 833 |
64 => RE_Null, |
| 834 |
65 => RE_Set_65, |
| 835 |
66 => RE_SetU_66, |
| 836 |
67 => RE_Set_67, |
| 837 |
68 => RE_SetU_68, |
| 838 |
69 => RE_Set_69, |
| 839 |
70 => RE_SetU_70, |
| 840 |
71 => RE_Set_71, |
| 841 |
72 => RE_SetU_72, |
| 842 |
73 => RE_Set_73, |
| 843 |
74 => RE_SetU_74, |
| 844 |
75 => RE_Set_75, |
| 845 |
76 => RE_SetU_76, |
| 846 |
77 => RE_Set_77, |
| 847 |
78 => RE_SetU_78, |
| 848 |
79 => RE_Set_79, |
| 849 |
80 => RE_SetU_80, |
| 850 |
81 => RE_Set_81, |
| 851 |
82 => RE_SetU_82, |
| 852 |
83 => RE_Set_83, |
| 853 |
84 => RE_SetU_84, |
| 854 |
85 => RE_Set_85, |
| 855 |
86 => RE_SetU_86, |
| 856 |
87 => RE_Set_87, |
| 857 |
88 => RE_SetU_88, |
| 858 |
89 => RE_Set_89, |
| 859 |
90 => RE_SetU_90, |
| 860 |
91 => RE_Set_91, |
| 861 |
92 => RE_SetU_92, |
| 862 |
93 => RE_Set_93, |
| 863 |
94 => RE_SetU_94, |
| 864 |
95 => RE_Set_95, |
| 865 |
96 => RE_SetU_96, |
| 866 |
97 => RE_Set_97, |
| 867 |
98 => RE_SetU_98, |
| 868 |
99 => RE_Set_99, |
| 869 |
100 => RE_SetU_100, |
| 870 |
101 => RE_Set_101, |
| 871 |
102 => RE_SetU_102, |
| 872 |
103 => RE_Set_103, |
| 873 |
104 => RE_SetU_104, |
| 874 |
105 => RE_Set_105, |
| 875 |
106 => RE_SetU_106, |
| 876 |
107 => RE_Set_107, |
| 877 |
108 => RE_SetU_108, |
| 878 |
109 => RE_Set_109, |
| 879 |
110 => RE_SetU_110, |
| 880 |
111 => RE_Set_111, |
| 881 |
112 => RE_SetU_112, |
| 882 |
113 => RE_Set_113, |
| 883 |
114 => RE_SetU_114, |
| 884 |
115 => RE_Set_115, |
| 885 |
116 => RE_SetU_116, |
| 886 |
117 => RE_Set_117, |
| 887 |
118 => RE_SetU_118, |
| 888 |
119 => RE_Set_119, |
| 889 |
120 => RE_SetU_120, |
| 890 |
121 => RE_Set_121, |
| 891 |
122 => RE_SetU_122, |
| 892 |
123 => RE_Set_123, |
| 893 |
124 => RE_SetU_124, |
| 894 |
125 => RE_Set_125, |
| 895 |
126 => RE_SetU_126, |
| 896 |
127 => RE_Set_127); |
| 897 |
|
| 898 |
----------------- |
| 899 |
-- Subprograms -- |
| 900 |
----------------- |
| 901 |
|
| 902 |
procedure Create_Packed_Array_Impl_Type (Typ : Entity_Id); |
| 903 |
-- Typ is a array type or subtype to which pragma Pack applies. If the |
| 904 |
-- Packed_Array_Impl_Type field of Typ is already set, then the call has |
| 905 |
-- no effect, otherwise a suitable type or subtype is created and stored in |
| 906 |
-- the Packed_Array_Impl_Type field of Typ. This created type is an Itype |
| 907 |
-- so that Gigi will simply elaborate and freeze the type on first use |
| 908 |
-- (which is typically the definition of the corresponding array type). |
| 909 |
-- |
| 910 |
-- Note: although this routine is included in the expander package for |
| 911 |
-- packed types, it is actually called unconditionally from Freeze, |
| 912 |
-- whether or not expansion (and code generation) is enabled. We do this |
| 913 |
-- since we want gigi to be able to properly compute type characteristics |
| 914 |
-- (for the Data Decomposition Annex of ASIS, and possible other future |
| 915 |
-- uses) even if code generation is not active. Strictly this means that |
| 916 |
-- this procedure is not part of the expander, but it seems appropriate |
| 917 |
-- to keep it together with the other expansion routines that have to do |
| 918 |
-- with packed array types. |
| 919 |
|
| 920 |
procedure Expand_Packed_Boolean_Operator (N : Node_Id); |
| 921 |
-- N is an N_Op_And, N_Op_Or or N_Op_Xor node whose operand type is a |
| 922 |
-- packed boolean array. This routine expands the appropriate operations |
| 923 |
-- to carry out the logical operation on the packed arrays. It handles |
| 924 |
-- both the modular and array representation cases. |
| 925 |
|
| 926 |
procedure Expand_Packed_Element_Reference (N : Node_Id); |
| 927 |
-- N is an N_Indexed_Component node whose prefix is a packed array. In |
| 928 |
-- the bit packed case, this routine can only be used for the expression |
| 929 |
-- evaluation case, not the assignment case, since the result is not a |
| 930 |
-- variable. See Expand_Bit_Packed_Element_Set for how the assignment case |
| 931 |
-- is handled in the bit packed case. For the enumeration case, the result |
| 932 |
-- of this call is always a variable, so the call can be used for both the |
| 933 |
-- expression evaluation and assignment cases. |
| 934 |
|
| 935 |
procedure Expand_Bit_Packed_Element_Set (N : Node_Id); |
| 936 |
-- N is an N_Assignment_Statement node whose name is an indexed |
| 937 |
-- component of a bit-packed array. This procedure rewrites the entire |
| 938 |
-- assignment statement with appropriate code to set the referenced |
| 939 |
-- bits of the packed array type object. Note that this procedure is |
| 940 |
-- used only for the bit-packed case, not for the enumeration case. |
| 941 |
|
| 942 |
procedure Expand_Packed_Eq (N : Node_Id); |
| 943 |
-- N is an N_Op_Eq node where the operands are packed arrays whose |
| 944 |
-- representation is an array-of-bytes type (the case where a modular |
| 945 |
-- type is used for the representation does not require any special |
| 946 |
-- handling, because in the modular case, unused bits are zeroes). |
| 947 |
|
| 948 |
procedure Expand_Packed_Not (N : Node_Id); |
| 949 |
-- N is an N_Op_Not node where the operand is packed array of Boolean |
| 950 |
-- in standard representation (i.e. component size is one bit). This |
| 951 |
-- procedure expands the corresponding not operation. Note that the |
| 952 |
-- non-standard representation case is handled by using a loop through |
| 953 |
-- elements generated by the normal non-packed circuitry. |
| 954 |
|
| 955 |
function Involves_Packed_Array_Reference (N : Node_Id) return Boolean; |
| 956 |
-- N is the node for a name. This function returns true if the name |
| 957 |
-- involves a packed array reference. A node involves a packed array |
| 958 |
-- reference if it is itself an indexed component referring to a bit- |
| 959 |
-- packed array, or it is a selected component whose prefix involves |
| 960 |
-- a packed array reference. |
| 961 |
|
| 962 |
procedure Expand_Packed_Address_Reference (N : Node_Id); |
| 963 |
-- The node N is an attribute reference for the 'Address reference, where |
| 964 |
-- the prefix involves a packed array reference. This routine expands the |
| 965 |
-- necessary code for performing the address reference in this case. |
| 966 |
|
| 967 |
procedure Expand_Packed_Bit_Reference (N : Node_Id); |
| 968 |
-- The node N is an attribute reference for the 'Bit reference, where the |
| 969 |
-- prefix involves a packed array reference. This routine expands the |
| 970 |
-- necessary code for performing the bit reference in this case. |
| 971 |
|
| 972 |
end Exp_Pakd; |