File: v2cc-impl.cc

package info (click to toggle)
freehdl 0.0.8-2.2
  • links: PTS
  • area: main
  • in suites: buster, sid, stretch
  • size: 8,632 kB
  • ctags: 10,443
  • sloc: cpp: 45,275; sh: 11,405; yacc: 4,206; ansic: 2,026; lex: 486; perl: 430; makefile: 390; tcl: 100
file content (3527 lines) | stat: -rw-r--r-- 140,518 bytes parent folder | download | duplicates (2)
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
#include <algorithm>
#include <stdlib.h>
#include <ctype.h>
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <freehdl/vaul.h>
#include "v2cc-chunk.h"
#include "mapping.h"
#include "v2cc-util.h"


void
emit_subprogram_associations (string &str, RegionStack &rstack, pIIR_AssociationList assocs, 
			      pIIR_InterfaceList formals, list<AccessDescriptor> &extra_parameter)
{
  string separator = "";

  // ****************************************************************************
  // Add normal subprogram parameter
  // ****************************************************************************
  for (pIIR_InterfaceList fl = formals; fl; fl = fl->rest) {
    pIIR_InterfaceDeclaration par = fl->first; // select formal parameter

    /* Select association element from an association list which
     * corresponds with given formal */
    list<pIIR_AssociationElement> a_list = find_matching_actuals(assocs, par); 
    assert (a_list.size() <= 1); // Only simple assoication is currently supported here!
    pIIR_AssociationElement a = a_list.size() == 0? NULL : a_list.front();
    
    str += separator;
    
    if (a != NULL && !a->actual->is(IR_OPEN_EXPRESSION)) {
      // An actual is associated with the formal
      if (a->formal_conversion)  {
	str += "/* converted by ";
	emit_id (a->formal_conversion, str, rstack);
	str += " */";
      }

      // *******************************************************
      // Handle signal parameter
      // *******************************************************
      if (par->is(IR_SIGNAL_INTERFACE_DECLARATION)) {
	// First, append sig_info pointer
	emit_expr (a->actual, str, rstack, SIGNAL);
	// Next, append reader if signal is of mode in or inout or buffer
	if (par->mode == IR_IN_MODE || par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE) {
	  str += ",";
	  emit_expr (a->actual, str, rstack, READER);
	}
	// Finally, append driver if mode is of out or inout or buffer
	if (par->mode == IR_OUT_MODE || par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE) {
	  str += ",";
	  emit_expr (a->actual, str, rstack, DRIVER);
	}
	
      } else
	// *******************************************************
	// Handle normal parameter (non signal)
	// *******************************************************
	emit_expr (a->actual, str, rstack, id_type(READER, DEREF));
      
    } else if (par->initial_value != NULL)
      // If the parameter was left open then insert the default
      // value if one is defined in the interface declaration
      emit_expr (par->initial_value, str, rstack, DEFAULT);
    
    else 
      // If no default value is defined for the formal then create a
      // dummy instance of the appropriate type
      str += create_default_instance(par->subtype, rstack);
    
    
    separator = ",";
  }
  
  // ****************************************************************************
  // Add extra subprogram parameter
  // ****************************************************************************
  for (list<AccessDescriptor>::iterator iter = extra_parameter.begin();
       iter != extra_parameter.end(); iter++) {
    pIIR_Declaration par = (*iter).declaration;

    if (par->is(IR_VARIABLE_INTERFACE_DECLARATION) ||
	par->is(IR_VARIABLE_DECLARATION) ||
	par->is(IR_CONSTANT_INTERFACE_DECLARATION) ||
	par->is(IR_CONSTANT_DECLARATION) ||
	par->is(IR_FILE_DECLARATION) ||
	par->is(IR_FILE_INTERFACE_DECLARATION)) {
      str += separator + qid(par, rstack, DEFAULT);
 
    } else if (par->is(IR_SIGNAL_INTERFACE_DECLARATION) ||
	       par->is(IR_SIGNAL_DECLARATION)) {
      pIIR_ObjectDeclaration opar = pIIR_ObjectDeclaration(par);
      AccessFlags &aflags = (*iter).access_type;
      // Add sign_info pointer if a signal function kind attribute has
      // been applied on the parameter
      if ((aflags & SIGNAL_FUNCTION_ATTRIBUTE)  ||
	  (aflags & SENSITIVE)) {
	str += separator + qid(par, rstack, SIGNAL);
	separator = ",";
      }
      // Next, append reader if signal is read
      if (aflags & READ) {
	str += separator + qid(par, rstack, READER);
	separator = ",";
      }
      // Finally, append driver if signal is written
      if (aflags & WRITE)
	str += separator + qid(par, rstack, DRIVER);

    } else if (par->is(IR_TYPE_DECLARATION) ||
	       par->is(IR_SUBTYPE_DECLARATION)) {
      // A type has been used and we need to pass over the type info
      // pointer of that type!
      str += separator + qid(par, rstack, INFO) + "_INFO";

    } else
      continue;

    // Set separator for next parameter
    separator = ",";
  }

}


// create code to initialize VHDL objects
void
emit_decls_init_item (pIIR_DeclarationList dl, string &str, RegionStack &rstack, int l)
{
  pIIR_TypeDeclaration type = NULL;
  string type_str = "";
  string init_str = "";
  string info_str = "";
  bool complex_info = false;
  pIIR_Declaration decl = pIIR_Declaration(dl->first);

  //***********************************************************************
  // first, check whether a info object has to be created at
  // runtime. This is required e.g. for objects of an implicit
  // created array subtype.
  // (e.g.: "variable var : bit_vector(0 to 3)")
  //***********************************************************************
  if (decl->is(IR_OBJECT_DECLARATION) &&
      pIIR_ObjectDeclaration(decl)->alias_base != NULL) {
    
  } else if (decl->is(V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR)) {
    // If this signal has not been used then do not output any
    // initialization for it!
    pV2CC_ImplicitSignalDeclaration_WaitFor obj = pV2CC_ImplicitSignalDeclaration_WaitFor(decl);
    info_str = "&L3std_Q8standard_I7boolean_INFO";
    complex_info = false;
    type = NULL;
    
  } else if (decl->is(IR_SIGNAL_DECLARATION) ||
	     decl->is(IR_VARIABLE_DECLARATION) ||
	     decl->is(IR_CONSTANT_DECLARATION)) {
    // currently, only signals, variables and constants are considered.
    // Try to find the corresponding type declaration.
    pIIR_ObjectDeclaration obj = pIIR_ObjectDeclaration(decl);
    complex_info = is_implicit_array_subtype(pIIR_ObjectDeclaration(decl)->subtype);
    type = get_declaration(obj->subtype);
    info_str = get_type_info_obj(obj->subtype, rstack, false);
    
  } else if (decl->is(V2CC_INTERNAL_OBJECT_DECLARATION)) {
    
  } else if (decl->is(IR_TYPE_DECLARATION)) {
    
  } else if (decl->is(IR_FILE_DECLARATION)) {
    
  } else if (decl->is(IR_SUBPROGRAM_DECLARATION)) {
    
  } else
    // all other kind of objects are not considered
    return;
  
  
  //***********************************************************************
  // Now, generate code to initialize objects depending on the object type
  //***********************************************************************
  if (decl->is(IR_OBJECT_DECLARATION) &&
      pIIR_ObjectDeclaration(decl)->alias_base != NULL) {
    // **************************************************************************
    // Alias declaration
    // **************************************************************************
    pIIR_ObjectDeclaration alias_decl = pIIR_ObjectDeclaration(decl);
    // Determine aliased object
    pIIR_ObjectDeclaration aliased_object = get_object_declaration(alias_decl->alias_base);
    
    if (aliased_object->is(IR_CONSTANT_DECLARATION) ||
	aliased_object->is(IR_VARIABLE_DECLARATION) || 
	aliased_object->is(IR_CONSTANT_INTERFACE_DECLARATION) ||
	aliased_object->is(IR_VARIABLE_INTERFACE_DECLARATION)) {
      
      if (is_array_type(alias_decl->subtype)) {
	// **************************************************************************
	// Array alias
	// **************************************************************************
	// Array alias objects are declared via a special array type
	// array_alias
	string array_info_str, array_data_str;
	
	// Check whether the aliased array is an array slice or the
	// entire array shall be aliased
	if (alias_decl->alias_base->is(IR_SLICE_REFERENCE)) {
	  pIIR_SliceReference sr = pIIR_SliceReference(alias_decl->alias_base);
	  // Get slice range
	  vector<RangeDescriptor> range_desc = get_discrete_range(sr, rstack, IR_NOT_STATIC);
	  StaticRangeDescriptor<string, string> range = 
	    range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));
	  // The array data pointer points to the left element of the slice
	  array_data_str += "&";
	  emit_expr(sr->array, array_data_str, rstack, id_type(READER, DEREF));
	  array_data_str += "[" + range.left + "]";
	  // Assume that no subtype is specified for the alias
	  // name. Hence, the array_info object is derived from the
	  // slice range.
	  array_info_str = create_array_info_obj(sr->subtype, sr->range, rstack, false);
	  
	} else {
	  // The entire array shall be aliased
	  emit_expr(alias_decl->alias_base, array_data_str, rstack, id_type(READER, DEREF));
	  array_data_str += ".data";
	  // Assume that no subtype is specified for the alias
	  // name. Hence, the array_info object is derived from the
	  // aliased array.
	  emit_expr(alias_decl->alias_base, array_info_str, rstack, id_type(READER, DEREF));
	  array_info_str += ".info";
	}
	
	// Compare subtypes of the alias array and the aliased
	// array. If they are equal then we assume that the array
	// subtype is dereived from the aliased array.
	if (alias_decl->subtype != alias_decl->alias_base->subtype)
	  array_info_str = get_type_info_obj(alias_decl->subtype, rstack, false);
	
	// Print line and file info
	last_pos_info = emit_posinfo(decl->pos, str, last_pos_info, l);
	
	str += spaces(l) + qid(decl, rstack, id_type()) + ".set(" + array_info_str + ", " + array_data_str + ");\n";
	
      } else {
	// Print line and file info
	last_pos_info = emit_posinfo(decl->pos, str, last_pos_info, l);
	
	// **************************************************************************
	// Remaining aliases
	// **************************************************************************
	// The other alias objects are implemented via
	// pointers. Hence, initialize the pointer with the address
	// of the aliased object address
	str += spaces(l) + qid(decl, rstack, id_type()) + "=&";
	emit_expr(alias_decl->alias_base, str, rstack, id_type(READER, DEREF));
	str += ";\n";
      }
      
    } else {
      codegen_error.error("%:error: sorry, this alias declaration is curently not supported", decl);
      exit(1);
    }
    
    
  } else if (decl->is(V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR)) { 
    // **************************************************************************
    // declaration of an implicit signal to handle waits with timeouts
    // **************************************************************************
    pV2CC_ImplicitSignalDeclaration_WaitFor sig = pV2CC_ImplicitSignalDeclaration_WaitFor(decl);
    // Print line and file info
    last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);
    // Create a new sig_info instance
    str += spaces(l) + qid(sig, rstack, id_type()) + string("=new sig_info<enumeration > ");
    str += "(iname, \":" + nid(sig->declarative_region,BARE) + ":" + nid(sig,BARE) + "\",\"" + 
      get_long_name(sig->declarative_region) + "\"," +
      info_str + ",vREGISTER,this);\n";
    
    
  } else if (decl->is(IR_SIGNAL_DECLARATION)) { 
    // **************************************************************************
    // signal declaration
    // **************************************************************************
    pIIR_SignalDeclaration sig = pIIR_SignalDeclaration(decl);
    // If the current signal is declared within a package then the scope
    // reference pointer from the package is passed over to the sig_info
    // constructor. Otherwise, the pointer to the current architecture
    // (or other declarative region) is used.
    string sref = is_PackageDeclarativeRegion(sig->declarative_region)? "sref" : "this";
    
    // Print line and file info
    last_pos_info = emit_posinfo(sig->pos, str, last_pos_info, l);
    
    // Create a new sig_info instance
    string type_str = type != NULL? qid(type, rstack, TYPE) : "enumeration";
    str += spaces(l) + qid(sig, rstack, id_type()) + string("=new sig_info<") + type_str + " > ";
    str += "(iname, \":" + nid(sig,BARE) + "\",\"" + get_long_name(sig->declarative_region) + "\"," +
      info_str + ",vREGISTER," + sref + ");\n";
    
    // generate code which initializes the object if an initial
    // value was given in the object declaration
    if (sig->initial_value) 
      {
	// Print line and file info
	last_pos_info = emit_posinfo(sig->pos, str, last_pos_info, l);
	
	str += spaces(l) + qid(sig, rstack, id_type()) + "->init(" ;
	emit_expr (sig->initial_value, str, rstack, DEFAULT);
	str += ");\n";
      }
    
    
  } else if (decl->is(IR_CONSTANT_DECLARATION) ||
	     decl->is(IR_VARIABLE_DECLARATION)) {
    // **************************************************************************
    // constant or variable declaration
    // **************************************************************************
    if (!pIIR_ObjectDeclaration(decl)->subtype->is(IR_ACCESS_TYPE) && 
	(complex_info || !is_scalar_type(pIIR_ObjectDeclaration(decl)->subtype)) &&
	(!is_array_type (pIIR_ObjectDeclaration(decl)->subtype) ||
	 is_constrained_array_type (pIIR_ObjectDeclaration(decl)->subtype))) {
      // if the corresponding info object is created at runtime or
      // the object is of a composite type then assign this info
      // instance to the object
      pIIR_Type base_subtype = get_base_type(pIIR_ObjectDeclaration(decl)->subtype);
      // If the object is an one-dimensional array of scalars then
      // determine the initial value of the scalars and pass it over
      // as an addditional argument to the init method. This helps
      // speeding up array initialization.
      string elem_init_value = "";
      if (is_array_type(base_subtype) &&
	  pIIR_ArrayType(base_subtype)->index_types->rest == NULL &&
	  is_scalar_type(pIIR_ArrayType(base_subtype)->element_type)) {
	// Get range of element type and determine left
	// bound. Usually, the left bound can be determined at
	// compile time. However, in some cases code must be
	// generated to access the info instance of the element
	// type.
	pIIR_Type element_type = pIIR_ArrayType(base_subtype)->element_type;
	vector<RangeDescriptor> range_desc = get_discrete_range(element_type, rstack, IR_NOT_STATIC);
	StaticRangeDescriptor<string, string> range = 
	  range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));
	elem_init_value = "," + range.left;
      }
      
      str += spaces(l) + qid(decl, rstack, id_type()) + ".init(" + info_str + elem_init_value + ");\n";
    }
    
    // skip if there is no initial value
    if (pIIR_ObjectDeclaration(decl)->initial_value != NULL &&
	is_array_type (pIIR_ObjectDeclaration(decl)->subtype) &&
	!is_constrained_array_type (pIIR_ObjectDeclaration(decl)->subtype) &&
	!is_constrained_array_type (pIIR_ObjectDeclaration(decl)->initial_value->subtype)) {
      // Enter this part if there is an initial value and the type of
      // the object is an unconstrained array and the type of the
      // initial value is also unconstrained. This might happen if the
      // initial value is determined from a function call that returns
      // an unconstrained array. In this case, the bounds of this
      // initial value are determined at runtime.
      id_type id = get_default_id_type(rstack);
      
      // Print line and file info
      last_pos_info = emit_posinfo(decl->pos, str, last_pos_info, l);
      
      str += spaces(l) + qid(decl, rstack, id_type()) + ".init(const_pointer(" ;
      emit_expr(((pIIR_ObjectDeclaration)decl)->initial_value, str, rstack, id);
      str += "));\n";

      // skip if there is no initial value
    } else if (pIIR_ObjectDeclaration(decl)->initial_value != NULL) {
      // processes or subprograms access objects declared within the
      // entity/architecture via pointers
      id_type id = get_default_id_type(rstack);
      
      // Print line and file info
      last_pos_info = emit_posinfo(decl->pos, str, last_pos_info, l);
      
      str += spaces(l) + qid(decl, rstack, id_type()) + "=" ;
      emit_expr(((pIIR_ObjectDeclaration)decl)->initial_value, str, rstack, id);
      str += ";\n";
      
    } else if (decl->is(IR_VARIABLE_DECLARATION)) {
      // Next, handle variable declarations without explicit initial
      // value
      id_type id = get_default_id_type(rstack);
      
      if (is_scalar_type(pIIR_VariableDeclaration(decl)->subtype)) {
	// Variable is scalar!
	// Get range of scalar subtype
	vector<RangeDescriptor> range_desc = 
	  get_discrete_range(pIIR_VariableDeclaration(decl)->subtype, rstack, IR_NOT_STATIC);
	
	// Print line and file info
	last_pos_info = emit_posinfo(decl->pos, str, last_pos_info, l);
	
	range_desc[0].constant_fold_rangedes(rstack);
	StaticRangeDescriptor<string, string> range = 
	  range_desc[0].rangedes_to_string(rstack, id);
	
	if (range.valid[0]) 
	  // If left bound is locally static then determine left
	  // bound at compile time
	  str += spaces(l) + qid(decl, rstack, id_type()) + "=" + range.left + ";\n";
	else
	  // If range is not locally static then use info pointer to
	  // determine intial value.
	  str += spaces(l) + qid(decl, rstack, id_type()) + "=" + info_str + "->left_bound;\n";
	
      } else if (pIIR_VariableDeclaration(decl)->subtype->is(IR_ACCESS_TYPE)) {
	// Variable is of an access type
	str += spaces(l) + qid(decl, rstack, id_type()) + "=NULL;\n";
	
      }
    }
    
    // Emit code to register constant/variable
    if (codegen_options.get_emit_register_code () && 
	!decl->declarative_region->is(IR_SUBPROGRAM_DECLARATION)) {
      pIIR_ObjectDeclaration odecl = pIIR_ObjectDeclaration(decl);
      
      // The current C++ source code is not associated with any real
      // VHDL source line
      last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);
      
      str += spaces(l);
      if (odecl->is(IR_VARIABLE_DECLARATION))
	str += "register_variable(&";
      else if (odecl->is(IR_CONSTANT_DECLARATION))
	str += "register_constant(&";
      
      // Get type_info pointer for object. If the object is scalar or
      // an access type then the pointer is retrieved from the
      // corresponding type. Otherwise the type_info pointer can be
      // extracted from the object itself (e.g., if the object is an
      // array then the type_info pointer is stored in the array
      // object).
      string info_str = 
	is_scalar_type(odecl->subtype) || 
	get_base_type (odecl->subtype)->is (IR_ACCESS_TYPE) ? 
	get_type_info_obj(odecl->subtype, rstack, false) :
	qid(odecl, rstack, id_type()) + ".info";

      string sref = "this";
      if (is_PackageDeclarativeRegion(odecl->declarative_region))
	sref = "sref";
      else if (static_declarative_region(odecl) == RootDeclarativeRegion(rstack))
	sref = "NULL";
      str += qid(odecl, rstack, id_type()) + ",\"" + get_long_name(odecl->declarative_region) + "\",\":" + 
	nid(odecl, BARE) + "\"," + info_str + "," + sref + ");\n";
    }
    
    
  } else if (decl->is(IR_FILE_DECLARATION)) {
    // ******************************************************************
    // initialize file object
    // ******************************************************************
    pIIR_FileDeclaration file_decl = pIIR_FileDeclaration(decl);
    
    // Print line and file info
    last_pos_info = emit_posinfo(file_decl->pos, str, last_pos_info, l);
    
    // File name given?
    if (file_decl->file_logical_name == NULL) return;
    // Add an corresponding call to file open
    str += spaces(l) + "file_open(" + qid(file_decl, rstack, id_type()) + ",";
    emit_expr(file_decl->file_logical_name, str, rstack, id_type(READER, DEREF));
    str += ",";
    if (file_decl->file_open_expression != NULL)
      emit_expr(file_decl->file_open_expression, str, rstack, id_type(READER, DEREF));
    else
      // If no open expression is present then set file mode to READ_MODE
      str += "enumeration(0)"; 
    str += ");\n";
    
    
  } else if (decl->is(V2CC_INTERNAL_OBJECT_DECLARATION)) {
    // ******************************************************************
    // initialize internal variables
    // ******************************************************************
    // Note that the process code must be emitted first because some 
    // internal variables are not created before code emission!       
    pV2CC_InternalObjectDeclaration obj = pV2CC_InternalObjectDeclaration(decl);
    
    // The current C++ source code is not associated with any real
    // VHDL source line
    last_pos_info = emit_posinfo(obj->pos != NULL? obj->pos : NO_SOURCE_LINE, 
				 str, last_pos_info, l);
    
    // Skip initialization if no inital value is given
    if (obj->cpp_initial_string == "" && obj->initial_value == NULL)
      return;
    init_str = get_internal_object_initial_string(obj, rstack);
    str += spaces(l) + obj->declarator->text.to_chars() + init_str + ";\n";
    
    
  } else if (decl->is(IR_TYPE_DECLARATION)) {
    // ******************************************************************
    // Declare a new type/subtype
    // ******************************************************************
    pIIR_TypeDeclaration tdecl = pIIR_TypeDeclaration(decl);
    pIIR_Type type = tdecl->type;
    string hdr, impl, info_init;
    emit_hdr(type, hdr, rstack, 0);
    emit_impl(type, impl, rstack, 0);
    // add internal code object to top region
    pIIR_DeclarativeRegion root_region = RootDeclarativeRegion(rstack);

    // emit type info
    emit_info_init(type, info_init, rstack, true, 0);
    if (static_declarative_region(decl) == root_region) {
      pIIR_DeclarationList *insert_pos = root_region == ActiveDeclarativeRegion(rstack) ? &dl->rest : NULL;
      insert_internal_code(insert_pos, root_region, decl->declarator->text.to_chars(), 
			   hdr, impl, DECLARE_GLOBALLY);
      // The new type is static. Hence, the type info object can be
      // globally defined.
      string register_str = ".register_type(\"" + get_long_name(tdecl->declarative_region) + "\"," + 
	"\"" + get_long_name(tdecl) + "\",\":" +  decl->declarator->text.to_chars() + "\",NULL)";
      // If the info instance is constant then declare it globally
      insert_internal_object_declaration(insert_pos, root_region, type->pos, qid(type, rstack, INFO) + "_INFO", 
					 qid(type, rstack, INFO), info_init + register_str, 
					 DECLARE_GLOBALLY);      

    } else {
      insert_internal_code(NULL, root_region, decl->declarator->text.to_chars(), 
			   hdr, impl, DECLARE_GLOBALLY);
      // emit code to register type if the type is not strictly bound
      // to a subprogram region. I.e., types which are only static
      // with respect to a subprogram are not registered.
      string register_str;
      if (static_declarative_region(decl) == NULL ||
	  !static_declarative_region(decl)->is(IR_SUBPROGRAM_DECLARATION))
	register_str = ".register_type(\"" + get_long_name(tdecl->declarative_region) + "\"," + 
	  "\"" + get_long_name(tdecl) + "\",\":" +  decl->declarator->text.to_chars() + "\",NULL)";
      // The new type is not static. Hence, the type info instance
      // is created locally. Note that non static type info
      // instances are not registered.
      insert_internal_object_declaration(&dl->rest, ActiveDeclarativeRegion(rstack), type->pos,
					 qid(type, rstack, INFO) + "_INFO", 
					 qid(type, rstack, INFO), info_init + register_str, DECLARE_LOCALLY);
    }
    

  } else if (decl->is(IR_SUBPROGRAM_DECLARATION)) {
    // **************************************************************************
    // Subprogram
    // **************************************************************************
    if (decl->is(IR_PREDEFINED_FUNCTION_DECLARATION)) {
      pIIR_PredefinedFunctionDeclaration pfunc = pIIR_PredefinedFunctionDeclaration(decl);
      if (get_operator_type(pfunc) == STD_OP) 
	// Predefined VHDL operators are implicitly defined. Hence,
	// there is nothing to do here.
	return;
    }
    
    string hdr, impl;
    // plot complete subprogram declaration into string
    emit_impl(decl, impl, rstack, 0);
    // plot subprogram prototype into string
    emit_hdr(decl, hdr, rstack, 0);
    // append internal code object to top region. This code is then
    // emitted globally. I.e., code for subprograms is collected in
    // internal code objects.
    pIIR_DeclarativeRegion root_region = RootDeclarativeRegion(rstack);
    insert_internal_code(NULL, root_region, decl->declarator->text.to_chars(), 
			 hdr, impl, DECLARE_GLOBALLY);
  }
}



