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