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
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
|
-- Iir to ortho translator.
-- Copyright (C) 2002 - 2014 Tristan Gingold
--
-- GHDL is free software; you can redistribute it and/or modify it under
-- the terms of the GNU General Public License as published by the Free
-- Software Foundation; either version 2, or (at your option) any later
-- version.
--
-- GHDL is distributed in the hope that it will be useful, but WITHOUT 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
-- along with GCC; see the file COPYING. If not, write to the Free
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-- 02111-1307, USA.
with Ada.Text_IO;
with Name_Table;
with Str_Table;
with Iirs_Utils; use Iirs_Utils;
with Iir_Chains; use Iir_Chains;
with Std_Package; use Std_Package;
with Errorout; use Errorout;
with Flags; use Flags;
with Canon;
with Evaluation; use Evaluation;
with Trans.Chap3;
with Trans.Chap4;
with Trans.Chap6;
with Trans.Chap8;
with Trans.Chap14;
with Trans.Rtis;
with Trans_Decls; use Trans_Decls;
with Trans.Helpers2; use Trans.Helpers2;
with Trans.Foreach_Non_Composite;
package body Trans.Chap7 is
use Trans.Helpers;
procedure Copy_Range (Dest : Mnode; Src : Mnode);
procedure Create_Operator_Instance (Interfaces : in out O_Inter_List;
Info : Operator_Info_Acc) is
begin
Subprgs.Add_Subprg_Instance_Interfaces
(Interfaces, Info.Operator_Instance);
end Create_Operator_Instance;
procedure Start_Operator_Instance_Use (Info : Operator_Info_Acc) is
begin
Subprgs.Start_Subprg_Instance_Use (Info.Operator_Instance);
end Start_Operator_Instance_Use;
procedure Finish_Operator_Instance_Use (Info : Operator_Info_Acc) is
begin
Subprgs.Finish_Subprg_Instance_Use (Info.Operator_Instance);
end Finish_Operator_Instance_Use;
function Translate_Static_Implicit_Conv
(Expr : O_Cnode; Expr_Type : Iir; Res_Type : Iir) return O_Cnode
is
Expr_Info : Type_Info_Acc;
Res_Info : Type_Info_Acc;
Val : Var_Type;
Res : O_Cnode;
List : O_Record_Aggr_List;
Bound : Var_Type;
begin
if Res_Type = Expr_Type then
return Expr;
end if;
-- EXPR must be already constrained.
pragma Assert (Get_Kind (Expr_Type) = Iir_Kind_Array_Subtype_Definition);
if Get_Kind (Res_Type) = Iir_Kind_Array_Subtype_Definition
and then Get_Constraint_State (Res_Type) = Fully_Constrained
then
-- constrained to constrained.
if not Chap3.Locally_Array_Match (Expr_Type, Res_Type) then
-- Sem should have replaced the expression by an overflow.
raise Internal_Error;
-- Chap6.Gen_Bound_Error (Loc);
end if;
-- Constrained to constrained should be OK, as already checked by
-- sem.
return Expr;
end if;
-- Handle only constrained to unconstrained conversion.
pragma Assert (Get_Kind (Res_Type) in Iir_Kinds_Array_Type_Definition);
Expr_Info := Get_Info (Expr_Type);
Res_Info := Get_Info (Res_Type);
Val := Create_Global_Const
(Create_Uniq_Identifier, Expr_Info.Ortho_Type (Mode_Value),
O_Storage_Private, Expr);
Bound := Expr_Info.S.Composite_Bounds;
if Bound = Null_Var then
Bound := Create_Global_Const
(Create_Uniq_Identifier, Expr_Info.B.Bounds_Type,
O_Storage_Private,
Chap3.Create_Static_Composite_Subtype_Bounds (Expr_Type));
Expr_Info.S.Composite_Bounds := Bound;
end if;
Start_Record_Aggr (List, Res_Info.Ortho_Type (Mode_Value));
New_Record_Aggr_El
(List, New_Global_Address (Get_Var_Label (Val),
Res_Info.B.Base_Ptr_Type (Mode_Value)));
New_Record_Aggr_El
(List, New_Global_Address (Get_Var_Label (Bound),
Expr_Info.B.Bounds_Ptr_Type));
Finish_Record_Aggr (List, Res);
return Res;
end Translate_Static_Implicit_Conv;
function Is_Static_Constant (Decl : Iir_Constant_Declaration) return Boolean
is
Expr : constant Iir := Get_Default_Value (Decl);
Atype : Iir;
Info : Iir;
begin
if Expr = Null_Iir then
-- Deferred constant.
return False;
end if;
-- Only aggregates are specially handled.
if not Is_Static_Construct (Expr)
or else Get_Kind (Expr) /= Iir_Kind_Aggregate
then
return False;
end if;
Atype := Get_Type (Decl);
-- Currently, only array aggregates are handled.
if Get_Kind (Get_Base_Type (Atype)) /= Iir_Kind_Array_Type_Definition
then
return False;
end if;
Info := Get_Aggregate_Info (Expr);
while Info /= Null_Iir loop
if Get_Aggr_Dynamic_Flag (Info) then
raise Internal_Error;
end if;
-- Currently, only positionnal aggregates are handled.
if Get_Aggr_Named_Flag (Info) then
return False;
end if;
-- Currently, others choice are not handled.
if Get_Aggr_Others_Flag (Info) then
return False;
end if;
Info := Get_Sub_Aggregate_Info (Info);
end loop;
return True;
end Is_Static_Constant;
procedure Translate_Static_String_Literal8_Inner
(List : in out O_Array_Aggr_List;
Str : Iir;
El_Type : Iir)
is
Literal_List : constant Iir_Flist :=
Get_Enumeration_Literal_List (Get_Base_Type (El_Type));
Len : constant Nat32 := Get_String_Length (Str);
Id : constant String8_Id := Get_String8_Id (Str);
Lit : Iir;
begin
for I in 1 .. Len loop
Lit := Get_Nth_Element
(Literal_List, Natural (Str_Table.Element_String8 (Id, Pos32 (I))));
New_Array_Aggr_El (List, Get_Ortho_Expr (Lit));
end loop;
end Translate_Static_String_Literal8_Inner;
procedure Translate_Static_Array_Aggregate_1
(List : in out O_Array_Aggr_List;
Aggr : Iir;
Aggr_Type : Iir;
Dim : Positive)
is
Nbr_Dims : constant Natural := Get_Nbr_Dimensions (Aggr_Type);
El_Type : constant Iir := Get_Element_Subtype (Aggr_Type);
begin
case Get_Kind (Aggr) is
when Iir_Kind_Aggregate =>
declare
Index_Type : constant Iir :=
Get_Index_Type (Aggr_Type, Dim - 1);
Index_Range : constant Iir := Eval_Static_Range (Index_Type);
Len : constant Iir_Int64 :=
Eval_Discrete_Range_Length (Index_Range);
Assocs : constant Iir := Get_Association_Choices_Chain (Aggr);
Vect : Iir_Array (0 .. Integer (Len - 1));
begin
if Len = 0 then
-- Should be automatically handled, but fails with some
-- old versions of gnat (gnatgpl 2014 with -O).
return;
end if;
Build_Array_Choices_Vector (Vect, Index_Range, Assocs);
if Dim = Nbr_Dims then
for I in Vect'Range loop
New_Array_Aggr_El
(List,
Translate_Static_Expression
(Get_Associated_Expr (Vect (I)), El_Type));
end loop;
else
for I in Vect'Range loop
Translate_Static_Array_Aggregate_1
(List, Get_Associated_Expr (Vect (I)),
Aggr_Type, Dim + 1);
end loop;
end if;
end;
when Iir_Kind_String_Literal8 =>
pragma Assert (Dim = Nbr_Dims);
Translate_Static_String_Literal8_Inner (List, Aggr, El_Type);
when others =>
Error_Kind ("translate_static_array_aggregate_1", Aggr);
end case;
end Translate_Static_Array_Aggregate_1;
function Translate_Static_Aggregate (Aggr : Iir) return O_Cnode
is
Aggr_Type : constant Iir := Get_Type (Aggr);
List : O_Array_Aggr_List;
Res : O_Cnode;
begin
Chap3.Translate_Anonymous_Subtype_Definition (Aggr_Type, False);
Start_Array_Aggr (List, Get_Ortho_Type (Aggr_Type, Mode_Value));
Translate_Static_Array_Aggregate_1 (List, Aggr, Aggr_Type, 1);
Finish_Array_Aggr (List, Res);
return Res;
end Translate_Static_Aggregate;
function Translate_Static_Simple_Aggregate (Aggr : Iir) return O_Cnode
is
Aggr_Type : constant Iir := Get_Type (Aggr);
El_List : constant Iir_Flist := Get_Simple_Aggregate_List (Aggr);
El_Type : constant Iir := Get_Element_Subtype (Aggr_Type);
El : Iir;
List : O_Array_Aggr_List;
Res : O_Cnode;
begin
Chap3.Translate_Anonymous_Subtype_Definition (Aggr_Type, False);
Start_Array_Aggr (List, Get_Ortho_Type (Aggr_Type, Mode_Value));
for I in Flist_First .. Flist_Last (El_List) loop
El := Get_Nth_Element (El_List, I);
New_Array_Aggr_El
(List, Translate_Static_Expression (El, El_Type));
end loop;
Finish_Array_Aggr (List, Res);
return Res;
end Translate_Static_Simple_Aggregate;
function Translate_Static_String_Literal8 (Str : Iir) return O_Cnode
is
Lit_Type : constant Iir := Get_Type (Str);
Element_Type : constant Iir := Get_Element_Subtype (Lit_Type);
Arr_Type : O_Tnode;
List : O_Array_Aggr_List;
Res : O_Cnode;
begin
Chap3.Translate_Anonymous_Subtype_Definition (Lit_Type, False);
Arr_Type := Get_Ortho_Type (Lit_Type, Mode_Value);
Start_Array_Aggr (List, Arr_Type);
Translate_Static_String_Literal8_Inner (List, Str, Element_Type);
Finish_Array_Aggr (List, Res);
return Res;
end Translate_Static_String_Literal8;
-- Create a variable (constant) for string or bit string literal STR.
-- The type of the literal element is ELEMENT_TYPE, and the ortho type
-- of the string (a constrained array type) is STR_TYPE.
function Create_String_Literal_Var_Inner
(Str : Iir; Element_Type : Iir; Str_Type : O_Tnode) return Var_Type
is
Val_Aggr : O_Array_Aggr_List;
Res : O_Cnode;
begin
Start_Array_Aggr (Val_Aggr, Str_Type);
case Get_Kind (Str) is
when Iir_Kind_String_Literal8 =>
Translate_Static_String_Literal8_Inner
(Val_Aggr, Str, Element_Type);
when others =>
raise Internal_Error;
end case;
Finish_Array_Aggr (Val_Aggr, Res);
return Create_Global_Const
(Create_Uniq_Identifier, Str_Type, O_Storage_Private, Res);
end Create_String_Literal_Var_Inner;
-- Create a variable (constant) for string or bit string literal STR.
function Create_String_Literal_Var (Str : Iir) return Var_Type
is
Str_Type : constant Iir := Get_Type (Str);
Arr_Type : O_Tnode;
begin
-- Create the string value.
Arr_Type := New_Constrained_Array_Type
(Get_Info (Str_Type).B.Base_Type (Mode_Value),
New_Unsigned_Literal (Ghdl_Index_Type,
Unsigned_64 (Get_String_Length (Str))));
return Create_String_Literal_Var_Inner
(Str, Get_Element_Subtype (Str_Type), Arr_Type);
end Create_String_Literal_Var;
-- Some strings literal have an unconstrained array type,
-- eg: 'image of constant. Its type is not constrained
-- because it is not so in VHDL!
function Translate_Non_Static_String_Literal (Str : Iir) return O_Enode
is
Len : constant Nat32 := Get_String_Length (Str);
Lit_Type : constant Iir := Get_Type (Str);
Type_Info : constant Type_Info_Acc := Get_Info (Lit_Type);
Index_Type : constant Iir := Get_Index_Type (Lit_Type, 0);
Index_Type_Info : constant Type_Info_Acc := Get_Info (Index_Type);
Bound_Aggr : O_Record_Aggr_List;
Index_Aggr : O_Record_Aggr_List;
Res_Aggr : O_Record_Aggr_List;
Res : O_Cnode;
Val : Var_Type;
Bound : Var_Type;
R : O_Enode;
begin
-- Create the string value.
Val := Create_String_Literal_Var (Str);
if Type_Info.Type_Mode = Type_Mode_Fat_Array then
-- Create the string bound.
Start_Record_Aggr (Bound_Aggr, Type_Info.B.Bounds_Type);
Start_Record_Aggr (Index_Aggr, Index_Type_Info.B.Range_Type);
New_Record_Aggr_El
(Index_Aggr,
New_Signed_Literal
(Index_Type_Info.Ortho_Type (Mode_Value), 1));
New_Record_Aggr_El
(Index_Aggr,
New_Signed_Literal (Index_Type_Info.Ortho_Type (Mode_Value),
Integer_64 (Len)));
New_Record_Aggr_El
(Index_Aggr, Ghdl_Dir_To_Node);
New_Record_Aggr_El
(Index_Aggr,
New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Len)));
Finish_Record_Aggr (Index_Aggr, Res);
New_Record_Aggr_El (Bound_Aggr, Res);
Finish_Record_Aggr (Bound_Aggr, Res);
Bound := Create_Global_Const
(Create_Uniq_Identifier, Type_Info.B.Bounds_Type,
O_Storage_Private, Res);
-- The descriptor.
Start_Record_Aggr (Res_Aggr, Type_Info.Ortho_Type (Mode_Value));
New_Record_Aggr_El
(Res_Aggr,
New_Global_Address (Get_Var_Label (Val),
Type_Info.B.Base_Ptr_Type (Mode_Value)));
New_Record_Aggr_El
(Res_Aggr,
New_Global_Address (Get_Var_Label (Bound),
Type_Info.B.Bounds_Ptr_Type));
Finish_Record_Aggr (Res_Aggr, Res);
Val := Create_Global_Const
(Create_Uniq_Identifier, Type_Info.Ortho_Type (Mode_Value),
O_Storage_Private, Res);
elsif Type_Info.Type_Mode in Type_Mode_Bounded_Arrays then
-- Type of string literal isn't statically known; check the
-- length.
Chap6.Check_Bound_Error
(New_Compare_Op
(ON_Neq,
New_Lit (New_Index_Lit (Unsigned_64 (Len))),
Chap3.Get_Array_Type_Length (Lit_Type),
Ghdl_Bool_Type),
Str, 1);
else
raise Internal_Error;
end if;
R := New_Address (Get_Var (Val),
Type_Info.Ortho_Ptr_Type (Mode_Value));
return R;
end Translate_Non_Static_String_Literal;
-- Only for Strings of STD.Character.
function Translate_Static_String (Str_Type : Iir; Str_Ident : Name_Id)
return O_Cnode
is
Img : constant String := Name_Table.Image (Str_Ident);
Literal_List : constant Iir_Flist :=
Get_Enumeration_Literal_List (Character_Type_Definition);
Lit : Iir;
List : O_Array_Aggr_List;
Res : O_Cnode;
begin
Chap3.Translate_Anonymous_Subtype_Definition (Str_Type, False);
Start_Array_Aggr (List, Get_Ortho_Type (Str_Type, Mode_Value));
for I in Img'Range loop
Lit := Get_Nth_Element (Literal_List, Character'Pos (Img (I)));
New_Array_Aggr_El (List, Get_Ortho_Expr (Lit));
end loop;
Finish_Array_Aggr (List, Res);
return Res;
end Translate_Static_String;
function Translate_Composite_Literal (Str : Iir; Res_Type : Iir)
return O_Enode
is
Str_Type : constant Iir := Get_Type (Str);
Is_Static : Boolean;
Vtype : Iir;
Var : Var_Type;
Info : Type_Info_Acc;
Res : O_Cnode;
R : O_Enode;
begin
if Get_Constraint_State (Str_Type) = Fully_Constrained
and then Are_Array_Indexes_Locally_Static (Str_Type)
then
Chap3.Create_Array_Subtype (Str_Type);
case Get_Kind (Str) is
when Iir_Kind_String_Literal8 =>
Res := Translate_Static_String_Literal8 (Str);
when Iir_Kind_Simple_Aggregate =>
Res := Translate_Static_Simple_Aggregate (Str);
when Iir_Kind_Simple_Name_Attribute =>
Res := Translate_Static_String
(Get_Type (Str), Get_Simple_Name_Identifier (Str));
when Iir_Kind_Aggregate =>
Res := Translate_Static_Aggregate (Str);
when others =>
raise Internal_Error;
end case;
Is_Static := Are_Array_Indexes_Locally_Static (Res_Type);
if Is_Static then
Res := Translate_Static_Implicit_Conv (Res, Str_Type, Res_Type);
Vtype := Res_Type;
else
Vtype := Str_Type;
end if;
Info := Get_Info (Vtype);
Var := Create_Global_Const
(Create_Uniq_Identifier, Info.Ortho_Type (Mode_Value),
O_Storage_Private, Res);
R := New_Address (Get_Var (Var), Info.Ortho_Ptr_Type (Mode_Value));
if not Is_Static then
R := Translate_Implicit_Conv
(R, Str_Type, Res_Type, Mode_Value, Str);
end if;
return R;
else
return Translate_Implicit_Conv
(Translate_Non_Static_String_Literal (Str), Str_Type, Res_Type,
Mode_Value, Str);
end if;
end Translate_Composite_Literal;
function Translate_Enumeration_Literal (Atype : Iir; Pos : Natural)
return O_Cnode
is
Lit_List : constant Iir_Flist :=
Get_Enumeration_Literal_List (Get_Base_Type (Atype));
Enum : constant Iir := Get_Nth_Element (Lit_List, Pos);
begin
return Get_Ortho_Expr (Enum);
end Translate_Enumeration_Literal;
function Translate_Numeric_Literal (Expr : Iir; Res_Type : O_Tnode)
return O_Cnode is
begin
case Get_Kind (Expr) is
when Iir_Kind_Integer_Literal =>
return New_Signed_Literal
(Res_Type, Integer_64 (Get_Value (Expr)));
when Iir_Kind_Enumeration_Literal =>
return Translate_Enumeration_Literal
(Get_Type (Expr), Natural (Get_Enum_Pos (Expr)));
when Iir_Kind_Floating_Point_Literal =>
return New_Float_Literal
(Res_Type, IEEE_Float_64 (Get_Fp_Value (Expr)));
when Iir_Kind_Physical_Int_Literal
| Iir_Kind_Physical_Fp_Literal
| Iir_Kind_Unit_Declaration =>
return New_Signed_Literal
(Res_Type, Integer_64 (Get_Physical_Value (Expr)));
when others =>
Error_Kind ("translate_numeric_literal", Expr);
end case;
exception
when Constraint_Error =>
-- Can be raised by Get_Physical_Value.
Error_Msg_Elab (Expr, "numeric literal not in range");
return New_Signed_Literal (Res_Type, 0);
end Translate_Numeric_Literal;
function Translate_Numeric_Literal (Expr : Iir; Res_Type : Iir)
return O_Cnode
is
Expr_Type : constant Iir := Get_Type (Expr);
Expr_Otype : O_Tnode;
Tinfo : Type_Info_Acc;
begin
Tinfo := Get_Info (Expr_Type);
if Res_Type /= Null_Iir then
Expr_Otype := Get_Ortho_Type (Res_Type, Mode_Value);
else
if Tinfo = null then
-- FIXME: this is a working kludge, in the case where EXPR_TYPE
-- is a subtype which was not yet translated.
-- (eg: evaluated array attribute)
Tinfo := Get_Info (Get_Base_Type (Expr_Type));
end if;
Expr_Otype := Tinfo.Ortho_Type (Mode_Value);
end if;
return Translate_Numeric_Literal (Expr, Expr_Otype);
end Translate_Numeric_Literal;
function Translate_Static_Expression (Expr : Iir; Res_Type : Iir)
return O_Cnode
is
Expr_Type : constant Iir := Get_Type (Expr);
begin
case Get_Kind (Expr) is
when Iir_Kind_Integer_Literal
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Floating_Point_Literal
| Iir_Kind_Physical_Int_Literal
| Iir_Kind_Unit_Declaration
| Iir_Kind_Physical_Fp_Literal =>
return Translate_Numeric_Literal (Expr, Res_Type);
when Iir_Kind_String_Literal8 =>
return Translate_Static_Implicit_Conv
(Translate_Static_String_Literal8 (Expr),
Expr_Type, Res_Type);
when Iir_Kind_Simple_Aggregate =>
return Translate_Static_Implicit_Conv
(Translate_Static_Simple_Aggregate (Expr),
Expr_Type, Res_Type);
when Iir_Kind_Aggregate =>
return Translate_Static_Implicit_Conv
(Translate_Static_Aggregate (Expr), Expr_Type, Res_Type);
when Iir_Kinds_Denoting_Name =>
return Translate_Static_Expression
(Get_Named_Entity (Expr), Res_Type);
when others =>
Error_Kind ("translate_static_expression", Expr);
end case;
end Translate_Static_Expression;
function Translate_Static_Range_Left
(Expr : Iir; Range_Type : Iir := Null_Iir) return O_Cnode
is
Bound : constant Iir := Get_Left_Limit (Expr);
Left : O_Cnode;
begin
Left := Chap7.Translate_Static_Expression (Bound, Range_Type);
-- if Range_Type /= Null_Iir
-- and then Get_Type (Bound) /= Range_Type then
-- Left := New_Convert_Ov
-- (Left, Get_Ortho_Type (Range_Type, Mode_Value));
-- end if;
return Left;
end Translate_Static_Range_Left;
function Translate_Static_Range_Right
(Expr : Iir; Range_Type : Iir := Null_Iir) return O_Cnode
is
Right : O_Cnode;
begin
Right := Chap7.Translate_Static_Expression (Get_Right_Limit (Expr),
Range_Type);
-- if Range_Type /= Null_Iir then
-- Right := New_Convert_Ov
-- (Right, Get_Ortho_Type (Range_Type, Mode_Value));
-- end if;
return Right;
end Translate_Static_Range_Right;
function Translate_Static_Range_Dir (Expr : Iir) return O_Cnode is
begin
case Get_Direction (Expr) is
when Iir_To =>
return Ghdl_Dir_To_Node;
when Iir_Downto =>
return Ghdl_Dir_Downto_Node;
end case;
end Translate_Static_Range_Dir;
function Translate_Static_Range_Length (Expr : Iir) return O_Cnode
is
Ulen : Unsigned_64;
begin
Ulen := Unsigned_64 (Eval_Discrete_Range_Length (Expr));
return New_Unsigned_Literal (Ghdl_Index_Type, Ulen);
end Translate_Static_Range_Length;
function Translate_Range_Expression_Left
(Expr : Iir; Range_Type : Iir := Null_Iir) return O_Enode
is
Left : O_Enode;
begin
Left := Chap7.Translate_Expression (Get_Left_Limit (Expr));
if Range_Type /= Null_Iir then
Left := New_Convert_Ov (Left,
Get_Ortho_Type (Range_Type, Mode_Value));
end if;
return Left;
end Translate_Range_Expression_Left;
function Translate_Range_Expression_Right
(Expr : Iir; Range_Type : Iir := Null_Iir) return O_Enode
is
Right : O_Enode;
begin
Right := Chap7.Translate_Expression (Get_Right_Limit (Expr));
if Range_Type /= Null_Iir then
Right := New_Convert_Ov (Right,
Get_Ortho_Type (Range_Type, Mode_Value));
end if;
return Right;
end Translate_Range_Expression_Right;
-- Compute the length of LEFT DIR (to/downto) RIGHT.
function Compute_Range_Length
(Left : O_Enode; Right : O_Enode; Dir : Iir_Direction) return O_Enode
is
Rng_Type : constant O_Tnode := Ghdl_I32_Type;
L : constant O_Enode := New_Convert_Ov (Left, Rng_Type);
R : constant O_Enode := New_Convert_Ov (Right, Rng_Type);
Val : O_Enode;
Tmp : O_Dnode;
Res : O_Dnode;
If_Blk : O_If_Block;
begin
case Dir is
when Iir_To =>
Val := New_Dyadic_Op (ON_Sub_Ov, R, L);
when Iir_Downto =>
Val := New_Dyadic_Op (ON_Sub_Ov, L, R);
end case;
Res := Create_Temp (Ghdl_Index_Type);
Open_Temp;
Tmp := Create_Temp (Rng_Type);
New_Assign_Stmt (New_Obj (Tmp), Val);
Start_If_Stmt
(If_Blk,
New_Compare_Op (ON_Lt, New_Obj_Value (Tmp),
New_Lit (New_Signed_Literal (Rng_Type, 0)),
Ghdl_Bool_Type));
Init_Var (Res);
New_Else_Stmt (If_Blk);
Val := New_Convert_Ov (New_Obj_Value (Tmp), Ghdl_Index_Type);
Val := New_Dyadic_Op (ON_Add_Ov, Val, New_Lit (Ghdl_Index_1));
New_Assign_Stmt (New_Obj (Res), Val);
Finish_If_Stmt (If_Blk);
Close_Temp;
return New_Obj_Value (Res);
end Compute_Range_Length;
function Translate_Range_Expression_Length (Expr : Iir) return O_Enode
is
Left, Right : O_Enode;
begin
if Get_Expr_Staticness (Expr) = Locally then
return New_Lit (Translate_Static_Range_Length (Expr));
else
Left := Chap7.Translate_Expression (Get_Left_Limit (Expr));
Right := Chap7.Translate_Expression (Get_Right_Limit (Expr));
return Compute_Range_Length (Left, Right, Get_Direction (Expr));
end if;
end Translate_Range_Expression_Length;
function Translate_Range_Length (Expr : Iir) return O_Enode is
begin
case Get_Kind (Expr) is
when Iir_Kind_Range_Expression =>
return Translate_Range_Expression_Length (Expr);
when Iir_Kind_Range_Array_Attribute =>
return Chap14.Translate_Length_Array_Attribute (Expr, Null_Iir);
when others =>
Error_Kind ("translate_range_length", Expr);
end case;
end Translate_Range_Length;
function Translate_Operator_Function_Call
(Call : Iir; Left : Iir; Right : Iir; Res_Type : Iir) return O_Enode
is
Imp : constant Iir := Get_Implementation (Call);
function Create_Assoc (Actual : Iir) return Iir
is
R : Iir;
begin
R := Create_Iir (Iir_Kind_Association_Element_By_Expression);
Location_Copy (R, Actual);
Set_Actual (R, Actual);
return R;
end Create_Assoc;
El_L : Iir;
El_R : Iir;
Res : O_Enode;
begin
El_L := Create_Assoc (Left);
if Right /= Null_Iir then
El_R := Create_Assoc (Right);
Set_Chain (El_L, El_R);
end if;
Res := Chap8.Translate_Subprogram_Call (Call, El_L, Null_Iir);
Free_Iir (El_L);
if Right /= Null_Iir then
Free_Iir (El_R);
end if;
return Translate_Implicit_Conv
(Res, Get_Return_Type (Imp), Res_Type, Mode_Value, Left);
end Translate_Operator_Function_Call;
function Convert_Constrained_To_Unconstrained
(Expr : Mnode; Res_Type : Iir) return Mnode
is
Type_Info : constant Type_Info_Acc := Get_Info (Res_Type);
Kind : constant Object_Kind_Type := Get_Object_Kind (Expr);
Stable_Expr : Mnode;
Res : Mnode;
begin
Res := Create_Temp (Type_Info, Kind);
Stable_Expr := Stabilize (Expr);
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Res)),
New_Convert_Ov (M2Addr (Chap3.Get_Composite_Base (Stable_Expr)),
Type_Info.B.Base_Ptr_Type (Kind)));
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)),
M2Addr (Chap3.Get_Composite_Bounds (Stable_Expr)));
return Res;
end Convert_Constrained_To_Unconstrained;
-- Innert procedure for Convert_Unconstrained_To_Constrained.
procedure Convert_To_Constrained_Check
(Bounds : Mnode; Expr_Type : Iir; Atype : Iir; Failure_Label : O_Snode)
is
Stable_Bounds : Mnode;
begin
Open_Temp;
Stable_Bounds := Stabilize (Bounds);
case Get_Kind (Expr_Type) is
when Iir_Kind_Array_Type_Definition
| Iir_Kind_Array_Subtype_Definition =>
declare
Expr_Indexes : constant Iir_Flist :=
Get_Index_Subtype_List (Expr_Type);
begin
for I in 1 .. Get_Nbr_Elements (Expr_Indexes) loop
Gen_Exit_When
(Failure_Label,
New_Compare_Op
(ON_Neq,
M2E (Chap3.Range_To_Length
(Chap3.Bounds_To_Range
(Stable_Bounds, Expr_Type, I))),
Chap6.Get_Array_Bound_Length
(T2M (Atype, Mode_Value), Atype, I),
Ghdl_Bool_Type));
end loop;
end;
when Iir_Kind_Record_Type_Definition
| Iir_Kind_Record_Subtype_Definition =>
declare
Expr_Els : constant Iir_Flist :=
Get_Elements_Declaration_List (Expr_Type);
Atype_Els : constant Iir_Flist :=
Get_Elements_Declaration_List (Atype);
Expr_El, Atype_El : Iir;
Expr_El_Type, Atype_El_Type : Iir;
begin
for I in Flist_First .. Flist_Last (Expr_Els) loop
Expr_El := Get_Nth_Element (Expr_Els, I);
Atype_El := Get_Nth_Element (Atype_Els, I);
Expr_El_Type := Get_Type (Expr_El);
Atype_El_Type := Get_Type (Atype_El);
if Expr_El_Type /= Atype_El_Type then
Convert_To_Constrained_Check
(Chap3.Bounds_To_Element_Bounds
(Stable_Bounds, Expr_El),
Expr_El_Type, Atype_El_Type, Failure_Label);
end if;
end loop;
end;
when others =>
Error_Kind ("convert_unconstrained_to_constrained_check",
Expr_Type);
end case;
Close_Temp;
end Convert_To_Constrained_Check;
function Convert_To_Constrained
(Expr : Mnode; Expr_Type : Iir; Atype : Iir; Loc : Iir) return Mnode
is
Expr_Stable : Mnode;
Success_Label : O_Snode;
Failure_Label : O_Snode;
begin
Expr_Stable := Stabilize (Expr);
Open_Temp;
-- Check each dimension.
Start_Loop_Stmt (Success_Label);
Start_Loop_Stmt (Failure_Label);
Convert_To_Constrained_Check
(Chap3.Get_Composite_Bounds (Expr_Stable), Expr_Type,
Atype, Failure_Label);
New_Exit_Stmt (Success_Label);
Finish_Loop_Stmt (Failure_Label);
Chap6.Gen_Bound_Error (Loc);
Finish_Loop_Stmt (Success_Label);
Close_Temp;
declare
Ainfo : constant Type_Info_Acc := Get_Info (Atype);
Kind : constant Object_Kind_Type := Get_Object_Kind (Expr);
Nptr : O_Enode;
begin
-- Pointer to the array.
Nptr := M2E (Chap3.Get_Composite_Base (Expr_Stable));
-- Convert it to pointer to the constrained type.
Nptr := New_Convert_Ov (Nptr, Ainfo.Ortho_Ptr_Type (Kind));
return E2M (Nptr, Ainfo, Kind);
end;
end Convert_To_Constrained;
function Translate_Implicit_Array_Conversion
(Expr : Mnode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir) return Mnode
is
Ainfo : Type_Info_Acc;
Einfo : Type_Info_Acc;
begin
pragma Assert
(Get_Kind (Expr_Type) in Iir_Kinds_Array_Type_Definition);
if Res_Type = Expr_Type then
return Expr;
end if;
Ainfo := Get_Info (Res_Type);
Einfo := Get_Info (Expr_Type);
case Ainfo.Type_Mode is
when Type_Mode_Unbounded_Array =>
-- X to unconstrained.
case Einfo.Type_Mode is
when Type_Mode_Unbounded_Array =>
-- unconstrained to unconstrained.
return Expr;
when Type_Mode_Bounded_Arrays =>
-- constrained to unconstrained.
return Convert_Constrained_To_Unconstrained (Expr, Res_Type);
when others =>
raise Internal_Error;
end case;
when Type_Mode_Static_Array =>
if Einfo.Type_Mode = Type_Mode_Static_Array then
-- FIXME: optimize static vs non-static
-- constrained to constrained.
if not Chap3.Locally_Array_Match (Expr_Type, Res_Type) then
-- FIXME: generate a bound error ?
-- Even if this is caught at compile-time,
-- the code is not required to run.
Chap6.Gen_Bound_Error (Loc);
end if;
return Expr;
else
-- Unbounded/bounded array to bounded array.
return Convert_To_Constrained (Expr, Expr_Type, Res_Type, Loc);
end if;
when Type_Mode_Complex_Array =>
return Convert_To_Constrained (Expr, Expr_Type, Res_Type, Loc);
when others =>
raise Internal_Error;
end case;
end Translate_Implicit_Array_Conversion;
function Translate_Implicit_Record_Conversion
(Expr : Mnode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir) return Mnode
is
Ainfo : Type_Info_Acc;
Einfo : Type_Info_Acc;
begin
if Res_Type = Expr_Type then
return Expr;
end if;
Ainfo := Get_Info (Res_Type);
Einfo := Get_Info (Expr_Type);
case Ainfo.Type_Mode is
when Type_Mode_Unbounded_Record =>
-- X to unbounded.
case Einfo.Type_Mode is
when Type_Mode_Unbounded_Record =>
-- unbounded to unbounded
return Expr;
when Type_Mode_Bounded_Records =>
-- bounded to unconstrained.
return Convert_Constrained_To_Unconstrained (Expr, Res_Type);
when others =>
raise Internal_Error;
end case;
when Type_Mode_Bounded_Records =>
-- X to bounded
case Einfo.Type_Mode is
when Type_Mode_Unbounded_Record =>
-- unbounded to bounded.
return Convert_To_Constrained
(Expr, Expr_Type, Res_Type, Loc);
when Type_Mode_Bounded_Records =>
-- bounded to bounded.
-- TODO: likewise ? check bounds ?
return Expr;
when others =>
raise Internal_Error;
end case;
when others =>
raise Internal_Error;
end case;
end Translate_Implicit_Record_Conversion;
-- Convert (if necessary) EXPR translated from EXPR_ORIG to type ATYPE.
function Translate_Implicit_Conv (Expr : O_Enode;
Expr_Type : Iir;
Atype : Iir;
Is_Sig : Object_Kind_Type;
Loc : Iir)
return O_Enode is
begin
-- Same type: nothing to do.
if Atype = Expr_Type then
return Expr;
end if;
if Expr_Type = Universal_Integer_Type_Definition then
return New_Convert_Ov (Expr, Get_Ortho_Type (Atype, Mode_Value));
elsif Expr_Type = Universal_Real_Type_Definition then
return New_Convert_Ov (Expr, Get_Ortho_Type (Atype, Mode_Value));
else
case Get_Kind (Expr_Type) is
when Iir_Kinds_Array_Type_Definition =>
return M2E (Translate_Implicit_Array_Conversion
(E2M (Expr, Get_Info (Expr_Type), Is_Sig),
Expr_Type, Atype, Loc));
when Iir_Kind_Record_Type_Definition
| Iir_Kind_Record_Subtype_Definition =>
return M2E (Translate_Implicit_Record_Conversion
(E2M (Expr, Get_Info (Expr_Type), Is_Sig),
Expr_Type, Atype, Loc));
when others =>
return Expr;
end case;
end if;
end Translate_Implicit_Conv;
type Predefined_To_Onop_Type is
array (Iir_Predefined_Functions) of ON_Op_Kind;
Predefined_To_Onop : constant Predefined_To_Onop_Type :=
(Iir_Predefined_Boolean_Or => ON_Or,
Iir_Predefined_Boolean_Not => ON_Not,
Iir_Predefined_Boolean_And => ON_And,
Iir_Predefined_Boolean_Xor => ON_Xor,
Iir_Predefined_Bit_Not => ON_Not,
Iir_Predefined_Bit_And => ON_And,
Iir_Predefined_Bit_Or => ON_Or,
Iir_Predefined_Bit_Xor => ON_Xor,
Iir_Predefined_Integer_Equality => ON_Eq,
Iir_Predefined_Integer_Inequality => ON_Neq,
Iir_Predefined_Integer_Less_Equal => ON_Le,
Iir_Predefined_Integer_Less => ON_Lt,
Iir_Predefined_Integer_Greater => ON_Gt,
Iir_Predefined_Integer_Greater_Equal => ON_Ge,
Iir_Predefined_Integer_Plus => ON_Add_Ov,
Iir_Predefined_Integer_Minus => ON_Sub_Ov,
Iir_Predefined_Integer_Mul => ON_Mul_Ov,
Iir_Predefined_Integer_Rem => ON_Rem_Ov,
Iir_Predefined_Integer_Mod => ON_Mod_Ov,
Iir_Predefined_Integer_Div => ON_Div_Ov,
Iir_Predefined_Integer_Absolute => ON_Abs_Ov,
Iir_Predefined_Integer_Negation => ON_Neg_Ov,
Iir_Predefined_Enum_Equality => ON_Eq,
Iir_Predefined_Enum_Inequality => ON_Neq,
Iir_Predefined_Enum_Greater_Equal => ON_Ge,
Iir_Predefined_Enum_Greater => ON_Gt,
Iir_Predefined_Enum_Less => ON_Lt,
Iir_Predefined_Enum_Less_Equal => ON_Le,
Iir_Predefined_Physical_Equality => ON_Eq,
Iir_Predefined_Physical_Inequality => ON_Neq,
Iir_Predefined_Physical_Less => ON_Lt,
Iir_Predefined_Physical_Less_Equal => ON_Le,
Iir_Predefined_Physical_Greater => ON_Gt,
Iir_Predefined_Physical_Greater_Equal => ON_Ge,
Iir_Predefined_Physical_Negation => ON_Neg_Ov,
Iir_Predefined_Physical_Absolute => ON_Abs_Ov,
Iir_Predefined_Physical_Minus => ON_Sub_Ov,
Iir_Predefined_Physical_Plus => ON_Add_Ov,
Iir_Predefined_Floating_Greater => ON_Gt,
Iir_Predefined_Floating_Greater_Equal => ON_Ge,
Iir_Predefined_Floating_Less => ON_Lt,
Iir_Predefined_Floating_Less_Equal => ON_Le,
Iir_Predefined_Floating_Equality => ON_Eq,
Iir_Predefined_Floating_Inequality => ON_Neq,
Iir_Predefined_Floating_Minus => ON_Sub_Ov,
Iir_Predefined_Floating_Plus => ON_Add_Ov,
Iir_Predefined_Floating_Mul => ON_Mul_Ov,
Iir_Predefined_Floating_Div => ON_Div_Ov,
Iir_Predefined_Floating_Negation => ON_Neg_Ov,
Iir_Predefined_Floating_Absolute => ON_Abs_Ov,
others => ON_Nil);
function Translate_Shortcut_Operator
(Imp : Iir_Function_Declaration; Left, Right : Iir) return O_Enode
is
Rtype : Iir;
Res : O_Dnode;
Res_Type : O_Tnode;
If_Blk : O_If_Block;
Val : Integer;
V : O_Cnode;
Kind : Iir_Predefined_Functions;
Invert : Boolean;
begin
Rtype := Get_Return_Type (Imp);
Res_Type := Get_Ortho_Type (Rtype, Mode_Value);
Res := Create_Temp (Res_Type);
Open_Temp;
New_Assign_Stmt (New_Obj (Res), Chap7.Translate_Expression (Left));
Close_Temp;
Kind := Get_Implicit_Definition (Imp);
-- Short cut: RIGHT is the result (and must be evaluated) iff
-- LEFT is equal to VAL (ie '0' or false for 0, '1' or true for 1).
case Kind is
when Iir_Predefined_Bit_And
| Iir_Predefined_Boolean_And =>
Invert := False;
Val := 1;
when Iir_Predefined_Bit_Nand
| Iir_Predefined_Boolean_Nand =>
Invert := True;
Val := 1;
when Iir_Predefined_Bit_Or
| Iir_Predefined_Boolean_Or =>
Invert := False;
Val := 0;
when Iir_Predefined_Bit_Nor
| Iir_Predefined_Boolean_Nor =>
Invert := True;
Val := 0;
when others =>
Ada.Text_IO.Put_Line
("translate_shortcut_operator: cannot handle "
& Iir_Predefined_Functions'Image (Kind));
raise Internal_Error;
end case;
V := Get_Ortho_Expr
(Get_Nth_Element (Get_Enumeration_Literal_List (Rtype), Val));
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Eq,
New_Obj_Value (Res), New_Lit (V),
Ghdl_Bool_Type));
Open_Temp;
New_Assign_Stmt (New_Obj (Res), Chap7.Translate_Expression (Right));
Close_Temp;
Finish_If_Stmt (If_Blk);
if Invert then
return New_Monadic_Op (ON_Not, New_Obj_Value (Res));
else
return New_Obj_Value (Res);
end if;
end Translate_Shortcut_Operator;
function Translate_Lib_Operator (Left, Right : O_Enode; Func : O_Dnode)
return O_Enode
is
Constr : O_Assoc_List;
begin
Start_Association (Constr, Func);
New_Association (Constr, Left);
if Right /= O_Enode_Null then
New_Association (Constr, Right);
end if;
return New_Function_Call (Constr);
end Translate_Lib_Operator;
function Translate_Predefined_Lib_Operator
(Left, Right : O_Enode; Func : Iir_Function_Declaration) return O_Enode
is
Info : constant Operator_Info_Acc := Get_Info (Func);
Constr : O_Assoc_List;
begin
Start_Association (Constr, Info.Operator_Node);
Subprgs.Add_Subprg_Instance_Assoc (Constr, Info.Operator_Instance);
New_Association (Constr, Left);
if Right /= O_Enode_Null then
New_Association (Constr, Right);
end if;
return New_Function_Call (Constr);
end Translate_Predefined_Lib_Operator;
function Translate_Predefined_Array_Operator
(Left, Right : O_Enode; Func : Iir) return O_Enode
is
Info : constant Type_Info_Acc := Get_Info (Get_Return_Type (Func));
Func_Info : constant Operator_Info_Acc := Get_Info (Func);
Res : O_Dnode;
Constr : O_Assoc_List;
begin
Create_Temp_Stack2_Mark;
Res := Create_Temp (Info.Ortho_Type (Mode_Value));
Start_Association (Constr, Func_Info.Operator_Node);
Subprgs.Add_Subprg_Instance_Assoc (Constr, Func_Info.Operator_Instance);
New_Association (Constr,
New_Address (New_Obj (Res),
Info.Ortho_Ptr_Type (Mode_Value)));
New_Association (Constr, Left);
if Right /= O_Enode_Null then
New_Association (Constr, Right);
end if;
New_Procedure_Call (Constr);
return New_Address (New_Obj (Res), Info.Ortho_Ptr_Type (Mode_Value));
end Translate_Predefined_Array_Operator;
function Translate_Predefined_Array_Operator_Convert
(Left, Right : O_Enode; Func : Iir; Res_Type : Iir) return O_Enode
is
Ret_Type : constant Iir := Get_Return_Type (Func);
Res : O_Enode;
begin
Res := Translate_Predefined_Array_Operator (Left, Right, Func);
return Translate_Implicit_Conv
(Res, Ret_Type, Res_Type, Mode_Value, Func);
end Translate_Predefined_Array_Operator_Convert;
-- A somewhat complex operation...
--
-- Previously, concatenation was handled like any other operator. This
-- is not efficient as for a serie of concatenation (like A & B & C & D),
-- this resulted in O(n**2) copies. The current implementation handles
-- many concatenations in a raw.
function Translate_Concatenation
(Concat_Imp : Iir; Left, Right : Iir; Res_Type : Iir) return O_Enode
is
Expr_Type : constant Iir := Get_Return_Type (Concat_Imp);
Index_Type : constant Iir := Get_Index_Type (Expr_Type, 0);
Info : constant Type_Info_Acc := Get_Info (Expr_Type);
Static_Length : Iir_Int64 := 0;
Nbr_Dyn_Expr : Natural := 0;
type Handle_Acc is access procedure (E : Iir);
type Handlers_Type is record
Handle_El : Handle_Acc;
Handle_Arr : Handle_Acc;
end record;
-- Call handlers for each leaf of LEFT CONCAT_IMP RIGHT.
-- Handlers.Handle_Arr is called for array leaves, and
-- Handlers.Handle_El for element leaves.
procedure Walk (Handlers : Handlers_Type)
is
Walk_Handlers : Handlers_Type;
-- Call handlers for each leaf of L IMP R.
procedure Walk_Concat (Imp : Iir; L, R : Iir);
-- Call handlers for each leaf of E (an array expression). First
-- check wether E is also a concatenation.
procedure Walk_Arr (E : Iir)
is
Imp : Iir;
Assocs : Iir;
begin
if Get_Kind (E) = Iir_Kind_Concatenation_Operator then
Imp := Get_Implementation (E);
if (Get_Implicit_Definition (Imp)
in Iir_Predefined_Concat_Functions)
and then Get_Return_Type (Imp) = Expr_Type
then
Walk_Concat (Imp, Get_Left (E), Get_Right (E));
return;
end if;
elsif Get_Kind (E) = Iir_Kind_Function_Call then
-- Also handle "&" (A, B)
-- Note that associations are always 'simple': no formal, no
-- default expression in implicit declarations.
Imp := Get_Implementation (E);
if (Get_Implicit_Definition (Imp)
in Iir_Predefined_Concat_Functions)
and then Get_Return_Type (Imp) = Expr_Type
then
Assocs := Get_Parameter_Association_Chain (E);
Walk_Concat
(Imp,
Get_Actual (Assocs), Get_Actual (Get_Chain (Assocs)));
return;
end if;
end if;
Walk_Handlers.Handle_Arr (E);
end Walk_Arr;
procedure Walk_Concat (Imp : Iir; L, R : Iir) is
begin
case Get_Implicit_Definition (Imp) is
when Iir_Predefined_Array_Array_Concat =>
Walk_Arr (L);
Walk_Arr (R);
when Iir_Predefined_Array_Element_Concat =>
Walk_Arr (L);
Walk_Handlers.Handle_El (R);
when Iir_Predefined_Element_Array_Concat =>
Walk_Handlers.Handle_El (L);
Walk_Arr (R);
when Iir_Predefined_Element_Element_Concat =>
Walk_Handlers.Handle_El (L);
Walk_Handlers.Handle_El (R);
when others =>
raise Internal_Error;
end case;
end Walk_Concat;
begin
Walk_Handlers := Handlers;
Walk_Concat (Concat_Imp, Left, Right);
end Walk;
-- Return TRUE if the bounds of E are known at analysis time.
function Is_Static_Arr (E : Iir) return Boolean
is
Etype : constant Iir := Get_Type (E);
begin
pragma Assert (Get_Base_Type (Etype) = Expr_Type);
return Is_Fully_Constrained_Type (Etype)
and then Get_Type_Staticness (Get_Index_Type (Etype, 0)) = Locally;
end Is_Static_Arr;
-- Pre_Walk: compute known static length and number of dynamic arrays.
procedure Pre_Walk_El (E : Iir)
is
pragma Unreferenced (E);
begin
Static_Length := Static_Length + 1;
end Pre_Walk_El;
procedure Pre_Walk_Arr (E : Iir)
is
Idx_Type : Iir;
begin
-- Three possibilities:
-- * type is fully constrained, range is static, length is known
-- * type is fully constrained, range is not static, length isn't
-- * type is not constrained
if Is_Static_Arr (E) then
Idx_Type := Get_Index_Type (Get_Type (E), 0);
Static_Length := Static_Length
+ Eval_Discrete_Range_Length (Get_Range_Constraint (Idx_Type));
else
Nbr_Dyn_Expr := Nbr_Dyn_Expr + 1;
end if;
end Pre_Walk_Arr;
-- In order to declare Dyn_Mnodes (below), create a function that can
-- be called now (not possible with procedures).
function Call_Pre_Walk return Natural is
begin
Walk ((Pre_Walk_El'Access, Pre_Walk_Arr'Access));
return Nbr_Dyn_Expr;
end Call_Pre_Walk;
-- Compute now the number of dynamic expressions.
Nbr_Dyn_Expr1 : constant Natural := Call_Pre_Walk;
pragma Assert (Nbr_Dyn_Expr1 = Nbr_Dyn_Expr);
Var_Bounds : Mnode;
Arr_Ptr : O_Dnode;
Var_Arr : Mnode;
Var_Length : O_Dnode;
Var_Res : O_Dnode;
Res : Mnode;
-- Common subexpression: get the range of the result as a Mnode.
function Get_Res_Range return Mnode is
begin
return Chap3.Bounds_To_Range (Var_Bounds, Expr_Type, 1);
end Get_Res_Range;
type Mnode_Array is array (1 .. Nbr_Dyn_Expr) of Mnode;
Dyn_Mnodes : Mnode_Array;
Dyn_I : Natural;
E_Length : O_Enode;
procedure Nil_El (E : Iir) is
begin
null;
end Nil_El;
-- Evaluate a dynamic parameter.
procedure Eval_Dyn_Arr (E : Iir)
is
E_Val : O_Enode;
begin
if not Is_Static_Arr (E) then
Dyn_I := Dyn_I + 1;
-- First, translate expression.
E_Val := Translate_Expression (E, Expr_Type);
-- Then create Mnode (type info may be computed by
-- translate_expression).
Dyn_Mnodes (Dyn_I) :=
Stabilize (E2M (E_Val, Get_Info (Expr_Type), Mode_Value));
end if;
end Eval_Dyn_Arr;
-- Add contribution to length of result from a dynamic parameter.
procedure Len_Dyn_Arr (E : Iir)
is
Elen : O_Enode;
begin
if not Is_Static_Arr (E) then
Dyn_I := Dyn_I + 1;
Elen := Chap3.Get_Array_Length (Dyn_Mnodes (Dyn_I), Get_Type (E));
if E_Length = O_Enode_Null then
E_Length := Elen;
else
E_Length := New_Dyadic_Op (ON_Add_Ov, E_Length, Elen);
end if;
end if;
end Len_Dyn_Arr;
-- Offset in the result.
Var_Off : O_Dnode;
-- Assign: write values to the result array.
procedure Assign_El (E : Iir)
is
El_Type : constant Iir := Get_Element_Subtype (Expr_Type);
begin
Chap3.Translate_Object_Copy
(Chap3.Index_Base (Var_Arr, Expr_Type, New_Obj_Value (Var_Off)),
Translate_Expression (E, El_Type), El_Type);
Inc_Var (Var_Off);
end Assign_El;
procedure Assign_Arr (E : Iir)
is
E_Val : O_Enode;
M : Mnode;
V_Arr : O_Dnode;
Var_Sub_Arr : Mnode;
begin
Open_Temp;
if Is_Static_Arr (E) then
-- First, translate expression.
E_Val := Translate_Expression (E, Expr_Type);
-- Then create Mnode (type info may be computed by
-- translate_expression).
M := E2M (E_Val, Get_Info (Expr_Type), Mode_Value);
Stabilize (M);
else
Dyn_I := Dyn_I + 1;
M := Dyn_Mnodes (Dyn_I);
end if;
-- Create a slice of the result
V_Arr := Create_Temp (Info.Ortho_Type (Mode_Value));
Var_Sub_Arr := Dv2M (V_Arr, Info, Mode_Value);
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Var_Sub_Arr)),
M2Addr (Chap3.Get_Composite_Bounds (M)));
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Var_Sub_Arr)),
M2Addr (Chap3.Slice_Base (Var_Arr,
Expr_Type,
New_Obj_Value (Var_Off))));
-- Copy
Chap3.Translate_Object_Copy (Var_Sub_Arr, M2E (M), Expr_Type);
-- Increase offset
New_Assign_Stmt
(New_Obj (Var_Off),
New_Dyadic_Op (ON_Add_Ov,
New_Obj_Value (Var_Off),
Chap3.Get_Array_Length (M, Expr_Type)));
Close_Temp;
end Assign_Arr;
-- Find last expression. This is used to get the bounds in the case of
-- a null-range result.
Last_Expr : Iir;
Last_Dyn_Expr : Natural;
procedure Find_Last_Arr (E : Iir) is
begin
Last_Expr := E;
if Is_Static_Arr (E) then
Last_Dyn_Expr := 0;
else
Dyn_I := Dyn_I + 1;
Last_Dyn_Expr := Dyn_I;
end if;
end Find_Last_Arr;
-- Copy Left and Dir from SRC to the result. Used for v87.
procedure Copy_Bounds_V87 (Src : Mnode)
is
Src1 : Mnode;
begin
Open_Temp;
Src1 := Stabilize (Src);
New_Assign_Stmt (M2Lv (Chap3.Range_To_Left (Get_Res_Range)),
M2E (Chap3.Range_To_Left (Src1)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir (Get_Res_Range)),
M2E (Chap3.Range_To_Dir (Src1)));
Close_Temp;
end Copy_Bounds_V87;
-- Vhdl 87 bounds: find the first non-null expression and assign
-- left and dir to the result.
Assign_Bounds_V87_Done : Boolean;
type O_If_Block_Array is array
(1 .. Nbr_Dyn_Expr * Boolean'Pos (Flags.Vhdl_Std = Vhdl_87))
of O_If_Block;
Assign_Bounds_Ifs : O_If_Block_Array;
procedure Assign_Bounds_El_V87 (E : Iir)
is
pragma Unreferenced (E);
begin
if Assign_Bounds_V87_Done then
return;
end if;
Copy_Bounds_V87 (Chap3.Type_To_Range (Get_Index_Type (Expr_Type, 0)));
Assign_Bounds_V87_Done := True;
end Assign_Bounds_El_V87;
procedure Assign_Bounds_Arr_V87 (E : Iir)
is
Idx_Rng : Iir;
begin
if Assign_Bounds_V87_Done then
return;
end if;
if Is_Static_Arr (E) then
Idx_Rng := Get_Range_Constraint
(Get_Index_Type (Get_Type (E), 0));
if Eval_Discrete_Range_Length (Idx_Rng) = 0 then
return;
end if;
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Left (Get_Res_Range)),
New_Lit (Translate_Static_Range_Left (Idx_Rng, Index_Type)));
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Dir (Get_Res_Range)),
New_Lit (Translate_Static_Range_Dir (Idx_Rng)));
Assign_Bounds_V87_Done := True;
else
Dyn_I := Dyn_I + 1;
Start_If_Stmt
(Assign_Bounds_Ifs (Dyn_I),
New_Compare_Op (ON_Neq,
Chap3.Get_Array_Length (Dyn_Mnodes (Dyn_I),
Expr_Type),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
Copy_Bounds_V87 (Chap3.Bounds_To_Range
(Chap3.Get_Composite_Bounds
(Dyn_Mnodes (Dyn_I)), Expr_Type, 1));
New_Else_Stmt (Assign_Bounds_Ifs (Dyn_I));
end if;
end Assign_Bounds_Arr_V87;
begin
-- Bounds
Var_Bounds := Dv2M
(Create_Temp (Info.B.Bounds_Type), Info, Mode_Value,
Info.B.Bounds_Type, Info.B.Bounds_Ptr_Type);
-- Base
Arr_Ptr := Create_Temp (Info.B.Base_Ptr_Type (Mode_Value));
Var_Arr := Dp2M (Arr_Ptr, Info, Mode_Value,
Info.B.Base_Type (Mode_Value),
Info.B.Base_Ptr_Type (Mode_Value));
-- Result
Var_Res := Create_Temp (Info.Ortho_Type (Mode_Value));
Res := Dv2M (Var_Res, Info, Mode_Value);
-- Set result bounds.
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)), M2Addr (Var_Bounds));
-- Evaluate all dynamic expressions
Dyn_I := 0;
Walk ((Nil_El'Access, Eval_Dyn_Arr'Access));
-- Check that all dynamic expressions have been handled.
pragma Assert (Dyn_I = Dyn_Mnodes'Last);
-- Compute length
if Static_Length /= 0 then
E_Length := New_Lit (New_Index_Lit (Unsigned_64 (Static_Length)));
else
E_Length := O_Enode_Null;
end if;
Dyn_I := 0;
Walk ((Nil_El'Access, Len_Dyn_Arr'Access));
pragma Assert (Dyn_I = Dyn_Mnodes'Last);
pragma Assert (E_Length /= O_Enode_Null);
Var_Length := Create_Temp_Init (Ghdl_Index_Type, E_Length);
-- Compute bounds.
declare
If_Blk : O_If_Block;
begin
if Static_Length = 0 then
-- The result may have null bounds. Note: we haven't optimize
-- the case when the result is known to have null bounds.
Start_If_Stmt
(If_Blk, New_Compare_Op (ON_Neq, New_Obj_Value (Var_Length),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
end if;
-- For a non-null bounds result.
if Flags.Vhdl_Std > Vhdl_87 or Flag_Relaxed_Rules then
-- Vhdl 93 case: lean and simple.
Chap3.Create_Range_From_Length
(Index_Type, Var_Length, Get_Res_Range, Left);
else
-- Vhdl 87 rules are error-prone and not very efficient:
-- LRM87 7.2.4
-- The left bound of this result is the left bound of the left
-- operand, unless the left operand is a null array, in which
-- case the result of the concatenation is the right operand.
-- The direction of the result is the direction of the left
-- operand, unless the left operand is a null array, in which
-- case the direction of the result is that of the right operand.
-- Assign length.
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Length (Get_Res_Range)),
New_Obj_Value (Var_Length));
-- Left and direction are copied from the first expressions with
-- non-null range.
Dyn_I := 0;
Assign_Bounds_V87_Done := False;
Walk ((Assign_Bounds_El_V87'Access, Assign_Bounds_Arr_V87'Access));
for I in reverse 1 .. Dyn_I loop
Finish_If_Stmt (Assign_Bounds_Ifs (I));
end loop;
-- Set right bound.
declare
Idx_Info : constant Type_Info_Acc := Get_Info (Index_Type);
Idx_Otype : constant O_Tnode :=
Idx_Info.Ortho_Type (Mode_Value);
Var_Length1 : O_Dnode;
Var_Right : O_Dnode;
If_Blk2 : O_If_Block;
begin
Open_Temp;
Var_Length1 := Create_Temp (Ghdl_Index_Type);
Var_Right := Create_Temp (Idx_Otype);
-- Note this substraction cannot overflow, since LENGTH >= 1.
New_Assign_Stmt
(New_Obj (Var_Length1),
New_Dyadic_Op (ON_Sub_Ov,
New_Obj_Value (Var_Length),
New_Lit (Ghdl_Index_1)));
-- Compute right bound of result:
-- if dir = dir_to then
-- right := left + length_1;
-- else
-- right := left - length_1;
-- end if;
Start_If_Stmt
(If_Blk2,
New_Compare_Op (ON_Eq,
M2E (Chap3.Range_To_Dir (Get_Res_Range)),
New_Lit (Ghdl_Dir_To_Node),
Ghdl_Bool_Type));
New_Assign_Stmt
(New_Obj (Var_Right),
New_Dyadic_Op (ON_Add_Ov,
M2E (Chap3.Range_To_Left (Get_Res_Range)),
New_Convert_Ov (New_Obj_Value (Var_Length1),
Idx_Otype)));
New_Else_Stmt (If_Blk2);
New_Assign_Stmt
(New_Obj (Var_Right),
New_Dyadic_Op (ON_Sub_Ov,
M2E (Chap3.Range_To_Left (Get_Res_Range)),
New_Convert_Ov (New_Obj_Value (Var_Length1),
Idx_Otype)));
Finish_If_Stmt (If_Blk2);
-- Check the right bounds is inside the bounds of the
-- index type.
Chap3.Check_Range (Var_Right, Null_Iir, Index_Type, Left);
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Right (Get_Res_Range)),
New_Obj_Value (Var_Right));
Close_Temp;
end;
end if;
if Static_Length = 0 then
New_Else_Stmt (If_Blk);
-- For a null bound result. Same rules for v87 and v93.
-- Find last expression.
Last_Expr := Null_Iir;
Last_Dyn_Expr := 0;
Dyn_I := 0;
Walk ((Nil_El'Access, Find_Last_Arr'Access));
pragma Assert (Dyn_I = Dyn_Mnodes'Last);
if Last_Dyn_Expr = 0 then
-- The last expression is not dynamic.
Translate_Discrete_Range
(Get_Res_Range, Get_Index_Type (Get_Type (Last_Expr), 0));
else
Copy_Range
(Get_Res_Range,
Chap3.Bounds_To_Range
(Chap3.Get_Composite_Bounds (Dyn_Mnodes (Last_Dyn_Expr)),
Expr_Type, 1));
end if;
Finish_If_Stmt (If_Blk);
end if;
end;
-- Allocate result.
New_Assign_Stmt
(New_Obj (Arr_Ptr),
Gen_Alloc (Alloc_Stack,
Chap3.Get_Object_Size (Res, Expr_Type),
Info.B.Base_Ptr_Type (Mode_Value)));
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Res)), M2Addr (Var_Arr));
-- Assign expressions
Open_Temp;
Var_Off := Create_Temp_Init (Ghdl_Index_Type, New_Lit (Ghdl_Index_0));
Dyn_I := 0;
Walk ((Assign_El'Access, Assign_Arr'Access));
pragma Assert (Dyn_I = Dyn_Mnodes'Last);
Close_Temp;
return Translate_Implicit_Conv
(M2E (Res), Expr_Type, Res_Type, Mode_Value, Left);
end Translate_Concatenation;
function Translate_Scalar_Min_Max
(Op : ON_Op_Kind; Left, Right : Iir; Res_Type : Iir) return O_Enode
is
Res_Otype : constant O_Tnode := Get_Ortho_Type (Res_Type, Mode_Value);
Res, L, R : O_Dnode;
If_Blk : O_If_Block;
begin
-- Create a variable for the result.
Res := Create_Temp (Res_Otype);
Open_Temp;
L := Create_Temp_Init
(Res_Otype, Translate_Expression (Left, Res_Type));
R := Create_Temp_Init
(Res_Otype, Translate_Expression (Right, Res_Type));
Start_If_Stmt (If_Blk, New_Compare_Op (Op,
New_Obj_Value (L),
New_Obj_Value (R),
Ghdl_Bool_Type));
New_Assign_Stmt (New_Obj (Res), New_Obj_Value (L));
New_Else_Stmt (If_Blk);
New_Assign_Stmt (New_Obj (Res), New_Obj_Value (R));
Finish_If_Stmt (If_Blk);
Close_Temp;
return New_Obj_Value (Res);
end Translate_Scalar_Min_Max;
function Translate_Predefined_Vector_Min_Max
(Is_Min : Boolean; Left : Iir; Res_Type : Iir) return O_Enode
is
Res_Otype : constant O_Tnode := Get_Ortho_Type (Res_Type, Mode_Value);
Left_Type : constant Iir := Get_Type (Left);
Res, El, Len : O_Dnode;
Arr : Mnode;
If_Blk : O_If_Block;
Label : O_Snode;
Op : ON_Op_Kind;
begin
-- Create a variable for the result.
Res := Create_Temp (Res_Otype);
Open_Temp;
if Is_Min then
Op := ON_Lt;
else
Op := ON_Gt;
end if;
New_Assign_Stmt
(New_Obj (Res),
Chap14.Translate_High_Low_Type_Attribute (Res_Type, Is_Min));
El := Create_Temp (Res_Otype);
Arr := Stabilize (E2M (Translate_Expression (Left),
Get_Info (Left_Type), Mode_Value));
Len := Create_Temp_Init
(Ghdl_Index_Type,
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (Arr, Left_Type, 1))));
-- Create:
-- loop
-- exit when LEN = 0;
-- LEN := LEN - 1;
-- if ARR[LEN] </> RES then
-- RES := ARR[LEN];
-- end if;
-- end loop;
Start_Loop_Stmt (Label);
Gen_Exit_When (Label, New_Compare_Op (ON_Eq, New_Obj_Value (Len),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
Dec_Var (Len);
New_Assign_Stmt
(New_Obj (El),
M2E (Chap3.Index_Base (Chap3.Get_Composite_Base (Arr),
Left_Type, New_Obj_Value (Len))));
Start_If_Stmt (If_Blk, New_Compare_Op (Op,
New_Obj_Value (El),
New_Obj_Value (Res),
Ghdl_Bool_Type));
New_Assign_Stmt (New_Obj (Res), New_Obj_Value (El));
Finish_If_Stmt (If_Blk);
Finish_Loop_Stmt (Label);
Close_Temp;
return New_Obj_Value (Res);
end Translate_Predefined_Vector_Min_Max;
function Translate_Std_Ulogic_Match
(Func : O_Dnode; L, R : O_Enode; Res_Type : O_Tnode) return O_Enode
is
Constr : O_Assoc_List;
begin
Start_Association (Constr, Func);
New_Association (Constr, New_Convert_Ov (L, Ghdl_I32_Type));
New_Association (Constr, New_Convert_Ov (R, Ghdl_I32_Type));
return New_Convert_Ov (New_Function_Call (Constr), Res_Type);
end Translate_Std_Ulogic_Match;
function Translate_To_String (Subprg : O_Dnode;
Res_Type : Iir;
Loc : Iir;
Val : O_Enode;
Arg2 : O_Enode := O_Enode_Null;
Arg3 : O_Enode := O_Enode_Null)
return O_Enode
is
Val_Type : constant Iir := Get_Base_Type (Res_Type);
Res : O_Dnode;
Assoc : O_Assoc_List;
begin
Res := Create_Temp (Std_String_Node);
Create_Temp_Stack2_Mark;
Start_Association (Assoc, Subprg);
New_Association (Assoc,
New_Address (New_Obj (Res), Std_String_Ptr_Node));
New_Association (Assoc, Val);
if Arg2 /= O_Enode_Null then
New_Association (Assoc, Arg2);
if Arg3 /= O_Enode_Null then
New_Association (Assoc, Arg3);
end if;
end if;
New_Procedure_Call (Assoc);
return M2E (Translate_Implicit_Array_Conversion
(Dv2M (Res, Get_Info (Val_Type), Mode_Value),
Val_Type, Res_Type, Loc));
end Translate_To_String;
function Translate_Bv_To_String (Subprg : O_Dnode;
Val : O_Enode;
Val_Type : Iir;
Res_Type : Iir;
Loc : Iir)
return O_Enode
is
Arr : Mnode;
begin
Arr := Stabilize (E2M (Val, Get_Info (Val_Type), Mode_Value));
return Translate_To_String
(Subprg, Res_Type, Loc,
M2E (Chap3.Get_Composite_Base (Arr)),
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (Arr, Val_Type, 1))));
end Translate_Bv_To_String;
subtype Predefined_Boolean_Logical is Iir_Predefined_Functions range
Iir_Predefined_Boolean_And .. Iir_Predefined_Boolean_Xnor;
function Translate_Predefined_Logical
(Op : Predefined_Boolean_Logical; Left, Right : O_Enode) return O_Enode is
begin
case Op is
when Iir_Predefined_Boolean_And =>
return New_Dyadic_Op (ON_And, Left, Right);
when Iir_Predefined_Boolean_Or =>
return New_Dyadic_Op (ON_Or, Left, Right);
when Iir_Predefined_Boolean_Nand =>
return New_Monadic_Op
(ON_Not, New_Dyadic_Op (ON_And, Left, Right));
when Iir_Predefined_Boolean_Nor =>
return New_Monadic_Op
(ON_Not, New_Dyadic_Op (ON_Or, Left, Right));
when Iir_Predefined_Boolean_Xor =>
return New_Dyadic_Op (ON_Xor, Left, Right);
when Iir_Predefined_Boolean_Xnor =>
return New_Monadic_Op
(ON_Not, New_Dyadic_Op (ON_Xor, Left, Right));
end case;
end Translate_Predefined_Logical;
function Translate_Predefined_TF_Array_Element
(Op : Predefined_Boolean_Logical;
Left, Right : Iir;
Res_Type : Iir;
Loc : Iir)
return O_Enode
is
Arr_Type : constant Iir := Get_Type (Left);
Res_Btype : constant Iir := Get_Base_Type (Res_Type);
Res_Info : constant Type_Info_Acc := Get_Info (Res_Btype);
Base_Ptr_Type : constant O_Tnode :=
Res_Info.B.Base_Ptr_Type (Mode_Value);
Arr : Mnode;
El : O_Dnode;
Base : O_Dnode;
Len : O_Dnode;
Label : O_Snode;
Res : Mnode;
begin
-- Translate the array.
Arr := Stabilize (E2M (Translate_Expression (Left),
Get_Info (Arr_Type), Mode_Value));
-- Extract its length.
Len := Create_Temp_Init
(Ghdl_Index_Type,
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (Arr, Arr_Type, 1))));
-- Allocate the result array.
Base := Create_Temp_Init
(Base_Ptr_Type,
Gen_Alloc (Alloc_Stack, New_Obj_Value (Len), Base_Ptr_Type));
Open_Temp;
-- Translate the element.
El := Create_Temp_Init (Get_Ortho_Type (Get_Type (Right), Mode_Value),
Translate_Expression (Right));
-- Create:
-- loop
-- exit when LEN = 0;
-- LEN := LEN - 1;
-- BASE[LEN] := EL op ARR[LEN];
-- end loop;
Start_Loop_Stmt (Label);
Gen_Exit_When (Label, New_Compare_Op (ON_Eq, New_Obj_Value (Len),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
Dec_Var (Len);
New_Assign_Stmt
(New_Indexed_Acc_Value (New_Obj (Base),
New_Obj_Value (Len)),
Translate_Predefined_Logical
(Op,
New_Obj_Value (El),
M2E (Chap3.Index_Base (Chap3.Get_Composite_Base (Arr),
Arr_Type, New_Obj_Value (Len)))));
Finish_Loop_Stmt (Label);
Close_Temp;
Res := Create_Temp (Res_Info, Mode_Value);
New_Assign_Stmt (M2Lp (Chap3.Get_Composite_Base (Res)),
New_Obj_Value (Base));
New_Assign_Stmt (M2Lp (Chap3.Get_Composite_Bounds (Res)),
M2Addr (Chap3.Get_Composite_Bounds (Arr)));
return Translate_Implicit_Conv (M2E (Res), Res_Btype, Res_Type,
Mode_Value, Loc);
end Translate_Predefined_TF_Array_Element;
function Translate_Predefined_TF_Reduction
(Op : ON_Op_Kind; Operand : Iir; Res_Type : Iir) return O_Enode
is
Arr_Type : constant Iir := Get_Type (Operand);
Enums : constant Iir_Flist :=
Get_Enumeration_Literal_List (Get_Base_Type (Res_Type));
Init_Enum : Iir;
Res : O_Dnode;
Arr_Expr : O_Enode;
Arr : Mnode;
Len : O_Dnode;
Label : O_Snode;
begin
if Op = ON_And then
Init_Enum := Get_Nth_Element (Enums, 1);
else
Init_Enum := Get_Nth_Element (Enums, 0);
end if;
Res := Create_Temp_Init (Get_Ortho_Type (Res_Type, Mode_Value),
New_Lit (Get_Ortho_Expr (Init_Enum)));
Open_Temp;
-- Translate the array. Note that Translate_Expression may create
-- the info for the array type, so be sure to call it before calling
-- Get_Info.
Arr_Expr := Translate_Expression (Operand);
Arr := Stabilize (E2M (Arr_Expr, Get_Info (Arr_Type), Mode_Value));
-- Extract its length.
Len := Create_Temp_Init
(Ghdl_Index_Type,
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (Arr, Arr_Type, 1))));
-- Create:
-- loop
-- exit when LEN = 0;
-- LEN := LEN - 1;
-- RES := RES op ARR[LEN];
-- end loop;
Start_Loop_Stmt (Label);
Gen_Exit_When (Label, New_Compare_Op (ON_Eq, New_Obj_Value (Len),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
Dec_Var (Len);
New_Assign_Stmt
(New_Obj (Res),
New_Dyadic_Op
(Op,
New_Obj_Value (Res),
M2E (Chap3.Index_Base (Chap3.Get_Composite_Base (Arr),
Arr_Type, New_Obj_Value (Len)))));
Finish_Loop_Stmt (Label);
Close_Temp;
return New_Obj_Value (Res);
end Translate_Predefined_TF_Reduction;
function Translate_Predefined_Array_Min_Max
(Is_Min : Boolean;
Left, Right : O_Enode;
Left_Type, Right_Type : Iir;
Res_Type : Iir;
Imp : Iir;
Loc : Iir)
return O_Enode
is
Arr_Type : constant Iir := Get_Base_Type (Left_Type);
Arr_Info : constant Type_Info_Acc := Get_Info (Arr_Type);
L, R : Mnode;
If_Blk : O_If_Block;
Res : Mnode;
begin
Res := Create_Temp (Arr_Info, Mode_Value);
L := Stabilize (E2M (Left, Get_Info (Left_Type), Mode_Value));
R := Stabilize (E2M (Right, Get_Info (Right_Type), Mode_Value));
Start_If_Stmt
(If_Blk,
New_Compare_Op
(ON_Eq,
Translate_Predefined_Lib_Operator (M2E (L), M2E (R), Imp),
New_Lit (Ghdl_Compare_Lt),
Std_Boolean_Type_Node));
if Is_Min then
Copy_Fat_Pointer (Res, Translate_Implicit_Array_Conversion
(L, Left_Type, Arr_Type, Loc));
else
Copy_Fat_Pointer (Res, Translate_Implicit_Array_Conversion
(R, Right_Type, Arr_Type, Loc));
end if;
New_Else_Stmt (If_Blk);
if Is_Min then
Copy_Fat_Pointer (Res, Translate_Implicit_Array_Conversion
(R, Right_Type, Arr_Type, Loc));
else
Copy_Fat_Pointer (Res, Translate_Implicit_Array_Conversion
(L, Left_Type, Arr_Type, Loc));
end if;
Finish_If_Stmt (If_Blk);
return M2E (Translate_Implicit_Array_Conversion
(Res, Arr_Type, Res_Type, Loc));
end Translate_Predefined_Array_Min_Max;
function Translate_Predefined_TF_Edge (Is_Rising : Boolean; Left : Iir)
return O_Enode
is
Enums : constant Iir_Flist :=
Get_Enumeration_Literal_List (Get_Base_Type (Get_Type (Left)));
Sig : Mnode;
Val : Mnode;
begin
Chap6.Translate_Signal_Name (Left, Sig, Val);
return New_Dyadic_Op
(ON_And,
New_Value (Chap14.Get_Signal_Field (Sig, Ghdl_Signal_Event_Field)),
New_Compare_Op
(ON_Eq,
M2E (Val),
New_Lit (Get_Ortho_Expr
(Get_Nth_Element (Enums, Boolean'Pos (Is_Rising)))),
Std_Boolean_Type_Node));
end Translate_Predefined_TF_Edge;
function Translate_Predefined_Std_Ulogic_Array_Match
(Subprg : O_Dnode; Left, Right : Iir; Res_Type : Iir) return O_Enode
is
Res_Otype : constant O_Tnode :=
Get_Ortho_Type (Res_Type, Mode_Value);
L_Type : constant Iir := Get_Type (Left);
R_Type : constant Iir := Get_Type (Right);
L_Expr, R_Expr : O_Enode;
L, R : Mnode;
Assoc : O_Assoc_List;
Res : O_Dnode;
begin
Res := Create_Temp (Ghdl_I32_Type);
Open_Temp;
-- Translate the arrays. Note that Translate_Expression may create
-- the info for the array type, so be sure to call it before calling
-- Get_Info.
L_Expr := Translate_Expression (Left);
L := Stabilize (E2M (L_Expr, Get_Info (L_Type), Mode_Value));
R_Expr := Translate_Expression (Right);
R := Stabilize (E2M (R_Expr, Get_Info (R_Type), Mode_Value));
Start_Association (Assoc, Subprg);
New_Association
(Assoc,
New_Convert_Ov (M2E (Chap3.Get_Composite_Base (L)), Ghdl_Ptr_Type));
New_Association
(Assoc,
M2E (Chap3.Range_To_Length (Chap3.Get_Array_Range (L, L_Type, 1))));
New_Association
(Assoc,
New_Convert_Ov (M2E (Chap3.Get_Composite_Base (R)), Ghdl_Ptr_Type));
New_Association
(Assoc,
M2E (Chap3.Range_To_Length (Chap3.Get_Array_Range (R, R_Type, 1))));
New_Assign_Stmt (New_Obj (Res), New_Function_Call (Assoc));
Close_Temp;
return New_Convert_Ov (New_Obj_Value (Res), Res_Otype);
end Translate_Predefined_Std_Ulogic_Array_Match;
function Translate_Predefined_Operator
(Expr : Iir_Function_Declaration; Left, Right : Iir; Res_Type : Iir)
return O_Enode
is
Imp : constant Iir := Get_Implementation (Expr);
Kind : constant Iir_Predefined_Functions :=
Get_Implicit_Definition (Imp);
Left_Tree : O_Enode;
Right_Tree : O_Enode;
Left_Type : Iir;
Right_Type : Iir;
Res_Otype : O_Tnode;
Op : ON_Op_Kind;
Inter : Iir;
Res : O_Enode;
begin
case Kind is
when Iir_Predefined_Bit_And
| Iir_Predefined_Bit_Or
| Iir_Predefined_Bit_Nand
| Iir_Predefined_Bit_Nor
| Iir_Predefined_Boolean_And
| Iir_Predefined_Boolean_Or
| Iir_Predefined_Boolean_Nand
| Iir_Predefined_Boolean_Nor =>
-- Right operand of shortcur operators may not be evaluated.
return Translate_Shortcut_Operator (Imp, Left, Right);
when Iir_Predefined_Array_Array_Concat
| Iir_Predefined_Element_Array_Concat
| Iir_Predefined_Array_Element_Concat
| Iir_Predefined_Element_Element_Concat =>
return Translate_Concatenation (Imp, Left, Right, Res_Type);
-- Operands of min/max are evaluated in a declare block.
when Iir_Predefined_Enum_Minimum
| Iir_Predefined_Integer_Minimum
| Iir_Predefined_Floating_Minimum
| Iir_Predefined_Physical_Minimum =>
return Translate_Scalar_Min_Max (ON_Le, Left, Right, Res_Type);
when Iir_Predefined_Enum_Maximum
| Iir_Predefined_Integer_Maximum
| Iir_Predefined_Floating_Maximum
| Iir_Predefined_Physical_Maximum =>
return Translate_Scalar_Min_Max (ON_Ge, Left, Right, Res_Type);
-- Avoid implicit conversion of the array parameters to the
-- unbounded type for optimizing purpose. FIXME: should do the
-- same for the result.
when Iir_Predefined_TF_Array_Element_And =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_And, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_And =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_And, Right, Left, Res_Type, Expr);
when Iir_Predefined_TF_Array_Element_Or =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Or, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_Or =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Or, Right, Left, Res_Type, Expr);
when Iir_Predefined_TF_Array_Element_Nand =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Nand, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_Nand =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Nand, Right, Left, Res_Type, Expr);
when Iir_Predefined_TF_Array_Element_Nor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Nor, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_Nor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Nor, Right, Left, Res_Type, Expr);
when Iir_Predefined_TF_Array_Element_Xor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Xor, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_Xor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Xor, Right, Left, Res_Type, Expr);
when Iir_Predefined_TF_Array_Element_Xnor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Xnor, Left, Right, Res_Type, Expr);
when Iir_Predefined_TF_Element_Array_Xnor =>
return Translate_Predefined_TF_Array_Element
(Iir_Predefined_Boolean_Xnor, Right, Left, Res_Type, Expr);
-- Avoid implicit conversion of the array parameters to the
-- unbounded type for optimizing purpose.
when Iir_Predefined_TF_Reduction_And =>
return Translate_Predefined_TF_Reduction
(ON_And, Left, Res_Type);
when Iir_Predefined_TF_Reduction_Or =>
return Translate_Predefined_TF_Reduction
(ON_Or, Left, Res_Type);
when Iir_Predefined_TF_Reduction_Nand =>
return New_Monadic_Op
(ON_Not,
Translate_Predefined_TF_Reduction (ON_And, Left, Res_Type));
when Iir_Predefined_TF_Reduction_Nor =>
return New_Monadic_Op
(ON_Not,
Translate_Predefined_TF_Reduction (ON_Or, Left, Res_Type));
when Iir_Predefined_TF_Reduction_Xor =>
return Translate_Predefined_TF_Reduction
(ON_Xor, Left, Res_Type);
when Iir_Predefined_TF_Reduction_Xnor =>
return New_Monadic_Op
(ON_Not,
Translate_Predefined_TF_Reduction (ON_Xor, Left, Res_Type));
when Iir_Predefined_Vector_Minimum =>
return Translate_Predefined_Vector_Min_Max
(True, Left, Get_Type (Expr));
when Iir_Predefined_Vector_Maximum =>
return Translate_Predefined_Vector_Min_Max
(False, Left, Get_Type (Expr));
when Iir_Predefined_Bit_Rising_Edge
| Iir_Predefined_Boolean_Rising_Edge =>
return Translate_Predefined_TF_Edge (True, Left);
when Iir_Predefined_Bit_Falling_Edge
| Iir_Predefined_Boolean_Falling_Edge =>
return Translate_Predefined_TF_Edge (False, Left);
when Iir_Predefined_Std_Ulogic_Array_Match_Equality =>
return Translate_Predefined_Std_Ulogic_Array_Match
(Ghdl_Std_Ulogic_Array_Match_Eq, Left, Right, Res_Type);
when Iir_Predefined_Std_Ulogic_Array_Match_Inequality =>
return Translate_Predefined_Std_Ulogic_Array_Match
(Ghdl_Std_Ulogic_Array_Match_Ne, Left, Right, Res_Type);
when others =>
null;
end case;
-- Evaluate parameters.
Res_Otype := Get_Ortho_Type (Res_Type, Mode_Value);
Inter := Get_Interface_Declaration_Chain (Imp);
if Left = Null_Iir then
Left_Tree := O_Enode_Null;
else
Left_Type := Get_Type (Inter);
Left_Tree := Translate_Expression (Left, Left_Type);
end if;
if Right = Null_Iir then
Right_Tree := O_Enode_Null;
else
Right_Type := Get_Type (Get_Chain (Inter));
Right_Tree := Translate_Expression (Right, Right_Type);
end if;
Op := Predefined_To_Onop (Kind);
if Op /= ON_Nil then
case Op is
when ON_Eq
| ON_Neq
| ON_Ge
| ON_Gt
| ON_Le
| ON_Lt =>
Res := New_Compare_Op (Op, Left_Tree, Right_Tree,
Std_Boolean_Type_Node);
when ON_Add_Ov
| ON_Sub_Ov
| ON_Mul_Ov
| ON_Div_Ov
| ON_Rem_Ov
| ON_Mod_Ov
| ON_Xor =>
Res := New_Dyadic_Op (Op, Left_Tree, Right_Tree);
when ON_Abs_Ov
| ON_Neg_Ov
| ON_Not =>
Res := New_Monadic_Op (Op, Left_Tree);
when others =>
Ada.Text_IO.Put_Line
("translate_predefined_operator: cannot handle "
& ON_Op_Kind'Image (Op));
raise Internal_Error;
end case;
Res := Translate_Implicit_Conv
(Res, Get_Return_Type (Imp), Res_Type, Mode_Value, Expr);
return Res;
end if;
case Kind is
when Iir_Predefined_Bit_Xnor
| Iir_Predefined_Boolean_Xnor =>
return Translate_Predefined_Logical
(Iir_Predefined_Boolean_Xnor, Left_Tree, Right_Tree);
when Iir_Predefined_Bit_Match_Equality =>
return New_Compare_Op (ON_Eq, Left_Tree, Right_Tree,
Get_Ortho_Type (Res_Type, Mode_Value));
when Iir_Predefined_Bit_Match_Inequality =>
return New_Compare_Op (ON_Neq, Left_Tree, Right_Tree,
Get_Ortho_Type (Res_Type, Mode_Value));
when Iir_Predefined_Bit_Condition =>
return New_Compare_Op
(ON_Eq, Left_Tree, New_Lit (Get_Ortho_Expr (Bit_1)),
Std_Boolean_Type_Node);
when Iir_Predefined_Integer_Identity
| Iir_Predefined_Floating_Identity
| Iir_Predefined_Physical_Identity =>
return Translate_Implicit_Conv
(Left_Tree, Left_Type, Res_Type, Mode_Value, Expr);
when Iir_Predefined_Access_Equality
| Iir_Predefined_Access_Inequality =>
if Is_Composite (Get_Info (Left_Type)) then
-- a fat pointer.
declare
T : Type_Info_Acc;
B : Type_Info_Acc;
L, R : O_Dnode;
V1, V2 : O_Enode;
Op1, Op2 : ON_Op_Kind;
begin
if Kind = Iir_Predefined_Access_Equality then
Op1 := ON_Eq;
Op2 := ON_And;
else
Op1 := ON_Neq;
Op2 := ON_Or;
end if;
T := Get_Info (Left_Type);
B := Get_Info (Get_Designated_Type (Left_Type));
L := Create_Temp (T.Ortho_Ptr_Type (Mode_Value));
R := Create_Temp (T.Ortho_Ptr_Type (Mode_Value));
New_Assign_Stmt (New_Obj (L), Left_Tree);
New_Assign_Stmt (New_Obj (R), Right_Tree);
V1 := New_Compare_Op
(Op1,
New_Value_Selected_Acc_Value
(New_Obj (L), B.B.Base_Field (Mode_Value)),
New_Value_Selected_Acc_Value
(New_Obj (R), B.B.Base_Field (Mode_Value)),
Std_Boolean_Type_Node);
V2 := New_Compare_Op
(Op1,
New_Value_Selected_Acc_Value
(New_Obj (L), B.B.Bounds_Field (Mode_Value)),
New_Value_Selected_Acc_Value
(New_Obj (R), B.B.Bounds_Field (Mode_Value)),
Std_Boolean_Type_Node);
return New_Dyadic_Op (Op2, V1, V2);
end;
else
-- a thin pointer.
if Kind = Iir_Predefined_Access_Equality then
return New_Compare_Op
(ON_Eq, Left_Tree, Right_Tree, Std_Boolean_Type_Node);
else
return New_Compare_Op
(ON_Neq, Left_Tree, Right_Tree, Std_Boolean_Type_Node);
end if;
end if;
when Iir_Predefined_Physical_Integer_Div =>
return New_Dyadic_Op (ON_Div_Ov, Left_Tree,
New_Convert_Ov (Right_Tree, Res_Otype));
when Iir_Predefined_Physical_Physical_Div =>
return New_Convert_Ov
(New_Dyadic_Op (ON_Div_Ov, Left_Tree, Right_Tree), Res_Otype);
-- LRM 7.2.6
-- Multiplication of a value P of a physical type Tp by a
-- value I of type INTEGER is equivalent to the following
-- computation: Tp'Val (Tp'Pos (P) * I)
-- FIXME: this is not what is really done...
when Iir_Predefined_Integer_Physical_Mul =>
return New_Dyadic_Op (ON_Mul_Ov,
New_Convert_Ov (Left_Tree, Res_Otype),
Right_Tree);
when Iir_Predefined_Physical_Integer_Mul =>
return New_Dyadic_Op (ON_Mul_Ov, Left_Tree,
New_Convert_Ov (Right_Tree, Res_Otype));
-- LRM 7.2.6
-- Multiplication of a value P of a physical type Tp by a
-- value F of type REAL is equivalten to the following
-- computation: Tp'Val (INTEGER (REAL (Tp'Pos (P)) * F))
-- FIXME: we do not restrict with INTEGER.
when Iir_Predefined_Physical_Real_Mul =>
declare
Right_Otype : O_Tnode;
begin
Right_Otype := Get_Ortho_Type (Right_Type, Mode_Value);
return New_Convert_Ov
(New_Dyadic_Op (ON_Mul_Ov,
New_Convert_Ov (Left_Tree, Right_Otype),
Right_Tree),
Res_Otype);
end;
when Iir_Predefined_Physical_Real_Div =>
declare
Right_Otype : O_Tnode;
begin
Right_Otype := Get_Ortho_Type (Right_Type, Mode_Value);
return New_Convert_Ov
(New_Dyadic_Op (ON_Div_Ov,
New_Convert_Ov (Left_Tree, Right_Otype),
Right_Tree),
Res_Otype);
end;
when Iir_Predefined_Real_Physical_Mul =>
declare
Left_Otype : O_Tnode;
begin
Left_Otype := Get_Ortho_Type (Left_Type, Mode_Value);
return New_Convert_Ov
(New_Dyadic_Op (ON_Mul_Ov,
Left_Tree,
New_Convert_Ov (Right_Tree, Left_Otype)),
Res_Otype);
end;
when Iir_Predefined_Universal_R_I_Mul =>
return New_Dyadic_Op (ON_Mul_Ov,
Left_Tree,
New_Convert_Ov (Right_Tree, Res_Otype));
when Iir_Predefined_Floating_Exp =>
Res := Translate_Lib_Operator
(New_Convert_Ov (Left_Tree, Std_Real_Otype),
Right_Tree, Ghdl_Real_Exp);
return New_Convert_Ov (Res, Res_Otype);
when Iir_Predefined_Integer_Exp =>
Res := Translate_Lib_Operator
(New_Convert_Ov (Left_Tree, Std_Integer_Otype),
Right_Tree,
Ghdl_Integer_Exp);
return New_Convert_Ov (Res, Res_Otype);
when Iir_Predefined_Array_Inequality
| Iir_Predefined_Record_Inequality =>
return New_Monadic_Op
(ON_Not, Translate_Predefined_Lib_Operator
(Left_Tree, Right_Tree, Imp));
when Iir_Predefined_Array_Equality
| Iir_Predefined_Record_Equality =>
return Translate_Predefined_Lib_Operator
(Left_Tree, Right_Tree, Imp);
when Iir_Predefined_Array_Greater =>
return New_Compare_Op
(ON_Eq,
Translate_Predefined_Lib_Operator (Left_Tree, Right_Tree,
Imp),
New_Lit (Ghdl_Compare_Gt),
Std_Boolean_Type_Node);
when Iir_Predefined_Array_Greater_Equal =>
return New_Compare_Op
(ON_Ge,
Translate_Predefined_Lib_Operator (Left_Tree, Right_Tree,
Imp),
New_Lit (Ghdl_Compare_Eq),
Std_Boolean_Type_Node);
when Iir_Predefined_Array_Less =>
return New_Compare_Op
(ON_Eq,
Translate_Predefined_Lib_Operator (Left_Tree, Right_Tree,
Imp),
New_Lit (Ghdl_Compare_Lt),
Std_Boolean_Type_Node);
when Iir_Predefined_Array_Less_Equal =>
return New_Compare_Op
(ON_Le,
Translate_Predefined_Lib_Operator (Left_Tree, Right_Tree,
Imp),
New_Lit (Ghdl_Compare_Eq),
Std_Boolean_Type_Node);
when Iir_Predefined_TF_Array_And
| Iir_Predefined_TF_Array_Or
| Iir_Predefined_TF_Array_Nand
| Iir_Predefined_TF_Array_Nor
| Iir_Predefined_TF_Array_Xor
| Iir_Predefined_TF_Array_Xnor
| Iir_Predefined_TF_Array_Not
| Iir_Predefined_Array_Srl
| Iir_Predefined_Array_Sra
| Iir_Predefined_Array_Ror =>
return Translate_Predefined_Array_Operator_Convert
(Left_Tree, Right_Tree, Imp, Res_Type);
when Iir_Predefined_Array_Sll
| Iir_Predefined_Array_Sla
| Iir_Predefined_Array_Rol =>
Right_Tree := New_Monadic_Op (ON_Neg_Ov, Right_Tree);
return Translate_Predefined_Array_Operator_Convert
(Left_Tree, Right_Tree, Imp, Res_Type);
when Iir_Predefined_Array_Array_Concat
| Iir_Predefined_Element_Array_Concat
| Iir_Predefined_Array_Element_Concat
| Iir_Predefined_Element_Element_Concat =>
raise Internal_Error;
when Iir_Predefined_Endfile =>
return Translate_Lib_Operator
(Left_Tree, O_Enode_Null, Ghdl_File_Endfile);
when Iir_Predefined_Now_Function =>
return New_Obj_Value (Ghdl_Now);
when Iir_Predefined_Std_Ulogic_Match_Equality =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Eq,
Left_Tree, Right_Tree, Res_Otype);
when Iir_Predefined_Std_Ulogic_Match_Inequality =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Ne,
Left_Tree, Right_Tree, Res_Otype);
when Iir_Predefined_Std_Ulogic_Match_Less =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Lt,
Left_Tree, Right_Tree, Res_Otype);
when Iir_Predefined_Std_Ulogic_Match_Less_Equal =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Le,
Left_Tree, Right_Tree, Res_Otype);
when Iir_Predefined_Std_Ulogic_Match_Greater =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Lt,
Right_Tree, Left_Tree, Res_Otype);
when Iir_Predefined_Std_Ulogic_Match_Greater_Equal =>
return Translate_Std_Ulogic_Match
(Ghdl_Std_Ulogic_Match_Le,
Right_Tree, Left_Tree, Res_Otype);
when Iir_Predefined_Bit_Array_Match_Equality =>
return New_Compare_Op
(ON_Eq,
Translate_Predefined_Lib_Operator
(Left_Tree, Right_Tree, Imp),
New_Lit (Std_Boolean_True_Node),
Res_Otype);
when Iir_Predefined_Bit_Array_Match_Inequality =>
return New_Compare_Op
(ON_Eq,
Translate_Predefined_Lib_Operator
(Left_Tree, Right_Tree, Imp),
New_Lit (Std_Boolean_False_Node),
Res_Otype);
when Iir_Predefined_Array_Minimum =>
return Translate_Predefined_Array_Min_Max
(True, Left_Tree, Right_Tree, Left_Type, Right_Type,
Res_Type, Imp, Expr);
when Iir_Predefined_Array_Maximum =>
return Translate_Predefined_Array_Min_Max
(False, Left_Tree, Right_Tree, Left_Type, Right_Type,
Res_Type, Imp, Expr);
when Iir_Predefined_Integer_To_String =>
case Get_Info (Left_Type).Type_Mode is
when Type_Mode_I32 =>
return Translate_To_String
(Ghdl_To_String_I32, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Ghdl_I32_Type));
when Type_Mode_I64 =>
return Translate_To_String
(Ghdl_To_String_I64, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Ghdl_I64_Type));
when others =>
raise Internal_Error;
end case;
when Iir_Predefined_Enum_To_String =>
-- LRM08 5.7 String representations
-- - For a given value of type CHARACTER, [...]
--
-- So special case for character.
if Get_Base_Type (Left_Type) = Character_Type_Definition then
return Translate_To_String
(Ghdl_To_String_Char, Res_Type, Expr, Left_Tree);
end if;
-- LRM08 5.7 String representations
-- - For a given value of type other than CHARACTER, [...]
declare
Conv : O_Tnode;
Subprg : O_Dnode;
begin
case Get_Info (Left_Type).Type_Mode is
when Type_Mode_B1 =>
Subprg := Ghdl_To_String_B1;
Conv := Ghdl_Bool_Type;
when Type_Mode_E8 =>
Subprg := Ghdl_To_String_E8;
Conv := Ghdl_I32_Type;
when Type_Mode_E32 =>
Subprg := Ghdl_To_String_E32;
Conv := Ghdl_I32_Type;
when others =>
raise Internal_Error;
end case;
return Translate_To_String
(Subprg, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Conv),
New_Lit (Rtis.New_Rti_Address
(Get_Info (Left_Type).Type_Rti)));
end;
when Iir_Predefined_Floating_To_String =>
return Translate_To_String
(Ghdl_To_String_F64, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Ghdl_Real_Type));
when Iir_Predefined_Real_To_String_Digits =>
return Translate_To_String
(Ghdl_To_String_F64_Digits, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Ghdl_Real_Type),
New_Convert_Ov (Right_Tree, Ghdl_I32_Type));
when Iir_Predefined_Real_To_String_Format =>
return Translate_To_String
(Ghdl_To_String_F64_Format, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Ghdl_Real_Type),
Right_Tree);
when Iir_Predefined_Physical_To_String =>
declare
Conv : O_Tnode;
Subprg : O_Dnode;
begin
case Get_Info (Left_Type).Type_Mode is
when Type_Mode_P32 =>
Subprg := Ghdl_To_String_P32;
Conv := Ghdl_I32_Type;
when Type_Mode_P64 =>
Subprg := Ghdl_To_String_P64;
Conv := Ghdl_I64_Type;
when others =>
raise Internal_Error;
end case;
return Translate_To_String
(Subprg, Res_Type, Expr,
New_Convert_Ov (Left_Tree, Conv),
New_Lit (Rtis.New_Rti_Address
(Get_Info (Left_Type).Type_Rti)));
end;
when Iir_Predefined_Time_To_String_Unit =>
return Translate_To_String
(Ghdl_Time_To_String_Unit, Res_Type, Expr,
Left_Tree, Right_Tree,
New_Lit (Rtis.New_Rti_Address
(Get_Info (Left_Type).Type_Rti)));
when Iir_Predefined_Bit_Vector_To_Ostring =>
return Translate_Bv_To_String
(Ghdl_BV_To_Ostring, Left_Tree, Left_Type, Res_Type, Expr);
when Iir_Predefined_Bit_Vector_To_Hstring =>
return Translate_Bv_To_String
(Ghdl_BV_To_Hstring, Left_Tree, Left_Type, Res_Type, Expr);
when Iir_Predefined_Array_Char_To_String =>
declare
El_Type : constant Iir := Get_Element_Subtype (Left_Type);
Subprg : O_Dnode;
Arg : Mnode;
begin
Arg := Stabilize
(E2M (Left_Tree, Get_Info (Left_Type), Mode_Value));
case Get_Info (El_Type).Type_Mode is
when Type_Mode_B1 =>
Subprg := Ghdl_Array_Char_To_String_B1;
when Type_Mode_E8 =>
Subprg := Ghdl_Array_Char_To_String_E8;
when Type_Mode_E32 =>
Subprg := Ghdl_Array_Char_To_String_E32;
when others =>
raise Internal_Error;
end case;
return Translate_To_String
(Subprg, Res_Type, Expr,
New_Convert_Ov (M2E (Chap3.Get_Composite_Base (Arg)),
Ghdl_Ptr_Type),
Chap3.Get_Array_Length (Arg, Left_Type),
New_Lit (Rtis.New_Rti_Address
(Get_Info (El_Type).Type_Rti)));
end;
when others =>
Ada.Text_IO.Put_Line
("translate_predefined_operator(2): cannot handle "
& Iir_Predefined_Functions'Image (Kind));
raise Internal_Error;
return O_Enode_Null;
end case;
end Translate_Predefined_Operator;
-- Assign EXPR to TARGET.
procedure Translate_Assign
(Target : Mnode; Val : O_Enode; Expr : Iir; Target_Type : Iir; Loc : Iir)
is
T_Info : constant Type_Info_Acc := Get_Info (Target_Type);
begin
case T_Info.Type_Mode is
when Type_Mode_Scalar =>
New_Assign_Stmt
(M2Lv (Target),
Chap3.Maybe_Insert_Scalar_Check (Val, Expr, Target_Type));
when Type_Mode_Acc
| Type_Mode_Bounds_Acc
| Type_Mode_File =>
New_Assign_Stmt (M2Lv (Target), Val);
when Type_Mode_Unbounded_Array =>
declare
T : Mnode;
E : O_Dnode;
begin
T := Stabilize (Target);
E := Create_Temp_Init
(T_Info.Ortho_Ptr_Type (Mode_Value), Val);
Chap3.Check_Array_Match
(Target_Type, T,
Get_Type (Expr), Dp2M (E, T_Info, Mode_Value), Loc);
Chap3.Translate_Object_Copy
(T, New_Obj_Value (E), Target_Type);
end;
when Type_Mode_Bounded_Arrays =>
-- Source is of type TARGET_TYPE, so no length check is
-- necessary.
Chap3.Translate_Object_Copy (Target, Val, Target_Type);
when Type_Mode_Bounded_Records =>
Chap3.Translate_Object_Copy (Target, Val, Target_Type);
when Type_Mode_Unbounded_Record =>
-- TODO
raise Internal_Error;
when Type_Mode_Unknown
| Type_Mode_Protected =>
raise Internal_Error;
end case;
end Translate_Assign;
procedure Translate_Assign (Target : Mnode; Expr : Iir; Target_Type : Iir)
is
Val : O_Enode;
begin
if Get_Kind (Expr) = Iir_Kind_Aggregate then
-- FIXME: handle overlap between TARGET and EXPR.
Translate_Aggregate (Target, Target_Type, Expr);
else
Open_Temp;
Val := Chap7.Translate_Expression (Expr, Target_Type);
Translate_Assign (Target, Val, Expr, Target_Type, Expr);
Close_Temp;
end if;
end Translate_Assign;
-- If AGGR is of the form (others => (others => EXPR)) (where the
-- number of (others => ) sub-aggregate is at least 1, return EXPR
-- otherwise return NULL_IIR.
function Is_Aggregate_Others (Aggr : Iir_Aggregate) return Iir
is
Chain : Iir;
Aggr1 : Iir;
--Type_Info : Type_Info_Acc;
begin
Aggr1 := Aggr;
-- Do not use translate_aggregate_others for a complex type.
--Type_Info := Get_Info (Get_Type (Aggr));
--if Type_Info.C /= null and then Type_Info.C.Builder_Need_Func then
-- return Null_Iir;
--end if;
loop
Chain := Get_Association_Choices_Chain (Aggr1);
if not Is_Chain_Length_One (Chain) then
return Null_Iir;
end if;
if Get_Kind (Chain) /= Iir_Kind_Choice_By_Others then
return Null_Iir;
end if;
Aggr1 := Get_Associated_Expr (Chain);
case Get_Kind (Aggr1) is
when Iir_Kind_Aggregate =>
if Get_Type (Aggr1) /= Null_Iir then
-- Stop when a sub-aggregate is in fact an aggregate.
return Aggr1;
end if;
when Iir_Kind_String_Literal8 =>
return Null_Iir;
--Error_Kind ("is_aggregate_others", Aggr1);
when others =>
return Aggr1;
end case;
end loop;
end Is_Aggregate_Others;
-- Generate code for (others => EL).
procedure Translate_Aggregate_Others
(Target : Mnode; Target_Type : Iir; El : Iir)
is
Base_Ptr : Mnode;
Info : Type_Info_Acc;
It : O_Dnode;
Len : O_Dnode;
Len_Val : O_Enode;
Label : O_Snode;
Arr_Var : Mnode;
El_Node : Mnode;
begin
Open_Temp;
Info := Get_Info (Target_Type);
case Info.Type_Mode is
when Type_Mode_Unbounded_Array =>
Arr_Var := Stabilize (Target);
Base_Ptr := Stabilize (Chap3.Get_Composite_Base (Arr_Var));
Len_Val := Chap3.Get_Array_Length (Arr_Var, Target_Type);
when Type_Mode_Bounded_Arrays =>
Base_Ptr := Stabilize (Chap3.Get_Composite_Base (Target));
Len_Val := Chap3.Get_Array_Type_Length (Target_Type);
when others =>
raise Internal_Error;
end case;
-- FIXME: use this (since this use one variable instead of two):
-- I := length;
-- loop
-- exit when I = 0;
-- I := I - 1;
-- A[I] := xxx;
-- end loop;
Len := Create_Temp_Init (Ghdl_Index_Type, Len_Val);
if True then
It := Create_Temp (Ghdl_Index_Type);
else
New_Var_Decl (It, Wki_I, O_Storage_Local, Ghdl_Index_Type);
end if;
Init_Var (It);
Start_Loop_Stmt (Label);
Gen_Exit_When
(Label, New_Compare_Op (ON_Eq,
New_Obj_Value (It), New_Obj_Value (Len),
Ghdl_Bool_Type));
El_Node := Chap3.Index_Base (Base_Ptr, Target_Type,
New_Obj_Value (It));
--New_Assign_Stmt (El_Node, Chap7.Translate_Expression (El));
Translate_Assign (El_Node, El, Get_Element_Subtype (Target_Type));
Inc_Var (It);
Finish_Loop_Stmt (Label);
Close_Temp;
end Translate_Aggregate_Others;
procedure Translate_Array_Aggregate_Gen
(Base_Ptr : Mnode;
Bounds_Ptr : Mnode;
Aggr : Iir;
Aggr_Type : Iir;
Dim : Natural;
Var_Index : O_Dnode)
is
Index_List : Iir_Flist;
Expr_Type : Iir;
Final : Boolean;
procedure Do_Assign (Expr : Iir)
is
begin
if Final then
Translate_Assign (Chap3.Index_Base (Base_Ptr, Aggr_Type,
New_Obj_Value (Var_Index)),
Expr, Expr_Type);
Inc_Var (Var_Index);
else
Translate_Array_Aggregate_Gen
(Base_Ptr, Bounds_Ptr, Expr, Aggr_Type, Dim + 1, Var_Index);
end if;
end Do_Assign;
P : Natural;
El : Iir;
begin
case Get_Kind (Aggr) is
when Iir_Kind_Aggregate =>
-- Continue below.
null;
when Iir_Kind_String_Literal8 =>
declare
Len : constant Nat32 := Get_String_Length (Aggr);
-- Type of the unconstrained array type.
Arr_Type : O_Tnode;
-- Type of the constrained array type.
Str_Type : O_Tnode;
Cst : Var_Type;
Var_I : O_Dnode;
Label : O_Snode;
begin
Expr_Type := Get_Element_Subtype (Aggr_Type);
-- Create a constant for the string.
-- First, create its type, because the literal has no
-- type (subaggregate).
Arr_Type := New_Array_Type
(Get_Ortho_Type (Expr_Type, Mode_Value),
Ghdl_Index_Type);
New_Type_Decl (Create_Uniq_Identifier, Arr_Type);
Str_Type := New_Constrained_Array_Type
(Arr_Type, New_Index_Lit (Unsigned_64 (Len)));
Cst := Create_String_Literal_Var_Inner
(Aggr, Expr_Type, Str_Type);
-- Copy it.
Open_Temp;
Var_I := Create_Temp (Ghdl_Index_Type);
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Gen_Exit_When
(Label,
New_Compare_Op (ON_Eq,
New_Obj_Value (Var_I),
New_Lit (New_Index_Lit (Nat32'Pos (Len))),
Ghdl_Bool_Type));
New_Assign_Stmt
(M2Lv (Chap3.Index_Base (Base_Ptr, Aggr_Type,
New_Obj_Value (Var_Index))),
New_Value (New_Indexed_Element (Get_Var (Cst),
New_Obj_Value (Var_I))));
Inc_Var (Var_I);
Inc_Var (Var_Index);
Finish_Loop_Stmt (Label);
Close_Temp;
end;
return;
when others =>
raise Internal_Error;
end case;
Index_List := Get_Index_Subtype_List (Aggr_Type);
-- FINAL is true if the elements of the aggregate are elements of
-- the array.
if Get_Nbr_Elements (Index_List) = Dim then
Expr_Type := Get_Element_Subtype (Aggr_Type);
Final:= True;
else
Final := False;
end if;
El := Get_Association_Choices_Chain (Aggr);
-- First, assign positionnal association.
-- FIXME: count the number of positionnal association and generate
-- an error if there is more positionnal association than elements
-- in the array.
P := 0;
loop
if El = Null_Iir then
-- There is only positionnal associations.
return;
end if;
exit when Get_Kind (El) /= Iir_Kind_Choice_By_None;
Do_Assign (Get_Associated_Expr (El));
P := P + 1;
El := Get_Chain (El);
end loop;
-- Then, assign named or others association.
if Get_Chain (El) = Null_Iir then
-- There is only one choice
case Get_Kind (El) is
when Iir_Kind_Choice_By_Others =>
-- falltrough...
null;
when Iir_Kind_Choice_By_Expression =>
Do_Assign (Get_Associated_Expr (El));
return;
when Iir_Kind_Choice_By_Range =>
declare
Var_Length : O_Dnode;
Var_I : O_Dnode;
Label : O_Snode;
begin
Open_Temp;
Var_Length := Create_Temp_Init
(Ghdl_Index_Type,
Chap7.Translate_Range_Length (Get_Choice_Range (El)));
Var_I := Create_Temp (Ghdl_Index_Type);
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Gen_Exit_When (Label,
New_Compare_Op (ON_Eq,
New_Obj_Value (Var_I),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
Do_Assign (Get_Associated_Expr (El));
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
Close_Temp;
end;
return;
when others =>
Error_Kind ("translate_array_aggregate_gen", El);
end case;
end if;
-- Several choices..
declare
Range_Type : Iir;
Var_Pos : O_Dnode;
Var_Len : O_Dnode;
Range_Ptr : Mnode;
Rtinfo : Type_Info_Acc;
If_Blk : O_If_Block;
Case_Blk : O_Case_Block;
Label : O_Snode;
El_Assoc : Iir;
Len_Tmp : O_Enode;
begin
Open_Temp;
-- Create a loop from left +- number of positionnals associations
-- to/downto right.
Range_Type :=
Get_Base_Type (Get_Nth_Element (Index_List, Dim - 1));
Rtinfo := Get_Info (Range_Type);
Var_Pos := Create_Temp (Rtinfo.Ortho_Type (Mode_Value));
Range_Ptr := Stabilize
(Chap3.Bounds_To_Range (Bounds_Ptr, Aggr_Type, Dim));
New_Assign_Stmt (New_Obj (Var_Pos),
M2E (Chap3.Range_To_Left (Range_Ptr)));
Var_Len := Create_Temp (Ghdl_Index_Type);
if P /= 0 then
Start_If_Stmt
(If_Blk,
New_Compare_Op (ON_Eq,
M2E (Chap3.Range_To_Dir (Range_Ptr)),
New_Lit (Ghdl_Dir_To_Node),
Ghdl_Bool_Type));
Chap8.Gen_Update_Iterator (Var_Pos, Iir_To, Unsigned_64 (P),
Range_Type);
New_Else_Stmt (If_Blk);
Chap8.Gen_Update_Iterator (Var_Pos, Iir_Downto, Unsigned_64 (P),
Range_Type);
Finish_If_Stmt (If_Blk);
end if;
Len_Tmp := M2E (Chap3.Range_To_Length (Range_Ptr));
if P /= 0 then
Len_Tmp := New_Dyadic_Op
(ON_Sub_Ov,
Len_Tmp,
New_Lit (New_Unsigned_Literal (Ghdl_Index_Type,
Unsigned_64 (P))));
end if;
New_Assign_Stmt (New_Obj (Var_Len), Len_Tmp);
-- Start loop.
Start_Loop_Stmt (Label);
-- Check if end of loop.
Gen_Exit_When
(Label,
New_Compare_Op (ON_Eq,
New_Obj_Value (Var_Len),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type));
-- convert aggr into a case statement.
Start_Case_Stmt (Case_Blk, New_Obj_Value (Var_Pos));
El_Assoc := Null_Iir;
while El /= Null_Iir loop
Start_Choice (Case_Blk);
Chap8.Translate_Case_Choice (El, Range_Type, Case_Blk);
if Get_Associated_Expr (El) /= Null_Iir then
El_Assoc := Get_Associated_Expr (El);
end if;
Finish_Choice (Case_Blk);
Do_Assign (El_Assoc);
P := P + 1;
El := Get_Chain (El);
end loop;
Finish_Case_Stmt (Case_Blk);
-- Update var_pos
Start_If_Stmt
(If_Blk,
New_Compare_Op (ON_Eq,
M2E (Chap3.Range_To_Dir (Range_Ptr)),
New_Lit (Ghdl_Dir_To_Node),
Ghdl_Bool_Type));
Chap8.Gen_Update_Iterator (Var_Pos, Iir_To, Unsigned_64 (1),
Range_Type);
New_Else_Stmt (If_Blk);
Chap8.Gen_Update_Iterator (Var_Pos, Iir_Downto, Unsigned_64 (1),
Range_Type);
Finish_If_Stmt (If_Blk);
New_Assign_Stmt
(New_Obj (Var_Len),
New_Dyadic_Op (ON_Sub_Ov,
New_Obj_Value (Var_Len),
New_Lit (Ghdl_Index_1)));
Finish_Loop_Stmt (Label);
Close_Temp;
end;
end Translate_Array_Aggregate_Gen;
procedure Translate_Record_Aggregate (Target : Mnode; Aggr : Iir)
is
Targ : Mnode;
Aggr_Type : constant Iir := Get_Type (Aggr);
Aggr_Base_Type : constant Iir_Record_Type_Definition :=
Get_Base_Type (Aggr_Type);
El_List : constant Iir_Flist :=
Get_Elements_Declaration_List (Aggr_Base_Type);
El_Index : Natural;
Nbr_El : constant Natural := Get_Nbr_Elements (El_List);
-- Record which elements of the record have been set. The 'others'
-- clause applies to all elements not already set.
type Bool_Array_Type is array (0 .. Nbr_El - 1) of Boolean;
pragma Pack (Bool_Array_Type);
Set_Array : Bool_Array_Type := (others => False);
-- The expression associated.
El_Expr : Iir;
-- Set an elements.
procedure Set_El (El : Iir_Element_Declaration) is
begin
Translate_Assign (Chap6.Translate_Selected_Element (Targ, El),
El_Expr, Get_Type (El));
Set_Array (Natural (Get_Element_Position (El))) := True;
end Set_El;
Assoc : Iir;
N_El_Expr : Iir;
begin
Open_Temp;
Targ := Stabilize (Target);
El_Index := 0;
Assoc := Get_Association_Choices_Chain (Aggr);
while Assoc /= Null_Iir loop
N_El_Expr := Get_Associated_Expr (Assoc);
if N_El_Expr /= Null_Iir then
El_Expr := N_El_Expr;
end if;
case Get_Kind (Assoc) is
when Iir_Kind_Choice_By_None =>
Set_El (Get_Nth_Element (El_List, El_Index));
El_Index := El_Index + 1;
when Iir_Kind_Choice_By_Name =>
Set_El (Get_Named_Entity (Get_Choice_Name (Assoc)));
El_Index := Natural'Last;
when Iir_Kind_Choice_By_Others =>
for J in Set_Array'Range loop
if not Set_Array (J) then
Set_El (Get_Nth_Element (El_List, J));
end if;
end loop;
when others =>
Error_Kind ("translate_record_aggregate", Assoc);
end case;
Assoc := Get_Chain (Assoc);
end loop;
Close_Temp;
end Translate_Record_Aggregate;
procedure Translate_Array_Aggregate
(Target : Mnode; Target_Type : Iir; Aggr : Iir)
is
Aggr_Type : constant Iir := Get_Type (Aggr);
Index_List : constant Iir_Flist :=
Get_Index_Subtype_List (Aggr_Type);
Targ_Index_List : constant Iir_Flist :=
Get_Index_Subtype_List (Target_Type);
Aggr_Info : Iir_Aggregate_Info;
Base : Mnode;
Bounds : Mnode;
Var_Index : O_Dnode;
Targ : Mnode;
Rinfo : Type_Info_Acc;
Bt : Iir;
-- Generate code for: (LVAL lop RNG.left) or (RVAL rop RNG.right)
function Check_Value (Lval : Iir;
Lop : ON_Op_Kind;
Rval : Iir;
Rop : ON_Op_Kind;
Rng : Mnode)
return O_Enode
is
L, R : O_Enode;
begin
L := New_Compare_Op
(Lop,
New_Lit (Translate_Static_Expression (Lval, Bt)),
M2E (Chap3.Range_To_Left (Rng)),
Ghdl_Bool_Type);
R := New_Compare_Op
(Rop,
New_Lit (Translate_Static_Expression (Rval, Bt)),
M2E (Chap3.Range_To_Right (Rng)),
Ghdl_Bool_Type);
return New_Dyadic_Op (ON_Or, L, R);
end Check_Value;
Range_Ptr : Mnode;
Subtarg_Type : Iir;
Subaggr_Type : Iir;
L, H : Iir;
Min : Iir_Int32;
Has_Others : Boolean;
Var_Err : O_Dnode;
E : O_Enode;
If_Blk : O_If_Block;
Op : ON_Op_Kind;
begin
Open_Temp;
Targ := Stabilize (Target);
Base := Stabilize (Chap3.Get_Composite_Base (Targ));
Bounds := Stabilize (Chap3.Get_Composite_Bounds (Targ));
Aggr_Info := Get_Aggregate_Info (Aggr);
-- Check type
for I in Flist_First .. Flist_Last (Index_List) loop
Subaggr_Type := Get_Index_Type (Index_List, I);
Subtarg_Type := Get_Index_Type (Targ_Index_List, I);
Bt := Get_Base_Type (Subaggr_Type);
Rinfo := Get_Info (Bt);
if Get_Aggr_Dynamic_Flag (Aggr_Info) then
-- Dynamic range, must evaluate it.
Open_Temp;
declare
A_Range : Mnode;
begin
-- Evaluate the range.
Chap3.Translate_Anonymous_Subtype_Definition
(Subaggr_Type, False);
A_Range :=
Dv2M (Create_Temp (Rinfo.B.Range_Type), Rinfo, Mode_Value,
Rinfo.B.Range_Type, Rinfo.B.Range_Ptr_Type);
Chap7.Translate_Range
(A_Range, Get_Range_Constraint (Subaggr_Type), Subaggr_Type);
-- Check range length VS target length.
Chap6.Check_Bound_Error
(New_Compare_Op
(ON_Neq,
M2E (Chap3.Range_To_Length (A_Range)),
M2E (Chap3.Range_To_Length
(Chap3.Bounds_To_Range
(Bounds, Target_Type, I + 1))),
Ghdl_Bool_Type),
Aggr, I);
end;
Close_Temp;
elsif Get_Type_Staticness (Subaggr_Type) /= Locally
or else Subaggr_Type /= Subtarg_Type
then
-- Note: if the aggregate has no others, then the bounds
-- must be the same, otherwise, aggregate bounds must be
-- inside type bounds.
Has_Others := Get_Aggr_Others_Flag (Aggr_Info);
Min := Get_Aggr_Min_Length (Aggr_Info);
L := Get_Aggr_Low_Limit (Aggr_Info);
if Min > 0 or L /= Null_Iir then
Open_Temp;
-- Pointer to the range.
Range_Ptr := Stabilize
(Chap3.Bounds_To_Range (Bounds, Target_Type, I + 1));
Var_Err := Create_Temp (Ghdl_Bool_Type);
H := Get_Aggr_High_Limit (Aggr_Info);
if L /= Null_Iir then
-- Check the index range of the aggregrate is equal
-- (or within in presence of 'others') the index range
-- of the target.
Start_If_Stmt
(If_Blk,
New_Compare_Op (ON_Eq,
M2E (Chap3.Range_To_Dir (Range_Ptr)),
New_Lit (Ghdl_Dir_To_Node),
Ghdl_Bool_Type));
if Has_Others then
E := Check_Value (L, ON_Lt, H, ON_Gt, Range_Ptr);
else
E := Check_Value (L, ON_Neq, H, ON_Neq, Range_Ptr);
end if;
New_Assign_Stmt (New_Obj (Var_Err), E);
New_Else_Stmt (If_Blk);
if Has_Others then
E := Check_Value (H, ON_Gt, L, ON_Lt, Range_Ptr);
else
E := Check_Value (H, ON_Neq, L, ON_Neq, Range_Ptr);
end if;
New_Assign_Stmt (New_Obj (Var_Err), E);
Finish_If_Stmt (If_Blk);
-- If L and H are greather than the minimum length,
-- then there is no need to check with min.
if Iir_Int32 (Eval_Pos (H) - Eval_Pos (L) + 1) >= Min then
Min := 0;
end if;
end if;
if Min > 0 then
-- Check the number of elements is equal (or less in
-- presence of 'others') than the length of the index
-- range of the target.
if Has_Others then
Op := ON_Lt;
else
Op := ON_Neq;
end if;
E := New_Compare_Op
(Op,
M2E (Chap3.Range_To_Length (Range_Ptr)),
New_Lit (New_Unsigned_Literal (Ghdl_Index_Type,
Unsigned_64 (Min))),
Ghdl_Bool_Type);
if L /= Null_Iir then
E := New_Dyadic_Op (ON_Or, E, New_Obj_Value (Var_Err));
end if;
New_Assign_Stmt (New_Obj (Var_Err), E);
end if;
Chap6.Check_Bound_Error (New_Obj_Value (Var_Err), Aggr, I);
Close_Temp;
end if;
end if;
-- Next dimension.
Aggr_Info := Get_Sub_Aggregate_Info (Aggr_Info);
end loop;
Var_Index := Create_Temp_Init
(Ghdl_Index_Type, New_Lit (Ghdl_Index_0));
Translate_Array_Aggregate_Gen
(Base, Bounds, Aggr, Aggr_Type, 1, Var_Index);
Close_Temp;
-- FIXME: creating aggregate subtype is expensive and rarely used.
-- (one of the current use - only ? - is check_array_match).
Chap3.Translate_Anonymous_Subtype_Definition (Aggr_Type, False);
end Translate_Array_Aggregate;
procedure Translate_Aggregate
(Target : Mnode; Target_Type : Iir; Aggr : Iir)
is
Aggr_Type : constant Iir := Get_Type (Aggr);
El : Iir;
begin
case Get_Kind (Aggr_Type) is
when Iir_Kind_Array_Subtype_Definition
| Iir_Kind_Array_Type_Definition =>
El := Is_Aggregate_Others (Aggr);
if El /= Null_Iir then
Translate_Aggregate_Others (Target, Target_Type, El);
else
Translate_Array_Aggregate (Target, Target_Type, Aggr);
end if;
when Iir_Kind_Record_Type_Definition
| Iir_Kind_Record_Subtype_Definition =>
Translate_Record_Aggregate (Target, Aggr);
when others =>
Error_Kind ("translate_aggregate", Aggr_Type);
end case;
end Translate_Aggregate;
function Translate_Allocator_By_Expression (Expr : Iir) return O_Enode
is
A_Type : constant Iir := Get_Type (Expr);
A_Info : constant Type_Info_Acc := Get_Info (A_Type);
D_Type : constant Iir := Get_Designated_Type (A_Type);
D_Info : constant Type_Info_Acc := Get_Info (D_Type);
Val : O_Enode;
R : Mnode;
begin
-- Compute the expression.
Val := Translate_Expression (Get_Expression (Expr), D_Type);
-- Allocate memory for the object.
case A_Info.Type_Mode is
when Type_Mode_Bounds_Acc =>
declare
Res : O_Dnode;
Val_Size : O_Dnode;
Bounds_Size : O_Cnode;
Val_M : Mnode;
begin
Res := Create_Temp (A_Info.Ortho_Type (Mode_Value));
Val_M := Stabilize (E2M (Val, D_Info, Mode_Value));
-- Size of the value (object without the bounds).
Val_Size := Create_Temp_Init
(Ghdl_Index_Type,
Chap3.Get_Subtype_Size
(D_Type, Chap3.Get_Composite_Bounds (Val_M), Mode_Value));
-- Size of the bounds.
Bounds_Size :=
New_Sizeof (D_Info.B.Bounds_Type, Ghdl_Index_Type);
-- Allocate the object.
New_Assign_Stmt
(New_Obj (Res),
Gen_Alloc (Alloc_Heap,
New_Dyadic_Op
(ON_Add_Ov,
New_Lit (Bounds_Size),
New_Obj_Value (Val_Size)),
A_Info.Ortho_Type (Mode_Value)));
-- Copy bounds.
Gen_Memcpy
(New_Obj_Value (Res),
M2Addr (Chap3.Get_Composite_Bounds (Val_M)),
New_Lit (Bounds_Size));
-- Copy values.
Gen_Memcpy
(Chap3.Get_Bounds_Acc_Base (New_Obj_Value (Res), D_Type),
M2Addr (Chap3.Get_Composite_Base (Val_M)),
New_Obj_Value (Val_Size));
return New_Obj_Value (Res);
end;
when Type_Mode_Acc =>
R := Dp2M (Create_Temp (D_Info.Ortho_Ptr_Type (Mode_Value)),
D_Info, Mode_Value);
Chap3.Translate_Object_Allocation
(R, Alloc_Heap, D_Type, Mnode_Null);
Chap3.Translate_Object_Copy (R, Val, D_Type);
return New_Convert_Ov (M2Addr (R), A_Info.Ortho_Type (Mode_Value));
when others =>
raise Internal_Error;
end case;
end Translate_Allocator_By_Expression;
function Bounds_Acc_To_Fat_Pointer (Ptr : O_Dnode; Acc_Type : Iir)
return Mnode
is
D_Type : constant Iir := Get_Designated_Type (Acc_Type);
D_Info : constant Type_Info_Acc := Get_Info (D_Type);
Res : Mnode;
begin
Res := Dv2M (Create_Temp (D_Info.Ortho_Type (Mode_Value)),
D_Info, Mode_Value);
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)),
New_Convert_Ov (New_Obj_Value (Ptr), D_Info.B.Bounds_Ptr_Type));
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Res)),
Chap3.Get_Bounds_Acc_Base (New_Obj_Value (Ptr), D_Type));
return Res;
end Bounds_Acc_To_Fat_Pointer;
function Translate_Allocator_By_Subtype (Expr : Iir) return O_Enode
is
A_Type : constant Iir := Get_Type (Expr);
A_Info : constant Type_Info_Acc := Get_Info (A_Type);
D_Type : constant Iir := Get_Designated_Type (A_Type);
D_Info : constant Type_Info_Acc := Get_Info (D_Type);
Bounds : Mnode;
Res : Mnode;
begin
case A_Info.Type_Mode is
when Type_Mode_Bounds_Acc =>
declare
Sub_Type : Iir;
Ptr : O_Dnode;
Val_Size : O_Dnode;
Bounds_Size : O_Cnode;
begin
Sub_Type := Get_Subtype_Indication (Expr);
Sub_Type := Get_Type_Of_Subtype_Indication (Sub_Type);
Chap3.Create_Array_Subtype (Sub_Type);
Ptr := Create_Temp (A_Info.Ortho_Type (Mode_Value));
-- Size of the value (object without the bounds).
Val_Size := Create_Temp_Init
(Ghdl_Index_Type,
Chap3.Get_Subtype_Size
(D_Type, Chap3.Get_Array_Type_Bounds (Sub_Type),
Mode_Value));
-- Size of the bounds.
Bounds_Size :=
New_Sizeof (D_Info.B.Bounds_Type, Ghdl_Index_Type);
-- Allocate the object.
New_Assign_Stmt
(New_Obj (Ptr),
Gen_Alloc (Alloc_Heap,
New_Dyadic_Op
(ON_Add_Ov,
New_Lit (Bounds_Size),
New_Obj_Value (Val_Size)),
A_Info.Ortho_Type (Mode_Value)));
-- Copy bounds.
Gen_Memcpy
(New_Obj_Value (Ptr),
M2Addr (Chap3.Get_Array_Type_Bounds (Sub_Type)),
New_Lit (Bounds_Size));
-- Create a fat pointer to initialize the object.
Res := Bounds_Acc_To_Fat_Pointer (Ptr, A_Type);
Chap3.Maybe_Call_Type_Builder (Res, D_Type);
Chap4.Init_Object (Res, D_Type);
return New_Obj_Value (Ptr);
end;
when Type_Mode_Acc =>
Res := Dp2M (Create_Temp (D_Info.Ortho_Ptr_Type (Mode_Value)),
D_Info, Mode_Value);
Bounds := Mnode_Null;
Chap3.Translate_Object_Allocation
(Res, Alloc_Heap, D_Type, Bounds);
Chap4.Init_Object (Res, D_Type);
return New_Convert_Ov
(M2Addr (Res), A_Info.Ortho_Type (Mode_Value));
when others =>
raise Internal_Error;
end case;
end Translate_Allocator_By_Subtype;
function Translate_Fat_Array_Type_Conversion
(Expr : O_Enode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir)
return O_Enode;
function Translate_Array_Subtype_Conversion
(Expr : O_Enode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir)
return O_Enode
is
Res_Info : constant Type_Info_Acc := Get_Info (Res_Type);
Expr_Info : constant Type_Info_Acc := Get_Info (Expr_Type);
E : Mnode;
begin
E := Stabilize (E2M (Expr, Expr_Info, Mode_Value));
case Res_Info.Type_Mode is
when Type_Mode_Bounded_Arrays =>
Chap3.Check_Array_Match
(Res_Type, T2M (Res_Type, Mode_Value),
Expr_Type, E,
Loc);
return New_Convert_Ov
(M2Addr (Chap3.Get_Composite_Base (E)),
Res_Info.Ortho_Ptr_Type (Mode_Value));
when Type_Mode_Unbounded_Array =>
declare
Res : Mnode;
begin
Res := Create_Temp (Res_Info);
Copy_Fat_Pointer (Res, E);
Chap3.Check_Array_Match (Res_Type, Res, Expr_Type, E, Loc);
return M2Addr (Res);
end;
when others =>
Error_Kind ("translate_array_subtype_conversion", Res_Type);
end case;
end Translate_Array_Subtype_Conversion;
function Translate_Type_Conversion
(Expr : O_Enode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir)
return O_Enode
is
Res_Info : constant Type_Info_Acc := Get_Info (Res_Type);
Res : O_Enode;
begin
case Get_Kind (Res_Type) is
when Iir_Kinds_Scalar_Type_And_Subtype_Definition =>
Res := New_Convert_Ov (Expr, Res_Info.Ortho_Type (Mode_Value));
if Chap3.Need_Range_Check (Null_Iir, Res_Type) then
Res := Chap3.Insert_Scalar_Check
(Res, Null_Iir, Res_Type, Loc);
end if;
return Res;
when Iir_Kinds_Array_Type_Definition =>
if Get_Constraint_State (Res_Type) = Fully_Constrained then
return Translate_Array_Subtype_Conversion
(Expr, Expr_Type, Res_Type, Loc);
else
return Translate_Fat_Array_Type_Conversion
(Expr, Expr_Type, Res_Type, Loc);
end if;
when Iir_Kind_Record_Type_Definition
| Iir_Kind_Record_Subtype_Definition =>
return Expr;
when others =>
Error_Kind ("translate_type_conversion", Res_Type);
end case;
end Translate_Type_Conversion;
procedure Translate_Type_Conversion_Bounds
(Res : Mnode; Src : Mnode; Res_Type : Iir; Src_Type : Iir; Loc : Iir)
is
Res_Indexes : constant Iir_Flist := Get_Index_Subtype_List (Res_Type);
Src_Indexes : constant Iir_Flist := Get_Index_Subtype_List (Src_Type);
Res_Base_Type : constant Iir := Get_Base_Type (Res_Type);
Src_Base_Type : constant Iir := Get_Base_Type (Src_Type);
Res_Base_Indexes : constant Iir_Flist :=
Get_Index_Subtype_List (Res_Base_Type);
Src_Base_Indexes : constant Iir_Flist :=
Get_Index_Subtype_List (Src_Base_Type);
R_El : Iir;
S_El : Iir;
begin
-- Convert bounds.
for I in Flist_First .. Flist_Last (Src_Indexes) loop
R_El := Get_Index_Type (Res_Indexes, I);
S_El := Get_Index_Type (Src_Indexes, I);
declare
Rb_Ptr : Mnode;
Sb_Ptr : Mnode;
Ee : O_Enode;
Same_Index_Type : constant Boolean :=
(Get_Index_Type (Res_Base_Indexes, I)
= Get_Index_Type (Src_Base_Indexes, I));
begin
Open_Temp;
Rb_Ptr := Stabilize (Chap3.Bounds_To_Range (Res, Res_Type, I + 1));
Sb_Ptr := Stabilize (Chap3.Bounds_To_Range (Src, Src_Type, I + 1));
-- Convert left and right (unless they have the same type -
-- this is an optimization but also this deals with null
-- array in common cases).
Ee := M2E (Chap3.Range_To_Left (Sb_Ptr));
if not Same_Index_Type then
Ee := Translate_Type_Conversion (Ee, S_El, R_El, Loc);
end if;
New_Assign_Stmt (M2Lv (Chap3.Range_To_Left (Rb_Ptr)), Ee);
Ee := M2E (Chap3.Range_To_Right (Sb_Ptr));
if not Same_Index_Type then
Ee := Translate_Type_Conversion (Ee, S_El, R_El, Loc);
end if;
New_Assign_Stmt (M2Lv (Chap3.Range_To_Right (Rb_Ptr)), Ee);
-- Copy Dir and Length.
New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir (Rb_Ptr)),
M2E (Chap3.Range_To_Dir (Sb_Ptr)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Length (Rb_Ptr)),
M2E (Chap3.Range_To_Length (Sb_Ptr)));
Close_Temp;
end;
end loop;
end Translate_Type_Conversion_Bounds;
function Translate_Fat_Array_Type_Conversion
(Expr : O_Enode; Expr_Type : Iir; Res_Type : Iir; Loc : Iir)
return O_Enode
is
Res_Info : constant Type_Info_Acc := Get_Info (Res_Type);
Expr_Info : constant Type_Info_Acc := Get_Info (Expr_Type);
Res : Mnode;
E : Mnode;
Bounds : O_Dnode;
begin
Res := Create_Temp (Res_Info, Mode_Value);
Bounds := Create_Temp (Res_Info.B.Bounds_Type);
Open_Temp;
E := Stabilize (E2M (Expr, Expr_Info, Mode_Value));
-- Set base.
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Res)),
New_Convert_Ov (M2Addr (Chap3.Get_Composite_Base (E)),
Res_Info.B.Base_Ptr_Type (Mode_Value)));
-- Set bounds.
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)),
New_Address (New_Obj (Bounds), Res_Info.B.Bounds_Ptr_Type));
-- Convert bounds.
Translate_Type_Conversion_Bounds
(Dv2M (Bounds, Res_Info, Mode_Value,
Res_Info.B.Bounds_Type, Res_Info.B.Bounds_Ptr_Type),
Stabilize (Chap3.Get_Composite_Bounds (E)),
Res_Type, Expr_Type, Loc);
Close_Temp;
return M2E (Res);
end Translate_Fat_Array_Type_Conversion;
function Sig2val_Prepare_Composite
(Targ : Mnode; Targ_Type : Iir; Data : Mnode) return Mnode
is
pragma Unreferenced (Targ, Targ_Type);
begin
if Get_Type_Info (Data).Type_Mode in Type_Mode_Unbounded then
return Stabilize (Chap3.Get_Composite_Base (Data));
else
return Stabilize (Data);
end if;
end Sig2val_Prepare_Composite;
function Sig2val_Update_Data_Array
(Val : Mnode; Targ_Type : Iir; Index : O_Dnode) return Mnode is
begin
return Chap3.Index_Base (Val, Targ_Type, New_Obj_Value (Index));
end Sig2val_Update_Data_Array;
function Sig2val_Update_Data_Record
(Val : Mnode; Targ_Type : Iir; El : Iir_Element_Declaration) return Mnode
is
pragma Unreferenced (Targ_Type);
begin
return Chap6.Translate_Selected_Element (Val, El);
end Sig2val_Update_Data_Record;
procedure Translate_Signal_Assign_Driving_Non_Composite
(Targ : Mnode; Targ_Type : Iir; Data: Mnode) is
begin
New_Assign_Stmt
(Chap14.Get_Signal_Value_Field (M2E (Targ), Targ_Type,
Ghdl_Signal_Driving_Value_Field),
M2E (Data));
end Translate_Signal_Assign_Driving_Non_Composite;
procedure Translate_Signal_Assign_Driving is new Foreach_Non_Composite
(Data_Type => Mnode,
Composite_Data_Type => Mnode,
Do_Non_Composite => Translate_Signal_Assign_Driving_Non_Composite,
Prepare_Data_Array => Sig2val_Prepare_Composite,
Update_Data_Array => Sig2val_Update_Data_Array,
Prepare_Data_Record => Sig2val_Prepare_Composite,
Update_Data_Record => Sig2val_Update_Data_Record);
function Translate_Signal_Value (Sig : O_Enode; Sig_Type : Iir)
return O_Enode
is
procedure Translate_Signal_Non_Composite
(Targ : Mnode;
Targ_Type : Iir;
Data : Mnode) is
begin
New_Assign_Stmt (M2Lv (Targ),
Read_Value (M2E (Data), Targ_Type));
end Translate_Signal_Non_Composite;
procedure Translate_Signal_Target is new Foreach_Non_Composite
(Data_Type => Mnode,
Composite_Data_Type => Mnode,
Do_Non_Composite => Translate_Signal_Non_Composite,
Prepare_Data_Array => Sig2val_Prepare_Composite,
Update_Data_Array => Sig2val_Update_Data_Array,
Prepare_Data_Record => Sig2val_Prepare_Composite,
Update_Data_Record => Sig2val_Update_Data_Record);
Tinfo : Type_Info_Acc;
begin
Tinfo := Get_Info (Sig_Type);
if Tinfo.Type_Mode in Type_Mode_Scalar then
return Read_Value (Sig, Sig_Type);
else
declare
Res : Mnode;
Var_Val : Mnode;
begin
-- allocate result array
if Tinfo.Type_Mode in Type_Mode_Unbounded then
Res := Create_Temp (Tinfo);
Var_Val := Stabilize (E2M (Sig, Tinfo, Mode_Signal));
-- Copy bounds.
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)),
M2Addr (Chap3.Get_Composite_Bounds (Var_Val)));
-- Allocate base.
Chap3.Allocate_Unbounded_Composite_Base
(Alloc_Stack, Res, Sig_Type);
elsif Is_Complex_Type (Tinfo) then
Res := Create_Temp (Tinfo);
Chap4.Allocate_Complex_Object (Sig_Type, Alloc_Stack, Res);
else
Res := Create_Temp (Tinfo);
end if;
Open_Temp;
if Tinfo.Type_Mode not in Type_Mode_Unbounded then
Var_Val := Stabilize (E2M (Sig, Tinfo, Mode_Signal));
end if;
Translate_Signal_Target (Res, Sig_Type, Var_Val);
Close_Temp;
return M2Addr (Res);
end;
end if;
end Translate_Signal_Value;
function Read_Signal_Driving_Value (Sig : O_Enode; Sig_Type : Iir)
return O_Enode is
begin
return New_Value (Chap14.Get_Signal_Value_Field
(Sig, Sig_Type, Ghdl_Signal_Driving_Value_Field));
end Read_Signal_Driving_Value;
function Translate_Signal_Driving_Value_1 is new Translate_Signal_Value
(Read_Value => Read_Signal_Driving_Value);
function Translate_Signal_Driving_Value
(Sig : O_Enode; Sig_Type : Iir) return O_Enode
renames Translate_Signal_Driving_Value_1;
procedure Set_Driving_Value
(Sig : Mnode; Sig_Type : Iir; Val : Mnode)
renames Translate_Signal_Assign_Driving;
function Translate_Overflow_Literal (Expr : Iir) return O_Enode
is
Expr_Type : constant Iir := Get_Type (Expr);
Tinfo : constant Type_Info_Acc := Get_Info (Expr_Type);
Otype : constant O_Tnode := Tinfo.Ortho_Type (Mode_Value);
L : O_Dnode;
begin
-- Generate the error message
Chap6.Gen_Bound_Error (Expr);
-- Create a dummy value, for type checking. But never
-- executed.
L := Create_Temp (Otype);
if Tinfo.Type_Mode in Type_Mode_Fat then
-- For fat pointers or arrays.
return New_Address (New_Obj (L),
Tinfo.Ortho_Ptr_Type (Mode_Value));
else
return New_Obj_Value (L);
end if;
end Translate_Overflow_Literal;
function Translate_Expression (Expr : Iir; Rtype : Iir := Null_Iir)
return O_Enode
is
Imp : Iir;
Expr_Type : Iir;
Res_Type : Iir;
Res : O_Enode;
begin
Expr_Type := Get_Type (Expr);
if Rtype = Null_Iir then
Res_Type := Expr_Type;
else
Res_Type := Rtype;
end if;
case Get_Kind (Expr) is
when Iir_Kind_Integer_Literal
| Iir_Kind_Enumeration_Literal
| Iir_Kind_Floating_Point_Literal =>
return New_Lit (Translate_Static_Expression (Expr, Rtype));
when Iir_Kind_Physical_Int_Literal
| Iir_Kind_Physical_Fp_Literal
| Iir_Kind_Unit_Declaration =>
declare
Otype : constant O_Tnode :=
Get_Ortho_Type (Expr_Type, Mode_Value);
Val : Iir_Int64;
begin
-- Get the value now, as it may generate a constraint_error.
Val := Get_Physical_Value (Expr);
return New_Lit (New_Signed_Literal (Otype, Integer_64 (Val)));
exception
when Constraint_Error =>
Warning_Msg_Elab (Warnid_Runtime_Error, Expr,
"physical literal out of range");
return Translate_Overflow_Literal (Expr);
end;
when Iir_Kind_String_Literal8
| Iir_Kind_Simple_Aggregate
| Iir_Kind_Simple_Name_Attribute =>
return Translate_Composite_Literal (Expr, Res_Type);
when Iir_Kind_Aggregate =>
if Get_Aggregate_Expand_Flag (Expr) then
return Translate_Composite_Literal (Expr, Res_Type);
else
declare
Aggr_Type : Iir;
Tinfo : Type_Info_Acc;
Mres : Mnode;
begin
-- Extract the type of the aggregate. Use the type of the
-- context if it is fully constrained.
Aggr_Type := Expr_Type;
if Rtype /= Null_Iir
and then Is_Fully_Constrained_Type (Rtype)
then
Aggr_Type := Rtype;
else
pragma Assert (Is_Fully_Constrained_Type (Expr_Type));
null;
end if;
if Get_Kind (Aggr_Type) = Iir_Kind_Array_Subtype_Definition
then
Chap3.Create_Array_Subtype (Aggr_Type);
end if;
-- FIXME: this may be not necessary
Tinfo := Get_Info (Aggr_Type);
-- The result area has to be created
if Is_Complex_Type (Tinfo) then
Mres := Create_Temp (Tinfo);
Chap4.Allocate_Complex_Object
(Aggr_Type, Alloc_Stack, Mres);
else
-- if thin array/record:
-- create result
Mres := Create_Temp (Tinfo);
end if;
Translate_Aggregate (Mres, Aggr_Type, Expr);
Res := M2E (Mres);
if Rtype /= Null_Iir and then Aggr_Type /= Rtype then
Res := Translate_Implicit_Conv
(Res, Aggr_Type, Rtype, Mode_Value, Expr);
end if;
return Res;
end;
end if;
when Iir_Kind_Null_Literal =>
declare
Tinfo : constant Type_Info_Acc := Get_Info (Expr_Type);
Otype : constant O_Tnode := Tinfo.Ortho_Type (Mode_Value);
begin
return New_Lit (New_Null_Access (Otype));
end;
when Iir_Kind_Overflow_Literal =>
return Translate_Overflow_Literal (Expr);
when Iir_Kind_Parenthesis_Expression =>
return Translate_Expression (Get_Expression (Expr), Rtype);
when Iir_Kind_Allocator_By_Expression =>
return Translate_Allocator_By_Expression (Expr);
when Iir_Kind_Allocator_By_Subtype =>
return Translate_Allocator_By_Subtype (Expr);
when Iir_Kind_Qualified_Expression =>
-- FIXME: check type.
Res := Translate_Expression (Get_Expression (Expr), Expr_Type);
when Iir_Kind_Constant_Declaration
| Iir_Kind_Variable_Declaration
| Iir_Kind_Signal_Declaration
| Iir_Kind_File_Declaration
| Iir_Kind_Object_Alias_Declaration
| Iir_Kind_Interface_Constant_Declaration
| Iir_Kind_Interface_Variable_Declaration
| Iir_Kind_Interface_Signal_Declaration
| Iir_Kind_Interface_File_Declaration
| Iir_Kind_Indexed_Name
| Iir_Kind_Slice_Name
| Iir_Kind_Selected_Element
| Iir_Kind_Dereference
| Iir_Kind_Implicit_Dereference
| Iir_Kind_Stable_Attribute
| Iir_Kind_Quiet_Attribute
| Iir_Kind_Delayed_Attribute
| Iir_Kind_Transaction_Attribute
| Iir_Kind_Guard_Signal_Declaration
| Iir_Kind_Attribute_Value
| Iir_Kind_Attribute_Name =>
Res := M2E (Chap6.Translate_Name (Expr, Mode_Value));
when Iir_Kind_Iterator_Declaration =>
declare
Expr_Info : Ortho_Info_Acc;
begin
Expr_Info := Get_Info (Expr);
Res := New_Value (Get_Var (Expr_Info.Iterator_Var));
if Rtype /= Null_Iir then
Res := New_Convert_Ov
(Res, Get_Ortho_Type (Rtype, Mode_Value));
end if;
return Res;
end;
when Iir_Kinds_Dyadic_Operator =>
Imp := Get_Implementation (Expr);
if Is_Implicit_Subprogram (Imp) then
return Translate_Predefined_Operator
(Expr, Get_Left (Expr), Get_Right (Expr), Res_Type);
else
return Translate_Operator_Function_Call
(Expr, Get_Left (Expr), Get_Right (Expr), Res_Type);
end if;
when Iir_Kinds_Monadic_Operator =>
Imp := Get_Implementation (Expr);
if Is_Implicit_Subprogram (Imp) then
return Translate_Predefined_Operator
(Expr, Get_Operand (Expr), Null_Iir, Res_Type);
else
return Translate_Operator_Function_Call
(Expr, Get_Operand (Expr), Null_Iir, Res_Type);
end if;
when Iir_Kind_Function_Call =>
Imp := Get_Implementation (Expr);
declare
Assoc_Chain : Iir;
begin
if Is_Implicit_Subprogram (Imp) then
declare
Left, Right : Iir;
begin
Assoc_Chain := Get_Parameter_Association_Chain (Expr);
if Assoc_Chain = Null_Iir then
Left := Null_Iir;
Right := Null_Iir;
else
Left := Get_Actual (Assoc_Chain);
Assoc_Chain := Get_Chain (Assoc_Chain);
if Assoc_Chain = Null_Iir then
Right := Null_Iir;
else
Right := Get_Actual (Assoc_Chain);
end if;
end if;
return Translate_Predefined_Operator
(Expr, Left, Right, Res_Type);
end;
else
Canon.Canon_Subprogram_Call (Expr);
Trans.Update_Node_Infos;
Assoc_Chain := Get_Parameter_Association_Chain (Expr);
Res := Chap8.Translate_Subprogram_Call
(Expr, Assoc_Chain, Get_Method_Object (Expr));
Expr_Type := Get_Return_Type (Imp);
end if;
end;
when Iir_Kind_Type_Conversion =>
declare
Conv_Expr : constant Iir := Get_Expression (Expr);
begin
Res := Translate_Type_Conversion
(Translate_Expression (Conv_Expr), Get_Type (Conv_Expr),
Expr_Type, Expr);
end;
when Iir_Kind_Length_Array_Attribute =>
return Chap14.Translate_Length_Array_Attribute
(Expr, Res_Type);
when Iir_Kind_Low_Array_Attribute =>
return Chap14.Translate_Low_Array_Attribute (Expr);
when Iir_Kind_High_Array_Attribute =>
return Chap14.Translate_High_Array_Attribute (Expr);
when Iir_Kind_Left_Array_Attribute =>
return Chap14.Translate_Left_Array_Attribute (Expr);
when Iir_Kind_Right_Array_Attribute =>
return Chap14.Translate_Right_Array_Attribute (Expr);
when Iir_Kind_Ascending_Array_Attribute =>
return Chap14.Translate_Ascending_Array_Attribute (Expr);
when Iir_Kind_Val_Attribute =>
return Chap14.Translate_Val_Attribute (Expr);
when Iir_Kind_Pos_Attribute =>
return Chap14.Translate_Pos_Attribute (Expr, Res_Type);
when Iir_Kind_Succ_Attribute
| Iir_Kind_Pred_Attribute
| Iir_Kind_Leftof_Attribute
| Iir_Kind_Rightof_Attribute =>
return Chap14.Translate_Succ_Pred_Attribute (Expr);
when Iir_Kind_Image_Attribute =>
Res := Chap14.Translate_Image_Attribute (Expr);
when Iir_Kind_Value_Attribute =>
return Chap14.Translate_Value_Attribute (Expr);
when Iir_Kind_Event_Attribute =>
return Chap14.Translate_Event_Attribute (Expr);
when Iir_Kind_Active_Attribute =>
return Chap14.Translate_Active_Attribute (Expr);
when Iir_Kind_Last_Value_Attribute =>
Res := Chap14.Translate_Last_Value_Attribute (Expr);
when Iir_Kind_High_Type_Attribute =>
return Chap14.Translate_High_Low_Type_Attribute
(Get_Type (Expr), True);
when Iir_Kind_Low_Type_Attribute =>
return Chap14.Translate_High_Low_Type_Attribute
(Get_Type (Expr), False);
when Iir_Kind_Left_Type_Attribute =>
return M2E
(Chap3.Range_To_Left
(Lv2M (Translate_Range (Get_Prefix (Expr), Expr_Type),
Get_Info (Get_Base_Type (Expr_Type)), Mode_Value)));
when Iir_Kind_Right_Type_Attribute =>
return M2E
(Chap3.Range_To_Right
(Lv2M (Translate_Range (Get_Prefix (Expr), Expr_Type),
Get_Info (Get_Base_Type (Expr_Type)), Mode_Value)));
when Iir_Kind_Last_Event_Attribute =>
return Chap14.Translate_Last_Time_Attribute
(Get_Prefix (Expr), Ghdl_Signal_Last_Event_Field);
when Iir_Kind_Last_Active_Attribute =>
return Chap14.Translate_Last_Time_Attribute
(Get_Prefix (Expr), Ghdl_Signal_Last_Active_Field);
when Iir_Kind_Driving_Value_Attribute =>
Res := Chap14.Translate_Driving_Value_Attribute (Expr);
when Iir_Kind_Driving_Attribute =>
Res := Chap14.Translate_Driving_Attribute (Expr);
when Iir_Kind_Path_Name_Attribute
| Iir_Kind_Instance_Name_Attribute =>
Res := Chap14.Translate_Path_Instance_Name_Attribute (Expr);
when Iir_Kind_Simple_Name
| Iir_Kind_Character_Literal
| Iir_Kind_Selected_Name =>
return Translate_Expression (Get_Named_Entity (Expr), Rtype);
when Iir_Kind_Psl_Endpoint_Declaration =>
declare
Info : constant Psl_Info_Acc := Get_Info (Expr);
begin
return New_Value (Get_Var (Info.Psl_Count_Var));
end;
when others =>
Error_Kind ("translate_expression", Expr);
end case;
-- Quick test to avoid useless calls.
if Expr_Type /= Res_Type then
Res := Translate_Implicit_Conv
(Res, Expr_Type, Res_Type, Mode_Value, Expr);
end if;
return Res;
end Translate_Expression;
-- Check if RNG is of the form:
-- 1 to T'length
-- or T'Length downto 1
-- or 0 to T'length - 1
-- or T'Length - 1 downto 0
-- In either of these cases, return T'Length
function Is_Length_Range_Expression (Rng : Iir_Range_Expression) return Iir
is
-- Pattern of a bound.
type Length_Pattern is
(
Pat_Unknown,
Pat_Length,
Pat_Length_1, -- Length - 1
Pat_1,
Pat_0
);
Length_Attr : Iir := Null_Iir;
-- Classify the bound.
-- Set LENGTH_ATTR is the pattern is Pat_Length.
function Get_Length_Pattern (Expr : Iir; Recurse : Boolean)
return Length_Pattern
is
begin
case Get_Kind (Expr) is
when Iir_Kind_Length_Array_Attribute =>
Length_Attr := Expr;
return Pat_Length;
when Iir_Kind_Integer_Literal =>
case Get_Value (Expr) is
when 0 =>
return Pat_0;
when 1 =>
return Pat_1;
when others =>
return Pat_Unknown;
end case;
when Iir_Kind_Substraction_Operator =>
if not Recurse then
return Pat_Unknown;
end if;
if Get_Length_Pattern (Get_Left (Expr), False) = Pat_Length
and then
Get_Length_Pattern (Get_Right (Expr), False) = Pat_1
then
return Pat_Length_1;
else
return Pat_Unknown;
end if;
when others =>
return Pat_Unknown;
end case;
end Get_Length_Pattern;
Left_Pat, Right_Pat : Length_Pattern;
begin
Left_Pat := Get_Length_Pattern (Get_Left_Limit (Rng), True);
if Left_Pat = Pat_Unknown then
return Null_Iir;
end if;
Right_Pat := Get_Length_Pattern (Get_Right_Limit (Rng), True);
if Right_Pat = Pat_Unknown then
return Null_Iir;
end if;
case Get_Direction (Rng) is
when Iir_To =>
if (Left_Pat = Pat_1 and Right_Pat = Pat_Length)
or else (Left_Pat = Pat_0 and Right_Pat = Pat_Length_1)
then
return Length_Attr;
end if;
when Iir_Downto =>
if (Left_Pat = Pat_Length and Right_Pat = Pat_1)
or else (Left_Pat = Pat_Length_1 and Right_Pat = Pat_0)
then
return Length_Attr;
end if;
end case;
return Null_Iir;
end Is_Length_Range_Expression;
procedure Translate_Range_Expression
(Res : Mnode; Expr : Iir; Range_Type : Iir)
is
T_Info : constant Type_Info_Acc := Get_Info (Range_Type);
Length_Attr : Iir;
Res1 : Mnode;
begin
Open_Temp;
Res1 := Stabilize (Res);
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Left (Res1)),
Chap7.Translate_Range_Expression_Left (Expr, Range_Type));
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Right (Res1)),
Chap7.Translate_Range_Expression_Right (Expr, Range_Type));
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Dir (Res1)),
New_Lit (Chap7.Translate_Static_Range_Dir (Expr)));
if T_Info.B.Range_Length /= O_Fnode_Null then
if Get_Expr_Staticness (Expr) = Locally then
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Length (Res1)),
New_Lit (Translate_Static_Range_Length (Expr)));
else
Length_Attr := Is_Length_Range_Expression (Expr);
if Length_Attr = Null_Iir then
Open_Temp;
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Length (Res1)),
Compute_Range_Length
(M2E (Chap3.Range_To_Left (Res1)),
M2E (Chap3.Range_To_Right (Res1)),
Get_Direction (Expr)));
Close_Temp;
else
New_Assign_Stmt
(M2Lv (Chap3.Range_To_Length (Res1)),
Chap14.Translate_Length_Array_Attribute
(Length_Attr, Null_Iir));
end if;
end if;
end if;
Close_Temp;
end Translate_Range_Expression;
-- Reverse range ARANGE.
procedure Translate_Reverse_Range
(Res : Mnode; Arange : O_Lnode; Range_Type : Iir)
is
Rinfo : constant Type_Info_Acc := Get_Info (Get_Base_Type (Range_Type));
Res1 : Mnode;
Arange1 : Mnode;
If_Blk : O_If_Block;
begin
Open_Temp;
Arange1 := Stabilize (Lv2M (Arange, Rinfo, Mode_Value,
Rinfo.B.Range_Type, Rinfo.B.Range_Ptr_Type));
Res1 := Stabilize (Res);
New_Assign_Stmt (M2Lv (Chap3.Range_To_Left (Res1)),
M2E (Chap3.Range_To_Right (Arange1)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Right (Res1)),
M2E (Chap3.Range_To_Left (Arange1)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Length (Res1)),
M2E (Chap3.Range_To_Length (Arange1)));
Start_If_Stmt
(If_Blk, New_Compare_Op (ON_Eq,
M2E (Chap3.Range_To_Dir (Arange1)),
New_Lit (Ghdl_Dir_To_Node),
Ghdl_Bool_Type));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir (Res1)),
New_Lit (Ghdl_Dir_Downto_Node));
New_Else_Stmt (If_Blk);
New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir (Res1)),
New_Lit (Ghdl_Dir_To_Node));
Finish_If_Stmt (If_Blk);
Close_Temp;
end Translate_Reverse_Range;
procedure Copy_Range (Dest : Mnode; Src : Mnode)
is
Info : constant Type_Info_Acc := Get_Type_Info (Dest);
Dest1 : Mnode;
Src1 : Mnode;
begin
Open_Temp;
Dest1 := Stabilize (Dest);
Src1 := Stabilize (Src);
New_Assign_Stmt (M2Lv (Chap3.Range_To_Left (Dest1)),
M2E (Chap3.Range_To_Left (Src1)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Right (Dest1)),
M2E (Chap3.Range_To_Right (Src1)));
New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir (Dest1)),
M2E (Chap3.Range_To_Dir (Src1)));
if Info.B.Range_Length /= O_Fnode_Null then
-- Floating point types have no length.
New_Assign_Stmt (M2Lv (Chap3.Range_To_Length (Dest1)),
M2E (Chap3.Range_To_Length (Src1)));
end if;
Close_Temp;
end Copy_Range;
procedure Translate_Range (Res : Mnode; Arange : Iir; Range_Type : Iir)
is
Rinfo : constant Type_Info_Acc := Get_Info (Get_Base_Type (Range_Type));
begin
case Get_Kind (Arange) is
when Iir_Kind_Range_Array_Attribute =>
declare
Ptr : O_Dnode;
begin
Open_Temp;
Ptr := Create_Temp_Ptr
(Rinfo.B.Range_Ptr_Type,
Chap14.Translate_Range_Array_Attribute (Arange));
Copy_Range (Res,
Dp2M (Ptr, Rinfo, Mode_Value,
Rinfo.B.Range_Type, Rinfo.B.Range_Ptr_Type));
Close_Temp;
end;
when Iir_Kind_Reverse_Range_Array_Attribute =>
Translate_Reverse_Range
(Res, Chap14.Translate_Range_Array_Attribute (Arange),
Range_Type);
when Iir_Kind_Range_Expression =>
Translate_Range_Expression (Res, Arange, Range_Type);
when others =>
Error_Kind ("translate_range_ptr", Arange);
end case;
end Translate_Range;
procedure Translate_Discrete_Range (Res : Mnode; Arange : Iir) is
begin
case Get_Kind (Arange) is
when Iir_Kind_Integer_Subtype_Definition
| Iir_Kind_Enumeration_Subtype_Definition =>
if not Is_Anonymous_Type_Definition (Arange) then
declare
Rinfo : constant Type_Info_Acc := Get_Info (Arange);
begin
Copy_Range (Res, Lv2M (Get_Var (Rinfo.S.Range_Var),
Rinfo, Mode_Value,
Rinfo.B.Range_Type,
Rinfo.B.Range_Ptr_Type));
end;
else
Translate_Range (Res,
Get_Range_Constraint (Arange),
Get_Base_Type (Arange));
end if;
when Iir_Kind_Range_Array_Attribute
| Iir_Kind_Reverse_Range_Array_Attribute
| Iir_Kind_Range_Expression =>
Translate_Range (Res, Arange, Get_Type (Arange));
when others =>
Error_Kind ("translate_discrete_range", Arange);
end case;
end Translate_Discrete_Range;
function Translate_Range (Arange : Iir; Range_Type : Iir) return O_Lnode is
begin
case Get_Kind (Arange) is
when Iir_Kinds_Denoting_Name =>
return Translate_Range (Get_Named_Entity (Arange), Range_Type);
when Iir_Kind_Subtype_Attribute
| Iir_Kind_Subtype_Declaration =>
return Translate_Range (Get_Type (Arange), Range_Type);
when Iir_Kinds_Scalar_Subtype_Definition
| Iir_Kind_Enumeration_Type_Definition =>
-- Must be a scalar subtype. Range of types is static.
return Get_Var (Get_Info (Arange).S.Range_Var);
when Iir_Kind_Range_Array_Attribute =>
return Chap14.Translate_Range_Array_Attribute (Arange);
when Iir_Kind_Reverse_Range_Array_Attribute =>
declare
Rinfo : constant Type_Info_Acc := Get_Info (Range_Type);
Res : O_Dnode;
begin
Res := Create_Temp (Rinfo.B.Range_Type);
Translate_Reverse_Range
(Dv2M (Res, Rinfo, Mode_Value),
Chap14.Translate_Range_Array_Attribute (Arange),
Range_Type);
return New_Obj (Res);
end;
when Iir_Kind_Range_Expression =>
declare
Rinfo : constant Type_Info_Acc := Get_Info (Range_Type);
Res : O_Dnode;
begin
Res := Create_Temp (Rinfo.B.Range_Type);
Translate_Range_Expression
(Dv2M (Res, Rinfo, Mode_Value,
Rinfo.B.Range_Type, Rinfo.B.Range_Ptr_Type),
Arange, Range_Type);
return New_Obj (Res);
end;
when others =>
Error_Kind ("translate_range", Arange);
end case;
end Translate_Range;
function Translate_Static_Range (Arange : Iir; Range_Type : Iir)
return O_Cnode
is
Constr : O_Record_Aggr_List;
Res : O_Cnode;
T_Info : constant Type_Info_Acc := Get_Info (Range_Type);
begin
Start_Record_Aggr (Constr, T_Info.B.Range_Type);
New_Record_Aggr_El
(Constr, Chap7.Translate_Static_Range_Left (Arange, Range_Type));
New_Record_Aggr_El
(Constr, Chap7.Translate_Static_Range_Right (Arange, Range_Type));
New_Record_Aggr_El
(Constr, Chap7.Translate_Static_Range_Dir (Arange));
if T_Info.B.Range_Length /= O_Fnode_Null then
New_Record_Aggr_El
(Constr, Chap7.Translate_Static_Range_Length (Arange));
end if;
Finish_Record_Aggr (Constr, Res);
return Res;
end Translate_Static_Range;
procedure Translate_Predefined_Array_Compare_Spec (Subprg : Iir)
is
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
Id : constant Name_Id :=
Get_Identifier (Get_Type_Declarator (Arr_Type));
Arr_Ptr_Type : constant O_Tnode := Tinfo.Ortho_Ptr_Type (Mode_Value);
F_Info : Operator_Info_Acc;
Interface_List : O_Inter_List;
begin
F_Info := Add_Info (Subprg, Kind_Operator);
-- Create function.
Start_Function_Decl (Interface_List, Create_Identifier (Id, "_CMP"),
Global_Storage, Ghdl_Compare_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Left,
Wki_Left, Arr_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Right,
Wki_Right, Arr_Ptr_Type);
Finish_Subprogram_Decl (Interface_List, F_Info.Operator_Node);
end Translate_Predefined_Array_Compare_Spec;
procedure Translate_Predefined_Array_Compare_Body (Subprg : Iir)
is
procedure Gen_Compare (L, R : O_Dnode)
is
If_Blk1, If_Blk2 : O_If_Block;
begin
Start_If_Stmt
(If_Blk1,
New_Compare_Op (ON_Neq, New_Obj_Value (L), New_Obj_Value (R),
Ghdl_Bool_Type));
Start_If_Stmt
(If_Blk2,
New_Compare_Op (ON_Gt, New_Obj_Value (L), New_Obj_Value (R),
Ghdl_Bool_Type));
New_Return_Stmt (New_Lit (Ghdl_Compare_Gt));
New_Else_Stmt (If_Blk2);
New_Return_Stmt (New_Lit (Ghdl_Compare_Lt));
Finish_If_Stmt (If_Blk2);
Finish_If_Stmt (If_Blk1);
end Gen_Compare;
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
If_Blk : O_If_Block;
Var_L_Len, Var_R_Len : O_Dnode;
Var_L_El, Var_R_El : O_Dnode;
Var_I, Var_Len : O_Dnode;
Label : O_Snode;
El_Otype : O_Tnode;
begin
if Global_Storage = O_Storage_External then
return;
end if;
El_Otype := Get_Ortho_Type
(Get_Element_Subtype (Arr_Type), Mode_Value);
Start_Subprogram_Body (F_Info.Operator_Node);
-- Compute length of L and R.
New_Var_Decl (Var_L_Len, Wki_L_Len,
O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_R_Len, Wki_R_Len,
O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_Len, Wki_Length, O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_I, Wki_I, O_Storage_Local, Ghdl_Index_Type);
New_Assign_Stmt (New_Obj (Var_L_Len),
Chap6.Get_Array_Bound_Length
(Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value),
Arr_Type, 1));
New_Assign_Stmt (New_Obj (Var_R_Len),
Chap6.Get_Array_Bound_Length
(Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value),
Arr_Type, 1));
-- Find the minimum length.
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Ge,
New_Obj_Value (Var_L_Len),
New_Obj_Value (Var_R_Len),
Ghdl_Bool_Type));
New_Assign_Stmt (New_Obj (Var_Len), New_Obj_Value (Var_R_Len));
New_Else_Stmt (If_Blk);
New_Assign_Stmt (New_Obj (Var_Len), New_Obj_Value (Var_L_Len));
Finish_If_Stmt (If_Blk);
-- for each element, compare elements; if not equal return the
-- comparaison result.
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Start_If_Stmt (If_Blk, New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I),
New_Obj_Value (Var_Len),
Ghdl_Bool_Type));
-- Compare the length and return the result.
Gen_Compare (Var_L_Len, Var_R_Len);
New_Return_Stmt (New_Lit (Ghdl_Compare_Eq));
Finish_If_Stmt (If_Blk);
Start_Declare_Stmt;
New_Var_Decl (Var_L_El, Get_Identifier ("l_el"), O_Storage_Local,
El_Otype);
New_Var_Decl (Var_R_El, Get_Identifier ("r_el"), O_Storage_Local,
El_Otype);
New_Assign_Stmt
(New_Obj (Var_L_El),
M2E (Chap3.Index_Base
(Chap3.Get_Composite_Base
(Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value)),
Arr_Type,
New_Obj_Value (Var_I))));
New_Assign_Stmt
(New_Obj (Var_R_El),
M2E (Chap3.Index_Base
(Chap3.Get_Composite_Base
(Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value)),
Arr_Type,
New_Obj_Value (Var_I))));
Gen_Compare (Var_L_El, Var_R_El);
Finish_Declare_Stmt;
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
Finish_Subprogram_Body;
end Translate_Predefined_Array_Compare_Body;
-- Find the declaration of the predefined function IMP in type
-- definition BASE_TYPE.
function Find_Predefined_Function
(Base_Type : Iir; Imp : Iir_Predefined_Functions) return Iir
is
El : Iir;
begin
El := Get_Chain (Get_Type_Declarator (Base_Type));
while El /= Null_Iir loop
pragma Assert (Is_Implicit_Subprogram (El));
if Get_Implicit_Definition (El) = Imp then
return El;
else
El := Get_Chain (El);
end if;
end loop;
raise Internal_Error;
end Find_Predefined_Function;
function Translate_Equality (L, R : Mnode; Etype : Iir) return O_Enode
is
Tinfo : Type_Info_Acc;
begin
Tinfo := Get_Type_Info (L);
case Tinfo.Type_Mode is
when Type_Mode_Scalar
| Type_Mode_Bounds_Acc
| Type_Mode_Acc =>
return New_Compare_Op (ON_Eq, M2E (L), M2E (R),
Ghdl_Bool_Type);
when Type_Mode_Arrays =>
declare
Base_Type : constant Iir_Array_Type_Definition
:= Get_Base_Type (Etype);
Lc, Rc : O_Enode;
Func : Iir;
begin
Func := Find_Predefined_Function
(Base_Type, Iir_Predefined_Array_Equality);
Lc := Translate_Implicit_Conv
(M2E (L), Etype, Base_Type, Mode_Value, Null_Iir);
Rc := Translate_Implicit_Conv
(M2E (R), Etype, Base_Type, Mode_Value, Null_Iir);
return Translate_Predefined_Lib_Operator (Lc, Rc, Func);
end;
when Type_Mode_Records =>
declare
Func : Iir;
begin
Func := Find_Predefined_Function
(Get_Base_Type (Etype), Iir_Predefined_Record_Equality);
return Translate_Predefined_Lib_Operator
(M2E (L), M2E (R), Func);
end;
when Type_Mode_Unknown
| Type_Mode_File
| Type_Mode_Protected =>
raise Internal_Error;
end case;
end Translate_Equality;
procedure Translate_Predefined_Array_Equality_Spec (Subprg : Iir)
is
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
Info : constant Type_Info_Acc := Get_Info (Arr_Type);
Id : constant Name_Id :=
Get_Identifier (Get_Type_Declarator (Arr_Type));
Arr_Ptr_Type : constant O_Tnode := Info.Ortho_Ptr_Type (Mode_Value);
F_Info : Operator_Info_Acc;
Interface_List : O_Inter_List;
begin
F_Info := Add_Info (Subprg, Kind_Operator);
-- Create function.
Start_Function_Decl (Interface_List, Create_Identifier (Id, "_EQ"),
Global_Storage, Std_Boolean_Type_Node);
Create_Operator_Instance (Interface_List, F_Info);
New_Interface_Decl (Interface_List, F_Info.Operator_Left,
Wki_Left, Arr_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Right,
Wki_Right, Arr_Ptr_Type);
Finish_Subprogram_Decl (Interface_List, F_Info.Operator_Node);
end Translate_Predefined_Array_Equality_Spec;
procedure Translate_Predefined_Array_Equality_Body (Subprg : Iir)
is
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
El_Type : constant Iir := Get_Element_Subtype (Arr_Type);
Info : constant Type_Info_Acc := Get_Info (Arr_Type);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
L, R : Mnode;
Indexes : constant Iir_Flist := Get_Index_Subtype_List (Arr_Type);
Nbr_Indexes : constant Natural := Get_Nbr_Elements (Indexes);
If_Blk : O_If_Block;
Var_I : O_Dnode;
Var_Len : O_Dnode;
Label : O_Snode;
Base_Le, Base_Re : Mnode;
Var_L, Var_R : Mnode;
begin
if Global_Storage = O_Storage_External then
return;
end if;
L := Dp2M (F_Info.Operator_Left, Info, Mode_Value);
R := Dp2M (F_Info.Operator_Right, Info, Mode_Value);
Start_Subprogram_Body (F_Info.Operator_Node);
Start_Operator_Instance_Use (F_Info);
-- for each dimension: if length mismatch: return false
for I in 1 .. Nbr_Indexes loop
Start_If_Stmt
(If_Blk,
New_Compare_Op
(ON_Neq,
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (L, Arr_Type, I))),
M2E (Chap3.Range_To_Length
(Chap3.Get_Array_Range (R, Arr_Type, I))),
Std_Boolean_Type_Node));
New_Return_Stmt (New_Lit (Std_Boolean_False_Node));
Finish_If_Stmt (If_Blk);
end loop;
-- For each element: if element is not equal, return false.
New_Var_Decl (Var_I, Wki_I, O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_Len, Wki_Length, O_Storage_Local, Ghdl_Index_Type);
Open_Temp;
New_Assign_Stmt (New_Obj (Var_Len),
Chap3.Get_Array_Length (L, Arr_Type));
Close_Temp;
Open_Temp;
Var_L := Chap3.Create_Maybe_Fat_Array_Element (L, Arr_Type);
Var_R := Chap3.Create_Maybe_Fat_Array_Element (R, Arr_Type);
Init_Var (Var_I);
Start_Loop_Stmt (Label);
-- If the end of the array is reached, return TRUE.
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I),
New_Obj_Value (Var_Len),
Ghdl_Bool_Type));
New_Return_Stmt (New_Lit (Std_Boolean_True_Node));
Finish_If_Stmt (If_Blk);
Open_Temp;
Base_Le := Chap3.Index_Array (L, Arr_Type, New_Obj_Value (Var_I));
Base_Le := Chap3.Assign_Maybe_Fat_Array_Element (Var_L, Base_Le);
Base_Re := Chap3.Index_Array (R, Arr_Type, New_Obj_Value (Var_I));
Base_Re := Chap3.Assign_Maybe_Fat_Array_Element (Var_R, Base_Re);
Start_If_Stmt
(If_Blk,
New_Monadic_Op (ON_Not,
Translate_Equality (Base_Le, Base_Re, El_Type)));
New_Return_Stmt (New_Lit (Std_Boolean_False_Node));
Finish_If_Stmt (If_Blk);
Close_Temp;
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
Close_Temp;
Finish_Operator_Instance_Use (F_Info);
Finish_Subprogram_Body;
end Translate_Predefined_Array_Equality_Body;
procedure Translate_Predefined_Record_Equality_Spec (Subprg : Iir)
is
Rec_Type : constant Iir_Record_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
Tinfo : constant Type_Info_Acc := Get_Info (Rec_Type);
Id : constant Name_Id :=
Get_Identifier (Get_Type_Declarator (Rec_Type));
Rec_Ptr_Type : constant O_Tnode := Tinfo.Ortho_Ptr_Type (Mode_Value);
F_Info : Operator_Info_Acc;
Interface_List : O_Inter_List;
begin
F_Info := Add_Info (Subprg, Kind_Operator);
Start_Function_Decl (Interface_List, Create_Identifier (Id, "_EQ"),
Global_Storage, Std_Boolean_Type_Node);
Create_Operator_Instance (Interface_List, F_Info);
New_Interface_Decl (Interface_List, F_Info.Operator_Left,
Wki_Left, Rec_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Right,
Wki_Right, Rec_Ptr_Type);
Finish_Subprogram_Decl (Interface_List, F_Info.Operator_Node);
end Translate_Predefined_Record_Equality_Spec;
procedure Translate_Predefined_Record_Equality_Body (Subprg : Iir)
is
Rec_Type : constant Iir_Record_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
Tinfo : constant Type_Info_Acc := Get_Info (Rec_Type);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
L, R : Mnode;
If_Blk : O_If_Block;
Le, Re : Mnode;
El_List : Iir_Flist;
El : Iir_Element_Declaration;
begin
if Global_Storage = O_Storage_External then
return;
end if;
Start_Subprogram_Body (F_Info.Operator_Node);
Start_Operator_Instance_Use (F_Info);
L := Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value);
R := Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value);
-- Compare each element.
El_List := Get_Elements_Declaration_List (Rec_Type);
for I in Flist_First .. Flist_Last (El_List) loop
El := Get_Nth_Element (El_List, I);
Open_Temp;
Le := Chap6.Translate_Selected_Element (L, El);
Re := Chap6.Translate_Selected_Element (R, El);
Start_If_Stmt
(If_Blk,
New_Monadic_Op (ON_Not,
Translate_Equality (Le, Re, Get_Type (El))));
New_Return_Stmt (New_Lit (Std_Boolean_False_Node));
Finish_If_Stmt (If_Blk);
Close_Temp;
end loop;
New_Return_Stmt (New_Lit (Std_Boolean_True_Node));
Finish_Operator_Instance_Use (F_Info);
Finish_Subprogram_Body;
end Translate_Predefined_Record_Equality_Body;
procedure Translate_Predefined_Array_Logical_Spec (Subprg : Iir)
is
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
-- Info for the array type.
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
-- Identifier of the type.
Id : constant Name_Id :=
Get_Identifier (Get_Type_Declarator (Arr_Type));
Arr_Ptr_Type : constant O_Tnode :=
Tinfo.Ortho_Ptr_Type (Mode_Value);
F_Info : Operator_Info_Acc;
Interface_List : O_Inter_List;
Name : O_Ident;
Is_Monadic : Boolean;
begin
F_Info := Add_Info (Subprg, Kind_Operator);
--Chap2.Clear_Instance_Data (F_Info.Subprg_Instance);
F_Info.Operator_Stack2 := True;
Is_Monadic := False;
case Iir_Predefined_TF_Array_Functions
(Get_Implicit_Definition (Subprg)) is
when Iir_Predefined_TF_Array_And =>
Name := Create_Identifier (Id, "_AND");
when Iir_Predefined_TF_Array_Or =>
Name := Create_Identifier (Id, "_OR");
when Iir_Predefined_TF_Array_Nand =>
Name := Create_Identifier (Id, "_NAND");
when Iir_Predefined_TF_Array_Nor =>
Name := Create_Identifier (Id, "_NOR");
when Iir_Predefined_TF_Array_Xor =>
Name := Create_Identifier (Id, "_XOR");
when Iir_Predefined_TF_Array_Xnor =>
Name := Create_Identifier (Id, "_XNOR");
when Iir_Predefined_TF_Array_Not =>
Name := Create_Identifier (Id, "_NOT");
Is_Monadic := True;
end case;
-- Create function.
Start_Procedure_Decl (Interface_List, Name, Global_Storage);
-- Note: contrary to user function which returns composite value
-- via a result record, a concatenation returns its value without
-- the use of the record.
New_Interface_Decl (Interface_List, F_Info.Operator_Res,
Wki_Res, Arr_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Left,
Wki_Left, Arr_Ptr_Type);
if not Is_Monadic then
New_Interface_Decl (Interface_List, F_Info.Operator_Right,
Wki_Right, Arr_Ptr_Type);
end if;
Finish_Subprogram_Decl (Interface_List, F_Info.Operator_Node);
end Translate_Predefined_Array_Logical_Spec;
procedure Translate_Predefined_Array_Logical_Body (Subprg : Iir)
is
Arr_Type : constant Iir_Array_Type_Definition :=
Get_Type (Get_Interface_Declaration_Chain (Subprg));
-- Info for the array type.
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
Res : Mnode;
Var_Length, Var_I : O_Dnode;
Var_Base : O_Dnode;
Var_L_Base : O_Dnode;
Var_R_Base : O_Dnode;
If_Blk : O_If_Block;
Label : O_Snode;
Is_Monadic : Boolean;
El, L_El : O_Enode;
Op : ON_Op_Kind;
Do_Invert : Boolean;
begin
if Global_Storage = O_Storage_External then
return;
end if;
Is_Monadic := False;
case Iir_Predefined_TF_Array_Functions
(Get_Implicit_Definition (Subprg)) is
when Iir_Predefined_TF_Array_And =>
Op := ON_And;
Do_Invert := False;
when Iir_Predefined_TF_Array_Or =>
Op := ON_Or;
Do_Invert := False;
when Iir_Predefined_TF_Array_Nand =>
Op := ON_And;
Do_Invert := True;
when Iir_Predefined_TF_Array_Nor =>
Op := ON_Or;
Do_Invert := True;
when Iir_Predefined_TF_Array_Xor =>
Op := ON_Xor;
Do_Invert := False;
when Iir_Predefined_TF_Array_Xnor =>
Op := ON_Xor;
Do_Invert := True;
when Iir_Predefined_TF_Array_Not =>
Is_Monadic := True;
Op := ON_Not;
Do_Invert := False;
end case;
Start_Subprogram_Body (F_Info.Operator_Node);
New_Var_Decl (Var_Length, Wki_Length, O_Storage_Local,
Ghdl_Index_Type);
New_Var_Decl (Var_I, Wki_I, O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_Base, Get_Identifier ("base"), O_Storage_Local,
Tinfo.B.Base_Ptr_Type (Mode_Value));
New_Var_Decl (Var_L_Base, Get_Identifier ("l_base"), O_Storage_Local,
Tinfo.B.Base_Ptr_Type (Mode_Value));
if not Is_Monadic then
New_Var_Decl
(Var_R_Base, Get_Identifier ("r_base"), O_Storage_Local,
Tinfo.B.Base_Ptr_Type (Mode_Value));
end if;
Open_Temp;
-- Get length of LEFT.
New_Assign_Stmt
(New_Obj (Var_Length),
Chap6.Get_Array_Bound_Length
(Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value), Arr_Type, 1));
-- If dyadic, check RIGHT has the same length.
if not Is_Monadic then
Chap6.Check_Bound_Error
(New_Compare_Op
(ON_Neq,
New_Obj_Value (Var_Length),
Chap6.Get_Array_Bound_Length
(Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value),
Arr_Type, 1),
Ghdl_Bool_Type),
Subprg, 0);
end if;
-- Create the result from LEFT bound.
Res := Dp2M (F_Info.Operator_Res, Tinfo, Mode_Value);
Chap3.Translate_Object_Allocation
(Res, Alloc_Return, Arr_Type,
Chap3.Get_Composite_Bounds
(Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value)));
New_Assign_Stmt
(New_Obj (Var_Base), M2Addr (Chap3.Get_Composite_Base (Res)));
New_Assign_Stmt
(New_Obj (Var_L_Base),
M2Addr (Chap3.Get_Composite_Base
(Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value))));
if not Is_Monadic then
New_Assign_Stmt
(New_Obj (Var_R_Base),
M2Addr (Chap3.Get_Composite_Base
(Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value))));
end if;
-- Do the logical operation on each element.
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
New_Return_Stmt;
Finish_If_Stmt (If_Blk);
L_El := New_Value (New_Indexed_Element
(New_Acc_Value (New_Obj (Var_L_Base)),
New_Obj_Value (Var_I)));
if Is_Monadic then
El := New_Monadic_Op (Op, L_El);
else
El := New_Dyadic_Op
(Op, L_El,
New_Value (New_Indexed_Element
(New_Acc_Value (New_Obj (Var_R_Base)),
New_Obj_Value (Var_I))));
end if;
if Do_Invert then
El := New_Monadic_Op (ON_Not, El);
end if;
New_Assign_Stmt (New_Indexed_Element
(New_Acc_Value (New_Obj (Var_Base)),
New_Obj_Value (Var_I)),
El);
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
Close_Temp;
Finish_Subprogram_Body;
end Translate_Predefined_Array_Logical_Body;
procedure Translate_Predefined_Array_Shift_Spec (Subprg : Iir)
is
Inter : constant Iir := Get_Interface_Declaration_Chain (Subprg);
Int_Info : constant Type_Info_Acc :=
Get_Info (Get_Type (Get_Chain (Inter)));
Int_Type : constant O_Tnode := Int_Info.Ortho_Type (Mode_Value);
-- Info for the array type.
Arr_Type : constant Iir_Array_Type_Definition := Get_Type (Inter);
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
Arr_Ptr_Type : constant O_Tnode := Tinfo.Ortho_Ptr_Type (Mode_Value);
Id : constant Name_Id := Get_Identifier (Get_Type_Declarator (Arr_Type));
F_Info : Operator_Info_Acc;
Interface_List : O_Inter_List;
Name : O_Ident;
begin
F_Info := Add_Info (Subprg, Kind_Operator);
--Chap2.Clear_Instance_Data (F_Info.Subprg_Instance);
F_Info.Operator_Stack2 := True;
case Iir_Predefined_Shift_Functions (Get_Implicit_Definition (Subprg)) is
when Iir_Predefined_Array_Sll
| Iir_Predefined_Array_Srl =>
-- Shift logical.
Name := Create_Identifier (Id, "_SHL");
when Iir_Predefined_Array_Sla
| Iir_Predefined_Array_Sra =>
-- Shift arithmetic.
Name := Create_Identifier (Id, "_SHA");
when Iir_Predefined_Array_Rol
| Iir_Predefined_Array_Ror =>
-- Rotation
Name := Create_Identifier (Id, "_ROT");
end case;
-- Create function.
Start_Procedure_Decl (Interface_List, Name, Global_Storage);
-- Note: contrary to user function which returns composite value
-- via a result record, a shift returns its value without
-- the use of the record.
New_Interface_Decl (Interface_List, F_Info.Operator_Res,
Wki_Res, Arr_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Left,
Wki_Left, Arr_Ptr_Type);
New_Interface_Decl (Interface_List, F_Info.Operator_Right,
Wki_Right, Int_Type);
Finish_Subprogram_Decl (Interface_List, F_Info.Operator_Node);
end Translate_Predefined_Array_Shift_Spec;
procedure Translate_Predefined_Array_Shift_Body (Subprg : Iir)
is
Inter : constant Iir := Get_Interface_Declaration_Chain (Subprg);
Int_Info : constant Type_Info_Acc :=
Get_Info (Get_Type (Get_Chain (Inter)));
Int_Type : constant O_Tnode := Int_Info.Ortho_Type (Mode_Value);
-- Info for the array type.
Arr_Type : constant Iir_Array_Type_Definition := Get_Type (Inter);
Tinfo : constant Type_Info_Acc := Get_Info (Arr_Type);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
type Shift_Kind is (Sh_Logical, Sh_Arith, Rotation);
Shift : Shift_Kind;
-- Body;
Var_Length, Var_I, Var_I1 : O_Dnode;
Var_Res_Base, Var_L_Base : O_Dnode;
Var_Rl : O_Dnode;
Var_E : O_Dnode;
L : Mnode;
If_Blk, If_Blk1 : O_If_Block;
Label : O_Snode;
Res : Mnode;
procedure Do_Shift (To_Right : Boolean)
is
Tmp : O_Enode;
begin
-- LEFT:
-- * I := 0;
if not To_Right then
Init_Var (Var_I);
end if;
-- * If R < LENGTH then
Start_If_Stmt (If_Blk1,
New_Compare_Op (ON_Lt,
New_Obj_Value (Var_Rl),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
-- Shift the elements (that remains in the result).
-- RIGHT:
-- * for I = R to LENGTH - 1 loop
-- * RES[I] := L[I - R]
-- LEFT:
-- * for I = 0 to LENGTH - R loop
-- * RES[I] := L[R + I]
if To_Right then
New_Assign_Stmt (New_Obj (Var_I), New_Obj_Value (Var_Rl));
Init_Var (Var_I1);
else
New_Assign_Stmt (New_Obj (Var_I1), New_Obj_Value (Var_Rl));
end if;
Start_Loop_Stmt (Label);
if To_Right then
Tmp := New_Obj_Value (Var_I);
else
Tmp := New_Obj_Value (Var_I1);
end if;
Gen_Exit_When (Label, New_Compare_Op (ON_Ge,
Tmp,
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
New_Assign_Stmt
(New_Indexed_Acc_Value (New_Obj (Var_Res_Base),
New_Obj_Value (Var_I)),
New_Value
(New_Indexed_Acc_Value (New_Obj (Var_L_Base),
New_Obj_Value (Var_I1))));
Inc_Var (Var_I);
Inc_Var (Var_I1);
Finish_Loop_Stmt (Label);
-- RIGHT:
-- * else
-- * R := LENGTH;
if To_Right then
New_Else_Stmt (If_Blk1);
New_Assign_Stmt (New_Obj (Var_Rl), New_Obj_Value (Var_Length));
end if;
Finish_If_Stmt (If_Blk1);
-- Pad the result.
-- RIGHT:
-- * For I = 0 to R - 1
-- * RES[I] := 0/L[0/LENGTH-1]
-- LEFT:
-- * For I = LENGTH - R to LENGTH - 1
-- * RES[I] := 0/L[0/LENGTH-1]
if To_Right then
Init_Var (Var_I);
else
-- I is yet correctly set.
null;
end if;
if Shift = Sh_Arith then
if To_Right then
Tmp := New_Lit (Ghdl_Index_0);
else
Tmp := New_Dyadic_Op
(ON_Sub_Ov,
New_Obj_Value (Var_Length),
New_Lit (Ghdl_Index_1));
end if;
New_Assign_Stmt
(New_Obj (Var_E),
New_Value (New_Indexed_Acc_Value (New_Obj (Var_L_Base),
Tmp)));
end if;
Start_Loop_Stmt (Label);
if To_Right then
Tmp := New_Obj_Value (Var_Rl);
else
Tmp := New_Obj_Value (Var_Length);
end if;
Gen_Exit_When (Label, New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I),
Tmp,
Ghdl_Bool_Type));
case Shift is
when Sh_Logical =>
declare
Enum_List : constant Iir_Flist :=
Get_Enumeration_Literal_List
(Get_Base_Type (Get_Element_Subtype (Arr_Type)));
begin
Tmp := New_Lit
(Get_Ortho_Expr (Get_Nth_Element (Enum_List, 0)));
end;
when Sh_Arith =>
Tmp := New_Obj_Value (Var_E);
when Rotation =>
raise Internal_Error;
end case;
New_Assign_Stmt
(New_Indexed_Acc_Value (New_Obj (Var_Res_Base),
New_Obj_Value (Var_I)), Tmp);
Inc_Var (Var_I);
Finish_Loop_Stmt (Label);
end Do_Shift;
begin
if Global_Storage = O_Storage_External then
return;
end if;
case Iir_Predefined_Shift_Functions (Get_Implicit_Definition (Subprg)) is
when Iir_Predefined_Array_Sll
| Iir_Predefined_Array_Srl =>
-- Shift logical.
Shift := Sh_Logical;
when Iir_Predefined_Array_Sla
| Iir_Predefined_Array_Sra =>
-- Shift arithmetic.
Shift := Sh_Arith;
when Iir_Predefined_Array_Rol
| Iir_Predefined_Array_Ror =>
-- Rotation
Shift := Rotation;
end case;
-- Body
Start_Subprogram_Body (F_Info.Operator_Node);
New_Var_Decl (Var_Length, Wki_Length, O_Storage_Local,
Ghdl_Index_Type);
if Shift /= Rotation then
New_Var_Decl (Var_Rl, Get_Identifier ("rl"), O_Storage_Local,
Ghdl_Index_Type);
end if;
New_Var_Decl (Var_I, Wki_I, O_Storage_Local, Ghdl_Index_Type);
New_Var_Decl (Var_I1, Get_Identifier ("I1"), O_Storage_Local,
Ghdl_Index_Type);
New_Var_Decl (Var_Res_Base, Get_Identifier ("res_base"),
O_Storage_Local, Tinfo.B.Base_Ptr_Type (Mode_Value));
New_Var_Decl (Var_L_Base, Get_Identifier ("l_base"),
O_Storage_Local, Tinfo.B.Base_Ptr_Type (Mode_Value));
if Shift = Sh_Arith then
New_Var_Decl (Var_E, Get_Identifier ("E"), O_Storage_Local,
Get_Info (Get_Element_Subtype (Arr_Type)).
Ortho_Type (Mode_Value));
end if;
Res := Dp2M (F_Info.Operator_Res, Tinfo, Mode_Value);
L := Dp2M (F_Info.Operator_Left, Tinfo, Mode_Value);
-- LRM93 7.2.3
-- The index subtypes of the return values of all shift operators is
-- the same as the index subtype of their left arguments.
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Bounds (Res)),
M2Addr (Chap3.Get_Composite_Bounds (L)));
-- Get length of LEFT.
New_Assign_Stmt (New_Obj (Var_Length),
Chap3.Get_Array_Length (L, Arr_Type));
-- LRM93 7.2.3 [6 times]
-- That is, if R is 0 or L is a null array, the return value is L.
Start_If_Stmt
(If_Blk,
New_Dyadic_Op
(ON_Or,
New_Compare_Op (ON_Eq,
New_Obj_Value (F_Info.Operator_Right),
New_Lit (New_Signed_Literal (Int_Type, 0)),
Ghdl_Bool_Type),
New_Compare_Op (ON_Eq,
New_Obj_Value (Var_Length),
New_Lit (Ghdl_Index_0),
Ghdl_Bool_Type)));
New_Assign_Stmt
(M2Lp (Chap3.Get_Composite_Base (Res)),
M2Addr (Chap3.Get_Composite_Base (L)));
New_Return_Stmt;
Finish_If_Stmt (If_Blk);
-- Allocate base.
New_Assign_Stmt
(New_Obj (Var_Res_Base),
Gen_Alloc (Alloc_Return, New_Obj_Value (Var_Length),
Tinfo.B.Base_Ptr_Type (Mode_Value)));
New_Assign_Stmt (M2Lp (Chap3.Get_Composite_Base (Res)),
New_Obj_Value (Var_Res_Base));
New_Assign_Stmt (New_Obj (Var_L_Base),
M2Addr (Chap3.Get_Composite_Base (L)));
Start_If_Stmt (If_Blk,
New_Compare_Op (ON_Gt,
New_Obj_Value (F_Info.Operator_Right),
New_Lit (New_Signed_Literal (Int_Type,
0)),
Ghdl_Bool_Type));
-- R > 0.
-- Ie, to the right
case Shift is
when Rotation =>
-- * I1 := LENGTH - (R mod LENGTH)
New_Assign_Stmt
(New_Obj (Var_I1),
New_Dyadic_Op
(ON_Sub_Ov,
New_Obj_Value (Var_Length),
New_Dyadic_Op
(ON_Mod_Ov,
New_Convert_Ov (New_Obj_Value (F_Info.Operator_Right),
Ghdl_Index_Type),
New_Obj_Value (Var_Length))));
when Sh_Logical
| Sh_Arith =>
-- Real SRL or SRA.
New_Assign_Stmt
(New_Obj (Var_Rl),
New_Convert_Ov (New_Obj_Value (F_Info.Operator_Right),
Ghdl_Index_Type));
Do_Shift (True);
end case;
New_Else_Stmt (If_Blk);
-- R < 0, to the left.
case Shift is
when Rotation =>
-- * I1 := (-R) mod LENGTH
New_Assign_Stmt
(New_Obj (Var_I1),
New_Dyadic_Op (ON_Mod_Ov,
New_Convert_Ov
(New_Monadic_Op
(ON_Neg_Ov,
New_Obj_Value (F_Info.Operator_Right)),
Ghdl_Index_Type),
New_Obj_Value (Var_Length)));
when Sh_Logical
| Sh_Arith =>
-- Real SLL or SLA.
New_Assign_Stmt
(New_Obj (Var_Rl),
New_Convert_Ov (New_Monadic_Op
(ON_Neg_Ov,
New_Obj_Value (F_Info.Operator_Right)),
Ghdl_Index_Type));
Do_Shift (False);
end case;
Finish_If_Stmt (If_Blk);
if Shift = Rotation then
-- * If I1 = LENGTH then
-- * I1 := 0
Start_If_Stmt (If_Blk, New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I1),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
Init_Var (Var_I1);
Finish_If_Stmt (If_Blk);
-- * for I = 0 to LENGTH - 1 loop
-- * RES[I] := L[I1];
Init_Var (Var_I);
Start_Loop_Stmt (Label);
Gen_Exit_When (Label, New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
New_Assign_Stmt
(New_Indexed_Acc_Value (New_Obj (Var_Res_Base),
New_Obj_Value (Var_I)),
New_Value
(New_Indexed_Acc_Value (New_Obj (Var_L_Base),
New_Obj_Value (Var_I1))));
Inc_Var (Var_I);
-- * I1 := I1 + 1
Inc_Var (Var_I1);
-- * If I1 = LENGTH then
-- * I1 := 0
Start_If_Stmt (If_Blk, New_Compare_Op (ON_Ge,
New_Obj_Value (Var_I1),
New_Obj_Value (Var_Length),
Ghdl_Bool_Type));
Init_Var (Var_I1);
Finish_If_Stmt (If_Blk);
Finish_Loop_Stmt (Label);
end if;
Finish_Subprogram_Body;
end Translate_Predefined_Array_Shift_Body;
procedure Translate_File_Subprogram_Spec (Subprg : Iir; File_Type : Iir)
is
Etype : constant Iir := Get_Type (Get_File_Type_Mark (File_Type));
Tinfo : constant Type_Info_Acc := Get_Info (Etype);
Kind : Iir_Predefined_Functions;
F_Info : Operator_Info_Acc;
Name : O_Ident;
Inter_List : O_Inter_List;
Id : Name_Id;
begin
if Tinfo.Type_Mode in Type_Mode_Scalar then
-- Intrinsic.
return;
end if;
F_Info := Add_Info (Subprg, Kind_Operator);
--Chap2.Clear_Instance_Data (F_Info.Subprg_Instance);
F_Info.Operator_Stack2 := False;
Id := Get_Identifier (Get_Type_Declarator (File_Type));
Kind := Get_Implicit_Definition (Subprg);
case Kind is
when Iir_Predefined_Write =>
Name := Create_Identifier (Id, "_WRITE");
when Iir_Predefined_Read
| Iir_Predefined_Read_Length =>
Name := Create_Identifier (Id, "_READ");
when others =>
raise Internal_Error;
end case;
-- Create function.
if Kind = Iir_Predefined_Read_Length then
Start_Function_Decl
(Inter_List, Name, Global_Storage, Std_Integer_Otype);
else
Start_Procedure_Decl (Inter_List, Name, Global_Storage);
end if;
Create_Operator_Instance (Inter_List, F_Info);
New_Interface_Decl (Inter_List, F_Info.Operator_Left,
Get_Identifier ("FILE"), Ghdl_File_Index_Type);
New_Interface_Decl (Inter_List, F_Info.Operator_Right,
Wki_Val, Tinfo.Ortho_Ptr_Type (Mode_Value));
Finish_Subprogram_Decl (Inter_List, F_Info.Operator_Node);
end Translate_File_Subprogram_Spec;
procedure Translate_File_Subprogram_Body (Subprg : Iir; File_Type : Iir)
is
Etype : constant Iir := Get_Type (Get_File_Type_Mark (File_Type));
Tinfo : constant Type_Info_Acc := Get_Info (Etype);
F_Info : constant Operator_Info_Acc := Get_Info (Subprg);
Kind : constant Iir_Predefined_Functions
:= Get_Implicit_Definition (Subprg);
procedure Translate_Rw (Val : Mnode; Val_Type : Iir; Proc : O_Dnode);
procedure Translate_Rw_Array
(Val : Mnode; Val_Type : Iir; Var_Max : O_Dnode; Proc : O_Dnode)
is
Var_It : O_Dnode;
Label : O_Snode;
begin
Var_It := Create_Temp (Ghdl_Index_Type);
Init_Var (Var_It);
Start_Loop_Stmt (Label);
Gen_Exit_When
(Label,
New_Compare_Op (ON_Eq,
New_Obj_Value (Var_It),
New_Obj_Value (Var_Max),
Ghdl_Bool_Type));
Translate_Rw
(Chap3.Index_Base (Val, Val_Type, New_Obj_Value (Var_It)),
Get_Element_Subtype (Val_Type), Proc);
Inc_Var (Var_It);
Finish_Loop_Stmt (Label);
end Translate_Rw_Array;
procedure Translate_Rw (Val : Mnode; Val_Type : Iir; Proc : O_Dnode)
is
Val_Info : Type_Info_Acc;
Assocs : O_Assoc_List;
begin
Val_Info := Get_Type_Info (Val);
case Val_Info.Type_Mode is
when Type_Mode_Scalar =>
Start_Association (Assocs, Proc);
-- compute file parameter (get an index)
New_Association (Assocs, New_Obj_Value (F_Info.Operator_Left));
-- compute the value.
New_Association
(Assocs, New_Convert_Ov (M2Addr (Val), Ghdl_Ptr_Type));
-- length.
New_Association
(Assocs,
New_Lit (New_Sizeof (Val_Info.Ortho_Type (Mode_Value),
Ghdl_Index_Type)));
-- call a predefined procedure
New_Procedure_Call (Assocs);
when Type_Mode_Bounded_Records =>
declare
El_List : constant Iir_Flist :=
Get_Elements_Declaration_List (Get_Base_Type (Val_Type));
El : Iir;
Val1 : Mnode;
begin
Open_Temp;
Val1 := Stabilize (Val);
for I in Flist_First .. Flist_Last (El_List) loop
El := Get_Nth_Element (El_List, I);
Translate_Rw
(Chap6.Translate_Selected_Element (Val1, El),
Get_Type (El), Proc);
end loop;
Close_Temp;
end;
when Type_Mode_Bounded_Arrays =>
declare
Var_Max : O_Dnode;
begin
Open_Temp;
Var_Max := Create_Temp (Ghdl_Index_Type);
New_Assign_Stmt
(New_Obj (Var_Max),
Chap3.Get_Array_Type_Length (Val_Type));
Translate_Rw_Array (Val, Val_Type, Var_Max, Proc);
Close_Temp;
end;
when Type_Mode_Unknown
| Type_Mode_File
| Type_Mode_Acc
| Type_Mode_Bounds_Acc
| Type_Mode_Unbounded_Array
| Type_Mode_Unbounded_Record
| Type_Mode_Protected =>
raise Internal_Error;
end case;
end Translate_Rw;
procedure Translate_Rw_Length (Var_Length : O_Dnode; Proc : O_Dnode)
is
Assocs : O_Assoc_List;
begin
Start_Association (Assocs, Proc);
New_Association (Assocs, New_Obj_Value (F_Info.Operator_Left));
New_Association
(Assocs, New_Unchecked_Address (New_Obj (Var_Length),
Ghdl_Ptr_Type));
New_Association
(Assocs,
New_Lit (New_Sizeof (Ghdl_Index_Type, Ghdl_Index_Type)));
New_Procedure_Call (Assocs);
end Translate_Rw_Length;
Var : Mnode;
begin
if F_Info = null then
return;
end if;
if Global_Storage = O_Storage_External then
return;
end if;
Start_Subprogram_Body (F_Info.Operator_Node);
Start_Operator_Instance_Use (F_Info);
Push_Local_Factory;
Var := Dp2M (F_Info.Operator_Right, Tinfo, Mode_Value);
case Kind is
when Iir_Predefined_Write =>
if Tinfo.Type_Mode = Type_Mode_Fat_Array then
declare
Var_Max : O_Dnode;
begin
Open_Temp;
Var_Max := Create_Temp_Init
(Ghdl_Index_Type,
Chap3.Get_Array_Length (Var, Etype));
Translate_Rw_Length (Var_Max, Ghdl_Write_Scalar);
Translate_Rw_Array (Chap3.Get_Composite_Base (Var), Etype,
Var_Max, Ghdl_Write_Scalar);
Close_Temp;
end;
else
Translate_Rw (Var, Etype, Ghdl_Write_Scalar);
end if;
when Iir_Predefined_Read =>
Translate_Rw (Var, Etype, Ghdl_Read_Scalar);
when Iir_Predefined_Read_Length =>
declare
Var_Len : O_Dnode;
begin
Open_Temp;
Var_Len := Create_Temp (Ghdl_Index_Type);
Translate_Rw_Length (Var_Len, Ghdl_Read_Scalar);
Chap6.Check_Bound_Error
(New_Compare_Op (ON_Gt,
New_Obj_Value (Var_Len),
Chap3.Get_Array_Length (Var, Etype),
Ghdl_Bool_Type),
Subprg, 1);
Translate_Rw_Array (Chap3.Get_Composite_Base (Var), Etype,
Var_Len, Ghdl_Read_Scalar);
New_Return_Stmt (New_Convert_Ov (New_Obj_Value (Var_Len),
Std_Integer_Otype));
Close_Temp;
end;
when others =>
raise Internal_Error;
end case;
Finish_Operator_Instance_Use (F_Info);
Pop_Local_Factory;
Finish_Subprogram_Body;
end Translate_File_Subprogram_Body;
procedure Init_Implicit_Subprogram_Infos
(Infos : out Implicit_Subprogram_Infos) is
begin
-- Be independant of declaration order since the same subprogram
-- may be used for several implicit operators (eg. array comparaison)
Infos.Arr_Eq_Info := null;
Infos.Arr_Cmp_Info := null;
Infos.Rec_Eq_Info := null;
Infos.Arr_Shl_Info := null;
Infos.Arr_Sha_Info := null;
Infos.Arr_Rot_Info := null;
end Init_Implicit_Subprogram_Infos;
procedure Translate_Implicit_Subprogram_Spec
(Subprg : Iir; Infos : in out Implicit_Subprogram_Infos)
is
Kind : constant Iir_Predefined_Functions :=
Get_Implicit_Definition (Subprg);
begin
case Get_Implicit_Definition (Subprg) is
when Iir_Predefined_Error
| Iir_Predefined_Explicit =>
raise Internal_Error;
when Iir_Predefined_Boolean_And
| Iir_Predefined_Boolean_Or
| Iir_Predefined_Boolean_Xor
| Iir_Predefined_Boolean_Not
| Iir_Predefined_Enum_Equality
| Iir_Predefined_Enum_Inequality
| Iir_Predefined_Enum_Less
| Iir_Predefined_Enum_Less_Equal
| Iir_Predefined_Enum_Greater
| Iir_Predefined_Enum_Greater_Equal
| Iir_Predefined_Bit_And
| Iir_Predefined_Bit_Or
| Iir_Predefined_Bit_Xor
| Iir_Predefined_Bit_Not
| Iir_Predefined_Integer_Equality
| Iir_Predefined_Integer_Inequality
| Iir_Predefined_Integer_Less
| Iir_Predefined_Integer_Less_Equal
| Iir_Predefined_Integer_Greater
| Iir_Predefined_Integer_Greater_Equal
| Iir_Predefined_Integer_Negation
| Iir_Predefined_Integer_Absolute
| Iir_Predefined_Integer_Plus
| Iir_Predefined_Integer_Minus
| Iir_Predefined_Integer_Mul
| Iir_Predefined_Integer_Div
| Iir_Predefined_Integer_Mod
| Iir_Predefined_Integer_Rem
| Iir_Predefined_Floating_Equality
| Iir_Predefined_Floating_Inequality
| Iir_Predefined_Floating_Less
| Iir_Predefined_Floating_Less_Equal
| Iir_Predefined_Floating_Greater
| Iir_Predefined_Floating_Greater_Equal
| Iir_Predefined_Floating_Negation
| Iir_Predefined_Floating_Absolute
| Iir_Predefined_Floating_Plus
| Iir_Predefined_Floating_Minus
| Iir_Predefined_Floating_Mul
| Iir_Predefined_Floating_Div
| Iir_Predefined_Physical_Equality
| Iir_Predefined_Physical_Inequality
| Iir_Predefined_Physical_Less
| Iir_Predefined_Physical_Less_Equal
| Iir_Predefined_Physical_Greater
| Iir_Predefined_Physical_Greater_Equal
| Iir_Predefined_Physical_Negation
| Iir_Predefined_Physical_Absolute
| Iir_Predefined_Physical_Plus
| Iir_Predefined_Physical_Minus =>
pragma Assert (Predefined_To_Onop (Kind) /= ON_Nil);
return;
when Iir_Predefined_Boolean_Nand
| Iir_Predefined_Boolean_Nor
| Iir_Predefined_Boolean_Xnor
| Iir_Predefined_Bit_Nand
| Iir_Predefined_Bit_Nor
| Iir_Predefined_Bit_Xnor
| Iir_Predefined_Bit_Match_Equality
| Iir_Predefined_Bit_Match_Inequality
| Iir_Predefined_Bit_Match_Less
| Iir_Predefined_Bit_Match_Less_Equal
| Iir_Predefined_Bit_Match_Greater
| Iir_Predefined_Bit_Match_Greater_Equal
| Iir_Predefined_Bit_Condition
| Iir_Predefined_Boolean_Rising_Edge
| Iir_Predefined_Boolean_Falling_Edge
| Iir_Predefined_Bit_Rising_Edge
| Iir_Predefined_Bit_Falling_Edge =>
-- Intrinsic.
null;
when Iir_Predefined_Enum_Minimum
| Iir_Predefined_Enum_Maximum
| Iir_Predefined_Enum_To_String =>
-- Intrinsic.
null;
when Iir_Predefined_Integer_Identity
| Iir_Predefined_Integer_Exp
| Iir_Predefined_Integer_Minimum
| Iir_Predefined_Integer_Maximum
| Iir_Predefined_Integer_To_String =>
-- Intrinsic.
null;
when Iir_Predefined_Universal_R_I_Mul
| Iir_Predefined_Universal_I_R_Mul
| Iir_Predefined_Universal_R_I_Div =>
-- Intrinsic
null;
when Iir_Predefined_Physical_Identity
| Iir_Predefined_Physical_Minimum
| Iir_Predefined_Physical_Maximum
| Iir_Predefined_Physical_To_String
| Iir_Predefined_Time_To_String_Unit =>
null;
when Iir_Predefined_Physical_Integer_Mul
| Iir_Predefined_Physical_Integer_Div
| Iir_Predefined_Integer_Physical_Mul
| Iir_Predefined_Physical_Real_Mul
| Iir_Predefined_Physical_Real_Div
| Iir_Predefined_Real_Physical_Mul
| Iir_Predefined_Physical_Physical_Div =>
null;
when Iir_Predefined_Floating_Exp
| Iir_Predefined_Floating_Identity
| Iir_Predefined_Floating_Minimum
| Iir_Predefined_Floating_Maximum
| Iir_Predefined_Floating_To_String
| Iir_Predefined_Real_To_String_Digits
| Iir_Predefined_Real_To_String_Format =>
null;
when Iir_Predefined_Record_Equality
| Iir_Predefined_Record_Inequality =>
if Infos.Rec_Eq_Info = null then
Translate_Predefined_Record_Equality_Spec (Subprg);
Infos.Rec_Eq_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Rec_Eq_Info);
end if;
when Iir_Predefined_Array_Equality
| Iir_Predefined_Array_Inequality
| Iir_Predefined_Bit_Array_Match_Equality
| Iir_Predefined_Bit_Array_Match_Inequality =>
if Infos.Arr_Eq_Info = null then
Translate_Predefined_Array_Equality_Spec (Subprg);
Infos.Arr_Eq_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Arr_Eq_Info);
end if;
when Iir_Predefined_Array_Greater
| Iir_Predefined_Array_Greater_Equal
| Iir_Predefined_Array_Less
| Iir_Predefined_Array_Less_Equal
| Iir_Predefined_Array_Minimum
| Iir_Predefined_Array_Maximum =>
if Infos.Arr_Cmp_Info = null then
Translate_Predefined_Array_Compare_Spec (Subprg);
Infos.Arr_Cmp_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Arr_Cmp_Info);
end if;
when Iir_Predefined_Array_Array_Concat
| Iir_Predefined_Array_Element_Concat
| Iir_Predefined_Element_Array_Concat
| Iir_Predefined_Element_Element_Concat =>
null;
when Iir_Predefined_Vector_Minimum
| Iir_Predefined_Vector_Maximum =>
null;
when Iir_Predefined_TF_Array_And
| Iir_Predefined_TF_Array_Or
| Iir_Predefined_TF_Array_Nand
| Iir_Predefined_TF_Array_Nor
| Iir_Predefined_TF_Array_Xor
| Iir_Predefined_TF_Array_Xnor
| Iir_Predefined_TF_Array_Not =>
Translate_Predefined_Array_Logical_Spec (Subprg);
when Iir_Predefined_TF_Reduction_And
| Iir_Predefined_TF_Reduction_Or
| Iir_Predefined_TF_Reduction_Nand
| Iir_Predefined_TF_Reduction_Nor
| Iir_Predefined_TF_Reduction_Xor
| Iir_Predefined_TF_Reduction_Xnor
| Iir_Predefined_TF_Reduction_Not
| Iir_Predefined_TF_Array_Element_And
| Iir_Predefined_TF_Element_Array_And
| Iir_Predefined_TF_Array_Element_Or
| Iir_Predefined_TF_Element_Array_Or
| Iir_Predefined_TF_Array_Element_Nand
| Iir_Predefined_TF_Element_Array_Nand
| Iir_Predefined_TF_Array_Element_Nor
| Iir_Predefined_TF_Element_Array_Nor
| Iir_Predefined_TF_Array_Element_Xor
| Iir_Predefined_TF_Element_Array_Xor
| Iir_Predefined_TF_Array_Element_Xnor
| Iir_Predefined_TF_Element_Array_Xnor =>
null;
when Iir_Predefined_Array_Sll
| Iir_Predefined_Array_Srl =>
if Infos.Arr_Shl_Info = null then
Translate_Predefined_Array_Shift_Spec (Subprg);
Infos.Arr_Shl_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Arr_Shl_Info);
end if;
when Iir_Predefined_Array_Sla
| Iir_Predefined_Array_Sra =>
if Infos.Arr_Sha_Info = null then
Translate_Predefined_Array_Shift_Spec (Subprg);
Infos.Arr_Sha_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Arr_Sha_Info);
end if;
when Iir_Predefined_Array_Rol
| Iir_Predefined_Array_Ror =>
if Infos.Arr_Rot_Info = null then
Translate_Predefined_Array_Shift_Spec (Subprg);
Infos.Arr_Rot_Info := Get_Info (Subprg);
else
Set_Info (Subprg, Infos.Arr_Rot_Info);
end if;
when Iir_Predefined_Access_Equality
| Iir_Predefined_Access_Inequality =>
-- Intrinsic.
null;
when Iir_Predefined_Deallocate =>
-- Intrinsic.
null;
when Iir_Predefined_File_Open
| Iir_Predefined_File_Open_Status
| Iir_Predefined_File_Close
| Iir_Predefined_Flush
| Iir_Predefined_Endfile =>
-- All of them have predefined definitions.
null;
when Iir_Predefined_Write
| Iir_Predefined_Read_Length
| Iir_Predefined_Read =>
declare
Param : constant Iir :=
Get_Interface_Declaration_Chain (Subprg);
File_Type : constant Iir := Get_Type (Param);
begin
if not Get_Text_File_Flag (File_Type) then
Translate_File_Subprogram_Spec (Subprg, File_Type);
end if;
end;
when Iir_Predefined_Array_Char_To_String
| Iir_Predefined_Bit_Vector_To_Ostring
| Iir_Predefined_Bit_Vector_To_Hstring
| Iir_Predefined_Std_Ulogic_Match_Equality
| Iir_Predefined_Std_Ulogic_Match_Inequality
| Iir_Predefined_Std_Ulogic_Match_Less
| Iir_Predefined_Std_Ulogic_Match_Less_Equal
| Iir_Predefined_Std_Ulogic_Match_Greater
| Iir_Predefined_Std_Ulogic_Match_Greater_Equal
| Iir_Predefined_Std_Ulogic_Array_Match_Equality
| Iir_Predefined_Std_Ulogic_Array_Match_Inequality =>
null;
when Iir_Predefined_Now_Function =>
null;
-- when others =>
-- Error_Kind ("translate_implicit_subprogram ("
-- & Iir_Predefined_Functions'Image (Kind) & ")",
-- Subprg);
end case;
end Translate_Implicit_Subprogram_Spec;
procedure Translate_Implicit_Subprogram_Body (Subprg : Iir)
is
Info : constant Operator_Info_Acc := Get_Info (Subprg);
begin
if Info = null or else Info.Operator_Body then
return;
end if;
-- Translate only once.
Info.Operator_Body := True;
case Get_Implicit_Definition (Subprg) is
when Iir_Predefined_Record_Equality
| Iir_Predefined_Record_Inequality =>
Translate_Predefined_Record_Equality_Body (Subprg);
when Iir_Predefined_Array_Equality
| Iir_Predefined_Array_Inequality
| Iir_Predefined_Bit_Array_Match_Equality
| Iir_Predefined_Bit_Array_Match_Inequality =>
Translate_Predefined_Array_Equality_Body (Subprg);
when Iir_Predefined_Array_Greater
| Iir_Predefined_Array_Greater_Equal
| Iir_Predefined_Array_Less
| Iir_Predefined_Array_Less_Equal
| Iir_Predefined_Array_Minimum
| Iir_Predefined_Array_Maximum =>
Translate_Predefined_Array_Compare_Body (Subprg);
when Iir_Predefined_TF_Array_And
| Iir_Predefined_TF_Array_Or
| Iir_Predefined_TF_Array_Nand
| Iir_Predefined_TF_Array_Nor
| Iir_Predefined_TF_Array_Xor
| Iir_Predefined_TF_Array_Xnor
| Iir_Predefined_TF_Array_Not =>
Translate_Predefined_Array_Logical_Body (Subprg);
when Iir_Predefined_Array_Sll
| Iir_Predefined_Array_Srl
| Iir_Predefined_Array_Sla
| Iir_Predefined_Array_Sra
| Iir_Predefined_Array_Rol
| Iir_Predefined_Array_Ror =>
Translate_Predefined_Array_Shift_Body (Subprg);
when Iir_Predefined_Write
| Iir_Predefined_Read_Length
| Iir_Predefined_Read =>
declare
Param : constant Iir :=
Get_Interface_Declaration_Chain (Subprg);
File_Type : constant Iir := Get_Type (Param);
begin
if not Get_Text_File_Flag (File_Type) then
Translate_File_Subprogram_Body (Subprg, File_Type);
end if;
end;
when others =>
raise Internal_Error;
end case;
end Translate_Implicit_Subprogram_Body;
end Trans.Chap7;
|