// create code to initialize VHDL objects
void
emit_decls_init (pIIR_DeclarationList decl_list, string &str, RegionStack &rstack, int l)
{
  //***********************************************************************
  // Analyze each item on the declaration list
  //***********************************************************************
  for (pIIR_DeclarationList dl = decl_list; dl; dl = dl->rest) {
    emit_decls_init_item (dl, str, rstack, l);
  }
}


/*
 * Simulation Object Implementation
 */

void
m_emit_impl (pIIR_ArrayType at, string &str, RegionStack &rstack, int l)
{
  /* Nothing to do */
}

IR_StaticLevel
m_emit_info_init (pIIR_ArrayType at, string &str, RegionStack &rstack, bool static_info, int l)
{
  // Count number of dimensions
  int counter = 0;
  for (pIIR_TypeList tl = at->index_types; tl; tl = tl->rest)
    counter++;
  
  // If the array has more than a single dimension then first declare
  // a separate internal array type for each dimension. Note that
  // e.g. a two-dimensional array "type mytype array(integer range <>,
  // positive range <>) of bit" is transformed into two one
  // dimentional arrays similar to: "type internal_array is
  // array(positive range <>) of bit" and "type mytype is
  // array(integer range <>) of internal_array".
  string array_info_str = get_type_info_obj(at->element_type, rstack, static_info);
  for (int i = counter; i >= 1; i--) {
    pIIR_TypeList tl = at->index_types;
    for (int j = 1; j < i; j++)
      tl = tl->rest;
    
    if (i == 1)
      array_info_str = ".set(" + array_info_str + "," + 
	get_type_info_obj(get_basic_type(tl->first), rstack, static_info) + "," + (static_info?"-1":"0") + ")";
    else
      array_info_str = "(new array_info(" + array_info_str + "," + 
	get_type_info_obj(get_basic_type(tl->first), rstack, static_info) + "," + (static_info?"-1":"0") + "))";
  }

  str += array_info_str;

  return IR_LOCALLY_STATIC;
}


void
m_emit_impl (pIIR_ArraySubtype ast, string &str, RegionStack &rstack, int l)
{
  /* Nothing to do */
}


IR_StaticLevel
m_emit_info_init (pIIR_ArraySubtype ast, string &str, RegionStack &rstack, bool static_info, int l)
{
  pIIR_TypeDeclaration decl = ast->declaration;
  IR_StaticLevel slevel = IR_LOCALLY_STATIC;
  string array_info_str;

  // Check whether the array subtype introduces some new constraints
  if (ast->constraint == NULL) {
    // No, no new constraints! Hence, get array info from immediate
    // base type
    array_info_str = get_type_info_obj(ast->immediate_base, rstack, static_info);
    // Determine static level of type by analyzing static level of
    // ranges and element type.
    slevel = get_static_level(ast, rstack);

  } else {
    // Ok, this there are some new constraints. Get base type of array
    // subtype.
    assert(ast->base->is(IR_ARRAY_TYPE));
    pIIR_ArrayType base_type = pIIR_ArrayType(ast->base);
    pIIR_Type basic_type = pIIR_ArrayType(get_basic_type(ast->immediate_base));

    // Count number of dimensions
    int counter = 0;
    for (pIIR_TypeList tl = ast->constraint; tl; tl = tl->rest)
      counter++;
    
    // Determine whether the base type of the array is named (i.e.,
    // whether there is an explicit type declaration for the base
    // type)
    bool named_basic_type = (decl == NULL) && (basic_type->declaration != NULL);

    // If the array hase more than a single dimension then first
    // declare a separate internal array type for each dimension. Note
    // that e.g. a two-dimensional array "type mytype array(integer
    // range <>, positive range <>) of bit" is transformed into two
    // one dimentional arrays similar to: "type internal_array is
    // array(positive range <>) of bit" and "type mytype is
    // array(integer range <>) of internal_array".  Get element type
    if (named_basic_type) {
      // If the base type is named then the element type is derived
      // from the base array type
      array_info_str = get_type_info_obj(basic_type, rstack, static_info) + "->element_type";
      for (int i = counter; i > 1; i--)
	array_info_str = "parray_info(" + array_info_str + ")->element_type";

    } else
      // Otherwise, the element type is determined directly from the
      // corresponding element subtype 
      array_info_str = get_type_info_obj(base_type->element_type, rstack, static_info);

    // Step through each dimension of the array starting with the last
    // dimension.
    for (int i = counter; i >= 1; i--) {
      string base_info_str;
      pIIR_TypeList tl = ast->constraint;
      for (int j = 1; j < i; j++) tl = tl->rest;
      // Get index range
      vector<RangeDescriptor> range_desc = get_discrete_range(tl->first, rstack, IR_NOT_STATIC);
      slevel = merge_level(range_desc[0].static_level, slevel);
      // Bail out if more than a single range descriptor is returned
      assert(range_desc.size() <= 1);
      // Next convert range descriptor to int strings
      StaticRangeDescriptor<string, string> range = 
	range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));
      // Get index info instance for the corresponding array index
      string index_info_str;
      if (named_basic_type) {
	// If the base type of the current array subtype is named then
	// the corresponding index subtype is derived from this type
	index_info_str = get_type_info_obj(basic_type, rstack, static_info);
	for (int k = i; k > 1; k--) 
	  index_info_str = "parray_info(" + index_info_str + ")->element_type";
	index_info_str = "parray_info(" + index_info_str + ")->index_type";

      } else
	// Otherwise, the index info is directly derived from the
	// corresponding index subtype
	index_info_str = get_type_info_obj(get_base_type(tl->first), rstack, static_info);

      string left_checked_str = range.left, right_checked_str = range.right;
      // Shall we perform runtime range checks?
      if ((do_runtime_checks & CG_CHECK_COMPOSITE_TYPE_RANGE)) {
	// Could the left bound be checked at compile time or do we
	// have to do this at runtime?
	if (runtime_checks(ast) & RT_CHECK_LEFT_ARRAY_BOUND)
	  left_checked_str = index_info_str + "->check(" + range.left + ")";
	// Could the right bound be checked at compile time or do we
	// have to do this at runtime?
	if (runtime_checks(ast) & RT_CHECK_RIGHT_ARRAY_BOUND)
	  right_checked_str = index_info_str + "->check(" + range.right + ")";
      }
      // setup init value for array info instance
      if (i == 1)
	array_info_str = ".set(" + array_info_str + "," + index_info_str + "," +
	  left_checked_str + "," + range.dir + "," + right_checked_str + "," +  
	  (static_info?"-1":"0") + ")";
      else
	array_info_str = "(new array_info(" + array_info_str + "," + index_info_str + "," +
	  left_checked_str + "," + range.dir + "," + right_checked_str + "," +  
	  (static_info?"-1":"0") + "))";
    }
  }

  str += array_info_str;

  return slevel; // return compound static level of ranges
}


void
m_emit_impl (pIIR_ScalarSubtype sst, string &str, RegionStack &rstack, int l)
{
  pIIR_TypeDeclaration decl = sst->declaration;

  // Is the subtype constrained or at least a resolution function hase
  // been added?
  if (sst->range == NULL && sst->resolution_function == NULL) {
    // No, the subtype is not constrained (e.g., "subtype color2 is
    // color;"). Hence, do nothing.
    
  } else if (sst->base->is(IR_ENUMERATION_TYPE)) {
    // ****************************************************************************
    // Enumeration subtype
    // ****************************************************************************
    // The subtype is constrained. Hence, left pos of new
    // enumeration subtype.
    vector<RangeDescriptor> range_desc = get_discrete_range(sst, rstack, IR_NOT_STATIC);
    // Check whether bounds and range direction are static
    StaticRangeDescriptor<string, string> range = 
      range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));
    if (and_reduce(range.valid)) {
      // The current C++ source code is not associated with any real
      // VHDL source line
      last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);
      
      str += "/* Implementation of enumeration type " + get_long_name(decl) + " */\n";
      str += "const char **" + qid(decl, rstack, INFO) + "::values=" + 
	"((enum_info_base&)" + qid(decl, rstack, INFO) + "_INFO).values=" +
	"&" + qid(sst->base->declaration, rstack, INFO) + "_INFO.get_values()[" + range.left + "];\n";
    }

  } else if (sst->base->is(IR_PHYSICAL_TYPE)) {
    pIIR_PhysicalType pt = pIIR_PhysicalType (sst->base);

    // The current C++ source code is not associated with any real
    // VHDL source line
    last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);
    
    str += ("/* Implementation of physical base type " +
	    get_long_name(decl) + " */\n");
    
    string pt_qid = qid (pt, rstack, INFO);

    str += "const char *" + pt_qid + "::units[] = {\n";
    int unit_count = 0;
    for (pIIR_UnitList ul = pt->units; ul; ul = ul->rest)
      {
	str += "  \"" + nid (ul->first, BARE) + "\"";
	if (ul->rest)
	  str += ",\n";
	unit_count++;
      }
    str += "\n};\n";
    
    str += "const lint " + pt_qid + "::scale[] = {\n";
    string scale_string = "1LL";
    str += "  " + scale_string;
    for (pIIR_UnitList ul = pt->units->rest; ul; ul = ul->rest)
      {
	pIIR_PhysicalUnit u = ul->first;
	string this_scale = "";
	emit_expr (u->multiplier, this_scale, rstack, DEFAULT);
	scale_string = this_scale + "*(" + scale_string + ")";
	str += ",\n  " + scale_string;
      }
    str += "\n};\n";
    
    str += ("const int " + pt_qid + "::unit_count = " + to_string (unit_count)
	    + ";\n");

  } else if (sst->base->is(IR_INTEGER_TYPE) ||
	     sst->base->is(IR_FLOATING_TYPE)) {

    // ****************************************************************************
    // Integer, physical or floating point subtype
    // ****************************************************************************

    
  } else
    codegen_error.error("%:error: sorry, this subtype declaration is currently not supported", sst);
}
  

