aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/repinfo.adb
blob: ecd35e94e142280d59a963638631fe4431717082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT COMPILER COMPONENTS                         --
--                                                                          --
--                              R E P I N F O                               --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--          Copyright (C) 1999-2023, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license.          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

with Alloc;
with Atree;          use Atree;
with Casing;         use Casing;
with Debug;          use Debug;
with Einfo;          use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils;    use Einfo.Utils;
with Lib;            use Lib;
with Namet;          use Namet;
with Nlists;         use Nlists;
with Opt;            use Opt;
with Output;         use Output;
with Osint.C;        use Osint.C;
with Sem_Aux;        use Sem_Aux;
with Sem_Eval;       use Sem_Eval;
with Sem_Util;
with Sinfo;          use Sinfo;
with Sinfo.Nodes;    use Sinfo.Nodes;
with Sinfo.Utils;    use Sinfo.Utils;
with Sinput;         use Sinput;
with Snames;         use Snames;
with Stand;          use Stand;
with Stringt;        use Stringt;
with Table;
with Ttypes;
with Uname;          use Uname;
with Urealp;         use Urealp;

with Ada.Unchecked_Conversion;

with GNAT.HTable;

package body Repinfo is

   SSU : Pos renames Ttypes.System_Storage_Unit;
   --  Value for Storage_Unit

   ---------------------------------------
   -- Representation of GCC Expressions --
   ---------------------------------------

   --    A table internal to this unit is used to hold the values of back
   --    annotated expressions.

   --    Node values are stored as Uint values using the negative of the node
   --    index in this table. Constants appear as non-negative Uint values.

   type Exp_Node is record
      Expr : TCode;
      Op1  : Node_Ref_Or_Val;
      Op2  : Node_Ref_Or_Val;
      Op3  : Node_Ref_Or_Val;
   end record;

   --  The following representation clause ensures that the above record
   --  has no holes. We do this so that when instances of this record are
   --  written, we do not write uninitialized values to the file.

   for Exp_Node use record
      Expr at  0 range 0 .. 31;
      Op1  at  4 range 0 .. 31;
      Op2  at  8 range 0 .. 31;
      Op3  at 12 range 0 .. 31;
   end record;

   for Exp_Node'Size use 16 * 8;
   --  This ensures that we did not leave out any fields

   package Rep_Table is new Table.Table (
      Table_Component_Type => Exp_Node,
      Table_Index_Type     => Nat,
      Table_Low_Bound      => 1,
      Table_Initial        => Alloc.Rep_Table_Initial,
      Table_Increment      => Alloc.Rep_Table_Increment,
      Table_Name           => "BE_Rep_Table");

   --------------------------------------------------------------
   -- Representation of Front-End Dynamic Size/Offset Entities --
   --------------------------------------------------------------

   package Dynamic_SO_Entity_Table is new Table.Table (
      Table_Component_Type => Entity_Id,
      Table_Index_Type     => Nat,
      Table_Low_Bound      => 1,
      Table_Initial        => Alloc.Rep_Table_Initial,
      Table_Increment      => Alloc.Rep_Table_Increment,
      Table_Name           => "FE_Rep_Table");

   Unit_Casing : Casing_Type;
   --  Identifier casing for current unit. This is set by List_Rep_Info for
   --  each unit, before calling subprograms which may read it.

   Need_Separator : Boolean;
   --  Set True if a separator is needed before outputting any information for
   --  the current entity.

   ------------------------------
   -- Set of Relevant Entities --
   ------------------------------

   Relevant_Entities_Size : constant := 4093;
   --  Number of headers in hash table

   subtype Entity_Header_Num is Integer range 0 .. Relevant_Entities_Size - 1;
   --  Range of headers in hash table

   function Entity_Hash (Id : Entity_Id) return Entity_Header_Num;
   --  Simple hash function for Entity_Ids

   package Relevant_Entities is new GNAT.Htable.Simple_HTable
     (Header_Num => Entity_Header_Num,
      Element    => Boolean,
      No_Element => False,
      Key        => Entity_Id,
      Hash       => Entity_Hash,
      Equal      => "=");
   --  Hash table to record which compiler-generated entities are relevant

   -----------------------
   -- Local Subprograms --
   -----------------------

   procedure List_Entities
     (Ent              : Entity_Id;
      Bytes_Big_Endian : Boolean;
      In_Subprogram    : Boolean := False);
   --  This procedure lists the entities associated with the entity E, starting
   --  with the First_Entity and using the Next_Entity link. If a nested
   --  package is found, entities within the package are recursively processed.
   --  When recursing within a subprogram body, Is_Subprogram suppresses
   --  duplicate information about signature.

   procedure List_Name (Ent : Entity_Id);
   --  List name of entity Ent in appropriate case. The name is listed with
   --  full qualification up to but not including the compilation unit name.

   procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
   --  List representation info for array type Ent

   procedure List_Common_Type_Info (Ent : Entity_Id);
   --  List common type info (name, size, alignment) for type Ent

   procedure List_Linker_Section (Ent : Entity_Id);
   --  List linker section for Ent (caller has checked that Ent is an entity
   --  for which the Linker_Section_Pragma field is defined).

   procedure List_Location (Ent : Entity_Id);
   --  List location information for Ent

   procedure List_Object_Info (Ent : Entity_Id);
   --  List representation info for object Ent

   procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean);
   --  List representation info for record type Ent

   procedure List_Scalar_Storage_Order
     (Ent              : Entity_Id;
      Bytes_Big_Endian : Boolean);
   --  List scalar storage order information for record or array type Ent.
   --  Also includes bit order information for record types, if necessary.

   procedure List_Subprogram_Info (Ent : Entity_Id);
   --  List subprogram info for subprogram Ent

   procedure List_Type_Info (Ent : Entity_Id);
   --  List type info for type Ent

   function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean;
   --  Returns True if Val represents a representation value that is known at
   --  compile time.

   procedure Spaces (N : Natural);
   --  Output given number of spaces

   procedure Write_Info_Line (S : String);
   --  Routine to write a line to Repinfo output file. This routine is passed
   --  as a special output procedure to Output.Set_Special_Output. Note that
   --  Write_Info_Line is called with an EOL character at the end of each line,
   --  as per the Output spec, but the internal call to the appropriate routine
   --  in Osint requires that the end of line sequence be stripped off.

   procedure Write_Mechanism (M : Mechanism_Type);
   --  Writes symbolic string for mechanism represented by M

   procedure Write_Separator;
   --  Called before outputting anything for an entity. Ensures that
   --  a separator precedes the output for a particular entity.

   procedure Write_Unknown_Val;
   --  Writes symbolic string for an unknown or non-representable value

   procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False);
   --  Given a representation value, write it out. No_Uint values or values
   --  dependent on discriminants are written as two question marks. If the
   --  flag Paren is set, then the output is surrounded in parentheses if it is
   --  other than a simple value.

   ------------------------
   -- Create_Discrim_Ref --
   ------------------------

   function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref is
   begin
      return Create_Node
        (Expr => Discrim_Val,
         Op1  => Discriminant_Number (Discr));
   end Create_Discrim_Ref;

   ---------------------------
   -- Create_Dynamic_SO_Ref --
   ---------------------------

   function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref is
   begin
      Dynamic_SO_Entity_Table.Append (E);
      return UI_From_Int (-Dynamic_SO_Entity_Table.Last);
   end Create_Dynamic_SO_Ref;

   -----------------
   -- Create_Node --
   -----------------

   function Create_Node
     (Expr : TCode;
      Op1  : Node_Ref_Or_Val;
      Op2  : Node_Ref_Or_Val := No_Uint;
      Op3  : Node_Ref_Or_Val := No_Uint) return Node_Ref
   is
   begin
      Rep_Table.Append (
        (Expr => Expr,
         Op1  => Op1,
         Op2  => Op2,
         Op3  => Op3));
      return UI_From_Int (-Rep_Table.Last);
   end Create_Node;

   -----------------
   -- Entity_Hash --
   -----------------

   function Entity_Hash (Id : Entity_Id) return Entity_Header_Num is
   begin
      return Entity_Header_Num (Id mod Relevant_Entities_Size);
   end Entity_Hash;

   ---------------------------
   -- Get_Dynamic_SO_Entity --
   ---------------------------

   function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id is
   begin
      return Dynamic_SO_Entity_Table.Table (-UI_To_Int (U));
   end Get_Dynamic_SO_Entity;

   -----------------------
   -- Is_Dynamic_SO_Ref --
   -----------------------

   function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean is
   begin
      return U < Uint_0;
   end Is_Dynamic_SO_Ref;

   ----------------------
   -- Is_Static_SO_Ref --
   ----------------------

   function Is_Static_SO_Ref (U : SO_Ref) return Boolean is
   begin
      return U >= Uint_0;
   end Is_Static_SO_Ref;

   ---------
   -- lgx --
   ---------

   procedure lgx (U : Node_Ref_Or_Val) is
   begin
      List_GCC_Expression (U);
      Write_Eol;
   end lgx;

   ----------------------
   -- List_Array_Info --
   ----------------------

   procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
   begin
      Write_Separator;

      if List_Representation_Info_To_JSON then
         Write_Line ("{");
      end if;

      List_Common_Type_Info (Ent);

      if List_Representation_Info_To_JSON then
         Write_Line (",");
         Write_Str ("  ""Component_Size"": ");
         Write_Val (Component_Size (Ent));
      else
         Write_Str ("for ");
         List_Name (Ent);
         Write_Str ("'Component_Size use ");
         Write_Val (Component_Size (Ent));
         Write_Line (";");
      end if;

      List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);

      List_Linker_Section (Ent);

      if List_Representation_Info_To_JSON then
         Write_Eol;
         Write_Line ("}");
      end if;

      --  The component type is relevant for an array

      if List_Representation_Info = 4
        and then Is_Itype (Component_Type (Base_Type (Ent)))
      then
         Relevant_Entities.Set (Component_Type (Base_Type (Ent)), True);
      end if;
   end List_Array_Info;

   ---------------------------
   -- List_Common_Type_Info --
   ---------------------------

   procedure List_Common_Type_Info (Ent : Entity_Id) is
   begin
      if List_Representation_Info_To_JSON then
         Write_Str ("  ""name"": """);
         List_Name (Ent);
         Write_Line (""",");
         List_Location (Ent);
      end if;

      --  Do not list size info for unconstrained arrays, not meaningful

      if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then
         null;

      else
         if Known_Esize (Ent) and then Known_RM_Size (Ent) then
            --  If Esize and RM_Size are the same, list as Size. This is a
            --  common case, which we may as well list in simple form.

            if Esize (Ent) = RM_Size (Ent) then
               if List_Representation_Info_To_JSON then
                  Write_Str ("  ""Size"": ");
                  Write_Val (Esize (Ent));
                  Write_Line (",");
               else
                  Write_Str ("for ");
                  List_Name (Ent);
                  Write_Str ("'Size use ");
                  Write_Val (Esize (Ent));
                  Write_Line (";");
               end if;

            --  Otherwise list size values separately

            else
               if List_Representation_Info_To_JSON then
                  Write_Str ("  ""Object_Size"": ");
                  Write_Val (Esize (Ent));
                  Write_Line (",");

                  Write_Str ("  ""Value_Size"": ");
                  Write_Val (RM_Size (Ent));
                  Write_Line (",");

               else
                  Write_Str ("for ");
                  List_Name (Ent);
                  Write_Str ("'Object_Size use ");
                  Write_Val (Esize (Ent));
                  Write_Line (";");

                  Write_Str ("for ");
                  List_Name (Ent);
                  Write_Str ("'Value_Size use ");
                  Write_Val (RM_Size (Ent));
                  Write_Line (";");
               end if;
            end if;
         end if;
      end if;

      if Known_Alignment (Ent) then
         if List_Representation_Info_To_JSON then
            Write_Str ("  ""Alignment"": ");
            Write_Val (Alignment (Ent));
         else
            Write_Str ("for ");
            List_Name (Ent);
            Write_Str ("'Alignment use ");
            Write_Val (Alignment (Ent));
            Write_Line (";");
         end if;

      --  Alignment is not always set for task, protected, and class-wide
      --  types, or when doing semantic analysis only. Representation aspects
      --  are not computed for types in a generic unit.

      else
         --  Add unknown alignment entry in JSON format to ensure the format is
         --  valid, as a comma is added by the caller before another field.

         if List_Representation_Info_To_JSON then
            Write_Str ("  ""Alignment"": ");
            Write_Unknown_Val;
         end if;

         pragma Assert
           (not Expander_Active or else
              Is_Concurrent_Type (Ent) or else
              Is_Class_Wide_Type (Ent) or else
              Sem_Util.In_Generic_Scope (Ent));
      end if;
   end List_Common_Type_Info;

   -------------------
   -- List_Entities --
   -------------------

   procedure List_Entities
     (Ent              : Entity_Id;
      Bytes_Big_Endian : Boolean;
      In_Subprogram    : Boolean := False)
   is
      Body_E : Entity_Id;
      E      : Entity_Id;

      function Find_Declaration (E : Entity_Id) return Node_Id;
      --  Utility to retrieve declaration node for entity in the
      --  case of package bodies and subprograms.

      ----------------------
      -- Find_Declaration --
      ----------------------

      function Find_Declaration (E : Entity_Id) return Node_Id is
         Decl : Node_Id;

      begin
         Decl := Parent (E);
         while Present (Decl)
           and then Nkind (Decl) /= N_Package_Body
           and then Nkind (Decl) /= N_Subprogram_Declaration
           and then Nkind (Decl) /= N_Subprogram_Body
         loop
            Decl := Parent (Decl);
         end loop;

         return Decl;
      end Find_Declaration;

   --  Start of processing for List_Entities

   begin
      --  List entity if we have one, and it is not a renaming declaration.
      --  For renamings, we don't get proper information, and really it makes
      --  sense to restrict the output to the renamed entity.

      if Present (Ent)
        and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration
        and then not Is_Ignored_Ghost_Entity (Ent)
      then
         --  If entity is a subprogram and we are listing mechanisms,
         --  then we need to list mechanisms for this entity. We skip this
         --  if it is a nested subprogram, as the information has already
         --  been produced when listing the enclosing scope.

         if List_Representation_Info_Mechanisms
           and then Is_Subprogram_Or_Entry (Ent)
           and then not In_Subprogram
         then
            List_Subprogram_Info (Ent);
         end if;

         E := First_Entity (Ent);
         while Present (E) loop
            --  We list entities that come from source (excluding private or
            --  incomplete types or deferred constants, for which we will list
            --  the information for the full view). If requested, we also list
            --  relevant entities that have been generated when processing the
            --  original entities coming from source. But if debug flag A is
            --  set, then all entities are listed.

            if ((Comes_From_Source (E)
                   or else (Ekind (E) = E_Block
                              and then
                            Nkind (Parent (E)) = N_Implicit_Label_Declaration
                              and then
                            Comes_From_Source (Label_Construct (Parent (E)))))
              and then not Is_Incomplete_Or_Private_Type (E)
              and then not (Ekind (E) = E_Constant
                              and then Present (Full_View (E))))
              or else (List_Representation_Info = 4
                         and then Relevant_Entities.Get (E))
              or else Debug_Flag_AA
            then
               if Is_Subprogram (E) then
                  if List_Representation_Info_Mechanisms then
                     List_Subprogram_Info (E);
                  end if;

                  --  Recurse into entities local to subprogram

                  List_Entities (E, Bytes_Big_Endian, True);

               elsif Ekind (E) in E_Entry
                                | E_Entry_Family
                                | E_Subprogram_Type
               then
                  if List_Representation_Info_Mechanisms then
                     List_Subprogram_Info (E);
                  end if;

               elsif Is_Record_Type (E) then
                  if List_Representation_Info >= 1 then
                     List_Record_Info (E, Bytes_Big_Endian);

                     --  Recurse into entities local to a record type

                     if List_Representation_Info = 4 then
                        List_Entities (E, Bytes_Big_Endian, False);
                     end if;
                  end if;

               elsif Is_Array_Type (E) then
                  if List_Representation_Info >= 1 then
                     List_Array_Info (E, Bytes_Big_Endian);
                  end if;

               elsif Is_Type (E) then
                  if List_Representation_Info >= 2 then
                     List_Type_Info (E);
                  end if;

               --  Note that formals are not annotated so we skip them here

               elsif Ekind (E) in E_Constant
                                | E_Loop_Parameter
                                | E_Variable
               then
                  if List_Representation_Info >= 2 then
                     List_Object_Info (E);
                  end if;
               end if;

               --  Recurse into nested package, but not child packages, and not
               --  nested package renamings (in particular renamings of the
               --  enclosing package, as for some Java bindings and for generic
               --  instances).

               if Ekind (E) = E_Package then
                  if No (Renamed_Entity (E)) and then not Is_Child_Unit (E)
                  then
                     List_Entities (E, Bytes_Big_Endian);
                  end if;

               --  Recurse into bodies

               elsif Ekind (E) in E_Package_Body
                                | E_Protected_Body
                                | E_Protected_Type
                                | E_Subprogram_Body
                                | E_Task_Body
                                | E_Task_Type
               then
                  List_Entities (E, Bytes_Big_Endian);

               --  Recurse into blocks

               elsif Ekind (E) = E_Block then
                  List_Entities (E, Bytes_Big_Endian);
               end if;
            end if;

            Next_Entity (E);
         end loop;

         --  For a package body, the entities of the visible subprograms are
         --  declared in the corresponding spec. Iterate over its entities in
         --  order to handle properly the subprogram bodies. Skip bodies in
         --  subunits, which are listed independently.

         if Ekind (Ent) = E_Package_Body
           and then Present (Corresponding_Spec (Find_Declaration (Ent)))
         then
            E := First_Entity (Corresponding_Spec (Find_Declaration (Ent)));
            while Present (E) loop
               if Is_Subprogram (E)
                 and then
                   Nkind (Find_Declaration (E)) = N_Subprogram_Declaration
               then
                  Body_E := Corresponding_Body (Find_Declaration (E));

                  if Present (Body_E)
                    and then
                      Nkind (Parent (Find_Declaration (Body_E))) /= N_Subunit
                  then
                     List_Entities (Body_E, Bytes_Big_Endian);
                  end if;
               end if;

               Next_Entity (E);
            end loop;
         end if;
      end if;
   end List_Entities;

   -------------------------
   -- List_GCC_Expression --
   -------------------------

   procedure List_GCC_Expression (U : Node_Ref_Or_Val) is

      procedure Print_Expr (Val : Node_Ref_Or_Val);
      --  Internal recursive procedure to print expression

      ----------------
      -- Print_Expr --
      ----------------

      procedure Print_Expr (Val : Node_Ref_Or_Val) is
      begin
         if Val >= 0 then
            UI_Write (Val, Decimal);

         else
            declare
               Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));

               procedure Unop (S : String);
               --  Output text for unary operator with S being operator name

               procedure Binop (S : String);
               --  Output text for binary operator with S being operator name

               ----------
               -- Unop --
               ----------

               procedure Unop (S : String) is
               begin
                  if List_Representation_Info_To_JSON then
                     Write_Str ("{ ""code"": """);
                     if S (S'Last) = ' ' then
                        Write_Str (S (S'First .. S'Last - 1));
                     else
                        Write_Str (S);
                     end if;
                     Write_Str (""", ""operands"": [ ");
                     Print_Expr (Node.Op1);
                     Write_Str (" ] }");
                  else
                     Write_Str (S);
                     Print_Expr (Node.Op1);
                  end if;
               end Unop;

               -----------
               -- Binop --
               -----------

               procedure Binop (S : String) is
               begin
                  if List_Representation_Info_To_JSON then
                     Write_Str ("{ ""code"": """);
                     Write_Str (S (S'First + 1 .. S'Last - 1));
                     Write_Str (""", ""operands"": [ ");
                     Print_Expr (Node.Op1);
                     Write_Str (", ");
                     Print_Expr (Node.Op2);
                     Write_Str (" ] }");
                  else
                     Write_Char ('(');
                     Print_Expr (Node.Op1);
                     Write_Str (S);
                     Print_Expr (Node.Op2);
                     Write_Char (')');
                  end if;
               end Binop;

            --  Start of processing for Print_Expr

            begin
               case Node.Expr is
                  when Cond_Expr =>
                     if List_Representation_Info_To_JSON then
                        Write_Str ("{ ""code"": ""?<>""");
                        Write_Str (", ""operands"": [ ");
                        Print_Expr (Node.Op1);
                        Write_Str (", ");
                        Print_Expr (Node.Op2);
                        Write_Str (", ");
                        Print_Expr (Node.Op3);
                        Write_Str (" ] }");
                     else
                        Write_Str ("(if ");
                        Print_Expr (Node.Op1);
                        Write_Str (" then ");
                        Print_Expr (Node.Op2);
                        Write_Str (" else ");
                        Print_Expr (Node.Op3);
                        Write_Str (" end)");
                     end if;

                  when Plus_Expr =>
                     Binop (" + ");

                  when Minus_Expr =>
                     Binop (" - ");

                  when Mult_Expr =>
                     Binop (" * ");

                  when Trunc_Div_Expr =>
                     Binop (" /t ");

                  when Ceil_Div_Expr =>
                     Binop (" /c ");

                  when Floor_Div_Expr =>
                     Binop (" /f ");

                  when Trunc_Mod_Expr =>
                     Binop (" modt ");

                  when Ceil_Mod_Expr =>
                     Binop (" modc ");

                  when Floor_Mod_Expr =>
                     Binop (" modf ");

                  when Exact_Div_Expr =>
                     Binop (" /e ");

                  when Negate_Expr =>
                     Unop ("-");

                  when Min_Expr =>
                     Binop (" min ");

                  when Max_Expr =>
                     Binop (" max ");

                  when Abs_Expr =>
                     Unop ("abs ");

                  when Truth_And_Expr =>
                     Binop (" and ");

                  when Truth_Or_Expr =>
                     Binop (" or ");

                  when Truth_Xor_Expr =>
                     Binop (" xor ");

                  when Truth_Not_Expr =>
                     Unop ("not ");

                  when Lt_Expr =>
                     Binop (" < ");

                  when Le_Expr =>
                     Binop (" <= ");

                  when Gt_Expr =>
                     Binop (" > ");

                  when Ge_Expr =>
                     Binop (" >= ");

                  when Eq_Expr =>
                     Binop (" == ");

                  when Ne_Expr =>
                     Binop (" != ");

                  when Bit_And_Expr =>
                     Binop (" & ");

                  when Discrim_Val =>
                     Unop ("#");

                  when Dynamic_Val =>
                     Unop ("var");
               end case;
            end;
         end if;
      end Print_Expr;

   --  Start of processing for List_GCC_Expression

   begin
      if No (U) then
         Write_Unknown_Val;
      else
         Print_Expr (U);
      end if;
   end List_GCC_Expression;

   -------------------------
   -- List_Linker_Section --
   -------------------------

   procedure List_Linker_Section (Ent : Entity_Id) is
      Args : List_Id;
      Sect : Node_Id;

   begin
      if Present (Linker_Section_Pragma (Ent)) then
         Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent));
         Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args)));

         if List_Representation_Info_To_JSON then
            Write_Line (",");
            Write_Str ("  ""Linker_Section"": """);
         else
            Write_Str ("pragma Linker_Section (");
            List_Name (Ent);
            Write_Str (", """);
         end if;

         pragma Assert (Nkind (Sect) = N_String_Literal);
         String_To_Name_Buffer (Strval (Sect));
         Write_Str (Name_Buffer (1 .. Name_Len));
         Write_Str ("""");
         if not List_Representation_Info_To_JSON then
            Write_Line (");");
         end if;
      end if;
   end List_Linker_Section;

   -------------------
   -- List_Location --
   -------------------

   procedure List_Location (Ent : Entity_Id) is
   begin
      pragma Assert (List_Representation_Info_To_JSON);
      Write_Str ("  ""location"": """);
      Write_Location (Sloc (Ent));
      Write_Line (""",");
   end List_Location;

   ---------------
   -- List_Name --
   ---------------

   procedure List_Name (Ent : Entity_Id) is
      C : Character;

   begin
      --  In JSON mode, we recurse up to Standard. This is also valid in
      --  default mode where we recurse up to the first compilation unit and
      --  should not get to Standard.

      if Scope (Ent) = Standard_Standard then
         null;
      elsif not Is_Compilation_Unit (Scope (Ent))
        or else List_Representation_Info_To_JSON
      then
         List_Name (Scope (Ent));
         Write_Char ('.');
      end if;

      Get_Unqualified_Decoded_Name_String (Chars (Ent));
      Set_Casing (Unit_Casing);

      --  The name of operators needs to be properly escaped for JSON

      for J in 1 .. Name_Len loop
         C := Name_Buffer (J);
         if C = '"' and then List_Representation_Info_To_JSON then
            Write_Char ('\');
         end if;
         Write_Char (C);
      end loop;
   end List_Name;

   ---------------------
   -- List_Object_Info --
   ---------------------

   procedure List_Object_Info (Ent : Entity_Id) is
   begin
      --  If size and alignment have not been computed (e.g. if we are in a
      --  generic unit, or if the back end is not being run), don't try to
      --  print them.

      pragma Assert (Known_Esize (Ent) = Known_Alignment (Ent));
      if not Known_Alignment (Ent) then
         return;
      end if;

      Write_Separator;

      if List_Representation_Info_To_JSON then
         Write_Line ("{");

         Write_Str ("  ""name"": """);
         List_Name (Ent);
         Write_Line (""",");
         List_Location (Ent);

         Write_Str ("  ""Size"": ");
         Write_Val (Esize (Ent));
         Write_Line (",");

         Write_Str ("  ""Alignment"": ");
         Write_Val (Alignment (Ent));

         List_Linker_Section (Ent);

         Write_Eol;
         Write_Line ("}");
      else
         Write_Str ("for ");
         List_Name (Ent);
         Write_Str ("'Size use ");
         Write_Val (Esize (Ent));
         Write_Line (";");

         Write_Str ("for ");
         List_Name (Ent);
         Write_Str ("'Alignment use ");
         Write_Val (Alignment (Ent));
         Write_Line (";");

         List_Linker_Section (Ent);
      end if;

      --  The type is relevant for an object

      if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
         Relevant_Entities.Set (Etype (Ent), True);
      end if;
   end List_Object_Info;

   ----------------------
   -- List_Record_Info --
   ----------------------

   procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is
      procedure Compute_Max_Length
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix_Length      : Natural := 0);
      --  Internal recursive procedure to compute the max length

      procedure List_Component_Layout
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix             : String := "";
         Indent             : Natural := 0);
      --  Procedure to display the layout of a single component

      procedure List_Record_Layout
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix             : String := "");
      --  Internal recursive procedure to display the layout

      procedure List_Structural_Record_Layout
        (Ent       : Entity_Id;
         Ext_Ent   : Entity_Id;
         Ext_Level : Integer := 0;
         Variant   : Node_Id := Empty;
         Indent    : Natural := 0);
      --  Internal recursive procedure to display the structural layout.
      --  If Ext_Ent is not equal to Ent, it is an extension of Ent and
      --  Ext_Level is the number of successive extensions between them,
      --  with the convention that this number is positive when we are
      --  called from the fixed part of Ext_Ent and negative when we are
      --  called from the variant part of Ext_Ent, if any; this is needed
      --  because the fixed and variant parts of a parent of an extension
      --  cannot be listed contiguously from this extension's viewpoint.
      --  If Variant is present, it's for a variant in the variant part
      --  instead of the common part of Ent. Indent is the indentation.

      Incomplete_Layout : exception;
      --  Exception raised if the layout is incomplete in -gnatc mode

      Not_In_Extended_Main : exception;
      --  Exception raised when an ancestor is not declared in the main unit

      Max_Name_Length : Natural := 0;
      Max_Spos_Length : Natural := 0;

      ------------------------
      -- Compute_Max_Length --
      ------------------------

      procedure Compute_Max_Length
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix_Length      : Natural := 0)
      is
         Comp : Entity_Id;

      begin
         Comp := First_Component_Or_Discriminant (Ent);
         while Present (Comp) loop

            --  Skip a completely hidden discriminant or a discriminant in an
            --  unchecked union (since it is not there).

            if Ekind (Comp) = E_Discriminant
              and then (Is_Completely_Hidden (Comp)
                         or else Is_Unchecked_Union (Ent))
            then
               goto Continue;
            end if;

            --  Skip _Parent component in extension (to avoid overlap)

            if Chars (Comp) = Name_uParent then
               goto Continue;
            end if;

            --  All other cases

            declare
               Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
               Bofs : constant Uint      := Component_Bit_Offset (Comp);
               Npos : Uint;
               Fbit : Uint;
               Spos : Uint;
               Sbit : Uint;

               Name_Length : Natural;

            begin
               Get_Decoded_Name_String (Chars (Comp));
               Name_Length := Prefix_Length + Name_Len;

               if Compile_Time_Known_Rep (Bofs) then
                  Npos := Bofs / SSU;
                  Fbit := Bofs mod SSU;

                  --  Complete annotation in case not done

                  if not Known_Normalized_First_Bit (Comp) then
                     Set_Normalized_Position  (Comp, Npos);
                     Set_Normalized_First_Bit (Comp, Fbit);
                  end if;

                  Spos := Starting_Position  + Npos;
                  Sbit := Starting_First_Bit + Fbit;

                  if Sbit >= SSU then
                     Spos := Spos + 1;
                     Sbit := Sbit - SSU;
                  end if;

                  --  If extended information is requested, recurse fully into
                  --  record components, i.e. skip the outer level.

                  if List_Representation_Info_Extended
                    and then Is_Record_Type (Ctyp)
                  then
                     Compute_Max_Length (Ctyp, Spos, Sbit, Name_Length + 1);
                     goto Continue;
                  end if;

                  UI_Image (Spos, Format => Decimal);
               else
                  --  If the record is not packed, then we know that all fields
                  --  whose position is not specified have starting normalized
                  --  bit position of zero.

                  if not Known_Normalized_First_Bit (Comp)
                    and then not Is_Packed (Ent)
                  then
                     Set_Normalized_First_Bit (Comp, Uint_0);
                  end if;

                  UI_Image_Length := 2; -- For "??" marker
               end if;

               Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length);
               Max_Spos_Length :=
                 Natural'Max (Max_Spos_Length, UI_Image_Length);
            end;

         <<Continue>>
            Next_Component_Or_Discriminant (Comp);
         end loop;
      end Compute_Max_Length;

      ---------------------------
      -- List_Component_Layout --
      ---------------------------

      procedure List_Component_Layout
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix             : String := "";
         Indent             : Natural := 0)
      is
         Esiz  : constant Uint := Esize (Ent);
         Npos  : constant Uint := Normalized_Position (Ent);
         Fbit  : constant Uint := Normalized_First_Bit (Ent);
         Spos  : Uint;
         Sbit  : Uint := No_Uint;
         Lbit  : Uint;

      begin
         if List_Representation_Info_To_JSON then
            Spaces (Indent);
            Write_Line ("    {");
            Spaces (Indent);
            Write_Str ("      ""name"": """);
            Write_Str (Prefix);
            Write_Str (Name_Buffer (1 .. Name_Len));
            Write_Line (""",");
            if Ekind (Ent) = E_Discriminant then
               Spaces (Indent);
               Write_Str ("      ""discriminant"": ");
               UI_Write (Discriminant_Number (Ent), Decimal);
               Write_Line (",");
            end if;
            Spaces (Indent);
            Write_Str ("      ""Position"": ");
         else
            Write_Str ("   ");
            Write_Str (Prefix);
            Write_Str (Name_Buffer (1 .. Name_Len));
            Spaces (Max_Name_Length - Prefix'Length - Name_Len);
            Write_Str (" at ");
         end if;

         if Known_Static_Normalized_Position (Ent) then
            Spos := Starting_Position  + Npos;
            Sbit := Starting_First_Bit + Fbit;

            if Sbit >= SSU then
               Spos := Spos + 1;
            end if;

            UI_Image (Spos, Format => Decimal);
            Spaces (Max_Spos_Length - UI_Image_Length);
            Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));

         elsif Known_Normalized_Position (Ent)
           and then List_Representation_Info >= 3
         then
            Spaces (Max_Spos_Length - 2);

            if Starting_Position /= Uint_0 then
               UI_Write (Starting_Position, Decimal);
               Write_Str (" + ");
            end if;

            Write_Val (Npos);

         else
            Write_Unknown_Val;
         end if;

         if List_Representation_Info_To_JSON then
            Write_Line (",");
            Spaces (Indent);
            Write_Str ("      ""First_Bit"": ");
         else
            Write_Str (" range  ");
         end if;

         if Known_Static_Normalized_First_Bit (Ent) then
            Sbit := Starting_First_Bit + Fbit;

            if Sbit >= SSU then
               Sbit := Sbit - SSU;
            end if;

            UI_Write (Sbit, Decimal);
         else
            Write_Unknown_Val;
         end if;

         if List_Representation_Info_To_JSON then
            Write_Line (", ");
            Spaces (Indent);
            Write_Str ("      ""Size"": ");
         else
            Write_Str (" .. ");
         end if;

         if Known_Static_Esize (Ent)
           and then Known_Static_Normalized_First_Bit (Ent)
         then
            Lbit := Sbit + Esiz - 1;

            if List_Representation_Info_To_JSON then
               UI_Write (Esiz, Decimal);
            else
               if Lbit >= 0 and then Lbit < 10 then
                  Write_Char (' ');
               end if;

               UI_Write (Lbit, Decimal);
            end if;

         elsif List_Representation_Info < 3 or else not Known_Esize (Ent) then
            Write_Unknown_Val;

         --  List_Representation >= 3 and Known_Esize (Ent)

         else
            Write_Val (Esiz, Paren => not List_Representation_Info_To_JSON);

            --  Add appropriate first bit offset

            if not List_Representation_Info_To_JSON then
               if Sbit = 0 then
                  Write_Str (" - 1");

               elsif Sbit = 1 then
                  null;

               else
                  Write_Str (" + ");
                  Write_Int (UI_To_Int (Sbit) - 1);
               end if;
            end if;
         end if;

         if List_Representation_Info_To_JSON then
            Write_Eol;
            Spaces (Indent);
            Write_Str ("    }");
         else
            Write_Line (";");
         end if;

         --  The type is relevant for a component

         if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then
            Relevant_Entities.Set (Etype (Ent), True);
         end if;
      end List_Component_Layout;

      ------------------------
      -- List_Record_Layout --
      ------------------------

      procedure List_Record_Layout
        (Ent                : Entity_Id;
         Starting_Position  : Uint := Uint_0;
         Starting_First_Bit : Uint := Uint_0;
         Prefix             : String := "")
      is
         Comp  : Entity_Id;
         First : Boolean := True;

      begin
         Comp := First_Component_Or_Discriminant (Ent);
         while Present (Comp) loop

            --  Skip a completely hidden discriminant or a discriminant in an
            --  unchecked union (since it is not there).

            if Ekind (Comp) = E_Discriminant
              and then (Is_Completely_Hidden (Comp)
                         or else Is_Unchecked_Union (Ent))
            then
               goto Continue;
            end if;

            --  Skip _Parent component in extension (to avoid overlap)

            if Chars (Comp) = Name_uParent then
               goto Continue;
            end if;

            --  All other cases

            declare
               Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
               Npos : constant Uint      := Normalized_Position (Comp);
               Fbit : constant Uint      := Normalized_First_Bit (Comp);
               Spos : Uint;
               Sbit : Uint;

            begin
               Get_Decoded_Name_String (Chars (Comp));
               Set_Casing (Unit_Casing);

               --  If extended information is requested, recurse fully into
               --  record components, i.e. skip the outer level.

               if List_Representation_Info_Extended
                 and then Is_Record_Type (Ctyp)
                 and then Known_Static_Normalized_Position (Comp)
                 and then Known_Static_Normalized_First_Bit (Comp)
               then
                  Spos := Starting_Position  + Npos;
                  Sbit := Starting_First_Bit + Fbit;

                  if Sbit >= SSU then
                     Spos := Spos + 1;
                     Sbit := Sbit - SSU;
                  end if;

                  List_Record_Layout (Ctyp,
                    Spos, Sbit, Prefix & Name_Buffer (1 .. Name_Len) & ".");

                  goto Continue;
               end if;

               if List_Representation_Info_To_JSON then
                  if First then
                     Write_Eol;
                     First := False;
                  else
                     Write_Line (",");
                  end if;
               end if;

               --  The Parent_Subtype in an extension is not back-annotated

               List_Component_Layout (
                 (if Known_Normalized_Position (Comp)
                  then Comp
                  else Original_Record_Component (Comp)),
                 Starting_Position, Starting_First_Bit, Prefix);
            end;

         <<Continue>>
            Next_Component_Or_Discriminant (Comp);
         end loop;
      end List_Record_Layout;

      -----------------------------------
      -- List_Structural_Record_Layout --
      -----------------------------------

      procedure List_Structural_Record_Layout
        (Ent       : Entity_Id;
         Ext_Ent   : Entity_Id;
         Ext_Level : Integer := 0;
         Variant   : Node_Id := Empty;
         Indent    : Natural := 0)
      is
         function Derived_Discriminant (Disc : Entity_Id) return Entity_Id;
         --  This function assumes that Ext_Ent is an extension of Ent.
         --  Disc is a discriminant of Ent that does not itself constrain a
         --  discriminant of the parent type of Ent. Return the discriminant
         --  of Ext_Ent that ultimately constrains Disc, if any.

         ----------------------------
         --  Derived_Discriminant  --
         ----------------------------

         function Derived_Discriminant (Disc : Entity_Id) return Entity_Id is
            Corr_Disc    : Entity_Id;
            Derived_Disc : Entity_Id;

         begin
            --  Deal with an extension of a type with unknown discriminants

            if Has_Unknown_Discriminants (Ext_Ent)
              and then Present (Underlying_Record_View (Ext_Ent))
            then
               Derived_Disc :=
                 First_Discriminant (Underlying_Record_View (Ext_Ent));
            else
               Derived_Disc := First_Discriminant (Ext_Ent);
            end if;

            --  Loop over the discriminants of the extension

            while Present (Derived_Disc) loop

               --  Check if this discriminant constrains another discriminant.
               --  If so, find the ultimately constrained discriminant and
               --  compare with the original components in the base type.

               if Present (Corresponding_Discriminant (Derived_Disc)) then
                  Corr_Disc := Corresponding_Discriminant (Derived_Disc);

                  while Present (Corresponding_Discriminant (Corr_Disc)) loop
                     Corr_Disc := Corresponding_Discriminant (Corr_Disc);
                  end loop;

                  if Original_Record_Component (Corr_Disc) =
                     Original_Record_Component (Disc)
                  then
                     return Derived_Disc;
                  end if;
               end if;

               Next_Discriminant (Derived_Disc);
            end loop;

            --  Disc is not constrained by a discriminant of Ext_Ent

            return Empty;
         end Derived_Discriminant;

         --  Local declarations

         Comp       : Node_Id;
         Comp_List  : Node_Id;
         First      : Boolean := True;
         Parent_Ent : Entity_Id := Empty;
         Var        : Node_Id;

      --  Start of processing for List_Structural_Record_Layout

      begin
         --  If we are dealing with a variant, just process the components

         if Present (Variant) then
            Comp_List := Component_List (Variant);

         --  Otherwise, we are dealing with the full record and need to get
         --  to its definition in order to retrieve its structural layout.

         else
            declare
               Definition : Node_Id :=
                              Type_Definition (Declaration_Node (Ent));

               Is_Extension : constant Boolean :=
                                Is_Tagged_Type (Ent)
                                  and then Nkind (Definition) =
                                             N_Derived_Type_Definition;

               Disc        : Entity_Id;
               Listed_Disc : Entity_Id;
               Parent_Type : Entity_Id;

            begin
               --  If this is an extension, first list the layout of the parent
               --  and then proceed to the extension part, if any.

               if Is_Extension then
                  Parent_Type := Parent_Subtype (Ent);
                  if No (Parent_Type) then
                     raise Incomplete_Layout;
                  end if;

                  if Is_Private_Type (Parent_Type) then
                     Parent_Type := Full_View (Parent_Type);
                     pragma Assert (Present (Parent_Type));
                  end if;

                  --  Do not list variants if one of them has been selected

                  if Has_Static_Discriminants (Parent_Type) then
                     List_Record_Layout (Parent_Type);

                  else
                     Parent_Type := Base_Type (Parent_Type);
                     if not In_Extended_Main_Source_Unit (Parent_Type) then
                        raise Not_In_Extended_Main;
                     end if;

                     Parent_Ent := Parent_Type;
                     if Ext_Level >= 0 then
                        List_Structural_Record_Layout
                          (Parent_Ent, Ext_Ent, Ext_Level + 1);
                     end if;
                  end if;

                  First := False;

                  if Present (Record_Extension_Part (Definition)) then
                     Definition := Record_Extension_Part (Definition);
                  end if;
               end if;

               --  If the record has discriminants and is not an unchecked
               --  union, then display them now. Note that, even if this is
               --  a structural layout, we list the visible discriminants.

               if Has_Discriminants (Ent)
                 and then not Is_Unchecked_Union (Ent)
                 and then Ext_Level >= 0
               then
                  Disc := First_Discriminant (Ent);
                  while Present (Disc) loop

                     --  If this is a record extension and the discriminant is
                     --  the renaming of another discriminant, skip it.

                     if Is_Extension
                       and then Present (Corresponding_Discriminant (Disc))
                     then
                        goto Continue_Disc;
                     end if;

                     --  If this is the parent type of an extension, retrieve
                     --  the derived discriminant from the extension, if any.

                     if Ent /= Ext_Ent then
                        Listed_Disc := Derived_Discriminant (Disc);

                        if No (Listed_Disc) then
                           goto Continue_Disc;

                        elsif not Known_Normalized_Position (Listed_Disc) then
                           Listed_Disc :=
                             Original_Record_Component (Listed_Disc);
                        end if;

                     else
                        Listed_Disc := Disc;
                     end if;

                     Get_Decoded_Name_String (Chars (Listed_Disc));
                     Set_Casing (Unit_Casing);

                     if First then
                        Write_Eol;
                        First := False;
                     else
                        Write_Line (",");
                     end if;

                     List_Component_Layout (Listed_Disc, Indent => Indent);

                  <<Continue_Disc>>
                     Next_Discriminant (Disc);
                  end loop;
               end if;

               Comp_List := Component_List (Definition);
            end;
         end if;

         --  Bail out for the null record

         if No (Comp_List) then
            return;
         end if;

         --  Now deal with the regular components, if any

         if Present (Component_Items (Comp_List))
           and then (Present (Variant) or else Ext_Level >= 0)
         then
            Comp := First_Non_Pragma (Component_Items (Comp_List));
            while Present (Comp) loop

               --  Skip _Parent component in extension (to avoid overlap)

               if Chars (Defining_Identifier (Comp)) = Name_uParent then
                  goto Continue_Comp;
               end if;

               Get_Decoded_Name_String (Chars (Defining_Identifier (Comp)));
               Set_Casing (Unit_Casing);

               if First then
                  Write_Eol;
                  First := False;
               else
                  Write_Line (",");
               end if;

               List_Component_Layout
                 (Defining_Identifier (Comp), Indent => Indent);

            <<Continue_Comp>>
               Next_Non_Pragma (Comp);
            end loop;
         end if;

         --  Stop there if we are called from the fixed part of Ext_Ent,
         --  we'll do the variant part when called from its variant part.

         if Ext_Level > 0 then
            return;
         end if;

         --  List the layout of the variant part of the parent, if any

         if Present (Parent_Ent) then
            List_Structural_Record_Layout
              (Parent_Ent, Ext_Ent, Ext_Level - 1);
         end if;

         --  We are done if there is no variant part

         if No (Variant_Part (Comp_List)) then
            return;
         end if;

         Write_Eol;
         Spaces (Indent);
         Write_Line ("  ],");
         Spaces (Indent);
         Write_Str ("  """);
         for J in Ext_Level .. -1 loop
            Write_Str ("parent_");
         end loop;
         Write_Str ("variant"" : [");

         --  Otherwise we recurse on each variant

         Var := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
         First := True;
         while Present (Var) loop
            if First then
               Write_Eol;
               First := False;
            else
               Write_Line (",");
            end if;

            Spaces (Indent);
            Write_Line ("    {");
            Spaces (Indent);
            Write_Str ("      ""present"": ");
            Write_Val (Present_Expr (Var));
            Write_Line (",");
            Spaces (Indent);
            Write_Str ("      ""record"": [");

            List_Structural_Record_Layout
              (Ent, Ext_Ent, Ext_Level, Var, Indent + 4);

            Write_Eol;
            Spaces (Indent);
            Write_Line ("      ]");
            Spaces (Indent);
            Write_Str ("    }");
            Next_Non_Pragma (Var);
         end loop;
      end List_Structural_Record_Layout;

   --  Start of processing for List_Record_Info

   begin
      Write_Separator;

      if List_Representation_Info_To_JSON then
         Write_Line ("{");
      end if;

      List_Common_Type_Info (Ent);

      --  First find out max line length and max starting position
      --  length, for the purpose of lining things up nicely.

      Compute_Max_Length (Ent);

      --  Then do actual output based on those values

      if List_Representation_Info_To_JSON then
         Write_Line (",");
         Write_Str ("  ""record"": [");

         --  ??? We can output structural layout only for base types fully
         --  declared in the extended main source unit for the time being,
         --  because otherwise declarations might not be processed at all.

         if Is_Base_Type (Ent) then
            begin
               List_Structural_Record_Layout (Ent, Ent);

            exception
               when Incomplete_Layout
                  | Not_In_Extended_Main
               =>
                  List_Record_Layout (Ent);

               when others =>
                  raise Program_Error;
            end;
         else
            List_Record_Layout (Ent);
         end if;

         Write_Eol;
         Write_Str ("  ]");
      else
         Write_Str ("for ");
         List_Name (Ent);
         Write_Line (" use record");

         List_Record_Layout (Ent);

         Write_Line ("end record;");
      end if;

      List_Scalar_Storage_Order (Ent, Bytes_Big_Endian);

      List_Linker_Section (Ent);

      if List_Representation_Info_To_JSON then
         Write_Eol;
         Write_Line ("}");
      end if;

      --  The type is relevant for a record subtype

      if List_Representation_Info = 4
        and then not Is_Base_Type (Ent)
        and then Is_Itype (Etype (Ent))
      then
         Relevant_Entities.Set (Etype (Ent), True);
      end if;
   end List_Record_Info;

   -------------------
   -- List_Rep_Info --
   -------------------

   procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is
      Col : Nat;

   begin
      if List_Representation_Info /= 0
        or else List_Representation_Info_Mechanisms
      then
         --  For the normal case, we output a single JSON stream

         if not List_Representation_Info_To_File
           and then List_Representation_Info_To_JSON
         then
            Write_Line ("[");
            Need_Separator := False;
         end if;

         for U in Main_Unit .. Last_Unit loop
            if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
               Unit_Casing := Identifier_Casing (Source_Index (U));

               if List_Representation_Info = 4 then
                  Relevant_Entities.Reset;
               end if;

               --  Normal case, list to standard output

               if not List_Representation_Info_To_File then
                  if not List_Representation_Info_To_JSON then
                     Write_Eol;
                     Write_Str ("Representation information for unit ");
                     Write_Unit_Name (Unit_Name (U));
                     Col := Column;
                     Write_Eol;

                     for J in 1 .. Col - 1 loop
                        Write_Char ('-');
                     end loop;

                     Write_Eol;
                     Need_Separator := True;
                  end if;

                  List_Entities (Cunit_Entity (U), Bytes_Big_Endian);

               --  List representation information to file

               else
                  Create_Repinfo_File
                    (Get_Name_String (File_Name (Source_Index (U))));
                  Set_Special_Output (Write_Info_Line'Access);
                  if List_Representation_Info_To_JSON then
                     Write_Line ("[");
                  end if;
                  Need_Separator := False;
                  List_Entities (Cunit_Entity (U), Bytes_Big_Endian);
                  if List_Representation_Info_To_JSON then
                     Write_Line ("]");
                  end if;
                  Cancel_Special_Output;
                  Close_Repinfo_File;
               end if;
            end if;
         end loop;

         if not List_Representation_Info_To_File
           and then List_Representation_Info_To_JSON
         then
            Write_Line ("]");
         end if;
      end if;
   end List_Rep_Info;

   -------------------------------
   -- List_Scalar_Storage_Order --
   -------------------------------

   procedure List_Scalar_Storage_Order
     (Ent              : Entity_Id;
      Bytes_Big_Endian : Boolean)
   is
      procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean);
      --  Show attribute definition clause for Attr_Name (an endianness
      --  attribute), depending on whether or not the endianness is reversed
      --  compared to native endianness.

      ---------------
      -- List_Attr --
      ---------------

      procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is
      begin
         if List_Representation_Info_To_JSON then
            Write_Line (",");
            Write_Str ("  """);
            Write_Str (Attr_Name);
            Write_Str (""": ""System.");
         else
            Write_Str ("for ");
            List_Name (Ent);
            Write_Char (''');
            Write_Str (Attr_Name);
            Write_Str (" use System.");
         end if;

         if Bytes_Big_Endian xor Is_Reversed then
            Write_Str ("High");
         else
            Write_Str ("Low");
         end if;

         Write_Str ("_Order_First");
         if List_Representation_Info_To_JSON then
            Write_Str ("""");
         else
            Write_Line (";");
         end if;
      end List_Attr;

      List_SSO : constant Boolean :=
                   Has_Rep_Item (Ent, Name_Scalar_Storage_Order)
                     or else SSO_Set_Low_By_Default  (Ent)
                     or else SSO_Set_High_By_Default (Ent);
      --  Scalar_Storage_Order is displayed if specified explicitly or set by
      --  Default_Scalar_Storage_Order.

   --  Start of processing for List_Scalar_Storage_Order

   begin
      --  For record types, list Bit_Order if not default, or if SSO is shown

      --  Also, when -gnatR4 is in effect always list bit order and scalar
      --  storage order explicitly, so that you don't need to know the native
      --  endianness of the target for which the output was produced in order
      --  to interpret it.

      if Is_Record_Type (Ent)
        and then (List_SSO
                   or else Reverse_Bit_Order (Ent)
                   or else List_Representation_Info = 4)
      then
         List_Attr ("Bit_Order", Reverse_Bit_Order (Ent));
      end if;

      --  List SSO if required. If not, then storage is supposed to be in
      --  native order.

      if List_SSO or else List_Representation_Info = 4 then
         List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent));
      else
         pragma Assert (not Reverse_Storage_Order (Ent));
         null;
      end if;
   end List_Scalar_Storage_Order;

   --------------------------
   -- List_Subprogram_Info --
   --------------------------

   procedure List_Subprogram_Info (Ent : Entity_Id) is
      First : Boolean := True;
      Plen  : Natural;
      Form  : Entity_Id;

   begin
      Write_Separator;

      if List_Representation_Info_To_JSON then
         Write_Line ("{");
         Write_Str ("  ""name"": """);
         List_Name (Ent);
         Write_Line (""",");
         List_Location (Ent);

         Write_Str ("  ""Convention"": """);
      else
         case Ekind (Ent) is
            when E_Function =>
               Write_Str ("function ");

            when E_Operator =>
               Write_Str ("operator ");

            when E_Procedure =>
               Write_Str ("procedure ");

            when E_Subprogram_Type =>
               Write_Str ("type ");

            when E_Entry
               | E_Entry_Family
            =>
               Write_Str ("entry ");

            when others =>
               raise Program_Error;
         end case;

         List_Name (Ent);
         Write_Str (" declared at ");
         Write_Location (Sloc (Ent));
         Write_Eol;

         Write_Str ("convention : ");
      end if;

      case Convention (Ent) is
         when Convention_Ada =>
            Write_Str ("Ada");

         when Convention_Ada_Pass_By_Copy =>
            Write_Str ("Ada_Pass_By_Copy");

         when Convention_Ada_Pass_By_Reference =>
            Write_Str ("Ada_Pass_By_Reference");

         when Convention_Intrinsic =>
            Write_Str ("Intrinsic");

         when Convention_Entry =>
            Write_Str ("Entry");

         when Convention_Protected =>
            Write_Str ("Protected");

         when Convention_Assembler =>
            Write_Str ("Assembler");

         when Convention_C =>
            Write_Str ("C");

         when Convention_C_Variadic =>
            declare
               N : Nat :=
                 Convention_Id'Pos (Convention (Ent)) -
                   Convention_Id'Pos (Convention_C_Variadic_0);
            begin
               Write_Str ("C_Variadic_");
               if N >= 10 then
                  Write_Char ('1');
                  N := N - 10;
               end if;
               pragma Assert (N < 10);
               Write_Char (Character'Val (Character'Pos ('0') + N));
            end;

         when Convention_COBOL =>
            Write_Str ("COBOL");

         when Convention_CPP =>
            Write_Str ("C++");

         when Convention_Fortran =>
            Write_Str ("Fortran");

         when Convention_Stdcall =>
            Write_Str ("Stdcall");

         when Convention_Stubbed =>
            Write_Str ("Stubbed");
      end case;

      if List_Representation_Info_To_JSON then
         Write_Line (""",");
         Write_Str ("  ""formal"": [");
      else
         Write_Eol;
      end if;

      --  Find max length of formal name

      Plen := 0;
      Form := First_Formal (Ent);
      while Present (Form) loop
         Get_Unqualified_Decoded_Name_String (Chars (Form));

         if Name_Len > Plen then
            Plen := Name_Len;
         end if;

         Next_Formal (Form);
      end loop;

      --  Output formals and mechanisms

      Form := First_Formal (Ent);
      while Present (Form) loop
         Get_Unqualified_Decoded_Name_String (Chars (Form));
         Set_Casing (Unit_Casing);

         if List_Representation_Info_To_JSON then
            if First then
               Write_Eol;
               First := False;
            else
               Write_Line (",");
            end if;

            Write_Line ("    {");
            Write_Str ("      ""name"": """);
            Write_Str (Name_Buffer (1 .. Name_Len));
            Write_Line (""",");

            Write_Str ("      ""mechanism"": """);
            Write_Mechanism (Mechanism (Form));
            Write_Line ("""");
            Write_Str ("    }");
         else
            while Name_Len <= Plen loop
               Name_Len := Name_Len + 1;
               Name_Buffer (Name_Len) := ' ';
            end loop;

            Write_Str ("   ");
            Write_Str (Name_Buffer (1 .. Plen + 1));
            Write_Str (": passed by ");

            Write_Mechanism (Mechanism (Form));
            Write_Eol;
         end if;

         Next_Formal (Form);
      end loop;

      if List_Representation_Info_To_JSON then
         Write_Eol;
         Write_Str ("  ]");
      end if;

      if Ekind (Ent) = E_Function then
         if List_Representation_Info_To_JSON then
            Write_Line (",");
            Write_Str ("  ""mechanism"": """);
            Write_Mechanism (Mechanism (Ent));
            Write_Str ("""");
         else
            Write_Str ("returns by ");
            Write_Mechanism (Mechanism (Ent));
            Write_Eol;
         end if;
      end if;

      if not Is_Entry (Ent) then
         List_Linker_Section (Ent);
      end if;

      if List_Representation_Info_To_JSON then
         Write_Eol;
         Write_Line ("}");
      end if;
   end List_Subprogram_Info;

   --------------------
   -- List_Type_Info --
   --------------------

   procedure List_Type_Info (Ent : Entity_Id) is
   begin
      Write_Separator;

      if List_Representation_Info_To_JSON then
         Write_Line ("{");
      end if;

      List_Common_Type_Info (Ent);

      --  Special stuff for fixed-point

      if Is_Fixed_Point_Type (Ent) then

         --  Write small (always a static constant)

         if List_Representation_Info_To_JSON then
            Write_Line (",");
            Write_Str ("  ""Small"": ");
            UR_Write_To_JSON (Small_Value (Ent));
         else
            Write_Str ("for ");
            List_Name (Ent);
            Write_Str ("'Small use ");
            UR_Write (Small_Value (Ent));
            Write_Line (";");
         end if;

         --  Write range if static

         declare
            R : constant Node_Id := Scalar_Range (Ent);

         begin
            if Nkind (Low_Bound (R)) = N_Real_Literal
                 and then
               Nkind (High_Bound (R)) = N_Real_Literal
            then
               if List_Representation_Info_To_JSON then
                  Write_Line (",");
                  Write_Str ("  ""Range"": [ ");
                  UR_Write_To_JSON (Realval (Low_Bound (R)));
                  Write_Str (", ");
                  UR_Write_To_JSON (Realval (High_Bound (R)));
                  Write_Str (" ]");
               else
                  Write_Str ("for ");
                  List_Name (Ent);
                  Write_Str ("'Range use ");
                  UR_Write (Realval (Low_Bound (R)));
                  Write_Str (" .. ");
                  UR_Write (Realval (High_Bound (R)));
                  Write_Line (";");
               end if;
            end if;
         end;
      end if;

      List_Linker_Section (Ent);

      if List_Representation_Info_To_JSON then
         Write_Eol;
         Write_Line ("}");
      end if;
   end List_Type_Info;

   ----------------------------
   -- Compile_Time_Known_Rep --
   ----------------------------

   function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean is
   begin
      return Present (Val) and then Val >= 0;
   end Compile_Time_Known_Rep;

   ---------------
   -- Rep_Value --
   ---------------

   function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is

      function B (Val : Boolean) return Ubool;
      --  Returns Uint_0 for False, Uint_1 for True

      function T (Val : Node_Ref_Or_Val) return Boolean;
      --  Returns True for 0, False for any non-zero (i.e. True)

      function V (Val : Node_Ref_Or_Val) return Uint;
      --  Internal recursive routine to evaluate tree

      function W (Val : Uint) return Word;
      --  Convert Val to Word, assuming Val is always in the Int range. This
      --  is a helper function for the evaluation of bitwise expressions like
      --  Bit_And_Expr, for which there is no direct support in uintp. Uint
      --  values out of the Int range are expected to be seen in such
      --  expressions only with overflowing byte sizes around, introducing
      --  inherent unreliabilities in computations anyway.

      -------
      -- B --
      -------

      function B (Val : Boolean) return Ubool is
      begin
         if Val then
            return Uint_1;
         else
            return Uint_0;
         end if;
      end B;

      -------
      -- T --
      -------

      function T (Val : Node_Ref_Or_Val) return Boolean is
      begin
         if V (Val) = 0 then
            return False;
         else
            return True;
         end if;
      end T;

      -------
      -- V --
      -------

      function V (Val : Node_Ref_Or_Val) return Uint is
         L, R, Q : Uint;

      begin
         if Val >= 0 then
            return Val;

         else
            declare
               Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val));

            begin
               case Node.Expr is
                  when Cond_Expr =>
                     if T (Node.Op1) then
                        return V (Node.Op2);
                     else
                        return V (Node.Op3);
                     end if;

                  when Plus_Expr =>
                     return V (Node.Op1) + V (Node.Op2);

                  when Minus_Expr =>
                     return V (Node.Op1) - V (Node.Op2);

                  when Mult_Expr =>
                     return V (Node.Op1) * V (Node.Op2);

                  when Trunc_Div_Expr =>
                     return V (Node.Op1) / V (Node.Op2);

                  when Ceil_Div_Expr =>
                     return
                       UR_Ceiling
                         (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));

                  when Floor_Div_Expr =>
                     return
                       UR_Floor
                         (V (Node.Op1) / UR_From_Uint (V (Node.Op2)));

                  when Trunc_Mod_Expr =>
                     return V (Node.Op1) rem V (Node.Op2);

                  when Floor_Mod_Expr =>
                     return V (Node.Op1) mod V (Node.Op2);

                  when Ceil_Mod_Expr =>
                     L := V (Node.Op1);
                     R := V (Node.Op2);
                     Q := UR_Ceiling (L / UR_From_Uint (R));
                     return L - R * Q;

                  when Exact_Div_Expr =>
                     return V (Node.Op1) / V (Node.Op2);

                  when Negate_Expr =>
                     return -V (Node.Op1);

                  when Min_Expr =>
                     return UI_Min (V (Node.Op1), V (Node.Op2));

                  when Max_Expr =>
                     return UI_Max (V (Node.Op1), V (Node.Op2));

                  when Abs_Expr =>
                     return UI_Abs (V (Node.Op1));

                  when Truth_And_Expr =>
                     return B (T (Node.Op1) and then T (Node.Op2));

                  when Truth_Or_Expr =>
                     return B (T (Node.Op1) or else T (Node.Op2));

                  when Truth_Xor_Expr =>
                     return B (T (Node.Op1) xor T (Node.Op2));

                  when Truth_Not_Expr =>
                     return B (not T (Node.Op1));

                  when Bit_And_Expr =>
                     L := V (Node.Op1);
                     R := V (Node.Op2);
                     return UI_From_Int (Int (W (L) and W (R)));

                  when Lt_Expr =>
                     return B (V (Node.Op1) < V (Node.Op2));

                  when Le_Expr =>
                     return B (V (Node.Op1) <= V (Node.Op2));

                  when Gt_Expr =>
                     return B (V (Node.Op1) > V (Node.Op2));

                  when Ge_Expr =>
                     return B (V (Node.Op1) >= V (Node.Op2));

                  when Eq_Expr =>
                     return B (V (Node.Op1) = V (Node.Op2));

                  when Ne_Expr =>
                     return B (V (Node.Op1) /= V (Node.Op2));

                  when Discrim_Val =>
                     declare
                        Sub : constant Int := UI_To_Int (Node.Op1);
                     begin
                        pragma Assert (Sub in D'Range);
                        return D (Sub);
                     end;

                  when Dynamic_Val =>
                     return No_Uint;
               end case;
            end;
         end if;
      end V;

      -------
      -- W --
      -------

      --  We use an unchecked conversion to map Int values to their Word
      --  bitwise equivalent, which we could not achieve with a normal type
      --  conversion for negative Ints. We want bitwise equivalents because W
      --  is used as a helper for bit operators like Bit_And_Expr, and can be
      --  called for negative Ints in the context of aligning expressions like
      --  X+Align & -Align.

      function W (Val : Uint) return Word is
         function To_Word is new Ada.Unchecked_Conversion (Int, Word);
      begin
         return To_Word (UI_To_Int (Val));
      end W;

   --  Start of processing for Rep_Value

   begin
      if No (Val) then
         return No_Uint;

      else
         return V (Val);
      end if;
   end Rep_Value;

   ------------
   -- Spaces --
   ------------

   procedure Spaces (N : Natural) is
   begin
      for J in 1 .. N loop
         Write_Char (' ');
      end loop;
   end Spaces;

   ---------------------
   -- Write_Info_Line --
   ---------------------

   procedure Write_Info_Line (S : String) is
   begin
      Write_Repinfo_Line (S (S'First .. S'Last - 1));
   end Write_Info_Line;

   ---------------------
   -- Write_Mechanism --
   ---------------------

   procedure Write_Mechanism (M : Mechanism_Type) is
   begin
      case M is
         when 0 =>
            Write_Str ("default");

         when -1 =>
            Write_Str ("copy");

         when -2 =>
            Write_Str ("reference");

         when others =>
            raise Program_Error;
      end case;
   end Write_Mechanism;

   ---------------------
   -- Write_Separator --
   ---------------------

   procedure Write_Separator is
   begin
      if Need_Separator then
         if List_Representation_Info_To_JSON then
            Write_Line (",");
         else
            Write_Eol;
         end if;
      else
         Need_Separator := True;
      end if;
   end Write_Separator;

   -----------------------
   -- Write_Unknown_Val --
   -----------------------

   procedure Write_Unknown_Val is
   begin
      if List_Representation_Info_To_JSON then
         Write_Str ("""??""");
      else
         Write_Str ("??");
      end if;
   end Write_Unknown_Val;

   ---------------
   -- Write_Val --
   ---------------

   procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is
   begin
      if Compile_Time_Known_Rep (Val) then
         UI_Write (Val, Decimal);
      elsif List_Representation_Info < 3 or else No (Val) then
         Write_Unknown_Val;
      else
         if Paren then
            Write_Char ('(');
         end if;

         List_GCC_Expression (Val);

         if Paren then
            Write_Char (')');
         end if;
      end if;
   end Write_Val;

end Repinfo;