IR_StaticLevel
m_emit_info_init(pIIR_ScalarSubtype sst, string &str, RegionStack &rstack, bool static_info, int l)
{
  // First, check out whether an resolution function is associated
  // with this type
  string add_resolver;
  if (sst->resolution_function != NULL) {
    vector<string> libunit = get_library_and_unit_name(sst->resolution_function);
    // Continue if the current declaration is predefined in
    // library std but not std.textio.
    string ideal_str = "false";
    if (libunit[0] == "ieee" && libunit[1] == "std_logic_1164") ideal_str = "true";
    // If a resolution function has been added then add code to
    // register the reolver handle
    add_resolver += ".add_resolver(resolver_handler<" + qid(sst, rstack, TYPE) + "," +
      qid(sst->resolution_function, rstack, DEFAULT) + ">," + 
      get_type_info_obj(sst->resolution_function->interface_declarations->first->subtype, rstack, INFO) + "," + 
      ideal_str + ")";
  }

  // Is the subtype constrained?
  if (sst->range == NULL) {
    // If not then the info instance is equal to the info instance of
    // the immedate base type
    str += ".set(" + get_type_info_obj(sst->immediate_base, rstack, false) + ")" + add_resolver;
    return get_static_level(sst, rstack);

  } else if (sst->base->is(IR_INTEGER_TYPE) ||
	     sst->base->is(IR_PHYSICAL_TYPE) ||
	     sst->base->is(IR_FLOATING_TYPE) ||
	     sst->base->is(IR_ENUMERATION_TYPE)) {
    // ****************************************************************************
    // Integer, enumeration, physical or floating point subtype
    // ****************************************************************************
    vector<RangeDescriptor> range_desc = get_discrete_range(sst, rstack, IR_NOT_STATIC);
    // Check whether bounds and range direction must be determined at
    // runtime
    StaticRangeDescriptor<string, string> range = 
      range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));
    if (!and_reduce(range.valid)) {
      // Ok, bounds are not static. Hence, they must be set at runtime
      // via the "set" method of integer_info_base.
      string left_checked_str = range.left, right_checked_str = range.right;
      // Shall we perform runtime range checks?
      if ((do_runtime_checks & CG_CHECK_SCALAR_TYPE_RANGE)) {
	string base_info_str = get_type_info_obj(get_basic_type(sst->immediate_base), rstack, false);
	// Could the left bound be checked at compile time or do we
	// have to do this at runtime?
	if (runtime_checks(sst) & RT_CHECK_LEFT_BOUND)
	  left_checked_str = base_info_str + "->check(" + range.left + ")";
	// Could the right bound be checked at compile time or do we
	// have to do this at runtime?
	if (runtime_checks(sst) & RT_CHECK_RIGHT_BOUND)
	  right_checked_str = base_info_str + "->check(" + range.right + ")";
      }
      if (sst->base->is(IR_PHYSICAL_TYPE)) {
	string info_base_str = get_type_info_obj(sst->base, rstack, false);
	str += ".set(" + left_checked_str + "," + right_checked_str + "," + 
	  "min(" + range.left + "," + range.right + ")," +
	  "max(" + range.left + "," + range.right + ")," + 
	  info_base_str + "->units," + info_base_str + "->scale," + info_base_str + "->unit_count)" + 
	  add_resolver;

      } else if (sst->base->is(IR_ENUMERATION_TYPE)) {
	string info_base_str = get_type_info_obj(sst->base, rstack, false);
	str += ".set(" + left_checked_str + "," + right_checked_str + "," + 
	  info_base_str + "->get_values()[" + range.left + "])" + add_resolver;
	

      } else 
	str += ".set(" + left_checked_str + "," + right_checked_str + "," + 
	  "min(" + range.left + "," + range.right + ")," +
	  "max(" + range.left + "," + range.right + "))" + add_resolver;
    }

    return range_desc[0].static_level;

  } else
    codegen_error.error("%:error: sorry, this subtype declaration is currently not supported", sst);

  return IR_LOCALLY_STATIC;
}



void
m_emit_impl (pIIR_EnumerationType et, string &str, RegionStack &rstack, int l)
{
  pIIR_TypeDeclaration decl = et->declaration;

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  str += "/* Implementation of enumeration type " + get_long_name(decl) + " */\n";
  str += "const char *" + qid(decl, rstack, INFO) + "::values[" +/* + to_string(enum_item_number(et))+*/ "]={";
  const char *separator = "";
  for (pIIR_EnumerationLiteralList ell = et->enumeration_literals; ell; ell = ell->rest) {
    str += string(separator) + "\"" + string(ell->first->declarator->text.to_chars()) + "\"";
    separator = ",";
  }
  str += "};\n";
}


IR_StaticLevel
m_emit_info_init (pIIR_EnumerationType et, string &str, RegionStack &rstack, bool static_info, int l)
{
  pIIR_TypeDeclaration decl = et->declaration;
  //str += "new " + qid(decl, rstack, INFO);

  return get_static_level(et, rstack);
}

void
m_emit_impl (pIIR_AccessType at, string &str, RegionStack &rstack, int l)
{
}


IR_StaticLevel
m_emit_info_init (pIIR_FileType ft, string &str, RegionStack &rstack, bool static_info, int l)
{
  str += ".set(" + get_type_info_obj(ft->type_mark, rstack, false) + ")";
  
  return get_static_level(ft, rstack);
}


void
m_emit_impl (pIIR_FileType ft, string &str, RegionStack &rstack, int l)
{
}

void
m_emit_impl (pIIR_RecordType rt, string &str, RegionStack &rstack, int l)
{
  int ec = 0;
  for (pIIR_ElementDeclarationList edl = rt->element_declarations;
       edl; edl = edl->rest)
    ec += 1;

  string qid_t = qid(rt, rstack, TYPE);

  str += "const char *" + qid(rt, rstack, TYPE) + "_NAMES[] = {\n";
  for (pIIR_ElementDeclarationList edl = rt->element_declarations;
       edl; edl = edl->rest)
    {
      str += "  \"" + nid (edl->first, BARE) + "\"";
      if (edl->rest)
	str += ",";
      str += "\n";
    }
  str += "};\n";

  str += "void *" + qid(rt, rstack, TYPE) + "_ELEM_ADDR(void *p, int i)\n";
  str += "{\n";
  str += "  " + qid(rt, rstack, TYPE) + "_DATA &obj=*(" + qid(rt, rstack, TYPE) + "_DATA*)p;\n";
  str += "  switch (i) {\n";
  int i = 0;
  for (pIIR_ElementDeclarationList edl = rt->element_declarations;
       edl; edl = edl->rest, i++)
    {
      str += "  case " + to_string (i) + ": return (void*)&obj." + nid (edl->first, DEFAULT) + ";\n";
    }
  str += "  };\n";
  str += "};\n";
}

void
m_emit_impl (pIIR_RecordSubtype ast, string &str, RegionStack &rstack, int l)
{
  /* Nothing to do */
}



IR_StaticLevel
m_emit_info_init (pIIR_RecordType rt, string &str, RegionStack &rstack, bool static_info, int l)
{
  int ec = 0;
  for (pIIR_ElementDeclarationList edl = rt->element_declarations;
       edl; edl = edl->rest)
    ec += 1;
  
  // First, initialize record info instance with basic information
  string tqid = qid(rt, rstack, TYPE);
  str +=
    ".set(" + to_string(ec)
    + ",sizeof(" + tqid + "_DATA),"
    + tqid + "_NAMES,"
    + tqid + "_ELEM_ADDR," + (static_info? "-1" : "0") + ")";

  // Finally, set info pointer of the various record elements. For
  // each record element method "set(int,type_info_interface*)" is
  // called.
  int i = 0;
  for (pIIR_ElementDeclarationList edl = rt->element_declarations;
       edl; edl = edl->rest)
    str += ".set(" + to_string(i++) + "," + get_type_info_obj(edl->first->subtype, rstack, static_info) + ")";
}


IR_StaticLevel
m_emit_info_init (pIIR_RecordSubtype rst, string &str, RegionStack &rstack, bool static_info, int l)
{
  pIIR_TypeDeclaration decl = rst->declaration;
  IR_StaticLevel slevel = IR_LOCALLY_STATIC;

  // base type
  string record_info_str = get_type_info_obj(rst->immediate_base, rstack, static_info);
  // Determine static level of type by analyzing static level of
  // record elements
  slevel = get_static_level(rst, rstack);

  str += ".set(" + record_info_str + "," + (static_info? "-1" : "0") + ")";

  return slevel; // return compound static level of ranges
}



IR_StaticLevel
m_emit_info_init (pIIR_AccessType at, string &str, RegionStack &rstack, bool static_info, int l)
{
  str += ".set(" + get_type_info_obj(at->designated_type, rstack, false) + ")";
  
  return get_static_level(at, rstack);
}


void
m_emit_impl (pIIR_EntityDeclaration e, string &str, RegionStack &rstack, int l)
{
  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  str += "/* Implementation of entity methods */\n";
  str += qid(e, rstack, id_type());
  str += "::\n";
  str += qid(e, rstack, id_type());
  str += "(name_stack &iname, map_list *mlist, void *father) {\n";
  str += "    father_component = father;\n";
  str += "    iname.push(\"\");\n";

  // Generics
  if (extended_generic_clause(e) != NULL)
    emit_decls_init(extended_generic_clause(e), str, rstack, 4);
  for (pIIR_DeclarationList dl = extended_generic_clause(e); dl; dl = dl->rest)
    if (dl->first->is(IR_CONSTANT_INTERFACE_DECLARATION))
      emit_generic_interfacecon(pIIR_ConstantInterfaceDeclaration(dl->first), str, rstack, 4);

  // Ports
  if (extended_port_clause(e) != NULL)
    emit_decls_init(extended_port_clause(e), str, rstack, 4);
  for (pIIR_DeclarationList dl = extended_port_clause(e); dl; dl = dl->rest)
    if (dl->first->is(IR_SIGNAL_INTERFACE_DECLARATION))
      emit_sig_interfacecon(pIIR_SignalInterfaceDeclaration(dl->first), str, rstack, 4);

  str += "    iname.pop();\n";
  str += "};\n";

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  str += "\n";
}


void
emit_handle (pIIR_ArchitectureDeclaration a ,string &str, RegionStack &rstack)
{
  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, 0);

  str += "/* handle for simulator to find architecture */\n";	// handle func
  str += "void*\n";
  str += qid (a, rstack, id_type());
  str += "_handle(name_stack &iname, map_list *mlist, void *father, int level) {\n";
  str += " REPORT(cout << \"Starting constructor ";
  str += qid (a, rstack, id_type());
  str += " ...\" << endl);\n";
  str += " return new " + qid (a, rstack, id_type());
  str += "(iname, mlist, father, level);\n";
  str += "};\n";
  str += "extern int " + qid (a, rstack, id_type()) + "_init ();\n";
  str += "handle_info *";					// dummy var
  str += qid (a, rstack, id_type());
  str += "_hinfo =\n";
  str += "  add_handle(\"";
  str += string(a->entity->library_name->text.to_chars()) + "\",\"" +  nid(a->entity, BARE) + "\",\"" + nid(a, BARE);
  str += "\",&";
  str += qid (a, rstack, id_type());
  str += "_handle,&";
  str +=  qid (a, rstack, id_type()) + "_init);\n";
}

void
m_emit_impl (pIIR_ArchitectureDeclaration a, string &str, RegionStack &rstack, int l)
{
  if (a->architecture_statement_part != NULL)
    emit_impl (a->architecture_statement_part, str, rstack, 2);		// process impls
  emit_handle (a, str, rstack);					// handle for sim
  emit_constructor(a, str, rstack);					// arch constructor
}


void
m_emit_impl (pIIR_PackageBodyDeclaration pb, string &str, RegionStack &rstack, int l)
{
  if (extended_declarations(pb))
    emit_decls_init (extended_declarations(pb), str, rstack, l);
}


void
m_emit_impl (pIIR_PackageDeclaration p, string &str, RegionStack &rstack, int l)
{
  if (extended_declarations(p))
    emit_decls_init(extended_declarations(p), str, rstack, l);
}


void
emit_generic_map (pIIR_AssociationElement ae, string &str, RegionStack &rstack)
{
  list<pair<pIIR_Expression, pIIR_Root> > formal_acl_list;
  get_acl(ae->formal, formal_acl_list, rstack, IR_NOT_STATIC, true);
  
  string formal_acl_str = formal_acl_list.size() == 0? "NULL" : 
    (sprint_acl(formal_acl_list, "&(tmpacl1->clear()", rstack, id_type(SIGNAL, ARCHREF)) + ")");
  str += "tmpml.generic_map(\":" + 
    convert_string(string(ae->formal_declaration->declarator->text.to_chars()), tolower) + "\"," +
    formal_acl_str + ",";
  str += "const_pointer(";
  if (ae->actual != NULL)
    emit_expr(ae->actual, str, rstack, id_type(READER, DEREF));
  else
    emit_expr(ae->formal_declaration->initial_value, str, rstack, id_type(READER, DEREF));
  str += "),&" + qid(get_base_type(ae->formal->subtype), rstack, INFO) + "_INFO";
  str += "); ";
}


void
emit_signal_map (pIIR_AssociationElement ae, string &str, RegionStack &rstack)
{
  // Determine mode of formal signal
  string formal_mode;
  switch (ae->formal_declaration->mode) {
  case IR_IN_MODE: formal_mode = "vIN"; break;
  case IR_OUT_MODE: formal_mode = "vOUT"; break;
  case IR_INOUT_MODE: formal_mode = "vINOUT"; break;
  case IR_BUFFER_MODE: formal_mode = "vBUFFER"; break;
  case IR_LINKAGE_MODE: formal_mode = "vLINKAGE"; break;
  default: assert(false);
  };

  list<pair<pIIR_Expression, pIIR_Root> > formal_acl_list;
  get_acl(ae->formal, formal_acl_list, rstack, IR_NOT_STATIC, true);
  
  string formal_acl_str = formal_acl_list.size() == 0? "NULL" : 
    (sprint_acl(formal_acl_list, "&(tmpacl1->clear()", rstack, id_type(SIGNAL, ARCHREF)) + ")");

  // Store pointer to signal decalration if actual references a
  // signal. Otherwise set pointer to NULL.
  pIIR_ObjectDeclaration actual_sig = NULL;
  if (ae->actual->is(IR_OBJECT_REFERENCE))
    {
      ContextInfo tmp_ctxt;
      actual_sig = pIIR_ObjectDeclaration(get_context(ae->actual, tmp_ctxt, rstack, false, 0)->declaration);
      if (!(actual_sig->is(IR_SIGNAL_DECLARATION) || 
	    actual_sig->is(IR_SIGNAL_INTERFACE_DECLARATION)))
	actual_sig = NULL;
    }
  
  string arg_str;
  if (ae->actual == NULL ||
      ae->actual->is (IR_OPEN_EXPRESSION)) 
    {
      /* Association with `open'. */
      arg_str = formal_acl_str + "," + formal_mode;
    }
  else if (actual_sig != NULL)
    {
      /* Association with a single signal object. */
      arg_str = formal_acl_str + "," + formal_mode + ",";
      arg_str += qid (actual_sig, rstack, id_type(SIGNAL, ARCHREF)) + ",";
      
      // Append acl for actual. If the entire actuak is mapped then
      // only a NULL pointer is passed over to signal_map. Otherwise,
      // a termporary will store the corresponding acl sequence.
      list<pair<pIIR_Expression, pIIR_Root> > actual_acl_list;
      get_acl (ae->actual, actual_acl_list, rstack, IR_GLOBALLY_STATIC, true);
      string actual_acl = actual_acl_list.size() == 0? "NULL" : 
	("&(" + sprint_acl(actual_acl_list, "tmpacl2->clear()", rstack, id_type(SIGNAL, ARCHREF)) + ")");
      arg_str += actual_acl;
    }
  else
    {
      // The formal is associated with an expression
      arg_str = formal_acl_str + "," + formal_mode + ",const_pointer(";
      emit_expr (ae->actual, arg_str, rstack, id_type(READER, DEREF));
      arg_str += ")," + get_type_info_obj(ae->actual->subtype, rstack, false);
    }

  const string formal_name = convert_string(string(ae->formal_declaration->declarator->text.to_chars()), tolower);
  str += "tmpml.signal_map(\":" + formal_name + "\"," + arg_str + "); ";
}


// emit component instantiation code
void 
emit_component_instantiation(pIIR_ComponentInstantiationStatement cs, string &str, 
			     RegionStack &rstack, int l)
{
  // First, get generic and port clause which is used as interface
  // definition of the design to be instantiated
  pIIR_InterfaceList generic_clause, port_clause;
  if (cs->binding->unit->is(IR_ARCHITECTURE_REF)) {
    // An architecture is directly instantiated. Hence, get the port
    // and generic clause of the corresponding entity declaration.
    pIIR_EntityDeclaration entity_decl = pIIR_ArchitectureRef(cs->binding->unit)->entity;
    generic_clause = entity_decl->generic_clause;
    port_clause = entity_decl->port_clause;

  } else if (cs->binding->unit->is(IR_COMPONENT_DECLARATION)) {
    // An *component* is instantiated. Hence, get port and generic
    // clause of the component declaration.
    generic_clause = pIIR_ComponentDeclaration(cs->binding->unit)->local_generic_clause;
    port_clause = pIIR_ComponentDeclaration(cs->binding->unit)->local_port_clause;
  }


  // Print line and file info
  last_pos_info = emit_posinfo(cs->pos, str, last_pos_info, l);

  str += spaces(l) + "tmpml.reset(); ";

  // Process generic map
  for (pIIR_AssociationList al = cs->binding->generic_map_list; al; al = al->rest)
    emit_generic_map (al->first, str, rstack);

  // Process port map
  for (pIIR_AssociationList al = cs->binding->port_map_list; al; al = al->rest)
    emit_signal_map (al->first, str, rstack);

  string comp_label =
    "\":" + convert_string(cs->declarator->text.to_chars(), tolower) + "\"";

  if (cs->binding->unit->is(IR_ARCHITECTURE_REF)) {
    //****************************************************************************
    // Entity/architecture pair shall be instantiated
    //****************************************************************************
    pIIR_ArchitectureRef aref = (pIIR_ArchitectureRef)cs->binding->unit;
    string library_name = convert_string(aref->entity->library_name->text.to_chars(), tolower);
    string entity_name = convert_string(aref->entity->declarator->text.to_chars(), tolower);
    string architecture_name = 
      aref->architecture_name != NULL? convert_string(aref->architecture_name->text.to_chars(), tolower) : "";
    str += "kernel.elaborate_architecture(\"" + library_name + "\",";
    str += "\"" + entity_name + "\",\"" + architecture_name + "\",iname,";
    str += comp_label + ",&tmpml,this,level);\n";

  } else if (cs->binding->unit->is(IR_CONFIGURATION_DECLARATION)) {
    //******************************************************************
    // Configuration shall be instantiated
    //******************************************************************

    pIIR_ConfigurationDeclaration conf =
      pIIR_ConfigurationDeclaration (cs->binding->unit);
    
    string library_name =
      "\"" + convert_string (conf->library_name->text.to_chars (),
			     tolower) +
      "\"";
    string conf_name =
      "\"" + convert_string (conf->declarator->text.to_chars (),
			     tolower) +
      "\"";

    str += 
      "kernel.elaborate_configuration (" +
      library_name + ", " + conf_name + ", iname, " + comp_label + ", " + 
      ", &tmpml, this, level);\n";
    
  } else if (cs->binding->unit->is(IR_COMPONENT_DECLARATION)) {
    //*****************************************************************
    // Component shall be instantiated
    //*****************************************************************

    pIIR_ComponentDeclaration comp_decl =
      pIIR_ComponentDeclaration(cs->binding->unit);

    // Currently, only default binding to an entity is supported.
    // Anything else will be emited anyway, and will fail at compile
    // or run-time.

    string default_library;
    string default_unit;
    string unit;
    
    unit = "\"" + convert_string(comp_decl->declarator->text.to_chars(), 
				 tolower) +
      "\"";

    if (cs->configuration)
      {
	codegen_error.info("%:unit %n (%s)",
			   cs, cs->configuration->unit,
			   cs->configuration->unit->kind_name ());
	assert (cs->configuration->unit->is (IR_LIBRARY_UNIT));
	pIIR_LibraryUnit unit = pIIR_LibraryUnit (cs->configuration->unit);

	default_library = 
	  "\"" + convert_string (unit->library_name->text.to_chars (),
				 tolower) +
	  "\"";
	default_unit = 
	  "\"" + convert_string (unit->declarator->text.to_chars (),
				 tolower) +
	  "\"";
      }
    else
      default_library = default_unit = "NULL";
    
    str +=
      "kernel.elaborate_component (" + unit + "," + 
      default_library + ", " + default_unit + ", iname, " +
      comp_label + ", &tmpml, this, level);\n";
    
  } else
    assert(false);

}


// Emit code to instantiate concurrent statements (processes,
// component instantiations, generate statements, block statements)
void
emit_concurrent_statement_constructors(pIIR_ConcurrentStatementList cl, string &str, RegionStack &rstack, 
				       pIIR_DeclarativeRegion region, int l)
{
  for (pIIR_ConcurrentStatementList s = cl; s != NULL; s = s->rest) {
    if (s->first->is(IR_PROCESS_STATEMENT)) {
      // ***************************************************************
      // Add process 
      // ***************************************************************
      pIIR_ProcessStatement p = pIIR_ProcessStatement(s->first); // !!!
      // Print line and file info
      last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);

      string constructor_pars = "this";
      for (pIIR_DeclarationList dl = extended_interface_declarations(p)->rest; dl; dl = dl->rest) {
	if (!dl->first->is(V2CC_INTERNAL_OBJECT_DECLARATION)) continue;
	pV2CC_InternalObjectDeclaration iobj = pV2CC_InternalObjectDeclaration(dl->first);
	constructor_pars += "," + string(iobj->declarator->text.to_chars());
      }
      constructor_pars += ",iname.set(\":" + nid(p,BARE) + "\")";

      // Add process constructor call
      str += "    kernel.add_process(new " + qid(p, rstack, id_type()) + "(" + constructor_pars + "),\"" + 
	get_long_name(p->declarative_region) + "\",\":" + nid(p,BARE) + "\",this);\n";

    } else if (s->first->is(IR_COMPONENT_INSTANTIATION_STATEMENT)) {
      // ***************************************************************
      // Add component 
      // ***************************************************************
      emit_component_instantiation((pIIR_ComponentInstantiationStatement)s->first, str, rstack, 4);

    } else if (s->first->is(IR_CONCURRENT_GENERATE_FOR_STATEMENT)) {
      // ***************************************************************
      // Add for generate statement
      // ***************************************************************
      pIIR_ConcurrentGenerateForStatement for_gen = pIIR_ConcurrentGenerateForStatement(s->first);

      // generate a internal variable for the loop variable, the
      // start value and the end value
      string loop_var_name = qid(for_gen->generate_parameter_specification, rstack, id_type (DEFAULT, NO_PREFIX));
      string loop_counter_name = loop_var_name + "_lc";
      string loop_step_name = loop_var_name + "_st";
      string loop_var_type = qid(get_declaration(for_gen->generate_parameter_specification->subtype), rstack, TYPE);

      // Print line and file info
      last_pos_info = emit_posinfo(for_gen->pos, str, last_pos_info, 0);

      // Get iteration range
      vector<RangeDescriptor> range_desc = 
	get_discrete_range (pIIR_ScalarSubtype(for_gen->generate_parameter_specification->subtype)->range, 
			    rstack, IR_NOT_STATIC);
      StaticRangeDescriptor<string, string> range = 
	range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));

      str += spaces(l) + "iname.set(\":" + convert_string(for_gen->declarator->text.to_chars(), tolower) + "\");\n";
      str += spaces(l) + "iname.push(\"\");\n";

      if (range_desc[0].is_explicit_range()) 
	{
	  str += spaces (l) + "for (" + loop_var_type + " " + loop_var_name + "=" + range.left + "," + loop_counter_name + "=" + 
	    string (range.dir == "to"? "up_range_to_length" : "down_range_to_length") + "<" + loop_var_type + ">(" +
	    range.left + "," + range.right + "); ";
	  str += loop_counter_name + "!=0; ";
	  str += loop_var_name + string (range.dir=="to"? "++" : "--") + "," + loop_counter_name + "--)";
	} 
      else 
	{
	  str += "for (" + loop_var_type + " " + loop_var_name + "=" + range.left + "," + loop_step_name + "=" + range.dir + "==to?+1:-1," + 
	    loop_counter_name + "=range_to_length<" + loop_var_type + ">(" + range.left + "," + range.dir + "," + range.right + ");";
	  str += loop_counter_name + "!=0" + "; ";
	  str += loop_var_name + "+=" + loop_step_name + "," + loop_counter_name + "--)";
	}
      str += "{\n";

      // Build parameter for constructor call
      string constructor_pars = "this";
      for (pIIR_DeclarationList dl = extended_interface_declarations(for_gen)->rest; dl; dl = dl->rest) {
	if (!dl->first->is(V2CC_INTERNAL_OBJECT_DECLARATION)) continue;
	pV2CC_InternalObjectDeclaration iobj = pV2CC_InternalObjectDeclaration(dl->first);
	constructor_pars += "," + string(iobj->declarator->text.to_chars());
      }
      constructor_pars += ",iname.set(" + loop_var_name + "),level";
      
      // Print line and file info
      last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);

      // Emit constructor call
      str += spaces(l + 2) + "new " + qid(for_gen, rstack, id_type()) + "(" + constructor_pars + ");\n"; 

      str += spaces(l) + "}\n";
      str += spaces(l) + "iname.pop();\n";


    } else if (s->first->is(IR_CONCURRENT_GENERATE_IF_STATEMENT)) {
      // ***************************************************************
      // Add if generate statement
      // ***************************************************************
      pIIR_ConcurrentGenerateIfStatement if_gen = pIIR_ConcurrentGenerateIfStatement(s->first);

      // Print line and file info
      last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);

      string constructor_pars = "this";
      for (pIIR_DeclarationList dl = extended_interface_declarations(if_gen)->rest; dl; dl = dl->rest) {
	if (!dl->first->is(V2CC_INTERNAL_OBJECT_DECLARATION)) continue;
	pV2CC_InternalObjectDeclaration iobj = pV2CC_InternalObjectDeclaration(dl->first);
	constructor_pars += "," + string(iobj->declarator->text.to_chars());
      }
      constructor_pars += ",iname,level";
      
      // Print line and file info
      last_pos_info = emit_posinfo(if_gen->condition->pos, str, last_pos_info, 0);

      str += spaces(l) + "if (";
      emit_expr(if_gen->condition, str, rstack, id_type(READER, DEREF));
      str += ") {\n";
      str += spaces(l + 2) + "iname.set(\":" + convert_string(if_gen->declarator->text.to_chars(), tolower) + "\");\n";

      // Print line and file info
      last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);

      // Emit constructor call
      str += spaces(l + 2) + "new " + qid(if_gen, rstack, id_type()) + "(" + constructor_pars + ");\n"; 
      str += spaces(l) + "}\n";

    } else
      assert(false);
  }  
}


// emit architecture constructor code
void
emit_constructor(pIIR_ArchitectureDeclaration a, string &str, RegionStack &rstack)
{
  rstack.push(a->entity);
  rstack.push(a);
  pIIR_EntityDeclaration e = a->entity;

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, 0);

  str += "/* Architecture Constructor */\n";	// handle func

  str += qid (a, rstack, id_type());
  str += "::\n";
  str += qid (a, rstack, id_type());
  str += "(name_stack &iname, map_list *mlist, void *father, int level) :\n  ";
  str += qid (e, rstack, id_type());
  str += "(iname, mlist, father) {\n";
  str += "    iname.push(\":";
  emit_noqual_id(a, str, rstack, BARE);
  str += "\");\n";
  str += "    iname.push(\"\");\n";
  int i=0;

  if (extended_declarations(a))
    // emit code to init object declared within the architecture
    emit_decls_init (extended_declarations(a), str, rstack, 4);

  // emit code to create all processes and components directly
  // instantiated within the architecture body
  if (a->architecture_statement_part != NULL)
    emit_concurrent_statement_constructors(a->architecture_statement_part, str, rstack, a, 4);
    
  // Print line and file info
  last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);
  str += spaces(4) + string("iname.pop(); /* pop last declaration from name stack */ ") +
    string("iname.pop(); /* pop architecture from name stack */\n");
  // Print line and file info
  last_pos_info = emit_posinfo(last_pos_info, str, last_pos_info, 0);
  str += string("};\n");

  rstack.pop();
  rstack.pop();
}
  

// emit port signal constructor part
void
emit_sig_interfacecon (pIIR_SignalInterfaceDeclaration s, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(s->pos, str, last_pos_info, 5);

  pIIR_TypeDeclaration type_declaration = get_declaration(get_basic_type(s->subtype));

  // determine info instance
  string info_str = get_type_info_obj(s->subtype, rstack, true);

  // determine mode of the port signal
  string mode_str;
  if (s->mode == IR_IN_MODE)
    mode_str = "vIN";
  else if (s->mode == IR_OUT_MODE)
    mode_str = "vOUT";
  else if (s->mode == IR_INOUT_MODE)
    mode_str = "vINOUT";
  else if (s->mode == IR_BUFFER_MODE)
    mode_str = "vBUFFER";
 
  // If the current signal is declared within a package then the scope
  // reference pointer from the package is passed over to the sig_info
  // constructor. Otherwise, the pointer to the current architecture
  // (or other declarative region) is used.
  string sref = is_PackageDeclarativeRegion(s->declarative_region)? "sref" : "this";
  // Create a new sig_info instance
  str += spaces(l) + qid(s, rstack, id_type()) + string("=new sig_info<");
  str += qid(type_declaration, rstack, TYPE);
  str += ">(iname,";
  str += "\":" + nid(s,BARE) + "\",\"" + get_long_name(s->declarative_region) + "\",mlist," + info_str + "," + 
    mode_str + "," + sref + ");\n";

  if (s->initial_value) 
    {
      str += "    " + qid(s, rstack, id_type()) + "->init(" ;
      emit_expr (s->initial_value, str, rstack, DEFAULT);
      str += ");\n";
    }
}


// emit port signal constructor part
void
emit_generic_interfacecon (pIIR_ConstantInterfaceDeclaration g, string &str, RegionStack &rstack, int l)
{
  // determine info instance
  string info_str = get_type_info_obj(get_basic_type(g->subtype), rstack, true);

  // Print line and file info
  last_pos_info = emit_posinfo(g->pos, str, last_pos_info, 5);

  string default_value_p_str = "NULL";
  if (g->initial_value != NULL) {
    default_value_p_str = "const_pointer(";
    emit_expr (g->initial_value, default_value_p_str, rstack, id_type(READER, DEREF));
    default_value_p_str += ")";
  }

  str += spaces(l) + "kernel.init_generic(&" + qid(g, rstack, id_type()) + "," + info_str + ",";
  str += "iname,";
  str += "\":" + nid(g,BARE) + "\",\"" + get_long_name(g->declarative_region) + "\",mlist," + default_value_p_str + ",this);\n";
}


void
m_emit_impl (pIIR_ConcurrentStatementList s, string &str, RegionStack &rstack, int l)
{
  while (s)
    {
      str += spaces(l);
      emit_impl (s->first, str, rstack, l);
      s = s->rest;
    }
}


void
m_emit_impl (pIIR_ProcessStatement p, string &str, RegionStack &rstack, int l)
{
  rstack.push(p);
  ContextInfo &ctxt = *ActiveContext(rstack);

  // Create a list of declarative region pointers beginning from the
  // target region up to the root region
  list<pIIR_DeclarativeRegion> RegionList = create_region_list(p);
  RegionList.pop_front();

  // For each generate region as well as the enclosing architecture
  // region a corresponding pointer is declared and added as a
  // parameter to the constructor.
  string constructor_pars, separator;
  for (list<pIIR_DeclarativeRegion>::iterator iter = RegionList.begin(); 
       iter != RegionList.end(); iter++)
    if ((*iter)->is(IR_ARCHITECTURE_DECLARATION) || 
	(*iter)->is(IR_CONCURRENT_GENERATE_STATEMENT) ||
	(*iter)->is(IR_BLOCK_STATEMENT)) {
      constructor_pars += separator + qid(*iter, rstack, id_type()) + " *" + qid(*iter, rstack, id_type()) + "_AP_PAR";
      insert_internal_object_declaration(get_last_rest_address(&extended_interface_declarations(p)), 
					 p, p->pos, qid(*iter, rstack, id_type()) + "_AP", 
					 qid(*iter, rstack, id_type()) + "*", 
					 "=" + qid(*iter, rstack, id_type()) + "_AP_PAR", 
					 DECLARE_LOCALLY);
      separator = ",";
  }



  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  // ******************************************************************
  // append prolog
  // ******************************************************************
  str += "/* Implementation of process " + get_long_name(p) + " methods */\n" +
    qid(p, rstack, id_type()) + "::\n" + 
    qid(p, rstack, id_type()) + "(" + constructor_pars + ",name_stack &iname) : process_base(iname) {\n";

  // Emit code to initialize some interal process members
  if (extended_interface_declarations(p)!= NULL)
    emit_decls_init(extended_interface_declarations(p), str, rstack, 4);

  // ******************************************************************
  // map signals which are read within the process
  // ******************************************************************
  string reader_code_str, implicit_sig_reader_code_str;
  list<AccessDescriptor> sig_read = 
    filter_unique(ctxt.accessed_objects, READ, 
		  tree_kind_list(IR_SIGNAL_DECLARATION, IR_SIGNAL_INTERFACE_DECLARATION));
  for (list<AccessDescriptor>::iterator i = sig_read.begin(); i != sig_read.end(); i++)
    if ((*i).declaration->is(V2CC_IMPLICIT_SIGNAL_DECLARATION))
      implicit_sig_reader_code_str += "    " + qid((*i).declaration, rstack, READER) + "=&" + 
	qid((*i).declaration, rstack, id_type(SIGNAL, ARCHREF)) + "->reader();\n"; 
    else
      reader_code_str += "    " + qid((*i).declaration, rstack, READER) + "=&" + 
	qid((*i).declaration, rstack, id_type(SIGNAL, ARCHREF)) + "->reader();\n"; 

 
  // ******************************************************************
  // map sig_info pointer for signals which are prefix of a signal 
  // function kind attribute.
  // ******************************************************************
  string sig_info_code_str;
  list<AccessDescriptor> sig_attr = 
    filter_unique(ctxt.accessed_objects, SIGNAL_FUNCTION_ATTRIBUTE, 
		  tree_kind_list(IR_SIGNAL_DECLARATION,IR_SIGNAL_INTERFACE_DECLARATION));
  for (list<AccessDescriptor>::iterator i = sig_attr.begin(); i != sig_attr.end(); i++)
      sig_info_code_str += "    " + qid((*i).declaration, rstack, DEFAULT) + "=" + 
	qid((*i).declaration, rstack, id_type(SIGNAL, ARCHREF)) + ";\n"; 


  // ******************************************************************
  // create the driver for the signals that are written by the process.
  // ******************************************************************
  // First extract written signals from ctxt.accessed_objects list.
  list<AccessDescriptor> written_signals = 
    filter(ctxt.accessed_objects, WRITE, 
	   tree_kind_list(IR_SIGNAL_DECLARATION, IR_SIGNAL_INTERFACE_DECLARATION));

  string driver_code_str;
  while (written_signals.size()) {
    set<string> acls_for_signal;
    // get first signal in written_signal list and remove it from the
    // list
    AccessDescriptor current_signal = written_signals.front();
    written_signals.erase(written_signals.begin());

    while (true) {
      // get acl for the signal target expression and convert it into a
      // string. Append the string to the other acl strings for that
      // signal.
      list<pair<pIIR_Expression, pIIR_Root> > acl_list;
      if (current_signal.access_expr != NULL) {
	get_acl(current_signal.access_expr, acl_list, rstack, IR_GLOBALLY_STATIC, true);
	acls_for_signal.insert(sprint_acl(acl_list, "tmpacl->clear()", rstack, 
			       id_type(SIGNAL, ARCHREF)));
      } else
	acls_for_signal.insert("");
      // search for the next assignment to the same signal
      list<AccessDescriptor>::iterator iter = written_signals.begin();
      for (; iter != written_signals.end(); iter++)
	if ((*iter).declaration == current_signal.declaration) break;
      // exit loop if no more assignment to the same signal were
      // found. Otherwise, copy found signal to current_sig and remove
      // the corresponding entry from written_signals.
      if (iter == written_signals.end()) break;
      current_signal = (*iter);
      written_signals.erase(iter);
    }
    
    // acls_for_signal contains all different acl values which were
    // created from the signal target expressions (wihtin a process)
    // for a specific signal. Now, build the driver creation code.
    string start_str = "    " + qid(current_signal.declaration, rstack, DRIVER) + 
      string("=kernel.get_driver(this,") + 
      qid(current_signal.declaration, rstack, id_type(SIGNAL, ARCHREF));
    string next_start_str = "    " + string("kernel.get_driver(") + 
	qid(current_signal.declaration, rstack, DRIVER) + ",this";

    for (set<string>::iterator aiter = acls_for_signal.begin();
	 aiter != acls_for_signal.end(); aiter++) {
      driver_code_str += start_str;
      if ((*aiter) != "") // add acl
	driver_code_str += ",&(" + (*aiter) + ")";
      driver_code_str += string(");\n");
      start_str = next_start_str;
    }
  }

  // ******************************************************************
  // create the wait_info objects
  // ******************************************************************

  string wait_info_code_str;
  int windex = 0;

  for (list<pIIR_SequentialStatement>::iterator witer = ctxt.wait_statements.begin(); 
       witer != ctxt.wait_statements.end(); witer++)
    {
      if (! (*witer)->is (IR_WAIT_STATEMENT)) continue;
      pIIR_WaitStatement ws = pIIR_WaitStatement (*witer);
      // collect all signals the wait statement is sensitive on
      ContextInfo wctxt;
      get_context(ws, wctxt, rstack, false, 0);
      
      // Analyze each signal which was referenced in the corresponding
      // wait expression
      list<string> sal_add_arg_list;
      string codestr;
      int length = 0;
      for (access_list::iterator iter = wctxt.accessed_objects.begin(); 
	   iter != wctxt.accessed_objects.end(); iter++) {
	if (!((*iter).access_type & SENSITIVE)) continue;
	list<pair<pIIR_Expression, pIIR_Root> > acl_list;
	// convert each signal expression into an acl list
	get_acl((*iter).access_expr, acl_list, rstack, IR_GLOBALLY_STATIC, true);
	string sal_add_arg = qid((*iter).declaration, rstack, id_type(SIGNAL, ARCHREF));
	if (acl_list.size())
	  sal_add_arg += ",&(" + sprint_acl(acl_list, "tmpacl->clear()", rstack, id_type(SIGNAL, ARCHREF)) + ")";
	// if the current signal (including acl) already has been
	// added to the sal list then do nothing
	if (find(sal_add_arg_list.begin(), sal_add_arg_list.end(), sal_add_arg) != sal_add_arg_list.end())
	  continue;
	// add argument string (sal_add_arg) to list in order to
	// remove dublicate calls
	sal_add_arg_list.push_back(sal_add_arg);
	codestr += string("     sal.add(") + sal_add_arg + ");\n";

	length++;
      }
      
      // If the wait statment has an timeout clause then make it
      // sensitiv to a implicit signal associated with the current
      // process. This implicit signal is used to implement the wait
      // for condition.
      if (ws->timeout_clause != NULL) {
	// Determine declaration of implicit signal. Becuases there is
	// only a signle implicit signal for each process which uses a
	// timeout clause simply access the first element of the list
	// returned from filter_unique.
	pV2CC_ImplicitSignalDeclaration_WaitFor implicit_signal_decl = 
	  pV2CC_ImplicitSignalDeclaration_WaitFor(filter_unique(extended_declarations(p), 
								V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR).front());
	codestr += string("     sal.add(") + qid(implicit_signal_decl, rstack, id_type(SIGNAL, ARCHREF)) + ");\n";
	// Increment length as the implicit wait for signal is also
	// added to the sensitivity list!
	length++; 
      }

      // prolog
      wait_info_code_str += 
	string("    {\n") +
	string("     sigacl_list sal(") + to_string (length) + string(");\n");
      
      // add code 
      wait_info_code_str += codestr;

      // epilog
      wait_info_index(ws) = windex++;
      wait_info_code_str += string("     winfo[") + to_string (wait_info_index (ws)) + 
	string("]=kernel.setup_wait_info(sal,this);\n") + string("    }\n");
    }

  // Next, check out whether the process calls procedures that
  // contain at least one wait statement. First, get get all
  // procedure that are called from this process. For each
  bool calls_delayed_procedures = false;
  for (list<pIIR_SequentialStatement>::iterator witer = ctxt.wait_statements.begin(); 
       witer != ctxt.wait_statements.end(); witer++)
    {
      if (! (*witer)->is (IR_PROCEDURE_CALL_STATEMENT)) continue;
      pIIR_ProcedureCallStatement pc = pIIR_ProcedureCallStatement (*witer);
      wait_info_index(pc) = windex++;
      wait_info_code_str += string("    winfo[") + to_string (wait_info_index (pc)) + 
	string("]=(winfo_item*)NULL;\n");
      calls_delayed_procedures = true;
    }

  // If the procedure calls other procedures that contain wait
  // statements then create an internal pointer variable that will be
  // used to store pointers to the corresponding procedure class
  // instances.
  if (calls_delayed_procedures)
    insert_internal_object_declaration(get_last_rest_address(&extended_declarations(p)), 
				       p, p->pos, "pdelayed_procedure", 
				       "delayed_procedure_base*", "", DECLARE_LOCALLY);

  // ******************************************************************
  // append epilog code
  // ******************************************************************

  string code_str;

  // Print line and file info
  last_pos_info = emit_posinfo(p->pos, code_str, NULL, l);

  code_str += string("bool ") + qid(p, rstack, id_type()) + string("::execute() {\n");

  emit_process_body (p, code_str, rstack, l+2);			// SeqStatList

  // Print line and file info
  last_pos_info = emit_posinfo(p->pos, code_str, last_pos_info, l);

  code_str += "}\n\n";
  
  // Add code to setup singal info pointers and signal readers
  str += sig_info_code_str;
  str += reader_code_str;

  // *****************************************************************************
  // init variables and constants.  Note that the process code is
  // emitted first as due to the operations some internal variables
  // may be generated which must be initialized now!!!!
  // *****************************************************************************

  if (extended_declarations(p))
    // Emit declarations
    emit_decls_init(extended_declarations(p), str, rstack, 4);

  // Add code to setup implicit signal reader, driver and wait info objects.
  str += implicit_sig_reader_code_str;
  str += driver_code_str;
  str += wait_info_code_str;

  str += "}\n";


  // Now, append process code!
  str += code_str;

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  // Remove context from context stack
  rstack.pop();
}



void
emit_process_body (pIIR_ProcessStatement p, string &str, RegionStack &rstack, int l)
{
  pIIR_SequentialStatementList sl = p->process_statement_part;

  ContextInfo &ctxt = *ActiveContext(rstack);

  if (ctxt.wait_statements.size() &&
      ! p->is(IR_SENSITIZED_PROCESS_STATEMENT) &&
      ! p->is(IR_IMPLICIT_PROCESS_STATEMENT)) {
    str += "  switch (jmp) {\n";					// create jump tbl
    for(unsigned int i=1 ; i <= ctxt.wait_statements.size(); i++)
      str += "      case " + to_string(i) + ": goto lab" + to_string(i) + ";\n";
    str += "  };\n\n  lab0:\n";
  }

  // emit sequential statements
  if (sl != NULL)
    emit_impl(sl, str, rstack, l);

  // the last statement of a process loops back to the beginning
  if (ctxt.wait_statements.size() &&
      ! p->is(IR_SENSITIZED_PROCESS_STATEMENT) &&
      ! p->is(IR_IMPLICIT_PROCESS_STATEMENT)) {
    // Print line and file info
    last_pos_info = emit_posinfo(p->pos, str, last_pos_info, l);
    str += spaces(l) + " goto lab0;\n";
  } else {
    // Else add return value to process code in order to prevent
    // warnings emitted by the c++ compiler.
    str += spaces(l) + "return true;\n";
  }
}


// Print subprogram implementation
void
emit_plain_subprogram_impl (pIIR_SubprogramDeclaration sbp, string &str, RegionStack &rstack, int l)
{
  // emit_subprogram_prototype is defined in v2cc-decl.cc
  extern string emit_subprogram_prototype(pIIR_SubprogramDeclaration, RegionStack &k, bool, int);

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  str += "/* Implementation of subprogram " + get_long_name(sbp) + " */\n";
  string return_type_str;
  string copy_back_code = spaces(4) + "rlabel:\n", parameter_setup_code;
  string separator = "";

  // Emit subprogram prototype
  str += emit_subprogram_prototype(sbp, rstack, true, 0);

  // Check whether sbp is a function or a procedure
  bool is_function = sbp->is(IR_FUNCTION_DECLARATION); 
  
  // ****************************************************************************
  // Analyze normal subprogram parameter
  // ****************************************************************************
  for (pIIR_DeclarationList il = extended_interface_declarations(sbp); il; il = il->rest) {
    if (!il->first->is(IR_INTERFACE_DECLARATION)) continue;
    pIIR_InterfaceDeclaration par = pIIR_InterfaceDeclaration(il->first);
    // Determine whether the parameter must be copied back
    bool copy_back = (is_scalar_type(par->subtype) ||
		      is_constrained_array_type (get_basic_type (par->subtype))) && 
      (par->mode == IR_OUT_MODE || par->mode == IR_INOUT_MODE || 
       par->mode == IR_BUFFER_MODE);
    // Determine whether the parameter must be copied in
    bool copy_in = copy_back && 
      (par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE);
    // Determine whether the parameter can be used directly used or a
    // temporary must be created. It cannot be used directly if the
    // parameter value must be copied back or the parameter type is a
    // constrained array type.
    bool direct_use = il->first->is(IR_SIGNAL_INTERFACE_DECLARATION) 
      || !(copy_back || is_constrained_array_type(par->subtype));

    // If the paramter is not used directly create another variable
    // which is actually used within the subprogram body
    if (!direct_use) {
      // The current C++ source code is not associated with any real
      // VHDL source line
      last_pos_info = emit_posinfo(NO_SOURCE_LINE, parameter_setup_code, last_pos_info, l);

      string par_name = qid(par, rstack, DEFAULT) + "_PAR";
      // If the parameter is passed back by copy then add the
      // corresponding code
      if (copy_back)
	copy_back_code += spaces(4) + par_name + "=" + qid(par, rstack, DEFAULT) + ";\n";
      
      // Check type of parameter. If it is an implicit array subtype
      // then append code to setup the array_info instance of the
      // parameter
      if (is_implicit_array_subtype(par->subtype)) 
	{
	  string info_str = get_type_info_obj(par->subtype, rstack, false);
	  parameter_setup_code += spaces(4) + 
	    qid(get_declaration(par->subtype), rstack, id_type(TYPE | ALIAS, DEFAULT)) + " " + 
	    qid(par, rstack, DEFAULT) + "(" + info_str + "," + par_name + ".data)";
	  parameter_setup_code += ";\n";
	} 
      else if (is_constrained_array_type (par->subtype))
	{
	  string info_str = get_type_info_obj(par->subtype, rstack, false);
	  parameter_setup_code += spaces(4) + 
	    qid(get_declaration(par->subtype), rstack, id_type(TYPE, DEFAULT)) + " " + 
	    qid(par, rstack, DEFAULT) + "(" + info_str + ",(" + 
	    qid(par->subtype, rstack, id_type(TYPE)) + "::E_type*)" + par_name + ".data)";
	  parameter_setup_code += ";\n";
	}
      else
	{
	  parameter_setup_code += spaces(4) + 
	    qid(get_declaration(par->subtype), rstack, TYPE) + " " + qid(par, rstack, DEFAULT);
	  
	  // If the parameter is passed in by copy then add the
	  // corresponding code
	  if (copy_in)
	    parameter_setup_code += "=" + par_name + ";\n";
	  else
	    parameter_setup_code += ";\n";
	}
    }

    // Set separator for next parameter
    separator = ",";
  }

  // ********************************************************
  // The subprogram body starts here!
  // ********************************************************
  str += "\n{\n";

  // Add parameter setup code
  str += parameter_setup_code;

  // Emit any internal declarations required by the subprogram
  // parameters
  if (extended_interface_declarations(sbp) != NULL)
    emit_decls_init(extended_interface_declarations(sbp), str, rstack, 4);

  // emit sequential statements
  string body_code;
  emit_impl(sbp->subprogram_body, body_code, rstack, 4);

  if (extended_declarations(sbp) != NULL) {
    string decl_init_str, decl_str;
    // Emit initialization code of local declarations
    emit_decls_init(extended_declarations(sbp), decl_init_str, rstack, 4);
    // Emit local declarations of the subprogram 
    emit_decls(extended_declarations(sbp), decl_str, rstack, 4);
    str += decl_str + decl_init_str;
  }

  // Now, append subprogram body code. Note that the subprogram body
  // is emitted first before the declarations are printed.
  str += body_code;
  
  // If subprogram is not a function then add copy back code and
  // return subprogram. The copy back code is executed when the
  // subprogram returns.
  if (!is_function)
    str += copy_back_code;

  if (!is_function)
    str += spaces(4) + "return;\n";

  str += "}\n";

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);
}


// Print subprogram implementation
void
emit_delayed_subprogram_impl (pIIR_ProcedureDeclaration sbp, string &str, RegionStack &rstack, int l)
{
  // emit_subprogram_prototype is defined in v2cc-decl.cc
  string emit_delayed_procedure_constructor (pIIR_ProcedureDeclaration, RegionStack &, bool, int);

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  const string separator = ",\n" + spaces(l + 2);
  str += "/* Class impl. for subprogram " + get_long_name(sbp) + " (contains waits) */\n";

  // Emit subprogram prototype
  string constructor_str, constructor_init_str, copy_back_code_str;
  constructor_str += "  /* Class constructor for subprogram " + get_long_name(sbp) + " */\n";
  constructor_str += qid(sbp, rstack, DEFAULT) + "::" + emit_delayed_procedure_constructor (sbp, rstack, true, 0)
    + " :\n" 
    + spaces (l + 2) + "delayed_procedure_base (process_PAR)";

  // ****************************************************************************
  // Analyze normal subprogram parameter
  // ****************************************************************************
  for (pIIR_DeclarationList il = extended_interface_declarations(sbp); il; il = il->rest) {
    if (!il->first->is(IR_INTERFACE_DECLARATION)) continue;
    pIIR_InterfaceDeclaration par = pIIR_InterfaceDeclaration(il->first);
    // The parameter is passed in by reference if it is a non scalar
    // type or if the parameter is of mode OUT, INOUT or BUFFER.
    bool call_by_reference = !is_scalar_type(par->subtype) ||
      par->mode == IR_OUT_MODE || par->mode == IR_INOUT_MODE || 
      par->mode == IR_BUFFER_MODE;
    // Determine whether the parameter must be copied back
    bool copy_back = (is_scalar_type(par->subtype) ||
		      is_constrained_array_type (par->subtype)) && 
      (par->mode == IR_OUT_MODE || par->mode == IR_INOUT_MODE || 
       par->mode == IR_BUFFER_MODE);
    // Determine whether the parameter must be copied in
    bool copy_in = copy_back && 
      (par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE);
    // Determine whether the parameter can be used directly or an
    // temporary must be created. It cannot be used directly if the
    // parameter value must be copied back or the parameter type is a
    // constrained array type.
    bool direct_use = !(copy_back || is_constrained_array_type (get_basic_type (par->subtype)));

    if (par->is(IR_VARIABLE_INTERFACE_DECLARATION)) {
      constructor_str += separator + qid(par, rstack, DEFAULT)
	+ string (copy_back ? "_REF" : "")
	+ "(" + qid(par, rstack, DEFAULT) + "_PAR)";
      if (copy_back)
	{
	  // If the parameter is passed over via copy back, there are
	  // actually two local variables required. One variable which
	  // is used to store a reference to the original parameter
	  // (ends with _REF; it is used to copy back the value if
	  // the subprogram returns) and another variable which is
	  // used by the procedure body to read/write this parameter.
	  if (is_constrained_array_type (get_basic_type (par->subtype)))
	    {
	      string info_str = get_type_info_obj(par->subtype, rstack, false);
	      constructor_init_str += spaces(l + 2) + 
		qid(par, rstack, DEFAULT) + ".init(" + info_str + ",const_pointer(" + 
		qid(par, rstack, DEFAULT) + "_PAR))";
	      constructor_init_str += ";\n";
	    }
	  else
	    {
	      constructor_init_str += spaces (l + 2) + qid(par, rstack, DEFAULT)
		+ "=" + qid(par, rstack, DEFAULT) + "_PAR;\n";
	    }
	  copy_back_code_str += spaces (l + 2) + qid(par, rstack, DEFAULT) + "_REF"
	    + "=" + qid(par, rstack, DEFAULT) + ";\n";
	}

    } else if (par->is(IR_CONSTANT_INTERFACE_DECLARATION)) {
      constructor_str += separator + qid(par, rstack, DEFAULT) 
	+ "(" + qid(par, rstack, DEFAULT) + "_PAR)";

    } else if (par->is(IR_FILE_INTERFACE_DECLARATION)) {
      constructor_str += separator + qid(par, rstack, DEFAULT) 
	+ "(" + qid(par, rstack, DEFAULT) + "_PAR)";

    } else if (par->is(IR_SIGNAL_INTERFACE_DECLARATION)) {
      // Signal values are NOT copied back! Instead, any operations
      // are directly applied on the corresponding reader/driver...
      copy_back = false;
      direct_use = true;
      // First, append sig_info pointer
      constructor_str += separator + qid(par, rstack, SIGNAL) 
	+ "(" + qid(par, rstack, SIGNAL) + "_PAR)";
      // Next, append reader if signal is of mode in or inout or buffer
      if (par->mode == IR_IN_MODE || par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE) {
	constructor_str += separator + qid(par, rstack, READER) 
	  + "(" + qid(par, rstack, READER) + "_PAR)";
      }
      // Finally, append driver if mode is of out or inout or buffer
      if (par->mode == IR_OUT_MODE || par->mode == IR_INOUT_MODE || par->mode == IR_BUFFER_MODE) {
	constructor_str += separator + qid(par, rstack, DRIVER) 
	  + "(" + qid(par, rstack, DRIVER) + "_PAR)";
      }
    }
  }

  // ****************************************************************************
  // Analyze extra subprogram parameter
  // ****************************************************************************
  list<AccessDescriptor> &extra_parameter = context(sbp).extra_interface_objects;
  for (list<AccessDescriptor>::iterator iter = extra_parameter.begin();
       iter != extra_parameter.end(); iter++) {
    pIIR_Declaration par = (*iter).declaration;

    if (par->is(IR_VARIABLE_INTERFACE_DECLARATION) ||
	par->is(IR_VARIABLE_DECLARATION) ||
	par->is(IR_CONSTANT_INTERFACE_DECLARATION) ||
	par->is(IR_CONSTANT_DECLARATION) || 
	par->is(IR_FILE_DECLARATION) ||
	par->is(IR_FILE_INTERFACE_DECLARATION)) {
      constructor_str += separator + qid(par, rstack, DEFAULT)
	+ "(" + qid(par, rstack, DEFAULT) + "_PAR)";
 
    } else if (par->is(IR_SIGNAL_INTERFACE_DECLARATION) ||
	       par->is(IR_SIGNAL_DECLARATION)) {
      pIIR_ObjectDeclaration opar = pIIR_ObjectDeclaration(par);
      AccessFlags &aflags = (*iter).access_type;

      // Add sig_info pointer if a signal function kind attribute has
      // been applied on the parameter

      if ((aflags & SIGNAL_FUNCTION_ATTRIBUTE) ||
	  (aflags & SENSITIVE)) {
	constructor_str += separator + qid(par, rstack, SIGNAL) 
	  + "(" + qid(par, rstack, SIGNAL) + "_PAR)";
      }
      // Next, append reader if signal is read
      if (aflags & READ) {
	constructor_str += separator + qid(par, rstack, READER) 
	  + "(" + qid(par, rstack, READER) + "_PAR)";
      }
      // Finally, append driver if signal is written
      if (aflags & WRITE) {
	constructor_str += separator + qid(par, rstack, DRIVER)
	  + "(" + qid(par, rstack, DRIVER)+ "_PAR)";
      }

    } else if (par->is(IR_TYPE_DECLARATION) ||
	       par->is(IR_SUBTYPE_DECLARATION)) {
      // A type has been used and we need to pass over the type info
      // pointer of that type!
      constructor_str += separator + qid(par, rstack, INFO) 
	+ "_INFO(" + qid(par, rstack, INFO) + "_INFO_PAR)";
    }
  }
  

  // ******************************************************************
  // create the wait_info objects
  // ******************************************************************

  ContextInfo &ctxt = *ActiveContext(rstack);
  string wait_info_code_str;
  int windex = 0;

  for (list<pIIR_SequentialStatement>::iterator witer = ctxt.wait_statements.begin(); 
       witer != ctxt.wait_statements.end(); witer++)
    {
      if (! (*witer)->is (IR_WAIT_STATEMENT)) continue;
      pIIR_WaitStatement ws = pIIR_WaitStatement (*witer);
      // collect all signals the wait statement is sensitive on
      ContextInfo wctxt;
      get_context(ws, wctxt, rstack, false, 0);
      
      // Analyze each signal which was referenced in the corresponding
      // wait expression
      list<string> sal_add_arg_list;
      string codestr;
      int length = 0;
      for (access_list::iterator iter = wctxt.accessed_objects.begin(); 
	   iter != wctxt.accessed_objects.end(); iter++) {
	if (!((*iter).access_type & SENSITIVE)) continue;
	list<pair<pIIR_Expression, pIIR_Root> > acl_list;
	// convert each signal expression into an acl list
	get_acl((*iter).access_expr, acl_list, rstack, IR_GLOBALLY_STATIC, true);
	string sal_add_arg = qid((*iter).declaration, rstack, id_type(SIGNAL, ARCHREF));
	if (acl_list.size())
	  sal_add_arg += ",&(" + sprint_acl(acl_list, "tmpacl->clear()", rstack, id_type(SIGNAL, ARCHREF)) + ")";
	// if the current signal (including acl) already has been
	// added to the sal list then do nothing
	if (find(sal_add_arg_list.begin(), sal_add_arg_list.end(), sal_add_arg) != sal_add_arg_list.end())
	  continue;
	// add argument string (sal_add_arg) to list in order to
	// remove dublicate calls
	sal_add_arg_list.push_back(sal_add_arg);
	codestr += string("     sal.add(") + sal_add_arg + ");\n";

	length++;
      }
      
      // If the wait statment has an timeout clause then make it
      // sensitiv to a implicit signal associated with the current
      // process. This implicit signal is used to implement the wait
      // for condition.
      if (ws->timeout_clause != NULL) {
	// Determine declaration of implicit signal. Because there is
	// only a single implicit signal for each process which uses a
	// timeout clause, simply access the first element of the list
	// returned from filter_unique.
	list <AccessDescriptor> implicit_signal_access_list =
	  filter_unique(ctxt.extra_interface_objects, ACCESS, 
			V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR);
	assert (implicit_signal_access_list.size () >= 1);
	pV2CC_ImplicitSignalDeclaration_WaitFor implicit_signal_decl = 
	  pV2CC_ImplicitSignalDeclaration_WaitFor (implicit_signal_access_list.front ().declaration);
	assert (implicit_signal_decl != NULL);
	codestr += string("     sal.add(") + qid (implicit_signal_decl, rstack, id_type (SIGNAL, ARCHREF)) + ");\n";
	// Increment length as the implicit wait for signal is also
	// added to the sensitivity list!
	length++; 
      }

      // prolog
      wait_info_code_str += 
	string("    {\n") +
	string("     sigacl_list sal(") + to_string (length) + string(");\n");
      
      // add code 
      wait_info_code_str += codestr;

      // epilog
      wait_info_index(ws) = windex++;
      wait_info_code_str += string("     winfo[") + to_string (wait_info_index (ws)) + 
	string("]=kernel.setup_wait_info(sal,process);\n") + string("    }\n");
    }

  // Next, check out whether the process calls procedures that
  // contain at least one wait statement. First, get get all
  // procedure that are called from this process.
  bool calls_delayed_procedures = false;
  for (list<pIIR_SequentialStatement>::iterator witer = ctxt.wait_statements.begin(); 
       witer != ctxt.wait_statements.end(); witer++)
    {
      if (! (*witer)->is (IR_PROCEDURE_CALL_STATEMENT)) continue;
      pIIR_ProcedureCallStatement pc = pIIR_ProcedureCallStatement (*witer);
      wait_info_index(pc) = windex++;
      wait_info_code_str += string("    winfo[") + to_string (wait_info_index (pc)) + 
	string("]=(winfo_item*)NULL;\n");
      calls_delayed_procedures = true;
    }

  // If the procedure calls other procedures that contain wait
  // statements then create an internal pointer variable that will be
  // used to store pointers to the corresponding procedure class
  // instances.
  if (calls_delayed_procedures)
    insert_internal_object_declaration(get_last_rest_address(&extended_declarations(sbp)), 
				       sbp, sbp->pos, "pdelayed_procedure", 
				       "delayed_procedure_base*", "", DECLARE_LOCALLY);

  
  // ******************************************************************
  // Build constructor code
  // ******************************************************************

  constructor_str += 
    spaces (l) + string ("\n{\n")
    + spaces (l + 2) + "winfo=(winfo_item*)winfo_PAR;\n"
    + spaces (l + 2) + "if (winfo == NULL) {\n"
    + spaces (l + 2) + "  winfo=new winfo_item[" + to_string (windex) + "];\n"  
    + wait_info_code_str
    + spaces (l + 2) + "  winfo_PAR=winfo;\n"  
    + spaces (l + 2) + "}\n"
    + constructor_init_str 
    + spaces (l) + "}\n";

  str += constructor_str;
  
  str += "  /* Class destructor for subprogram " + get_long_name(sbp) + " */\n";
  str += spaces(l) + qid(sbp, rstack, DEFAULT) + "::~" + qid(sbp, rstack, DEFAULT) + "()\n"
    + spaces (l) + "{\n"
    + copy_back_code_str 
    + spaces (l) + "}\n";

  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  string code_str;
  code_str += "  /* Execute method for subprogram " + get_long_name(sbp) + " */\n";
  code_str += spaces(l) + "bool " + qid(sbp, rstack, DEFAULT) + "::execute()\n";
  code_str += spaces(l) + "{\n";
  code_str += spaces(l) + "  switch (jmp) {\n";
  for(unsigned int i = 1; i <= ctxt.wait_statements.size(); i++)
    code_str += "      case " + to_string(i) + ": goto lab" + to_string(i) + ";\n";
  code_str += spaces(l) + "  };\n\n  lab0:\n";
  
  // emit sequential statements
  pIIR_SequentialStatementList sl = sbp->subprogram_body;
  if (sl != NULL)
    emit_impl(sl, code_str, rstack, l + 2);

  // Print line and file info
  last_pos_info = emit_posinfo(sbp->pos, code_str, last_pos_info, l);
  code_str += spaces(l) + "  rlabel: return false;\n";

  code_str += spaces(l) + "}\n";

  str += code_str;
}


// Print subprogram implementation
void
m_emit_impl (pIIR_SubprogramDeclaration sbp, string &str, RegionStack &rstack, int l)
{
  // If no subprogram body is defined then do nothing!
  if (sbp->subprogram_body == NULL)
    return;

  rstack.push(sbp);
  
  // Procedures that includes wait statements (or call procedure that
  // contain waits) must be handled different from plain subprograms.
  if (sbp->is (IR_PROCEDURE_DECLARATION) &&
      (has_wait (pIIR_ProcedureDeclaration (sbp)) ||
       has_wait_for (pIIR_ProcedureDeclaration (sbp))))
    {
      emit_delayed_subprogram_impl (pIIR_ProcedureDeclaration (sbp), str, rstack, l);
    } 
  else
    {
      emit_plain_subprogram_impl (sbp, str, rstack, l);
    }

  rstack.pop();
}





// Print subprogram implementation
void
m_emit_impl (pIIR_PredefinedFunctionDeclaration sbp, string &str, RegionStack &rstack, int l)
{
  // Nothing to do.
}


// Print subprogram implementation
void
m_emit_impl (pIIR_PredefinedProcedureDeclaration sbp, string &str, RegionStack &rstack, int l)
{
  // Nothing to do.
}


void                                                            // SeqStatList impl
m_emit_impl (pIIR_SequentialStatementList sl, string &str, RegionStack &rstack, int l)	
{
  while (sl)
    {
      pIIR_SequentialStatement s = sl->first;
      
      //if (s->label)
      //{
      //  emit_id (s->label->declarator, str, rstack);
      //  str += ": ";
      //}
      emit_impl (s, str, rstack, l);
      sl = sl->rest;
    }
}


void
m_emit_impl (pIIR_NullStatement, string &str, RegionStack &rstack, int l)
{
  str += "/* NullStat impl */;\n";
}


void
m_emit_impl (pIIR_ReturnStatement r, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(r->pos, str, last_pos_info, l);

  if (r->return_expression != NULL) {
    // Ok, this return statement belongs to a function
    pIIR_FunctionDeclaration func = pIIR_FunctionDeclaration(r->enclosing_subprogram);
    
    string return_expr;
    emit_expr (r->return_expression, return_expr, rstack, DEFAULT);

    if (is_array_type(func->return_type))
      // Return value is an array
      if (is_constrained_array_type(func->return_type)) {
	string alias_expr = "array_alias<" + 
	  qid(get_declaration(get_base_type(func->return_type)), rstack, id_type()) + " >(" + 
	  get_type_info_obj(func->return_type, rstack, false);
	return_expr = alias_expr + ",(" + return_expr + ").data)";

      } else {
	string alias_expr = "array_alias<" + 
	  qid(get_declaration(get_base_type(func->return_type)), rstack, id_type()) + " >(" + 
	  get_type_info_obj(func->return_type, rstack, false);
	return_expr = alias_expr + "," + return_expr + ")";

      }

    str += spaces(l) + "return " + return_expr + ";\n";

  } else
    // Ok, this return statement belongs to a procedure
    str += spaces(l) + "goto rlabel;\n";
}


void
m_emit_impl (pIIR_VariableAssignmentStatement a, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(a->pos, str, last_pos_info, l);
  
  str += spaces(l);
  emit_expr (a->target, str, rstack, id_type(READER, DEREF));
  str += "=";
  emit_expr (a->expression, str, rstack, id_type(READER, DEREF));
  str += ";\n";
}

void
m_emit_impl (pIIR_IfStatement is, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(is->pos, str, last_pos_info, l);

  str += spaces(l) + "if(";
  emit_expr (is->condition, str, rstack, DEFAULT);
  str += ") {\n";
  if (is->then_sequence != NULL)
    emit_impl (is->then_sequence, str, rstack, l+2);
  if (is->else_sequence != NULL)
    {
      str += spaces(l) + "} else {\n";
      emit_impl (is->else_sequence, str, rstack, l+2);
    }
  str += spaces(l) + "}\n";
}


// Emit code for a case statement where the selection expression is
// scalar
void
emit_impl_scalar_case_statement (pIIR_CaseStatement cs, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(cs->pos, str, last_pos_info, l);

  str += spaces(l) + "switch(";
  emit_expr (cs->expression, str, rstack, id_type(READER, DEREF));
  str += ") {\n";
  
  for (pIIR_CaseStatementAlternativeList al = cs->case_statement_alternatives; al; al = al->rest) {
    pIIR_CaseStatementAlternative a = al->first;
    
    string case_str = spaces(l);
    
    for (pIIR_ChoiceList cl = a->choices; cl; cl = cl->rest)
      
      if (cl->first->is(IR_CHOICE_BY_RANGE)) {
	//***************************************
	// Choice by range
	//***************************************
	
	pIIR_ChoiceByRange cbr = pIIR_ChoiceByRange(cl->first);
	
	// Get range.
	vector<RangeDescriptor> range_desc = get_discrete_range(cbr->range, rstack, IR_LOCALLY_STATIC);
	StaticRangeDescriptor<lint, IR_Direction> range = 
	  range_desc[0].rangedes_to_lint(rstack);
	if (range.left == range.right)
	  case_str += "case " + to_string(range.left) + ": ";
	else if (range.left < range.right && range.dir == IR_DIRECTION_UP)
	  case_str += "case " + to_string(range.left) + " ... " + to_string(range.right) + ": ";
	else if (range.left > range.right && range.dir != IR_DIRECTION_UP)
	  case_str += "case " + to_string(range.right) + " ... " + to_string(range.left) + ": ";
	
      } else if (cl->first->is(IR_CHOICE_BY_EXPRESSION)) {
	//***************************************
	// Choice by expression
	//***************************************
	
	pIIR_ChoiceByExpression cbe = pIIR_ChoiceByExpression(cl->first);
	int value = int(folded_value(cbe->value).long_value());
	case_str += "case " + to_string(value) + ": ";
	
      } else if (cl->first->is(IR_CHOICE_BY_OTHERS)) {
	//***************************************
	// Choice by others
	//***************************************
	case_str += "default: ";
      }
    
    str += case_str + "{\n";
    if (a->sequence_of_statements != NULL)
      // Analyze sequential statements associated with alternative
      emit_impl(a->sequence_of_statements, str, rstack, l + 2);
    str += spaces(l + 1) + "} break;\n";
  }
  
  str += spaces(l) + "}\n";
}



template <class T>
struct bitwise_and : public binary_function<T,T,T>
{
  bool operator()(const T& x, const T& y) const { return x & y; }
};
 
template <class T>
struct bitwise_or : public binary_function<T,T,T>
{
  bool operator()(const T& x, const T& y) const { return x | y; }
};
 

template <class T>
struct bitwise_xor : public binary_function<T,T,T>
{
  bool operator()(const T& x, const T& y) const { return x ^ y; }
};
 

inline unsigned int
rotate_left(unsigned int value, int count)
{
  return (value << count) | (value >> (sizeof(unsigned int) * 8 - count));
} 


// Count bit set in value. The algorithm is not very smart...
inline int
bit_count(unsigned int value)
{
  int result = 0;
  while (value) {
    if (value & 0x1) result++;
    value >>= 1;
  }
  return result;
}


// Find an bit shift width for pattern "bits" so that after shifting
// most of the bits set in "bits" are also set in free_bits.
int 
find_best_shift(unsigned int free_bits, int bits)
{
  const int max_shift = sizeof(int) * 8 - 1;
  int best_shift = -1, best_result = -1;

  for (int i = 0; i < max_shift; i++) {
    int result = bit_count(free_bits & rotate_left((unsigned int)bits, i));
    if (result > best_result) {
      best_result = result;
      best_shift = i;
    }
  }

  return best_shift;
}


// Emit code for a case statement where the selection expression is
// an one dimensional array
void
emit_impl_array_case_statement (pIIR_CaseStatement cs, string &str, RegionStack &rstack, int l)
{
  // We generate hash numbers from each selection expression to
  // speedup the slection process. A case statement like:
  
  // case var is
  // when "000" => ...
  // when "001" => ...
  // when  others => ...
  // end case;

  // is translated to (the hash numbers are chosen arbitrarily):

  // enumeration int1_lit[] = { 0, 0, 0 };
  // enumeration int2_lit[] = { 0, 0, 1 };
  // unsigned int int3_keys[] = { 12, 34 }; /* two hash numbers */
  // unsigned int int4_key_to_lit[] = { 0, 2 }; 
  // enumeration *int5_lit_tab[] = { int1_lit,  0, int2_lit,  0};
  // int          int6_action[] =  {        0, -1,       1 , -1};
  // memcpy(int7_selection, slection_expression.data, 3);
  // switch (do_case_select(3, 2, int7_selesction[0]^rot_left(int7_selection[1], 1), 
  //            int7_selection, int3_keys, int4_key_to_lit, int5_lit_tab, 
  //            int6_action)) {
  // case 0: ...
  // case 1: ...
  // default: ...
  // }

  // int1_lit and int2_lit are literal values translated into
  // enumeration array constant. int3_keys stores for each literal the
  // corresponding hash number while int4_key_to_lit is an index table
  // which points to the corresponding entry in int5_lit_tab. E.g., if
  // hash number 34 is calculated from the selection expression then
  // the *second* element of the key tables matches. Hence, we select
  // the *second* element of the int4_key_to_lit table which gives us
  // index number 1. This index is used to address the lit_tab table
  // which holds pointers to the corresponding array literal
  // constant(s). We need this constants to re-check whether the
  // selection expression really matches the array literal. Note that
  // more than one choice pattern my have the same hash value. Hence,
  // we compare all literal constants until the number 0 is reached in
  // the int5_lit_tab table. When we have a match (or a 0 is reached)
  // then the *corresponding* entry in the action table (int6_action)
  // is chosen as action number. This action number is finally used in
  // the case statement to select the appropriate alternative. Note
  // that do_case_select is an inlined function which performs most of
  // the described processing.
  
  // Note further that the hash number is generated by packing four
  // consecutive elements of the enumeration value into a int and then
  // processing the int values as shown below.
  
  // First, collect all pattern into a single list
  typedef vector<int> int_vec;
  vector<int_vec> all_pattern;
  int_vec alternative_number;
  int current_alternative_number = 0;
  for (pIIR_CaseStatementAlternativeList al = cs->case_statement_alternatives; 
       al; al = al->rest, current_alternative_number++) {
    pIIR_CaseStatementAlternative a = al->first;
    for (pIIR_ChoiceList cl = a->choices; cl; cl = cl->rest)
      if (cl->first->is(IR_CHOICE_BY_EXPRESSION)) {
	pIIR_ChoiceByExpression cbe = pIIR_ChoiceByExpression(cl->first);
	all_pattern.push_back(folded_value(cbe->value).array_literal_value());
	alternative_number.push_back(current_alternative_number);
      } 
  }

  // Next, determine pairwise difference of all pattern pairs and or
  // together these differences. This is done in order so detect
  // whether there are some bits that have the SAME value among all
  // choice pattern. After execution of the main loop diff_pattern
  // will consist of a sequence of integer values where each bit set
  // to 1 indicates that there are at least two pattern which are
  // having different bit values at the corresponding bit position
  // (the reason where are doing this here is: bits that are always
  // the same among all pattern are ingnored when generating the hash
  // values from the pattern).
  const int pattern_length = all_pattern.size() == 0? 0 : all_pattern[0].size();
  int_vec diff_pattern(pattern_length);
  fill(diff_pattern.begin(), diff_pattern.end(), 0);
  for (vector<int_vec>::iterator iter1 = all_pattern.begin(); iter1 != all_pattern.end(); iter1++) {
    vector<int_vec>::iterator iter1_next = iter1;
    for (vector<int_vec>::iterator iter2 = ++iter1_next; iter2 != all_pattern.end(); iter2++) {
      // First, xor pattern pair
      int_vec diff(pattern_length);
      transform((*iter1).begin(), (*iter1).end(), (*iter2).begin(), diff.begin(), bitwise_xor<int>());
      // Then, or result into diff_pattern
      transform(diff.begin(), diff.end(), diff_pattern.begin(), diff_pattern.begin(), bitwise_or<int>());
    }
  }
  
  const int sizeof_uint = sizeof(unsigned int);
  
  // Now find for each group of four (or less in case of the last
  // elements) elements of the difference vector a shift value so that
  // the set bits of all elements do not overlap. This is not possible
  // for the general case. Hence, try to minimize overlapping.
  int_vec shift_vector((pattern_length + sizeof_uint - 1)/sizeof_uint);
  fill(shift_vector.begin(), shift_vector.end(), 0);
  unsigned int free_bits = 0;
  for (int i = 0, word = 0; i < pattern_length; i += sizeof_uint, word++) {
    // If there are no more free bits to use then set all bits of
    // free_bits
    if (free_bits == 0)
      free_bits = (unsigned)0 - (unsigned)1;
    unsigned int diff_group = 0;
    for (int byte = i; (byte < pattern_length) && (byte < i + sizeof_uint); byte++) {
#ifndef WORDS_BIGENDIAN 
      // This is a little endian machine 
      diff_group |= (unsigned int)diff_pattern[byte] << (8 * (byte - i));
#else
      // This is a big endian machine
      diff_group |= (unsigned int)diff_pattern[byte] << (8 * (sizeof_uint - 1 - (byte - i)));
#endif
    } 
    // If all elements of all choice vectors are the same then we
    // simply store a -1 as shift value to indicate that this
    // particular group should not be used.
    if (diff_group == 0) {
      shift_vector[word] = -1;
      continue;
    }
    shift_vector[word] = find_best_shift(free_bits, diff_group);
    // Remove used bits from free_bits
    free_bits &= ~rotate_left(diff_group, shift_vector[word]);
  }

  // Calculate hash number for each pattern. The hash number is
  // stored in key_vector.
  vector<unsigned int> key_vector(all_pattern.size());
  for (unsigned int i = 0; i < all_pattern.size(); i++) {
    unsigned int key = 0;
    int_vec &pattern = all_pattern[i];
    for (int j = 0, word = 0; j < pattern_length; j += sizeof_uint, word++) {
      if (shift_vector[word] == -1)
	continue;
      unsigned int pattern_group = 0;
      for (int byte = j; (byte < pattern_length) && (byte < j + sizeof_uint); byte++) {
#ifndef WORDS_BIGENDIAN 
	// This is a little endian machine 
	pattern_group |= (unsigned int)pattern[byte] << (8 * (byte - j));
#else
	// This is a big endian machine
	pattern_group |= (unsigned int)pattern[byte] << (8 * (sizeof_uint - 1 - (byte - j)));
#endif
      } 
      key ^= rotate_left(pattern_group, shift_vector[word]);
    }
    key_vector[i] = key;
  }
  
  // Create internal array constants which store the literal
  // values. Note that this constants will be declared globally.
  pIIR_DeclarativeRegion root_region = RootDeclarativeRegion(rstack);
  vector<string> literal_names(all_pattern.size());
  for (unsigned int i = 0; i < all_pattern.size(); i++) {
    // Generate internal constant name
    literal_names[i] = get_new_internal_var_prefix() + "_lit";
    // The initial value of the constant is the concatenation of all
    // integer values separated by ","
    string init_str = "[]={" + concat_to_string(all_pattern[i].begin(), all_pattern[i].end(), ",") + "}";
    // Declare the internal variable as a global constant 
    insert_internal_object_declaration(NULL, root_region, NULL, literal_names[i],
				       "enumeration", init_str, DECLARE_GLOBALLY | DECLARE_AND_INIT);
  }

  // Calculate the various tables shown in the following example:
  // unsigned int int3_keys[] = { 12, 34 }; /* two hash numbers */
  // unsigned int int4_key_to_lit[] = { 0, 2 }; 
  // enumeration *int5_lit_tab[] = { int1_lit,  0, int2_lit,  0};
  // int          int6_action[] =  {        0, -1,       1 , -1};
  vector<bool> done(all_pattern.size());
  fill(done.begin(), done.end(), false);
  list<unsigned int> key_list, key_to_lit_list;
  list<int> action_list;
  list<string> lit_tab_list;
  int current_key_to_lit_index = 0;
  for (unsigned int i = 0; i < all_pattern.size(); i++ ) {
    if (done[i]) continue;
    done[i] = true;
    key_list.push_back(key_vector[i]);
    key_to_lit_list.push_back(current_key_to_lit_index);
    lit_tab_list.push_back(literal_names[i]);
    action_list.push_back(alternative_number[i]);
    for (unsigned int j = i + 1; j < all_pattern.size(); j++)
      if (key_vector[i] == key_vector[j]) {
	lit_tab_list.push_back(literal_names[j]);
	action_list.push_back(alternative_number[j]);
	done[j] = true;
      }
    lit_tab_list.push_back(string("0"));
    action_list.push_back(-1);
    current_key_to_lit_index = lit_tab_list.size();
  }


  // Create and init key constant array
  string key_list_name = get_new_internal_var_prefix() + "_keys";
  string init_str = "[]={" + concat_to_string(key_list.begin(), key_list.end(), ",") + "}";
  insert_internal_object_declaration(NULL, root_region, NULL, key_list_name,
				     "const unsigned int", init_str, DECLARE_GLOBALLY | DECLARE_AND_INIT);

  // Create and init key_to_lit constant array
  string key_to_lit_name = get_new_internal_var_prefix() + "_key_to_lit";
  init_str = "[]={" + concat_to_string(key_to_lit_list.begin(), key_to_lit_list.end(), ",") + "}";
  insert_internal_object_declaration(NULL, root_region, NULL, key_to_lit_name,
				     "const int", init_str, DECLARE_GLOBALLY | DECLARE_AND_INIT);

  // Create and init lit_tab constant array
  string lit_tab_name = get_new_internal_var_prefix() + "_lit_tab";
  init_str = "[]={" + concat_to_string(lit_tab_list.begin(), lit_tab_list.end(), ",") + "}";
  insert_internal_object_declaration(NULL, root_region, NULL, lit_tab_name,
				     "const enumeration *", init_str, DECLARE_GLOBALLY | DECLARE_AND_INIT);

  // Create and init action constant array
  string action_name = get_new_internal_var_prefix() + "_action";
  init_str = "[]={" + concat_to_string(action_list.begin(), action_list.end(), ",") + "}";
  insert_internal_object_declaration(NULL, root_region, NULL, action_name,
				     "const int", init_str, DECLARE_GLOBALLY | DECLARE_AND_INIT);

  // Create an global variable which stores the data part of the
  // selection array. Note that this variable does not have a real
  // initial value as it will be initialised each time the case
  // statement is executed.
  string selection_var_name = get_new_internal_var_prefix() + "_selection";
  insert_internal_object_declaration(NULL, root_region, NULL, selection_var_name,
				     "unsigned int", "[" + to_string((pattern_length + sizeof_uint - 1) / sizeof_uint) + "]", 
				     DECLARE_GLOBALLY | DECLARE_AND_INIT);

  // Generate the code which calculates the hash number from an
  // selection value
  list<string> hash_number_code_items;
  for (int i = 0, word = 0; i < pattern_length; i += sizeof_uint, word++)
    if (shift_vector[word] != -1) {
      unsigned int mask = (unsigned int)0 - (unsigned int)1;
#ifndef WORDS_BIGENDIAN 
      // This is a little endian machine 
      mask = (i + sizeof_uint - 1 < pattern_length)? 
	mask : (mask >> (sizeof_uint - i % sizeof_uint) * 8);
#else
      // This is a big endian machine
      mask = (i + sizeof_uint - 1 < pattern_length)? 
	mask : (mask >> ((i % sizeof_uint) * 8));
#endif
      // Create code which fetches the next four bytes of the
      // selection array. Note that usually four enumeration values
      // are fetched concurrently this way.
      string code_item = selection_var_name + "[" + to_string(word) + "]";
      if (~mask != 0)
	// If not all bits in mask are set then use mask to remove
	// unused bytes in the fetched word
	code_item = "(" + code_item + "&" + to_string(mask) + ")";
      // If the shift value for the current word is not equal to zero
      // than add code to perform the rotate operations.
      if (shift_vector[word] != 0)
	code_item = "rotate_left(" + code_item + "," + to_string(shift_vector[word]) + ")";
      // Finally, add code_item to list
      hash_number_code_items.push_back(code_item);
    }

  // Print line and file info
  last_pos_info = emit_posinfo(cs->pos, str, last_pos_info, l);
  str += spaces(l) + "memcpy(" + selection_var_name + ",";
  emit_expr (cs->expression, str, rstack, id_type(READER, DEREF));
  str += ".data," + to_string(pattern_length) + "*sizeof(enumeration)); ";
  // Add the code to calculate the selection expression for the
  // transformed case statement
  string hash_number_code = hash_number_code_items.size() != 0? 
    concat_to_string(hash_number_code_items.begin(), hash_number_code_items.end(), "^") : "0";
  str += "switch (do_case_select(" + 
    to_string(pattern_length) + "," + 
    to_string(key_list.size()) + "," + 
    hash_number_code + "," + 
    selection_var_name + "," + 
    key_list_name + "," + 
    key_to_lit_name + "," + 
    lit_tab_name + "," + 
    action_name + ")) {\n";

  // Now, add the code for the alternatives of the case statement
  int case_counter = 0;
  for (pIIR_CaseStatementAlternativeList al = cs->case_statement_alternatives; al; al = al->rest, case_counter++) {
    pIIR_CaseStatementAlternative a = al->first;
    
    str += spaces(l);
    
    if (a->choices->first->is(IR_CHOICE_BY_OTHERS))
	//***************************************
	// Choice by others
	//***************************************
      str += "default: ";
    else
      str += "case " + to_string(case_counter) + ":";

    str += "{\n";
    // Emit sequential statements associated with alternative
    if (a->sequence_of_statements != NULL)
      emit_impl(a->sequence_of_statements, str, rstack, l + 2);
    str += spaces(l + 1) + "} break;\n";
  }
  str += spaces(l) + "}\n";

}


void
m_emit_impl (pIIR_CaseStatement cs, string &str, RegionStack &rstack, int l)
{
  // A case statement. This is probably too complicated. We should
  // somehow unify ranges and subtypes
  
  if (is_scalar_type(cs->expression->subtype))
    //****************************************************
    // Expression is scalar
    //****************************************************
    emit_impl_scalar_case_statement(cs, str, rstack, l);
  else
    //****************************************************
    // Expression is an array 
    //****************************************************
    emit_impl_array_case_statement(cs, str, rstack, l);
}


void
m_emit_impl (pIIR_LoopStatement ls, string &str, RegionStack &rstack, int l)
{
  ContextInfo &ctxt = *ActiveContext(rstack);
  pIIR_DeclarativeRegion active_region = ActiveDeclarativeRegion(rstack);

  // Check whether a name has been associated with the loop statement
  if (ls->declarative_region->declarator == NULL) {
    // If the loop statement has no name then create a default name
    string loop_name = to_string(ls->declarative_region->seqno) + loop_default_postfix;
    ls->declarative_region->declarator = new IIR_TextLiteral(0, loop_name.c_str());
  }

  // Print line and file info
  last_pos_info = emit_posinfo(ls->pos, str, last_pos_info, l);

  if (ls->is(IR_WHILE_LOOP_STATEMENT))
    {
      str += spaces(l) + "while(";
      emit_expr (pIIR_WhileLoopStatement(ls)->condition, str, rstack, DEFAULT);
      str += ")";
    }
  else if (ls->is(IR_FOR_LOOP_STATEMENT))
    {
      pIIR_ForLoopStatement fl = pIIR_ForLoopStatement (ls);
      // generate a internal variable for the loop variable, and the
      // loop counter which stores the number of iterations.
      string loop_var_name = qid(fl->iterator, rstack, id_type());
      string loop_counter_name = loop_var_name + "_lc";
      string loop_step_name = loop_var_name + "_ls";
      string loop_var_type = qid(get_declaration(fl->iterator->subtype), rstack, TYPE);

      // Get iteration range
      vector<RangeDescriptor> range_desc = 
	get_discrete_range (pIIR_ScalarSubtype(fl->iterator->subtype)->range, rstack, IR_NOT_STATIC);
      StaticRangeDescriptor<string, string> range = 
	range_desc[0].rangedes_to_string(rstack, get_default_id_type(rstack));

      // Create internal variables which will hold the iteration
      // bounds
      insert_internal_object_declaration(NULL, active_region, NULL, loop_var_name, loop_var_type, "", 0);
      insert_internal_object_declaration(NULL, active_region, NULL, loop_counter_name, loop_var_type, "", 0);
      if (!range_desc[0].is_explicit_range())
	insert_internal_object_declaration(NULL, active_region, NULL, loop_step_name, loop_var_type, "", 0);

      if (range_desc[0].is_explicit_range())
	{
	  str += spaces (l) + "for (" + loop_var_name + "=" + range.left + "," + loop_counter_name + "=" + 
	    string (range.dir == "to"? "up_range_to_length" : "down_range_to_length") + "<" + loop_var_type + ">(" +
	    range.left + "," + range.right + "); ";
	  str += loop_counter_name + "!=0; ";
	  str += loop_var_name + string(range.dir=="to"? "++" : "--") + "," + loop_counter_name + "--)";
	} 
      else 
	{
	  str +=  spaces (l) + "for (" + loop_var_name + "=" + range.left + "," + loop_step_name + "=" + range.dir + "==to?+1:-1," + 
	    loop_counter_name + "=range_to_length<" + loop_var_type + ">(" + range.left + "," + range.dir + "," + range.right + ");";
	  str += loop_counter_name + "!=0" + "; ";
	  str += loop_var_name + "+=" + loop_step_name + "," + loop_counter_name + "--)";
	}
    }
  else
    str += spaces(l) + "while(1)";

  str += " {\n";
  if (ls->sequence_of_statements != NULL)
    emit_impl (ls->sequence_of_statements, str, rstack, l+2);
  str += spaces(l);

  // If a next statement has been used for this loop then add an
  // appropriate label
  if (next_statement_used(ls))
    str += "next_" + to_string(loop_id(ls)) + ":; ";

  str += "}";

  // If a exit statement has been used for this loop then add an
  // appropriate label
  if (exit_statement_used(ls))
    str += " exit_" + to_string(loop_id(ls)) + ":; ";

  str += "\n";
}


void
m_emit_impl (pIIR_NextStatement ns, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(ns->pos, str, last_pos_info, l);

  string jump_code = "goto next_" + to_string(loop_id(ns->loop)) + ";\n";
  if (ns->condition) {
    str += spaces(l) + "if (";
    emit_expr (ns->condition, str, rstack, id_type(READER, DEREF));
    str += ") " + jump_code;
  } else
    str += spaces(l) + jump_code;
}


void
m_emit_impl (pIIR_ExitStatement es, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(es->pos, str, last_pos_info, l);

  string jump_code = "goto exit_" + to_string(loop_id(es->loop)) + ";\n";
  if (es->condition) {
    str += spaces(l) + "if (";
    emit_expr (es->condition, str, rstack, id_type(READER, DEREF));
    str += ") " + jump_code;
  } else
    str += spaces(l) + jump_code;
}


void
m_emit_impl (pIIR_ProcedureCallStatement pcs, string &str, RegionStack &rstack, int l)
{
  // A procedure call.

  // Print line and file info
  last_pos_info = emit_posinfo(pcs->pos, str, last_pos_info, l);

  pIIR_ProcedureDeclaration p = pcs->procedure;

  // Check whether the procedure contains wait statements
  if (has_wait (pIIR_ProcedureDeclaration (p)) ||
      has_wait_for (pIIR_ProcedureDeclaration (p)))
    {
      // This procedure contains wait statements. Hence, a
      // corresponding instance of the procedure object is
      // created and called.

      // If the caller is a process, then the this pointer is passed
      // over to the procedure class constructor. Otherwise (i.e., if
      // the caller is also a procedure), variable "process" must be
      // passed over. Note that this variable points to the
      // corresponding process this procedure is called from. The
      // constructor needs this information in order to idnetify the
      // "source" process.
      pIIR_DeclarativeRegion base_region = BaseDeclarativeRegion(rstack);
      string caller_str = base_region->is (IR_PROCESS_STATEMENT)? "this" : "process";

      int windex = wait_info_index (pcs);
      str += spaces (l) + "pdelayed_procedure=new " 
	+ qid (p, rstack, DEFAULT) + "(" + caller_str + ",winfo[" + to_string (windex) + "]";
      
      string assoc_str;
      emit_subprogram_associations (assoc_str, rstack, pcs->actual_parameter_part, 
				    p->interface_declarations,
				    context(p).extra_interface_objects);
      str += (assoc_str != ""? "," : "" ) + assoc_str;
      str += "); ";
      str += "jmp=" + to_string (windex + 1) + "; lab" + to_string (windex + 1) + ":" 
	+ " if (((" + qid (p, rstack, DEFAULT) + "*)pdelayed_procedure)->execute()) return true; "
	+ "delete (" +  qid (p, rstack, DEFAULT) + "*)pdelayed_procedure;\n";
    }
  else
    {
      // Ok, this is a plain procedure without wait statements
      str += spaces(l) + qid(p, rstack, DEFAULT);
      str += " (";
      emit_subprogram_associations (str, rstack, pcs->actual_parameter_part, 
				    p->interface_declarations,
				    context(p).extra_interface_objects);
      str += ");\n";
    }
}

void
m_emit_impl (pIIR_WaitStatement ws, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(ws->pos, str, last_pos_info, l);

  pIIR_DeclarativeRegion region = BaseDeclarativeRegion (rstack);
  if (region->is (IR_SENSITIZED_PROCESS_STATEMENT) ||
      region->is (IR_IMPLICIT_PROCESS_STATEMENT)) {
    /* If the wait is in an implicit process (concurrent signal
     * assignment) then any code to activate the wait statement can
     * be skipped, because only a single wait will be active all the
     * time. */
    return;

  } else if (ws->condition_clause == NULL &&
      ws->timeout_clause == NULL &&
      ws->sensitivity_list == NULL) {
    // If there is no condition clause and no timeout clause and no
    // sensitivity_list then this wait statements shall stop the
    // process for the rest of the simulation time.
    str += spaces(l) + "wait(PROCESS_STOP); return true;\n";

  } else {
    int windex = wait_info_index(ws);
    str += spaces(l) + "wait(winfo[" + to_string(windex) + "]); ";
    str += "jmp = " + to_string(windex + 1) + "; ";

    pV2CC_ImplicitSignalDeclaration_WaitFor implicit_signal_decl = NULL;
    if (ws->timeout_clause != NULL) {
      // Determine declaration of implicit signal. Because there is
      // only a single implicit signal for each process which uses a
      // timeout clause simply access the first element of the list
      // returned from filter_unique.
      list<pIIR_Declaration> l = 
	filter_unique(extended_declarations(BaseDeclarativeRegion(rstack)),
		      V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR);
      // Check whether an appropriate implicit signal could be
      // found. If not, then we are probably in a subprogram. In this
      // case, search the extra interface objects for an appropriate
      // signal. Note that in case of an "wait for" executed within a
      // subprogram, an appropriate implicit signal is declared within
      // the corresponding process and this signal is passed over to
      // the subprogram via its interface.
      if (l.size () == 0 &&
	  BaseDeclarativeRegion (rstack)->is (IR_SUBPROGRAM_DECLARATION))
	{
	  // Search extra interface objects for an appropriate
	  // implicit signal.
	  list < AccessDescriptor > al =
	    filter_unique(BaseContext (rstack)->extra_interface_objects,
			  ACCESS, 
			  V2CC_IMPLICIT_SIGNAL_DECLARATION_WAIT_FOR);
	  // Ok, if we found one, then extract the signal declaration
	  // and push it on the result list l.
	  if (al.size () > 0)
	    l.push_back (al.front ().declaration);
	}
      assert (l.size() > 0);
      implicit_signal_decl =
	pV2CC_ImplicitSignalDeclaration_WaitFor(l.front());

      // Generate a signal assignment to a special implicit signal
      // which activates the process in case of a timeout. The
      // assignment is a special signal assignment as it removes all
      // pending transactions from the driver and also immediately
      // sets the reader value to '0'.
      str += qid(implicit_signal_decl, rstack, id_type(DRIVER)) + "->reset_assign(0,1,";
      emit_expr(ws->timeout_clause, str, rstack, id_type(READER, DEREF));
      str += "); ";
    }
    str += "return true; ";
    str += "lab" + to_string(windex + 1) + ":; ";
      
    // Emit code to test condition 
    if (ws->condition_clause != NULL) {
      if (ws->timeout_clause != NULL)
	str += "if ((!" + qid(implicit_signal_decl, rstack, id_type(READER, DEREF)) + ")&&(";
      else 
	str += "if (!(";
      emit_expr(ws->condition_clause, str, rstack, id_type(READER, DEREF)); 
      str += ")) return false;";
    }
    str += "\n";
  }
}

void
m_emit_impl (pIIR_AssertionStatement as, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(as->pos, str, last_pos_info, l);

  str += spaces(l) + "if(!";
  emit_expr (as->assertion_condition, str, rstack, DEFAULT);
  str += ")\n";
  str += spaces(l + 2) + "report(";
  if (as->report_expression != NULL)
    {
      emit_expr (as->report_expression, str, rstack, DEFAULT);
      str += ",";
    }
  if (as->severity_expression != NULL)
    emit_expr (as->severity_expression, str, rstack, DEFAULT);
  else
    str += "0";
  str += ");\n";
}

void
m_emit_impl (pIIR_ReportStatement rs, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(rs->pos, str, last_pos_info, l);

  str += spaces(l) + "report(";
  if (rs->report_expression != NULL)
    {
      emit_expr (rs->report_expression, str, rstack, DEFAULT);
      str += ",";
    }
  if (rs->severity_expression != NULL)
    emit_expr (rs->severity_expression, str, rstack, DEFAULT);
  else
    str += "0";
  str += ");\n";
}


void
m_emit_impl (pIIR_SignalAssignmentStatement sa, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(sa->pos, str, last_pos_info, l);

  // determine the signals that are written!
  ContextInfo &ctxt = *ActiveContext(rstack);

  // Determine target signals.
  ContextInfo local_ctxt;
  get_context(sa->target, local_ctxt, rstack, true, 0);
  list<AccessDescriptor> sig_written = 
    filter(local_ctxt.accessed_objects, WRITE, 
	   tree_kind_list(IR_SIGNAL_DECLARATION, IR_SIGNAL_INTERFACE_DECLARATION));

  // bail out if more than one signal is written. Only simple signal
  // assignment targets are supported yet.
  if (sig_written.size() > 1)
    codegen_error.error("%:error: sorry, no resolved signals are supproted yet", sa);
    
  // Get decelration of target signal
  pIIR_SignalDeclaration target_sig_decl = (pIIR_SignalDeclaration)sig_written.front().declaration;

  // Determine the first part of the synthesized signal assignment statement
  string target_str, target_specifier;

  if (codegen_options.get_verbose ())
    codegen_error.info ("%:target %n", sa, target_sig_decl);

  if (is_scalar_type(target_sig_decl->subtype)) {
    //******************************************************************
    // if the target is a scalar signal then simply get the driver for
    // that signal
    //******************************************************************
    target_str = qid(target_sig_decl, rstack, id_type(DRIVER));

  } else if (is_scalar_type(sa->waveform->first->value->subtype)) {
    //******************************************************************
    // if the target is a *scalar* element of a composite signal then
    // get the scalar driver for that element
    //******************************************************************
    list<pair<pIIR_Expression, pIIR_Root> >acl_list;
    get_acl(sig_written.front().access_expr, acl_list, rstack, IR_NOT_STATIC, true);
    // generate a name for a new acl object
    string internal_var_name = create_internal_acl(get_acl_size(acl_list), rstack, false);
    // Create signal assignment code
    target_str = qid(target_sig_decl, rstack, id_type(DRIVER)) + 
      "->scalar_driver(&(" + sprint_acl(acl_list, internal_var_name + "->clear()", 
					rstack, id_type(DEFAULT, DEREF)) + "))";

  } else {
    //******************************************************************
    // Several elements of a composite signal are target of the
    // assignment operation. First, get acl for assignment target
    //******************************************************************
    list<pair<pIIR_Expression, pIIR_Root> > acl_list;
    get_acl(sig_written.front().access_expr, acl_list, rstack, IR_NOT_STATIC, true);

    // Check whether the entrire signal or a only a part of the signal
    // is target of the assignement
    if (acl_list.size()) {
      // Only a part of the signal is targeted. First, generate a name
      // for a new acl object
      string internal_var_name = create_internal_acl(get_acl_size(acl_list), rstack, false);
      // Create signal assignment code
      target_str = qid(target_sig_decl, rstack, id_type(DRIVER));
      target_specifier = ",&(" + sprint_acl(acl_list, internal_var_name + "->clear()", 
					    rstack, id_type(DEFAULT, DEREF)) + ")";
      
    } else {
      // the *entire* signal is assignement target
      target_str = qid(target_sig_decl, rstack, id_type(DRIVER));
      target_specifier = ",0";
    }
  }

  bool first = true;
  for (pIIR_WaveformList wl = sa->waveform; wl; wl = wl->rest)
    {
      if (!first)
        str += spaces(1);
      str += spaces(l) + target_str;
      if (sa->delay_mechanism==IR_INERTIAL_DELAY && first)
	str += "->inertial_assign(";
      else
	str += "->transport_assign(";

      pIIR_WaveformElement we = wl->first;
      string value_str;
      emit_expr (we->value, value_str, rstack, id_type(READER, DEREF));
      value_str += target_specifier;
      if (we->time) {
	value_str += ",vtime(";
	emit_expr (we->time, value_str, rstack, id_type(READER));     
      } else 
	value_str += ",vtime(0";

      str += value_str + "));\n";
      first = false;
    }
}


void
m_emit_impl (pIIR_SequentialStatement s, string &str, RegionStack &rstack, int l)
{
  str += string("/* emit statement ") + s->kind_name () + string(" */\n");
}


void
m_emit_impl (pIIR_ComponentInstantiationStatement ci, string &str, RegionStack &rstack, int l)
{
}

void
m_emit_impl (pIIR_BlockStatement bs, string &str, RegionStack &rstack, int l)
{
  // Print line and file info
  last_pos_info = emit_posinfo(bs->pos, str, last_pos_info, l);

  str += "block ";
  str += string("\n") + spaces(l) + string("{\n");
  emit_decls (extended_declarations(bs), str, rstack, l+2);
  if (extended_declarations(bs))
    str += "\n";
  //  emit (bs->block_statement_part, str, rstack, l+2);
  str += spaces(l) + string("}\n\n");
}

void
m_emit_impl (pIIR_ConcurrentGenerateStatement gs, string &str, RegionStack &rstack, int l)
{
  rstack.push(gs);

  // First, emit concurrent statement code
  emit_impl(gs->concurrent_statement_part, str, rstack, l);

  // Create a list of declarative region pointers beginning from the
  // target region up to the root region
  list<pIIR_DeclarativeRegion> RegionList = create_region_list(gs);
  RegionList.pop_front();

  // For each generate region as well as the enclosing architecture
  // region a corresponding pointer is declared and added as a
  // parameter to the constructor.
  string constructor_pars, separator;
  for (list<pIIR_DeclarativeRegion>::iterator iter = RegionList.begin(); 
       iter != RegionList.end(); iter++)
    if ((*iter)->is(IR_ARCHITECTURE_DECLARATION) || 
	(*iter)->is(IR_CONCURRENT_GENERATE_STATEMENT) ||
	(*iter)->is(IR_BLOCK_STATEMENT)) {
      constructor_pars += separator + qid(*iter, rstack, id_type()) + " *" + qid(*iter, rstack, id_type()) + "_AP_PAR";
      insert_internal_object_declaration(get_last_rest_address(&extended_interface_declarations(gs)), 
					 gs, gs->pos, qid(*iter, rstack, id_type()) + "_AP", 
					 qid(*iter, rstack, id_type()) + "*", 
					 "=" + qid(*iter, rstack, id_type()) + "_AP_PAR", 
					 DECLARE_LOCALLY);
      separator = ",";
  }

  // If this is a "for" generate statement then an additional class
  // member is created which stores the value of the iterator
  // variable. Note that this member is actually set only once during
  // elaboration. Note further that for each iteration a new instance
  // of this class is generated!
  if (gs->is(IR_CONCURRENT_GENERATE_FOR_STATEMENT)) {
    pIIR_ConcurrentGenerateForStatement for_gs = pIIR_ConcurrentGenerateForStatement(gs);
    // First, remove the iteration variable from the normal
    // decalaration list. 
    pIIR_DeclarationList *prev_rest_pointer = &extended_declarations(gs);
    for (pIIR_DeclarationList dl = *prev_rest_pointer; dl; prev_rest_pointer = &dl->rest, dl = dl->rest) 
      if (dl->first == for_gs->generate_parameter_specification) {
	// If iteration variable is found then remove it from the list
	*prev_rest_pointer = dl->rest;
	break;
      }
    // Next, add a corresponding parameter to the constructor
    constructor_pars += separator + qid(for_gs->generate_parameter_specification->subtype, rstack, TYPE) + " " + 
      qid(for_gs->generate_parameter_specification, rstack, id_type()) + "_AP_PAR";
    separator = ",";
    // Finally, add the iteration variable as an internal object.
    insert_internal_object_declaration(get_last_rest_address(&extended_interface_declarations(gs)), 
				       gs, gs->pos, qid(for_gs->generate_parameter_specification, rstack, id_type()), 
				       qid(for_gs->generate_parameter_specification->subtype, rstack, TYPE), 
				       "=" + qid(for_gs->generate_parameter_specification, rstack, id_type()) + "_AP_PAR", 
				       DECLARE_LOCALLY);
  }


  // ******************************************************************
  // Constructor
  // ******************************************************************
  str += "/* Implementation of generate class " + get_long_name(gs) + " methods */\n" +
    qid(gs, rstack, id_type()) + "::\n" + 
    qid(gs, rstack, id_type()) + "(" + constructor_pars + ",name_stack &iname,int level) {\n";
 
  // The current C++ source code is not associated with any real
  // VHDL source line
  last_pos_info = emit_posinfo(NO_SOURCE_LINE, str, last_pos_info, l);

  str += spaces(l + 4) + "iname.push(\"\");\n";

  // Emit code to initialize some interal process members
  if (extended_interface_declarations(gs)!= NULL)
    emit_decls_init(extended_interface_declarations(gs), str, rstack, 4);

  // Emit code to initialize remaining declarations
  if (extended_declarations(gs)!= NULL)
    emit_decls_init(extended_declarations(gs), str, rstack, 4);

  if (gs->concurrent_statement_part != NULL)
    emit_concurrent_statement_constructors(gs->concurrent_statement_part, str, rstack, gs, 4);

  str += spaces(l + 4) + "iname.pop();\n";

  str += "}\n";

  rstack.pop();
}


void
m_emit_impl (pIIR_ConcurrentStatement cs, string &str, RegionStack &rstack, int l)
{
  str += string("/* ") + string(cs->kind_name()) + string(" */\n");
}