aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/cil32/gen-cil.c
blob: 994fcc0306e8905a54a4ec24fb3d8f2a429f3995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
/* Dump of the GENERIC trees in CIL.

   Copyright (C) 2006-2007 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

Authors:
   Andrea Bona
   Andrea Ornstein
   Erven Rohou
   Roberto Costa

Contact information at STMicroelectronics:
Andrea C. Ornstein      <andrea.ornstein@st.com>
Erven Rohou             <erven.rohou@st.com>
*/

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "diagnostic.h"
#include "real.h"
#include "hashtab.h"
#include "tree-flow.h"
#include "langhooks.h"
#include "tree-iterator.h"
#include "tree-pass.h"
#include "timevar.h"
#include "toplev.h"
#include "pointer-set.h"
#include "output.h"
#include "varray.h"
#include "ebitmap.h"
#include "ggc.h"
#include "tree-simp-cil.h"
#include "gen-cil.h"
#include "emit-hints.h"

/* Nonzero for a type which is at file scope.  */
#define TYPE_FILE_SCOPE_P(EXP)                                  \
  (! TYPE_CONTEXT (EXP)                                         \
   || TREE_CODE (TYPE_CONTEXT (EXP)) == TRANSLATION_UNIT_DECL)

/* Nonzero for a zero-length array type */
#define ARRAY_TYPE_ZEROLENGTH(EXP)                              \
  (TYPE_SIZE (EXP) == NULL_TREE)

/* Nonzero for a variable-length array type */
#define ARRAY_TYPE_VARLENGTH(EXP)                               \
  (TYPE_SIZE (EXP) != NULL_TREE && TREE_CODE (TYPE_SIZE (EXP)) != INTEGER_CST)

/* Length of compacted identifiers (in characters) */
#define COMPACT_ID_LENGTH 16

struct fnct_attr
{
  const char *assembly_name;
  const char *cil_name;
  const char *cusattr_string;
  const char *pinvoke_assembly;
  const char *pinvoke_fname;
};

/* Element of the pointer id hash table */
struct pointer_id_data
{
  const void *ptr;
  unsigned int id;
};

/* Local functions, macros and variables.  */
static hashval_t pointer_id_data_hash (const void *);
static int pointer_id_data_eq (const void *, const void *);
static void decode_function_attrs (tree, struct fnct_attr *);
static bool fill_goto_labels (void *, void **, void *);
static void mark_referenced_type (tree);
static void mark_referenced_string (tree);
static unsigned int get_string_cst_id (tree);
static void dump_decl_name (FILE *, tree);
static void dump_string_name (FILE *, tree);
static void dump_label_name (FILE *, tree);
static void dump_entry_label_name (FILE *, basic_block);
static void dump_fun_type (FILE *, tree, tree, const char *, bool);
static void dump_valuetype_name (FILE *, tree);
static void gen_addr_expr (FILE *, tree);
static void print_type_suffix (FILE *, tree, bool);
static void gen_cil_modify_expr (FILE *, tree, tree);
static char * append_string (char *, const char *,
                             unsigned int *, unsigned int *);
static char * append_coded_type (char *, tree, unsigned int *, unsigned int *);
static char * get_compact_identifier (const char *, size_t, size_t *);
static tree make_valuetype_identifier (tree);
static void print_valuetype_decl (FILE *, tree);
static void print_array_decl (FILE *, tree);
static void print_enum_decl (FILE *, tree);
static void print_struct_union_decl (FILE *, tree);
static void dump_type (FILE *, tree, bool, bool);
static void dump_string_type (FILE *, tree);
static void dump_complex_type (FILE *, tree, bool);
static void dump_vector_type (FILE *, tree, bool);
static void dump_type_promotion (FILE *, tree, bool);
static bool dump_type_promoted_type_def (FILE *, tree);
static void dump_type_for_builtin (FILE *, tree, bool);
static void dump_type_eval_mode (FILE *, tree, bool, bool);

static void stack_set (unsigned int) ATTRIBUTE_UNUSED;
static void stack_reset (void);
static void stack_push (unsigned int);
static void stack_pop (unsigned int);
static void gen_conv (FILE *, bool, tree, tree);
static void gen_integral_conv (FILE *, tree, tree);
static void gen_binary_cond_branch (FILE *, tree, tree);
static void gen_call_expr (FILE *, tree);
static void gen_start_function (FILE *);
static void gen_string_custom_attr (FILE *, const char*);
static void gen_computed_goto (FILE *, tree);
static unsigned int gen_cil (void);
static void gen_cil_vcg (FILE *);
static void gen_cil_1 (FILE *);
static void gen_cil_node (FILE *, tree);
static bool gen_cil_gate (void);
static void print_pinvoke_function (FILE *, tree);
static void print_string_decl (FILE *, tree);
static void print_used_strings (FILE *);
static void create_init_method(void);


static struct pointer_set_t *referenced_types;
static GTY(()) varray_type referenced_strings;
static struct pointer_set_t *referenced_string_ptrs;
static struct pointer_set_t *referenced_pinvoke;
static GTY(()) varray_type pending_ctors;
static htab_t pointer_id_htable;
static unsigned int pointer_next_id = 0;
static unsigned int stack;
static unsigned int max_stack;
static basic_block bb;

static struct pointer_map_t *labels_map;
static tree *goto_labels;
static unsigned int taken_labels;

/* Hashing and equality routines for pointer id hash table.  */
static hashval_t
pointer_id_data_hash (const void *p)
{
  return ((unsigned long)((struct pointer_id_data *)p)->ptr >> 4) & 255;
}

static int
pointer_id_data_eq (const void *p1, const void *p2)
{
  const void* ptr1 = ((struct pointer_id_data *)p1)->ptr;
  const void* ptr2 = ((struct pointer_id_data *)p2)->ptr;

  return ptr1 == ptr2;
}

/* stack_* functions are used to keep track of the number of elements
   in the evaluation stack, in order to record the maximum number.
   This is emitted in .maxstack directive for each function.   */

/* Set that the evaluation stack contains n elements.   */

static void
stack_set (unsigned int n)
{
  stack = n;
  if (stack > max_stack)
    max_stack = stack;
}

/* Set that the evaluation stack is empty.   */

static inline void
stack_reset (void)
{
  stack = 0;
}

/* Add n elements to the evaluation stack.   */

static void
stack_push (unsigned int n)
{
  stack += n;
  if (stack > max_stack)
    max_stack = stack;
}

/* Remove n elements from the evaluation stack.   */

static inline void
stack_pop (unsigned int n)
{
  gcc_assert (stack >= n);
  stack -= n;
}

/* Given the FUNCTION_DECL tree T, decode its CIL-specific function
   attributes and record them in ATTRS.   */

static void
decode_function_attrs (tree t, struct fnct_attr *attrs)
{
  tree tmp;

  gcc_assert (TREE_CODE (t) == FUNCTION_DECL);

  attrs->assembly_name    = 0;
  attrs->cil_name         = 0;
  attrs->cusattr_string   = 0;
  attrs->pinvoke_assembly = 0;
  attrs->pinvoke_fname    = 0;

  tmp = DECL_ATTRIBUTES (t);
  while (tmp)
    {
      const char *attr_name = IDENTIFIER_POINTER (TREE_PURPOSE (tmp));
      tree params = TREE_VALUE (tmp);

      if (strcmp (attr_name, "assembly_name") == 0)
        attrs->assembly_name = TREE_STRING_POINTER (TREE_VALUE (params));
      else if (strcmp (attr_name, "cil_name") == 0)
        attrs->cil_name = TREE_STRING_POINTER (TREE_VALUE (params));
      else if (strcmp (attr_name, "cil_strattr") == 0)
        attrs->cusattr_string = TREE_STRING_POINTER (TREE_VALUE (params));
      else if (strcmp (attr_name, "pinvoke") == 0)
        {
          attrs->pinvoke_assembly = TREE_STRING_POINTER (TREE_VALUE (params));
          if (TREE_CHAIN (params))
            attrs->pinvoke_fname = TREE_STRING_POINTER (TREE_VALUE (TREE_CHAIN (params)));
        }
      tmp = TREE_CHAIN (tmp);
    }
}

/* Mark the type represented by tree T as referenced.
   This function works recursively, since types referenced by type T
   itself are also marked as referenced.
   Referenced types are emitted at the end of the compilation unit,
   non-referenced types are not.
   T must be a type node.   */

static void
mark_referenced_type (tree t)
{
  if (t == NULL_TREE || t == error_mark_node)
    return;

  t = TYPE_MAIN_VARIANT (t);

  if (t == cil32_arg_iterator_type)
    return;

  /* If the type was already referenced, nothing else to do */
  if (pointer_set_contains (referenced_types, t))
    return;

  /* Give the aggregate a name unless it has it already */
  switch (TREE_CODE (t))
    {
    /* Incomplete and variable-length arrays are pointers and
       they must be dealt with as such.   */
    case ARRAY_TYPE:
      if (! TYPE_DOMAIN (t) || ARRAY_TYPE_VARLENGTH (t))
        break;
    case ENUMERAL_TYPE:
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      if (TYPE_NAME (t) == 0)
        {
          tree type_decl = build0 (TYPE_DECL, t);
          DECL_NAME (type_decl) = make_valuetype_identifier (t);
          TYPE_NAME (t) = type_decl;
        }
      break;

    default:
      /* Nothing to do for the other types */
      ;
    }

  /* Transform local-scope types into global-scope types */
  if (!TYPE_FILE_SCOPE_P (t))
    {
      tree type_name = TYPE_NAME (t);
      const char *orig_name;
      size_t tmp_name_max_len = 256;
      size_t tmp_name_len = 0;
      char *tmp_name;
      char suffix[32];

      gcc_assert (type_name != 0);
      gcc_assert (DECL_P (type_name)
                  || TREE_CODE (type_name) == IDENTIFIER_NODE);

      if (TREE_CODE (type_name) == IDENTIFIER_NODE)
        orig_name = IDENTIFIER_POINTER (type_name);
      else
        orig_name = IDENTIFIER_POINTER (DECL_NAME (type_name));

      snprintf (suffix, 15, "?vt%u", TYPE_UID (t));

      tmp_name = (char *)xmalloc (tmp_name_max_len);
      tmp_name = append_string (tmp_name, orig_name,
                                &tmp_name_len, &tmp_name_max_len);
      tmp_name = append_string (tmp_name, suffix,
                                &tmp_name_len, &tmp_name_max_len);

      TYPE_NAME (t) = get_identifier_with_length (tmp_name, tmp_name_len);
      TYPE_CONTEXT (t) = 0;
      free (tmp_name);
    }

  switch (TREE_CODE (t))
    {
    case ENUMERAL_TYPE:
      pointer_set_insert (referenced_types, t);
      break;

    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      {
        tree tmp;

        pointer_set_insert (referenced_types, t);
        tmp = TYPE_FIELDS (t);

        while (tmp)
          {
            if (DECL_BIT_FIELD (tmp))
              mark_referenced_type (DECL_BIT_FIELD_TYPE (tmp));
            else
              mark_referenced_type (TREE_TYPE (tmp));
            tmp = TREE_CHAIN (tmp);
          }
      }
      break;

    case POINTER_TYPE:
    case REFERENCE_TYPE:
      mark_referenced_type (TREE_TYPE (t));
      break;

    case ARRAY_TYPE:
      if (TYPE_DOMAIN (t) && ! ARRAY_TYPE_VARLENGTH (t))
        pointer_set_insert (referenced_types, t);
      mark_referenced_type (TREE_TYPE (t));
      break;

    case FUNCTION_TYPE:
      {
         tree args_type;
         mark_referenced_type (TREE_TYPE (t));
         args_type = TYPE_ARG_TYPES (t);
         while (args_type)
           {
             mark_referenced_type (TREE_VALUE (args_type));
             args_type = TREE_CHAIN (args_type);
           }
      }
      break;

    default:
      /* Nothing to do for the other types */
      ;
    }
}

/* Mark the string represented by tree T as referenced.
   Referenced strings are emitted at the end of the compilation unit,
   non-referenced strings are not.
   T must be a STRING_CST node.   */

static void
mark_referenced_string (tree t)
{
  gcc_assert (TREE_CODE (t) == STRING_CST);
  if (!pointer_set_contains (referenced_string_ptrs,
                             (void *)(TREE_STRING_POINTER (t))))
    {
      VARRAY_PUSH_TREE (referenced_strings, t);
      pointer_set_insert (referenced_string_ptrs,
                          (void *)(TREE_STRING_POINTER (t)));
    }
}

/* Get an unique id for string constant NODE.   */

static
unsigned int get_string_cst_id (tree node)
{
  struct pointer_id_data tmp_pid;
  void **slot;

  gcc_assert (TREE_CODE (node) == STRING_CST);

  tmp_pid.ptr = TREE_STRING_POINTER (node);
  slot = htab_find_slot (pointer_id_htable, &tmp_pid, INSERT);

  if (*slot != NULL)
    return ((struct pointer_id_data *)(*slot))->id;
  else
    {
      struct pointer_id_data *pid = XNEW (struct pointer_id_data);

      *slot = pid;
      pid->ptr = TREE_STRING_POINTER (node);
      pid->id = pointer_next_id++;

      return pid->id;
    }
}

/* Mark the function represented by tree T as a pinvoke.
   T must be a FUNCTION_DECL node.   */

void
cil_add_pinvoke (tree t)
{
  gcc_assert (TREE_CODE (t) == FUNCTION_DECL);
  pointer_set_insert (referenced_pinvoke, t);
  mark_referenced_type (TREE_TYPE (t));
}

/* Dump the name of a _DECL node.  */

static void
dump_decl_name (FILE* file, tree node)
{
  gcc_assert (DECL_P (node));
  fputs ("'", file);

  mark_decl_referenced (node);

  if (DECL_ASSEMBLER_NAME_SET_P (node))
    {
      const char* tname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node));
      if (tname[0] == '*')
        fprintf (file, tname+1);
      else
        fprintf (file, tname);
    }
  else if (DECL_NAME (node))
    fprintf (file, IDENTIFIER_POINTER (DECL_NAME (node)));
  else
    fprintf (file, "?UNNAMED%d", DECL_UID (node));

  fputs ("'", file);
}

/* Dump the name of a STRING_CST node.  */

static void
dump_string_name (FILE* file, tree node)
{
  gcc_assert (TREE_CODE (node) == STRING_CST);

  fprintf (file, "'?string%u'", get_string_cst_id (node));
}

/* Dump the name of a label.  */

static void
dump_label_name (FILE* file, tree node)
{
  /* Always print the label id. */
  fprintf (file, "?L" HOST_WIDE_INT_PRINT_DEC, LABEL_DECL_UID (node));

  /* For convenience, also print the identifier when available.  Note that the
     identifier alone is incorrect: in case of inlining, several labels can
     end up with the same id. */
  if (DECL_NAME (node))
    {
      fputs ("_", file);
      fprintf (file, IDENTIFIER_POINTER (DECL_NAME (node)));
    }
}

/* Helper function used to fill the computed GOTOs label array.  */

static bool
fill_goto_labels (void *key, void **val, void *data)
{
  tree *goto_labels = (tree *) data;
  tree label_decl = (tree) key;
  unsigned int idx = tree_low_cst ((tree) *val, 1);

  goto_labels[idx] = label_decl;

  return true;
}

static void
dump_entry_label_name (FILE *stream, basic_block bb)
{
  block_stmt_iterator bsi = bsi_start (bb);
  if (!bsi_end_p (bsi))
    {
      tree stmt = bsi_stmt (bsi);
      if (TREE_CODE (stmt) == LABEL_EXPR)
        {
          tree op0 = TREE_OPERAND (stmt, 0);
          dump_label_name (stream, op0);
        }
      else
        {
          fprintf (stream, "<no label>");
        }
    }
  else
    {
      fprintf (stream, "<no basic block>");
    }
}

/* Dump the name of a valuetype.
   T must be an aggregate type or an enumeral type, since these are
   the types emitted as CIL valuetypes.   */

static void
dump_valuetype_name (FILE *file, tree t)
{
  tree type_name;

  gcc_assert (AGGREGATE_TYPE_P (t) || TREE_CODE (t) == ENUMERAL_TYPE);
  gcc_assert (TYPE_MAIN_VARIANT (t) == t);
  gcc_assert (TYPE_FILE_SCOPE_P (t));
  gcc_assert (TYPE_NAME (t));

  type_name = TYPE_NAME (t);
  gcc_assert (DECL_P (type_name) || TREE_CODE (type_name) == IDENTIFIER_NODE);

  fputs ("'", file);
  if (TREE_CODE (type_name) == IDENTIFIER_NODE)
    fprintf (file, IDENTIFIER_POINTER (type_name));
  else if (DECL_NAME (type_name))
    fprintf (file, IDENTIFIER_POINTER (DECL_NAME (type_name)));
  else
    fprintf (file, "?UNNAMED%d", DECL_UID (type_name));
  fputs ("'", file);
}

/* Dump the signature of function type FUN_TYPE.
   The function name that is dumped is taken from function_decl FUN
   or from NAME. Only and exactly one of the two must be non-null.
   REF tells whether the function type (and the types of the return value
   and of the incoming parameters) have to be marked as referenced.
   FUN_TYPE must be a FUNCTION_TYPE.
   FUN, if not null, must be a FUNCTION_DECL.   */

static void
dump_fun_type (FILE *stream, tree fun_type, tree fun, const char *name, bool ref)
{
  tree args_type;
  tree last_arg_type = NULL;
  bool varargs = FALSE;

  gcc_assert (! (fun && name));

  if (ref)
    mark_referenced_type (fun_type);

  args_type = TYPE_ARG_TYPES (fun_type);

  if (args_type == NULL)
    warning (OPT_Wcil_missing_prototypes,
             "Missing function %s prototype, guessing it, you should fix the code",
             fun?IDENTIFIER_POINTER (DECL_NAME (fun)):"");
  else
    {
      last_arg_type = args_type;
      while (TREE_CHAIN (last_arg_type))
        last_arg_type = TREE_CHAIN (last_arg_type);

      if (TREE_VALUE (last_arg_type) != void_type_node)
        {
          last_arg_type = NULL;
          varargs = TRUE;
        }
    }

  if (varargs)
    fputs ("vararg ", stream);

  dump_type (stream, TREE_TYPE (fun_type), ref, false);

  fputs (" ", stream);
  if (fun)
    {
      struct fnct_attr attrs;

      decode_function_attrs (fun, &attrs);

      if (attrs.assembly_name)
        fprintf (stream, "[%s]", attrs.assembly_name);
      else if (TARGET_EMIT_EXTERNAL_ASSEMBLY && DECL_EXTERNAL (fun))
        fputs ("[ExternalAssembly]ExternalAssembly::", stream);

      if (attrs.cil_name)
        fprintf (stream, "%s", attrs.cil_name);
      else
        dump_decl_name (stream, fun);
    }

  if (name)
    fputs (name, stream);

  fputs ("(", stream);

  while (args_type != last_arg_type)
    {
      dump_type (stream, TREE_VALUE (args_type), ref, true);
      args_type = TREE_CHAIN (args_type);

      if (args_type != last_arg_type)
        fputs (", ", stream);
    }

  if (varargs)
    fputs (", ...", stream);

  fputs (")", stream);
}

/* Dump type NODE.
   REF tells whether the function type (and the types of the return value
   and of the incoming parameters) have to be marked as referenced.
   QUALIF tells whether to emit C qualifiers (const, restrict, volatile)
   NODE must be a type node.   */

static void
dump_type (FILE *file, tree node, bool ref, bool qualif)
{
  if (node == NULL_TREE || node == error_mark_node)
    return;

/*   node = TYPE_MAIN_VARIANT (node); */

  if (TYPE_MAIN_VARIANT (node) == cil32_arg_iterator_type)
    {
      fputs ("valuetype [mscorlib]System.ArgIterator", file);
      return;
    }

  switch (TREE_CODE (node))
    {
    /* Incomplete and variable-length arrays are pointers and
       they must be dealt with as such.   */
    case ARRAY_TYPE:
      if (! TYPE_DOMAIN (node) || ARRAY_TYPE_VARLENGTH (node))
        goto pointer;
    case ENUMERAL_TYPE:
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      node = TYPE_MAIN_VARIANT (node);

      /* Reference the type if told to do so */
      if (ref)
        mark_referenced_type (node);

      /* Print the name of the structure.  */
      fputs ("valuetype ", file);
      dump_valuetype_name (file, node);
      break;

    case VOID_TYPE:
      fputs ("void", file);
      break;

    case INTEGER_TYPE:
      {
        int type_size = GET_MODE_BITSIZE (TYPE_MODE (node));

        if (TYPE_UNSIGNED (node))
          fputs ("unsigned ", file);

        switch (type_size)
          {
          case 8:  fputs ("int8",  file); break;
          case 16: fputs ("int16", file); break;
          case 32: fputs ("int32", file); break;
          case 64: fputs ("int64", file); break;
          default:
            fprintf (stderr, "Unsupported integer size %d\n", type_size);
            gcc_assert (0);
          }
      }
      break;

    case REAL_TYPE:
      {
        int type_size = TYPE_PRECISION (node);

        switch (type_size)
          {
          case 32: fputs ("float32", file); break;
          case 64: fputs ("float64", file); break;
          default:
            fprintf (stderr, "Unsupported floating point size %d\n", type_size);
            gcc_assert (0);
          }
      }
      break;

    case BOOLEAN_TYPE:
      fputs ("int8", file);
      break;

    pointer:
    case POINTER_TYPE:
      if (TREE_CODE (TREE_TYPE (node)) == FUNCTION_TYPE)
        {
          fputs ("method ", file);
          dump_fun_type (file, TREE_TYPE (node), NULL, " * ", ref);
        }
      else
        {
          dump_type (file, TREE_TYPE (node), ref, qualif);
          fputs (" *", file);
        }
      break;

    case FUNCTION_TYPE:
/*       dump_fun_type (file, node, NULL, NULL, ref); */
      gcc_assert (0);
      break;

    case VECTOR_TYPE:
      dump_vector_type (file, node, true);
      break;

    case COMPLEX_TYPE:
      dump_complex_type (file, node, true);
      break;

    case REFERENCE_TYPE:

    default:
      fprintf (stderr, "%s: %s\n", __func__, tree_code_name[TREE_CODE (node)]);
      gcc_assert (0);
      break;
    }

  if (qualif)
    {
      unsigned int quals = TYPE_QUALS (node);

      if (quals & TYPE_QUAL_CONST)
        fputs (" modopt([gcc4net]gcc4net.CQualifiers.IsConst)", file);
      if (quals & TYPE_QUAL_RESTRICT)
        fputs (" modopt([gcc4net]gcc4net.CQualifiers.IsRestrict)", file);
#if 0
      if (quals & TYPE_QUAL_VOLATILE)
        fputs (" modopt([gcc4net]gcc4net.CQualifiers.IsVolatile)", file);
#endif
    }

}

static void
dump_string_type (FILE *file, tree node)
{
  tree domain;
  tree min;
  tree max;
  unsigned int size;
  gcc_assert(TREE_CODE (node) == ARRAY_TYPE
             && TYPE_DOMAIN (node)
             && ! ARRAY_TYPE_VARLENGTH (node));
  domain = TYPE_DOMAIN (node);
  min = TYPE_MIN_VALUE (domain);
  max = TYPE_MAX_VALUE (domain);
  gcc_assert(min
             && max
             && integer_zerop (min)
             && host_integerp (max, 0));
  size = TREE_INT_CST_LOW (max) + 1;
  fprintf (file, "valuetype '?string_type?%d'", size);
}


static void
dump_complex_type (FILE *file, tree node, bool full)
{
  int type_size = TYPE_PRECISION (TREE_TYPE (node));

  gcc_assert (TREE_CODE (node) == COMPLEX_TYPE);

  if (full)
    fputs ("valuetype [gcc4net]gcc4net.", file);

  fputs ("complex_", file);
  if (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (node))) == MODE_INT)
    {
      if (TYPE_UNSIGNED (node))
        fputs ("u", file);

      switch (type_size)
        {
        case 8: fputs ("char", file); break;
        case 16: fputs ("short", file); break;
        case 32: fputs ("int", file); break;
        case 64: fputs ("long", file); break;
        default:
          fprintf (stderr, "Unsupported complex size %d\n", type_size);
          gcc_assert (0);
        }
    }
  else
    {
      switch (type_size)
        {
        case 32: fputs ("float", file); break;
        case 64: fputs ("double", file); break;
        default:
          fprintf (stderr, "Unsupported complex size %d\n", type_size);
          gcc_assert (0);
        }
    }
}


/* Dump vector type NODE.

   FULL tells whether the type must be qualified with the 'valuetype' keyword,
   assembly and namespace.
   NODE must be a type node of type VECTOR_TYPE.   */

static void
dump_vector_type (FILE *file, tree node, bool full)
{
  int  vec_bitsize = TREE_INT_CST_LOW (TYPE_SIZE (node));
  tree innertype = TREE_TYPE (node);
  int  inner_bitsize = TYPE_PRECISION (innertype);
  enum machine_mode innermode = TYPE_MODE (innertype);

  gcc_assert (TREE_CODE (node) == VECTOR_TYPE);

  if (full)
    fputs ("valuetype [gcc4net]gcc4net.", file);

  fprintf (file, "V%d", vec_bitsize / inner_bitsize);

  if (GET_MODE_CLASS (innermode) == MODE_INT)
    {
      switch (inner_bitsize)
        {
        case 8:  fputs ("QI",  file); break;
        case 16: fputs ("HI", file); break;
        case 32: fputs ("SI", file); break;
        case 64: fputs ("DI", file); break;
        default:
          fprintf (stderr, "Unsupported integer size %d\n", inner_bitsize);
          gcc_assert (0);
        }
    }
  else if (GET_MODE_CLASS (innermode) == MODE_FLOAT)
    {
      switch (inner_bitsize)
        {
        case 32: fputs ("SF", file); break;
        case 64: fputs ("DF", file); break;
        default:
          fprintf (stderr, "Unsupported float size %d\n", inner_bitsize);
          gcc_assert (0);
        }
    }
  else
    {
      fprintf (stderr, "Unsupported mode class\n");
      gcc_assert (0);
    }

}


/* Dump type NODE, promoted following C conventions for var args.
   REF tells whether the function type (and the types of the return value
   and of the incoming parameters) have to be marked as referenced.
   NODE must be a type node.   */

static void
dump_type_promotion (FILE *stream, tree node, bool ref)
{
  if (node == NULL_TREE || node == error_mark_node)
    return;

  switch (TREE_CODE (node))
    {
    /* Incomplete and variable-length arrays are pointers and
       they must be dealt with as such.   */
    case ARRAY_TYPE:
      if (! TYPE_DOMAIN (node) || ARRAY_TYPE_VARLENGTH (node))
        goto pointer;
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      node = TYPE_MAIN_VARIANT (node);

      /* Reference the type if told to do so */
      if (ref)
        mark_referenced_type (node);

      /* Print the name of the structure.  */
      fputs ("valuetype ", stream);
      dump_valuetype_name (stream, node);
      break;

    case COMPLEX_TYPE:
      dump_complex_type (stream, node, true);
      break;

    case ENUMERAL_TYPE:
    case INTEGER_TYPE:
    case BOOLEAN_TYPE:
      {
        int type_size = TYPE_PRECISION (node);

        gcc_assert (type_size <= 64);

        if (type_size <= 32)
          fputs ("unsigned int32", stream);
        else
          fputs ("unsigned int64", stream);
      }
      break;

    case REAL_TYPE:
      fputs ("float64", stream);
      break;

    pointer:
    case POINTER_TYPE:
      /* cil32 is a 32bit machine, in case we support 64bit model
       * changes are needed
       */
      fputs ("unsigned int32", stream);
      break;

    default:
      fprintf (stderr, "%s: %s\n", __func__, tree_code_name[TREE_CODE (node)]);
      gcc_assert (0);
      break;
    }
}

/* Dump the type def of type NODE, promoted following C conventions
   for var args.
   NODE must be a type node.
   returns true iff the dumped type is a pointer */

static bool
dump_type_promoted_type_def (FILE *stream, tree node)
{
  bool result = false;

  if (node == NULL_TREE || node == error_mark_node)
    return false;

  switch (TREE_CODE (node))
    {
    /* Incomplete and variable-length arrays are pointers and
       they must be dealt with as such.   */
    case ARRAY_TYPE:
      if (! TYPE_DOMAIN (node) || ARRAY_TYPE_VARLENGTH (node))
        goto pointer;
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      node = TYPE_MAIN_VARIANT (node);

      /* Reference the type if told to do so */
      mark_referenced_type (node);

      /* Print the name of the structure.  */
      fputs ("valuetype ", stream);
      dump_valuetype_name (stream, node);
      break;

    case COMPLEX_TYPE:
      dump_complex_type (stream, node, true);
      break;

    case ENUMERAL_TYPE:
    case INTEGER_TYPE:
    case BOOLEAN_TYPE:
      {
        int type_size = TYPE_PRECISION (node);

        gcc_assert (type_size <= 64);

        if (type_size <= 32)
          fputs ("class [mscorlib]System.UInt32", stream);
        else
          fputs ("class [mscorlib]System.UInt64", stream);
      }
      break;

    case REAL_TYPE:
      fputs ("class [mscorlib]System.Double", stream);
      break;

    pointer:
    case POINTER_TYPE:
      /* cil32 is a 32bit machine, in case we support 64bit model
       * changes are needed
       */
      fputs ("class [mscorlib]System.UInt32", stream);
      result = true;
      break;

    default:
      fprintf (stderr, "%s: %s\n", __func__, tree_code_name[TREE_CODE (node)]);
      gcc_assert (0);
      break;
    }
  return result;
}

static void
dump_type_for_builtin (FILE *file, tree node, bool all_types)
{
  if (node == NULL_TREE || node == error_mark_node)
    return;

/*   node = TYPE_MAIN_VARIANT (node); */

  switch (TREE_CODE (node))
    {
    case ENUMERAL_TYPE:
    case INTEGER_TYPE:
    case BOOLEAN_TYPE:
      {
        int type_size = GET_MODE_BITSIZE (TYPE_MODE (node));

        if (TYPE_UNSIGNED (node))
          fputs ("unsigned ", file);

        switch (type_size)
          {
          case 8:  if (all_types) { fputs ("int8",  file); return; }
          case 16: if (all_types) { fputs ("int16", file); return; }
          case 32: fputs ("int32", file); break;
          case 64: fputs ("int64", file); break;
          default:
            fprintf (stderr, "Unsupported integer size %d\n", type_size);
            gcc_assert (0);
          }
      }
      break;

    case REAL_TYPE:
      {
        int type_size = TYPE_PRECISION (node);

        switch (type_size)
          {
          case 32: fputs ("float32", file); break;
          case 64: fputs ("float64", file); break;
          default:
            fprintf (stderr, "Unsupported floating point size %d\n", type_size);
            gcc_assert (0);
          }
      }
      break;

    default:
      fprintf (stderr, "%s: %s\n", __func__, tree_code_name[TREE_CODE (node)]);
      gcc_assert (0);
      break;
  }
}

static void
dump_type_eval_mode (FILE *stream, tree node, bool all_types, bool sign)
{
  if (node == NULL_TREE || node == error_mark_node)
    return;

  switch (TREE_CODE (node))
    {
    case ENUMERAL_TYPE:
    case INTEGER_TYPE:
    case BOOLEAN_TYPE:
      {
        int type_size = GET_MODE_BITSIZE (TYPE_MODE (node));

        if (sign && TYPE_UNSIGNED (node))
          fputs ("u", stream);

        switch (type_size)
          {
          case 8:  if (all_types) { fputs ("qi", stream); break; }
          case 16: if (all_types) { fputs ("hi", stream); break; }
          case 32: fputs ("si", stream); break;
          case 64: fputs ("di", stream); break;
          default:
            fprintf (stderr, "Unsupported integer size %d\n", type_size);
            gcc_assert (0);
          }
      }
      break;

    case REAL_TYPE:
      {
        int type_size = GET_MODE_BITSIZE (TYPE_MODE (node));

        switch (type_size)
          {
          case 32: fputs ("sf", stream); break;
          case 64: fputs ("df", stream); break;
          default:
            fprintf (stderr, "Unsupported floating point size %d\n",
                     type_size);
            gcc_assert (0);
          }
      }
      break;

    case VECTOR_TYPE:
      dump_vector_type (stream, node, false);
      break;

    default:
      fprintf (stderr, "%s: %s\n", __func__, tree_code_name[TREE_CODE (node)]);
      gcc_assert (0);
      break;
    }
}

static void
gen_addr_expr (FILE *file, tree t)
{
  if (t == NULL_TREE || t == error_mark_node)
    return;

  switch (TREE_CODE (t))
    {
    case STRING_CST:
      mark_referenced_string (t);
      fputs ("\n\tldsflda\t", file);
      dump_string_type (file, TREE_TYPE (t));
      fputs (" ", file);
      dump_string_name (file, t);
      stack_push (1);
      break;

    case VAR_DECL:
      if (!DECL_FILE_SCOPE_P (t))
        fputs ("\n\tldloca\t", file);
      else
        {
          fputs ("\n\tldsflda\t", file);
          if (COMPLETE_TYPE_P (TREE_TYPE (t)))
            dump_type (file, TREE_TYPE (t), true, false);
          else
            fputs ("native int", file);
          fputs (" ", file);
          if (TARGET_EMIT_EXTERNAL_ASSEMBLY && DECL_EXTERNAL (t))
            fputs ("[ExternalAssembly]ExternalAssembly::", file);
        }

      dump_decl_name (file, t);
      stack_push (1);
      break;

    case PARM_DECL:
      fputs ("\n\tldarga\t", file);
      dump_decl_name (file, t);
      stack_push (1);
      break;

    case FUNCTION_DECL:
      fputs ("\n\tldftn\t", file);
      dump_fun_type (file, TREE_TYPE (t), t, NULL, true);
      stack_push (1);
      break;

    case LABEL_DECL:
      {
	/* We cannot emit the address of the label in CIL, so we map each
	  label to an ID and emit the ID.  The GOTO will then be implemented
	  with a switch based on that ID.  The ID is simply the position in
	  the list of all address taken labels. */

	tree cst = *pointer_map_contains (labels_map, t);
        fprintf (file, "\n\tldc.i4\t%d", (unsigned int) tree_low_cst (cst, 1));
        stack_push (1);
      }
      break;

    case INDIRECT_REF:
      gen_cil_node (file, TREE_OPERAND (t, 0));
      break;

    case ARRAY_REF:
      {
        tree node = t;

        do {
          gcc_assert (integer_zerop (TREE_OPERAND (node, 1)));
          node = TREE_OPERAND (node, 0);
        } while (TREE_CODE (node) == ARRAY_REF);

        gen_addr_expr (file, node);
      }
      break;

    case COMPONENT_REF:
      {
        tree obj = TREE_OPERAND (t, 0);
        tree fld = TREE_OPERAND (t, 1);
        tree obj_type = TYPE_MAIN_VARIANT (TREE_TYPE (obj));

        gcc_assert (! DECL_BIT_FIELD (fld));

        gen_addr_expr (file, obj);
        fputs ("\n\tldflda\t", file);
        dump_type (file, TREE_TYPE (fld), true, false);
        fputs (" ", file);
        mark_referenced_type (obj_type);
        dump_valuetype_name (file, obj_type);
        fputs ("::", file);
        dump_decl_name (file, fld);
      }
      break;

    default:
      fprintf (stderr, "%s: %s\n",
               __func__, tree_code_name[TREE_CODE (t)]);
      gcc_assert (0);
    }

  if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
    fputs ("\n\tconv.i", file);
}

static void
print_type_suffix (FILE *file, tree type_node, bool unsign)
{
  switch (TREE_CODE (type_node))
    {
    case ENUMERAL_TYPE:
    case INTEGER_TYPE:
      {
        int type_size = TYPE_PRECISION (type_node);
        bool uns = unsign && TYPE_UNSIGNED (type_node);

        switch (type_size)
          {
          case 8:  fputs ((uns)?"u1":"i1", file); break;
          case 16: fputs ((uns)?"u2":"i2", file); break;
          case 32: fputs ((uns)?"u4":"i4", file); break;
          case 64: fputs ((uns)?"u8":"i8", file); break;
          default:
            fprintf (stderr, "Unsupported integer size %d\n", type_size);
            gcc_assert (0);
            break;
          }
      }
      break;

    case BOOLEAN_TYPE:
      fputs ((unsign && TYPE_UNSIGNED (type_node))?"u1":"i1", file);
      break;

    case REAL_TYPE:
      {
        int type_size = TYPE_PRECISION (type_node);

        switch (type_size)
          {
          case 32: fputs ("r4", file); break;
          case 64: fputs ("r8", file); break;
          default:
            fprintf (stderr, "Unsupported floating point size %d\n", type_size);
            gcc_assert (0);
            break;
          }
      }
      break;

    case POINTER_TYPE:
      fputs ("i", file);
      break;

    case VECTOR_TYPE:
      {
        int type_size = TREE_INT_CST_LOW (TYPE_SIZE (type_node));
        bool uns = TYPE_UNSIGNED (type_node) && unsign;
        tree innertype = TREE_TYPE (type_node);
        enum machine_mode innermode = TYPE_MODE (innertype);

        /* Only expect integer vectors */
        gcc_assert (GET_MODE_CLASS (innermode) == MODE_INT);

        switch (type_size)
          {
          case 8:  fputs ((uns)?"u1":"i1", file); break;
          case 16: fputs ((uns)?"u2":"i2", file); break;
          case 32: fputs ((uns)?"u4":"i4", file); break;
          case 64: fputs ((uns)?"u8":"i8", file); break;
          default:
            fprintf (stderr, "Unsupported integer size %d\n", type_size);
            gcc_assert (0);
            break;
          }
        break;
      }

    default:
      internal_error ("print_type_suffix %s\n",
                      tree_code_name[TREE_CODE (type_node)]);
      gcc_assert (0);
      break;
    }
}

/* Emit a conversion from type IN_TYPE to type OUT_TYPE to file FILE.
   IS_NOP says whether the conversion comes from a NOP_EXPR.   */

static void
gen_conv (FILE *file, bool is_nop, tree out_type, tree in_type)
{
  if (is_nop
      && INTEGRAL_TYPE_P (out_type)
      && INTEGRAL_TYPE_P (in_type))
    {
      if (TYPE_PRECISION (out_type) > TYPE_PRECISION (in_type))
        {
          tree tmp_type = TYPE_UNSIGNED (in_type)
                          ? unsigned_type_for (out_type)
                          : signed_type_for (out_type);

          gen_integral_conv (file, tmp_type, in_type);
          gen_integral_conv (file, out_type, tmp_type);
        }
      else
        gen_integral_conv (file, out_type, in_type);
    }

  /* Special case for conversion to float type are not orthogonal
     in CIL opcode set.   */
  else if (SCALAR_FLOAT_TYPE_P (out_type)
           && INTEGRAL_TYPE_P (in_type)
           && TYPE_UNSIGNED (in_type))
    {
      fputs ("\n\tconv.r.un", file);

      if (TYPE_PRECISION (out_type) <= 32)
        fputs ("\n\tconv.r4", file);
    }

  /* Do nothing for a conversion from two REAL_TYPEs with the
     same precision.   */
  else if (! SCALAR_FLOAT_TYPE_P (out_type)
           || ! SCALAR_FLOAT_TYPE_P (in_type)
           || TYPE_PRECISION (out_type) != TYPE_PRECISION (in_type))
    {
      fputs ("\n\tconv.", file);
      print_type_suffix (file, out_type, true);
    }
}

/* Emit a conversion from integral or pointer type IN_TYPE
   to integral type OUT_TYPE to file FILE.
   If the precision of OUT_TYPE is bigger than that of IN_TYPE,
   then IN_TYPE and OUT_TYPE have to have the same signedness.   */

static void
gen_integral_conv (FILE *file, tree out_type, tree in_type)
{
  unsigned int out_bits, cont_size, in_bits;

  gcc_assert (INTEGRAL_TYPE_P (out_type));
  gcc_assert (INTEGRAL_TYPE_P (in_type) || POINTER_TYPE_P (in_type));
  gcc_assert (TYPE_PRECISION (out_type) <= 64);
  gcc_assert (TYPE_PRECISION (out_type) <= TYPE_PRECISION (in_type)
              || TYPE_UNSIGNED (out_type) == TYPE_UNSIGNED (in_type));

  /* Get the precision of the output and input types and the size
     of the output type container */
  in_bits = TYPE_PRECISION (in_type);
  out_bits = TYPE_PRECISION (out_type);
  cont_size = GET_MODE_BITSIZE (TYPE_MODE (out_type));
  gcc_assert (cont_size >= out_bits);

  /* Dump a conv with for the container size, if not superfluous */
  if ((cont_size == out_bits && (out_bits != in_bits || out_bits < 32))
      || ((out_bits > 32) ^ (in_bits > 32)))
    {
      fputs ("\n\tconv.", file);
      print_type_suffix (file, get_integer_type (cont_size,
                                                 TYPE_UNSIGNED (out_type)),
                                                 true);
    }

  /* If the container is bigger than the output type precision,
     force the output to be of the desired precision.   */
  if (cont_size > out_bits)
    {
      if (TYPE_UNSIGNED (out_type))
        {
          unsigned HOST_WIDEST_INT mask;
          double_int mask_di;

          /* Compute the mask to be applied to the existing value */
          gcc_assert (HOST_BITS_PER_WIDEST_INT >= 64);
          mask = (1LL << out_bits) - 1LL;
          mask_di.low = mask;
          mask_di.high = (HOST_WIDE_INT)(mask >> HOST_BITS_PER_WIDE_INT);

          /* Apply the mask */
          if (out_bits <= 32)
            fputs ("\n\tldc.i4\t", file);
          else
            fputs ("\n\tldc.i8\t", file);
          dump_double_int (file, mask_di, false);
          fputs ("\n\tand", file);
        }
      else
        {
          unsigned int cont_size = (out_bits > 32) ? 64 : 32;
          unsigned int shift = cont_size - out_bits;

          /* Do a pair of shift to perform the sign extension */
          fprintf (file, "\n\tldc.i4\t%d", shift);
          fputs ("\n\tshl\t", file);
          fprintf (file, "\n\tldc.i4\t%d", shift);
          fputs ("\n\tshr\t", file);
        }

      stack_push (1);
      stack_pop (1);
    }
}

static void
gen_binary_cond_branch (FILE *file, tree node, tree label)
{
  tree op0 = TREE_OPERAND (node, 0);
  tree op1 = TREE_OPERAND (node, 1);
  bool is_unsigned = TYPE_UNSIGNED (TREE_TYPE (op0));

  gcc_assert (TREE_CODE (label) == LABEL_DECL);

  if (TREE_CODE (node) == UNORDERED_EXPR
      || TREE_CODE (node) == ORDERED_EXPR)
    {
      gen_cil_node (file, op0);
      fputs ("\n\tdup"
             "\n\tceq", file);

      stack_push (1);
      stack_pop (1);

      gen_cil_node (file, op1);
      fputs ("\n\tdup"
             "\n\tceq"
             "\n\tand"
             "\n\tbr", file);

      if (TREE_CODE (node) == UNORDERED_EXPR)
        fputs ("false\t", file);
      else
        fputs ("true\t", file);

      dump_label_name (file, label);

      stack_push (1);
      stack_pop (3);

      return;
    }

  gen_cil_node (file, op0);
  gen_cil_node (file, op1);

  switch (TREE_CODE (node))
    {
    case LE_EXPR:   fputs ("\n\tble", file); break;
    case LT_EXPR:   fputs ("\n\tblt", file); break;
    case GE_EXPR:   fputs ("\n\tbge", file); break;
    case GT_EXPR:   fputs ("\n\tbgt", file); break;
    case EQ_EXPR:   fputs ("\n\tbeq", file); is_unsigned = FALSE; break;
    case NE_EXPR:   fputs ("\n\tbne", file); is_unsigned = TRUE;  break;
    case UNLT_EXPR: fputs ("\n\tblt", file); is_unsigned = TRUE;  break;
    case UNLE_EXPR: fputs ("\n\tble", file); is_unsigned = TRUE;  break;
    case UNGT_EXPR: fputs ("\n\tbgt", file); is_unsigned = TRUE;  break;
    case UNGE_EXPR: fputs ("\n\tbge", file); is_unsigned = TRUE;  break;
    default:
      gcc_unreachable ();
    }

  if (is_unsigned)
    fputs (".un\t", file);
  else
    fputs ("\t", file);
  dump_label_name (file, label);

  stack_pop (2);
}

/* Dump a CALL_EXPR gimple node NODE in CIL on the file FILE. */

static void
gen_call_expr (FILE *file, tree node)
{
  bool done = false;
  tree fdecl;
  tree fun_expr;
  tree fun_type;
  bool direct_call;
  unsigned int nargs;

  gcc_assert(TREE_CODE (node) == CALL_EXPR);

  fun_expr = get_callee_fndecl (node);
  if (fun_expr)
    {
      fdecl = fun_expr;
      fun_type = TREE_TYPE (fun_expr);
      direct_call = true;
    }
  else
    {
      fun_expr = CALL_EXPR_FN (node);
      fdecl    = NULL_TREE;
      fun_type = TREE_TYPE (TREE_TYPE (fun_expr));
      direct_call = false;
    }
  nargs = call_expr_nargs(node);

  /* Built-in functions must be handled in a special way */
  if (direct_call && DECL_BUILT_IN (fdecl))
    {

      if (DECL_BUILT_IN_CLASS (fdecl) == BUILT_IN_MD)
        {
          switch (DECL_FUNCTION_CODE (fdecl))
            {
            case CIL32_BUILT_IN_VA_START:
              {
                tree va = CALL_EXPR_ARG (node, 0);

                gcc_assert (POINTER_TYPE_P (TREE_TYPE (va))
                            && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (va)))
                               == cil32_arg_iterator_type);

                gen_cil_node (file, va);
                fputs ("\n\tdup"
                       "\n\tinitobj\tvaluetype [mscorlib]System.ArgIterator"
                       "\n\targlist"
                       "\n\tcall\tinstance void "
                       "[mscorlib]System.ArgIterator::.ctor(valuetype "
                       "[mscorlib]System.RuntimeArgumentHandle)",
                       file);

                stack_push (1);
                stack_pop (2);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_VA_ARG:
              {
                tree va    = CALL_EXPR_ARG (node, 0);
                tree dummy = CALL_EXPR_ARG (node, 1);
                tree type  = TREE_TYPE (TREE_TYPE (dummy));

                gcc_assert (POINTER_TYPE_P (TREE_TYPE (va))
                            && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (va)))
                               == cil32_arg_iterator_type);

                gen_cil_node (file, va);
                fputs ("\n\tcall\tinstance typedref [mscorlib]System.ArgIterator::GetNextArg()"
                       "\n\trefanyval ",
                       file);

                if (dump_type_promoted_type_def (file, type))
                  fputs ("\n\tconv.i", file);

                done = true;
              }
              break;

            case CIL32_BUILT_IN_VA_END:
              {
                tree va = CALL_EXPR_ARG (node, 0);

                gcc_assert (POINTER_TYPE_P (TREE_TYPE (va))
                            && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (va)))
                               == cil32_arg_iterator_type);

                gen_cil_node (file, va);
                fputs ("\n\tcall\tinstance void [mscorlib]System.ArgIterator::End()",
                       file);

                stack_pop (1);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_VA_COPY:
              {
                tree va_dest = CALL_EXPR_ARG (node, 0);
                tree va_src  = CALL_EXPR_ARG (node, 1);

                gcc_assert (POINTER_TYPE_P (TREE_TYPE (va_dest))
                            && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (va_dest)))
                               == cil32_arg_iterator_type);
                gcc_assert (POINTER_TYPE_P (TREE_TYPE (va_src))
                            && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (va_src)))
                               == cil32_arg_iterator_type);

                gen_cil_node (file, va_dest);
                fputs ("\n\tdup"
                       "\n\tinitobj\tvaluetype [mscorlib]System.ArgIterator",
                       file);
                stack_push (1);
                stack_pop (1);

                gen_cil_node (file, va_src);
                fputs ("\n\tcpobj\t[mscorlib]System.ArgIterator", file);

                stack_pop (2);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_CPBLK:
              {
                tree ptr_dst = CALL_EXPR_ARG (node, 0);
                tree ptr_src = CALL_EXPR_ARG (node, 1);
                tree size    = CALL_EXPR_ARG (node, 2);

                gen_cil_node (file, ptr_dst);
                gen_cil_node (file, ptr_src);
                gen_cil_node (file, size);

                fputs ("\n\tunaligned. 1"
                       "\n\tcpblk", file);
                stack_pop (3);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_INITBLK:
              {
                tree ptr   = CALL_EXPR_ARG (node, 0);
                tree value = CALL_EXPR_ARG (node, 1);
                tree size  = CALL_EXPR_ARG (node, 2);

                gen_cil_node (file, ptr);
                gen_cil_node (file, value);
                gen_cil_node (file, size);

                fputs ("\n\tunaligned. 1"
                       "\n\tinitblk", file);
                stack_pop (3);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_IS_LITTLE_ENDIAN:
              {
                fputs ("\n\tcall\tbool [gcc4net]gcc4net.Crt::__isLittleEndian()",
                       file);

                stack_push (1);
                done = true;
              }
              break;

            case CIL32_BUILT_IN_ENDIAN_SELECT:
              {
                tree le_tree = CALL_EXPR_ARG (node, 0);
                tree be_tree = CALL_EXPR_ARG (node, 1);

                gen_cil_node (file, le_tree);
                gen_cil_node (file, be_tree);
                fputs ("\n\tcall\tvoid* [gcc4net]gcc4net.Crt::__EndianSelect(void*, void*)",
                       file);

                stack_pop (2);
                stack_push (1);
                done = true;
              }
              break;

            case CIL32_V2SF_CTOR:
            case CIL32_V4SF_CTOR:
            case CIL32_V4QI_CTOR:
            case CIL32_V2HI_CTOR:
            case CIL32_V8QI_CTOR:
            case CIL32_V4HI_CTOR:
            case CIL32_V2SI_CTOR:
            case CIL32_V4SI_CTOR:
            case CIL32_V8HI_CTOR:
            case CIL32_V16QI_CTOR:
              {
                unsigned int i;
                tree arg;
                call_expr_arg_iterator iter;
                tree arg_type;
                tree result = TREE_TYPE (fun_type);

                /* the type should be the same for all args. */
                arg_type = TREE_TYPE (CALL_EXPR_ARG (node, 0));
                FOR_EACH_CALL_EXPR_ARG (arg, iter, node)
                  gen_cil_node (file, arg);

                fputs ("\n\tcall ", file);
                dump_vector_type (file, result, true);
                fputs (" [gcc4net]gcc4net.", file);
                dump_vector_type (file, result, false);
                fputs ("::", file);
                dump_decl_name (file, fdecl);
                fputs ("(", file);

                /* emit the same type 'nargs' times */
                for(i = 0; i < nargs; ++i)
                  {
                    if (i)
                      fputs (", ", file);

                    if (TREE_CODE (arg_type) == INTEGER_TYPE
                        && !TYPE_UNSIGNED (arg_type))
                      fputs ("unsigned ", file);

                    dump_type (file, arg_type, false, false);
                  }
                fputs (")", file);

                stack_pop (nargs-1);
                done = true;
                break;
              }

            default:
              gcc_assert (0);
            }
        }
      else
        {
          switch (DECL_FUNCTION_CODE (fdecl))
            {
            case BUILT_IN_VA_START:
            case BUILT_IN_VA_END:
            case BUILT_IN_VA_COPY:
              gcc_assert (0);
              break;

            case BUILT_IN_INIT_TRAMPOLINE:
            case BUILT_IN_ADJUST_TRAMPOLINE:
            case BUILT_IN_NONLOCAL_GOTO:
              internal_error ("Builtins to support Trampolines not implemented\n");
              break;

            case BUILT_IN_PROFILE_FUNC_ENTER:
            case BUILT_IN_PROFILE_FUNC_EXIT:
              internal_error ("Builtins to support Profiling not implemented\n");
              break;

            case BUILT_IN_SETJMP_SETUP:
            case BUILT_IN_SETJMP_DISPATCHER:
            case BUILT_IN_SETJMP_RECEIVER:
              internal_error ("Builtins to support Setjump not implemented\n");
              break;

            case BUILT_IN_MEMSET:
              {
                tree ptr   = CALL_EXPR_ARG (node, 0);
                tree value = CALL_EXPR_ARG (node, 1);
                tree size  = CALL_EXPR_ARG (node, 2);

                gen_cil_node (file, ptr);
                fputs ("\n\tdup", file);
                stack_push (1);

                gen_cil_node (file, value);
                gen_cil_node (file, size);

                fputs ("\n\tunaligned. 1"
                       "\n\tinitblk", file);
                stack_pop (3);
                done = true;
              }
              break;

            case BUILT_IN_MEMCPY:
              {
                tree ptr_dst = CALL_EXPR_ARG (node, 0);
                tree ptr_src = CALL_EXPR_ARG (node, 1);
                tree size    = CALL_EXPR_ARG (node, 2);

                gen_cil_node (file, ptr_dst);
                fputs ("\n\tdup", file);
                stack_push (1);

                gen_cil_node (file, ptr_src);
                gen_cil_node (file, size);

                fputs ("\n\tunaligned. 1"
                       "\n\tcpblk", file);
                stack_pop (3);
                done = true;
              }
              break;

            case BUILT_IN_ALLOCA:
              {
                tree size = CALL_EXPR_ARG (node, 0);

                gen_cil_node (file, size);
                fputs ("\n\tlocalloc", file);

                done = true;
              }
              break;

            case BUILT_IN_STACK_SAVE:
              /* This built-in is only used for the implementation
                 of variable-length arrays.
                 It's not needed in CIL.   */
              fputs ("\n\tldc.i4.0"
                     "\n\tconv.i", file);
              stack_push (1);
              done = true;
              break;

            case BUILT_IN_STACK_RESTORE:
              /* This built-in is only used for the implementation
                 of variable-length arrays.
                 It's not needed in CIL.   */
              done = true;
              break;

            case BUILT_IN_EXPECT:
              /* __builtin_expect(exp,val) evalutes exp and tells the
                 compiler that it most likely gives val.  We just
                 evaluate exp.  */
              gen_cil_node (file, CALL_EXPR_ARG (node, 0));
              done = true;
              break;

            case BUILT_IN_TRAP:
              fputs ("\n\tcall\tvoid 'abort' ()", file);
              done = true;
              break;

            case BUILT_IN_CLZ:
            case BUILT_IN_CLZL:
            case BUILT_IN_CLZLL:
            case BUILT_IN_CTZ:
            case BUILT_IN_CTZL:
            case BUILT_IN_CTZLL:
            case BUILT_IN_FFS:
            case BUILT_IN_FFSL:
            case BUILT_IN_FFSLL:
            case BUILT_IN_PARITY:
            case BUILT_IN_PARITYL:
            case BUILT_IN_PARITYLL:
            case BUILT_IN_POPCOUNT:
            case BUILT_IN_POPCOUNTL:
            case BUILT_IN_POPCOUNTLL:
              {
                tree fun_arg_types = TYPE_ARG_TYPES (fun_type);
                tree arg = CALL_EXPR_ARG (node, 0);
                tree arg_type = TREE_VALUE (fun_arg_types);
                gen_cil_node (file, arg);
                fputs ("\n\tcall\tint32 [gcc4net]gcc4net.Crt::__", file);
                switch (DECL_FUNCTION_CODE (fdecl))
                  {
                  case BUILT_IN_CLZ:
                  case BUILT_IN_CLZL:
                  case BUILT_IN_CLZLL:
                    fputs ("clz", file);
                    break;
                  case BUILT_IN_CTZ:
                  case BUILT_IN_CTZL:
                  case BUILT_IN_CTZLL:
                    fputs ("ctz", file);
                    break;
                  case BUILT_IN_FFS:
                  case BUILT_IN_FFSL:
                  case BUILT_IN_FFSLL:
                    fputs ("ffs", file);
                    break;
                  case BUILT_IN_PARITY:
                  case BUILT_IN_PARITYL:
                  case BUILT_IN_PARITYLL:
                    fputs ("parity", file);
                    break;
                  case BUILT_IN_POPCOUNT:
                  case BUILT_IN_POPCOUNTL:
                  case BUILT_IN_POPCOUNTLL:
                    fputs ("popcount", file);
                    break;
                  default:
                    gcc_assert (0);
                    break;
                  }
                dump_type_eval_mode (file, arg_type, false, false);
                fputs ("2(", file);
                dump_type_for_builtin (file, arg_type, false);
                fputs (")", file);
              }
              done = true;
              break;

            default:
              if (DECL_ASSEMBLER_NAME_SET_P (node))
                {
                  /* Go Ahead as a normal function call */
                }
/*               else */
/*                 { */
/*                   fprintf (stderr, */
/*                            "unsupported builtin: %s\n", */
/*                            IDENTIFIER_POINTER (DECL_NAME (fdecl))); */
/*                   gcc_assert (0); */
/*                 } */
            }
        }
    }

  if (!done)
    {
      tree args;
      tree args_type;
      tree static_chain;
      bool varargs;
      unsigned int nargs_base;
      unsigned int aidx;

      args_type = TYPE_ARG_TYPES (fun_type);
      varargs = FALSE;

      if (args_type == NULL)
        {
          if (direct_call)
            warning (OPT_Wcil_missing_prototypes,
                     "Missing function %s prototype, guessing it, "
                     "you should fix the code",
                     IDENTIFIER_POINTER (DECL_NAME (fdecl)));
          else
            warning (OPT_Wcil_missing_prototypes,
                     "Missing indirect function prototype, guessing it, "
                     "you should fix the code");
          /* Guess types using the type of the arguments */
          nargs_base = 0;
        }
      else
        {
          tree last_arg_type = tree_last (args_type);
          nargs_base = list_length (args_type);

          if (TREE_VALUE (last_arg_type) != void_type_node)
            {
              varargs = TRUE;
            }
          else
            {
              --nargs_base;
            }
        }

      /* Print parameters.  */

      /* If static Chain present, it will be the first argument */
      static_chain = CALL_EXPR_STATIC_CHAIN(node);
      if (static_chain)
        gen_cil_node (file, static_chain);

      for (aidx=0;aidx<nargs_base;++aidx)
        {
          gen_cil_node (file, CALL_EXPR_ARG (node, aidx));
        }

      for (;aidx<nargs;++aidx) {
          tree targ = CALL_EXPR_ARG (node, aidx);
          tree targ_type = TREE_TYPE(targ);
          gen_cil_node (file, targ);
          if (TREE_CODE (targ_type) == POINTER_TYPE
              || (TREE_CODE (targ_type) == ARRAY_TYPE
                  && (! TYPE_DOMAIN (targ_type) || ARRAY_TYPE_VARLENGTH (targ_type))))
            fputs ("\n\tconv.i", file);
      }

      /* Print function pointer, in case of indirect call */
      if (!direct_call)
        gen_cil_node (file, fun_expr);

#if 0
      if (0 && CALL_EXPR_RETURN_SLOT_OPT (node))
        fprintf (file, " [return slot optimization]");
#endif

      fprintf (file, "\n\t");
#if 0
      if (CALL_EXPR_TAILCALL (node))
        fprintf (file, "tail.");
#endif
      if (direct_call)
        fputs ("call\t", file);
      else
        fputs ("calli\t", file);

      if (varargs)
        fputs ("vararg ", file);

      dump_type (file, TREE_TYPE (fun_type), true, false);

      if (direct_call)
        {
          struct fnct_attr attrs;
          decode_function_attrs (fdecl, &attrs);

          fputs (" ", file);

          if (attrs.assembly_name)
            fprintf (file, "[%s]", attrs.assembly_name);
          else if (TARGET_EMIT_EXTERNAL_ASSEMBLY && DECL_EXTERNAL (fdecl))
            fputs ("[ExternalAssembly]ExternalAssembly::", file);

          if (attrs.cil_name)
            fprintf (file, "%s", attrs.cil_name);
          else
            dump_decl_name (file, fdecl);
        }

      fputs (" (", file);
      args = TREE_OPERAND (node, 1);

      if (static_chain)
        {
          dump_type (file, TREE_TYPE (static_chain), true, true);
          if (nargs_base > 0)
            fputs (", ", file);
        }

      for (aidx=0;aidx<nargs_base;++aidx)
        {
          if (aidx!=0)
            {
              fputs (", ", file);
            }

          dump_type (file, TREE_VALUE (args_type), true, true);
          args_type = TREE_CHAIN (args_type);
        }

      if (varargs && aidx<nargs)
        fputs (", ..., ", file);

      for (;aidx<nargs;++aidx)
        {
          if (aidx!=nargs_base)
            {
              fputs (", ", file);
            }

          dump_type_promotion (file, TREE_TYPE (CALL_EXPR_ARG (node, aidx)), true);
        }

      fputs (")", file);

      if (!direct_call)
        ++nargs;
      if (static_chain)
        ++nargs;
      stack_pop (nargs);

      if (TREE_CODE (TREE_TYPE (fun_type)) != VOID_TYPE)
        stack_push (1);
    }
}

/* Dump the node NODE in CIL on the file FILE. */

static void
gen_cil_node (FILE *file, tree node)
{
  tree op0, op1;

  if (node == NULL_TREE || node == error_mark_node)
    return;

  if (TARGET_EMIT_GIMPLE_COMMENTS && EXPR_HAS_LOCATION (node))
    {
      expanded_location xloc = expand_location (EXPR_LOCATION (node));
      if (xloc.file)
        fprintf (file, "\n\t/* [file:%s,line:%d] */", xloc.file, xloc.line);
      else
        fprintf (file, "\n\t/* [line:%d] */", xloc.line);
    }

  switch (TREE_CODE (node))
    {
    case INTEGER_CST:
      {
        int type_size = TYPE_PRECISION (TREE_TYPE (node));

        gcc_assert (type_size <= 64);
        if (type_size <= 32)
          fputs ("\n\tldc.i4\t", file);
        else
          fputs ("\n\tldc.i8\t", file);
        dump_double_int (file, TREE_INT_CST (node), false);

        if (POINTER_TYPE_P (TREE_TYPE (node)))
          fputs ("\n\tconv.i", file);

        stack_push (1);
      }
      break;

    case COMPLEX_CST:
      {
        tree cplx_type = TREE_TYPE (node);
        tree re = TREE_REALPART (node);
        tree im = TREE_IMAGPART (node);

        gen_cil_node (file, re);
        gen_cil_node (file, im);
        fputs ("\n\tcall ", file);
        dump_complex_type (file, cplx_type, true);
        fputs (" [gcc4net]gcc4net.", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("::", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("_ctor (", file);
        dump_type (file, TREE_TYPE (re), false, false);
        fputs (", ", file);
        dump_type (file, TREE_TYPE (re), false, false);
        fputs (")", file);
        stack_pop (2);
        stack_push (1);
      }
      break;

    case REAL_CST:
      {
        REAL_VALUE_TYPE d;
        tree type_tree;
        int type_size;
        enum machine_mode mode;
        char string[100];
        /* we have 32 and 64 bit reals, real_to_format fills 32 bits per long */
        long  buf[2];

        d = TREE_REAL_CST (node);
        type_tree = TREE_TYPE (node);
        mode = TYPE_MODE (type_tree);
        real_to_target (buf, &d, mode);
        real_to_decimal (string, &d, sizeof (string), 5, 1);
        type_size = TYPE_PRECISION (type_tree);

        switch (type_size)
          {
          case 32:
            fprintf (file, "\n\tldc.r4\tfloat32(%#08lx)", buf[0]);
            break;

          case 64:
            fprintf (file, "\n\tldc.r8\tfloat64(%#08lx%08lx)", buf[1], buf[0]);
            break;

          default:
            internal_error ("\nldc.r: unsupported float size %d\n", type_size);
            break;
          }
        fprintf (file, "  /* %s */", string);
        stack_push (1);
        break;
      }

    case VECTOR_CST:
      {
        int  num_elt = 0;
        int  i;
        tree elt;
        tree vector_type = TREE_TYPE (node);
        int  vector_bitsize = TREE_INT_CST_LOW (TYPE_SIZE (vector_type));
        tree unit_type = TREE_TYPE (vector_type);
        int  unit_bitsize = TYPE_PRECISION (unit_type);

        gcc_assert (HOST_BITS_PER_WIDEST_INT >= 64);

        for (elt = TREE_VECTOR_CST_ELTS (node); elt; elt = TREE_CHAIN (elt))
          {
            tree elt_val = TREE_VALUE (elt);
            gen_cil_node (file, elt_val);
            ++num_elt;
          }
        /* Fill in the missing initializers, if any */
        for ( ; num_elt < vector_bitsize/unit_bitsize; ++num_elt)
          {
            if (GET_MODE_CLASS (TYPE_MODE (unit_type)) == MODE_INT)
            {
              fputs ("\n\tldc.i4.0", file);
            }
            else if (GET_MODE_CLASS (TYPE_MODE (unit_type)) == MODE_FLOAT)
            {
              fputs ("\n\tldc.r4 0.0", file);
            }
            else
              internal_error ("\n\nDo not know how to initialize vector\n");

            stack_push (1);
          }
        fputs ("\n\tcall ", file);
        dump_type(file, vector_type, false, false);
        fputs (" [gcc4net]gcc4net.", file);
        dump_vector_type(file, vector_type, false);
        fputs ("::", file);
        dump_vector_type(file, vector_type, false);
        fputs ("_ctor1(", file);
        for (i=0; i < num_elt; ++i)
          {
            if (i)
              fputs (", ", file);
            if ((GET_MODE_CLASS (TYPE_MODE (unit_type)) == MODE_INT) &&
                (!TYPE_UNSIGNED (unit_type)))
            {
              fputs ("unsigned ", file);
            }

            dump_type (file, unit_type, false, false);
          }
        fputs (")", file);
        stack_pop (num_elt);
        stack_push (1);
        break;
      }

    case LABEL_DECL:
      internal_error ("use dump_label_name instead of gen_cil_node\n");
      break;

    case INIT_EXPR:
    case MODIFY_EXPR:
    case GIMPLE_MODIFY_STMT:
      gen_cil_modify_expr (file,
                           GENERIC_TREE_OPERAND (node, 0),
                           GENERIC_TREE_OPERAND (node, 1));
      break;

    case GOTO_EXPR:
      {
        tree label_decl = GOTO_DESTINATION (node);

	if (TREE_CODE (label_decl) != LABEL_DECL)
	  {
	    /* This is a goto to the address of a label. Labels have been
	       numbered, and we emit a switch based on that ID. */
	    gen_computed_goto (file, label_decl);
	  }
        else
          {
            basic_block dest_bb = label_to_block (label_decl);

            if (bb->next_bb != dest_bb)
              {
                fputs ("\n\tbr\t", file);
                dump_label_name (file, label_decl);
              }
          }
        gcc_assert (stack == 0);
      }
      break;

    case COND_EXPR:
      {
        tree label_then, label_else;

        if (COND_EXPR_THEN (node)
            && simple_goto_p (COND_EXPR_THEN (node)))
          {
            /* At this point, both clauses of COND_EXPR must contain simple gotos */
            gcc_assert (COND_EXPR_ELSE (node)
                        && simple_goto_p (COND_EXPR_ELSE (node)));
            label_then = GOTO_DESTINATION (COND_EXPR_THEN (node));
            label_else = GOTO_DESTINATION (COND_EXPR_ELSE (node));
          }
        else
          {
            edge true_edge;
            edge false_edge;
            extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
            label_then = tree_block_label (true_edge->dest);
            label_else = tree_block_label (false_edge->dest);
          }

        gcc_assert (label_then != NULL_TREE && label_else != NULL_TREE);

        op0 = COND_EXPR_COND (node);
        if (TREE_CODE (op0) == EQ_EXPR
            || TREE_CODE (op0) == NE_EXPR)
          {
            tree op00 = TREE_OPERAND (op0, 0);
            tree op01 = TREE_OPERAND (op0, 1);
            tree cond_type = TREE_TYPE (op00);

            if ((INTEGRAL_TYPE_P (cond_type) || POINTER_TYPE_P (cond_type))
                && ((TREE_CODE (op00) == INTEGER_CST
                     && double_int_zero_p (TREE_INT_CST (op00)))
                    || (TREE_CODE (op01) == INTEGER_CST
                        && double_int_zero_p (TREE_INT_CST (op01)))))
              {
                if ((TREE_CODE (op00) == INTEGER_CST
                     && double_int_zero_p (TREE_INT_CST (op00))))
                  gen_cil_node (file, op01);
                else
                  gen_cil_node (file, op00);

                if (TREE_CODE (op0) == EQ_EXPR)
                  fputs ("\n\tbrfalse\t", file);
                else
                  fputs ("\n\tbrtrue\t", file);
                dump_label_name (file, label_then);

                stack_pop (1);
              }
            else
              gen_binary_cond_branch (file, op0, label_then);
          }
        else if (TREE_CODE (op0) == LE_EXPR
                 || TREE_CODE (op0) == LT_EXPR
                 || TREE_CODE (op0) == GE_EXPR
                 || TREE_CODE (op0) == GT_EXPR
                 || TREE_CODE (op0) == UNLT_EXPR
                 || TREE_CODE (op0) == UNLE_EXPR
                 || TREE_CODE (op0) == UNGT_EXPR
                 || TREE_CODE (op0) == UNGE_EXPR)
          {
            gen_binary_cond_branch (file, op0, label_then);
          }
        else
          {
            gen_cil_node (file, op0);
            fputs ("\n\tldc.i4.0"
                   "\n\tbne.un\t", file);
            dump_label_name (file, label_then);
            stack_push (1);
            stack_pop (2);
          }

        if (TARGET_EMIT_JIT_COMPILATION_HINTS)
          branch_probability_add (file, node);

        {
          basic_block dest_bb = label_to_block (label_else);

          /* Emit else block only if it is not a fallthrough */
          if (bb->next_bb != dest_bb)
            {
              fputs ("\n\tbr\t", file);
              dump_label_name (file, label_else);
            }
          gcc_assert (stack == 0);
        }
      }
      break;

    case SWITCH_EXPR:
      {
        tree vec = SWITCH_LABELS (node);
        unsigned int vec_len, i;
        bool first_case = true;
        tree min_val = 0, max_val = 0;
        double_int max_min_diff;
        unsigned int switch_n;
        tree default_label;
        tree *labels;

        /* The switch body is lowered in gimplify.c, we should never have
           switches with a non-NULL SWITCH_BODY here.  */
        gcc_assert (vec && !SWITCH_BODY (node));
        vec_len = TREE_VEC_LENGTH (vec);

        /* Compute range of cases */
        for (i = 0; i < vec_len - 1 ; ++i)
          {
            tree elt  = TREE_VEC_ELT (vec, i);
            tree low  = CASE_LOW (elt);
            tree high = CASE_HIGH (elt);

            if (!high)
              high = low;

            gcc_assert (low && high);

            /* Discard empty ranges.  */
            if (INT_CST_LT (high, low))
              continue;

            if (first_case)
              {
                min_val = low;
                max_val = high;
                first_case = false;
              }
            else
              {
                if (INT_CST_LT (low, min_val))
                  min_val = low;

                if (INT_CST_LT (max_val, high))
                  max_val = high;
              }
          }
        gcc_assert (!INT_CST_LT (max_val, min_val));

        /* Get the default label */
        gcc_assert (!CASE_HIGH (TREE_VEC_ELT (vec, TREE_VEC_LENGTH (vec)- 1)));
        gcc_assert (!CASE_LOW (TREE_VEC_ELT (vec, TREE_VEC_LENGTH (vec) - 1)));
        default_label = CASE_LABEL (TREE_VEC_ELT (vec,
                                                  TREE_VEC_LENGTH (vec) - 1));

        /* Prepare a table with the label for each value of the condition */
        max_min_diff = double_int_add (double_int_neg (TREE_INT_CST (min_val)),
                                       TREE_INT_CST (max_val));
        gcc_assert (max_min_diff.high == 0 && max_min_diff.low < 8192);
        switch_n = max_min_diff.low + 1;
        gcc_assert (switch_n > 0);
        labels = (tree*)xmalloc (switch_n * sizeof (tree));

        for (i=0 ; i < switch_n; ++i)
          labels[i] = default_label;

        for (i = 0; i < vec_len - 1 ; ++i)
          {
            tree elt  = TREE_VEC_ELT (vec, i);
            tree low  = CASE_LOW (elt);
            tree high = CASE_HIGH (elt);
            double_int low_val, high_val, end, j;
            double_int minus_min_val = double_int_neg (TREE_INT_CST (min_val));

            if (!high)
              high = low;

            gcc_assert (low && high);

            /* Discard empty ranges.  */
            if (INT_CST_LT (high, low))
              continue;

            low_val  = TREE_INT_CST (low);
            high_val = TREE_INT_CST (high);
            end = double_int_add (high_val, double_int_one);

            for (j = low_val;
                 !double_int_equal_p (j, end);
                 j = double_int_add (j, double_int_one)
                )
              {
                double_int norm_j = double_int_add (j, minus_min_val);

                gcc_assert (norm_j.high == 0 && norm_j.low < 8192);
                labels[norm_j.low] = CASE_LABEL (elt);
              }
          }

        /* Emit switch condition */
        gen_cil_node (file, SWITCH_COND (node));

        /* Emit subtraction to normalize the condition */
        if (!double_int_equal_p (TREE_INT_CST (min_val), double_int_zero))
          {
            double_int min = TREE_INT_CST (min_val);

            fputs ("\n\tldc.i4\t", file);

            if (double_int_negative_p (min))
              {
                dump_double_int (file, double_int_neg (min), false);
                fputs ("\n\tadd", file);
              }
            else
              {
                dump_double_int (file, min, false);
                fputs ("\n\tsub", file);
              }

            stack_push (1);
            stack_pop (1);
          }

        /* Emit switch instruction */
        fputs ("\n\tswitch\t(", file);
        for (i=0 ; i < switch_n; ++i)
          {
            dump_label_name (file, labels[i]);
            if (i < switch_n - 1)
              fputs (", ", file);
          }
        fputs (")", file);
        stack_pop (1);

        /* Emit branch for default label */
        fputs ("\n\tbr\t", file);
        dump_label_name (file, default_label);
        gcc_assert (stack == 0);
      }
      break;

    case CALL_EXPR:
      gen_call_expr (file, node);
      break;

    case MULT_EXPR:
    case PLUS_EXPR:
    case POINTER_PLUS_EXPR:
    case MINUS_EXPR:
    case RDIV_EXPR:
    case LSHIFT_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gen_cil_node (file, op1);

      switch (TREE_CODE (node))
        {
        case MULT_EXPR:    fputs ("\n\tmul", file); break;
        case POINTER_PLUS_EXPR:
        case PLUS_EXPR:    fputs ("\n\tadd", file); break;
        case MINUS_EXPR:   fputs ("\n\tsub", file); break;
        case RDIV_EXPR:    fputs ("\n\tdiv", file); break;
        case LSHIFT_EXPR:  fputs ("\n\tshl", file); break;
        default:
          gcc_unreachable ();
        }

      stack_pop (1);

      /* Values with precision smaller than the one used
         on the evaluation stack require an explicit conversion.   */
      if (INTEGRAL_TYPE_P (TREE_TYPE (node)))
        gen_integral_conv (file, TREE_TYPE (node), TREE_TYPE (node));
      break;

    case BIT_IOR_EXPR:
    case BIT_XOR_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gen_cil_node (file, op1);

      switch (TREE_CODE (node))
        {
        case BIT_IOR_EXPR: fputs ("\n\tor",  file); break;
        case BIT_XOR_EXPR: fputs ("\n\txor", file); break;
        default:
          gcc_unreachable ();
        }

      /* No need for conversions even in case of values with precision
         smaller than the one used on the evaluation stack,
         since for these operations the output is
         always less or equal than both operands.   */

      stack_pop (1);
      break;

    case BIT_AND_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      if (TREE_CODE (op0) == INTEGER_CST
          && (TREE_INT_CST_LOW (op0) == 255U
              || TREE_INT_CST_LOW (op0) == 65535U
              || TREE_INT_CST_LOW (op0) == 4294967295U)
          && TREE_INT_CST_HIGH (op0) == 0)
        {
          gen_cil_node (file, op1);

          fputs ("\n\tconv.u", file);

          switch (TREE_INT_CST_LOW (op0))
            {
            case 255U:        fputs ("1", file); break;
            case 65535U:      fputs ("2", file); break;
            case 4294967295U: fputs ("4", file); break;
            default:
              gcc_unreachable ();
            }

          if (TYPE_PRECISION (TREE_TYPE (node)) > 32)
            fputs ("\n\tconv.u8", file);
        }
      else if (TREE_CODE (op1) == INTEGER_CST
               && (TREE_INT_CST_LOW (op1) == 255U
                   || TREE_INT_CST_LOW (op1) == 65535U
                   || TREE_INT_CST_LOW (op1) == 4294967295U)
               && TREE_INT_CST_HIGH (op1) == 0)
        {
          gen_cil_node (file, op0);

          fputs ("\n\tconv.u", file);

          switch (TREE_INT_CST_LOW (op1))
            {
            case 255U:        fputs ("1", file); break;
            case 65535U:      fputs ("2", file); break;
            case 4294967295U: fputs ("4", file); break;
            default:
              gcc_unreachable ();
            }

          if (TYPE_PRECISION (TREE_TYPE (node)) > 32)
            fputs ("\n\tconv.u8", file);
        }
      else
        {
          gen_cil_node (file, op0);
          gen_cil_node (file, op1);

          fputs ("\n\tand", file);

          /* No need for conversions even in case of values with precision
             smaller than the one used on the evaluation stack,
             since for these operations the output is
             always less or equal than both operands.   */

          stack_pop (1);
        }
      break;

    case LT_EXPR:
    case GT_EXPR:
    case EQ_EXPR:
    case NE_EXPR:
    case UNLT_EXPR:
    case UNGT_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gen_cil_node (file, op1);

      switch (TREE_CODE (node))
        {
        case LT_EXPR:
          fputs (TYPE_UNSIGNED (TREE_TYPE (op0))?"\n\tclt.un":"\n\tclt", file);
          break;

        case GT_EXPR:
          fputs (TYPE_UNSIGNED (TREE_TYPE (op0))?"\n\tcgt.un":"\n\tcgt", file);
          break;

        case EQ_EXPR:   fputs ("\n\tceq", file); break;
        case NE_EXPR:   fputs ("\n\tceq"
                               "\n\tldc.i4.1"
                               "\n\txor", file); break;
        case UNLT_EXPR: fputs ("\n\tclt.un", file); break;
        case UNGT_EXPR: fputs ("\n\tcgt.un", file); break;

        default:
          gcc_unreachable ();
        }

      if (TYPE_PRECISION (TREE_TYPE (node)) > 32)
        fputs ("\n\tconv.i8", file);

      stack_pop (1);
      break;

    case LE_EXPR:
    case GE_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gen_cil_node (file, op1);

      switch (TREE_CODE (node))
        {
        case LE_EXPR:
          fputs (TYPE_UNSIGNED (TREE_TYPE (op0))?"\n\tcgt.un":"\n\tcgt", file);
          break;

        case GE_EXPR:
          fputs (TYPE_UNSIGNED (TREE_TYPE (op0))?"\n\tclt.un":"\n\tclt", file);
          break;

        default:
          gcc_unreachable ();
        }

      fputs ("\n\tldc.i4.1"
             "\n\txor", file);

      if (TYPE_PRECISION (TREE_TYPE (node)) > 32)
        fputs ("\n\tconv.i8", file);

      stack_pop (1);
      break;

    case UNORDERED_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      fputs ("\n\tdup"
             "\n\tceq", file);

      stack_push (1);
      stack_pop (1);

      gen_cil_node (file, op1);
      fputs ("\n\tdup"
             "\n\tceq"
             "\n\tand"
             "\n\tldc.i4.1"
             "\n\txor", file);

      stack_push (1);
      stack_pop (2);
      break;

    case ORDERED_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      fputs ("\n\tdup"
             "\n\tceq", file);

      stack_push (1);
      stack_pop (1);

      gen_cil_node (file, op1);
      fputs ("\n\tdup"
             "\n\tceq"
             "\n\tand", file);

      stack_push (1);
      stack_pop (2);
      break;

    case EXACT_DIV_EXPR:
    case TRUNC_DIV_EXPR:
    case TRUNC_MOD_EXPR:
    case RSHIFT_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gen_cil_node (file, op1);

      switch (TREE_CODE (node))
        {
        case EXACT_DIV_EXPR:
        case TRUNC_DIV_EXPR: fputs ("\n\tdiv", file); break;
        case TRUNC_MOD_EXPR: fputs ("\n\trem", file); break;
        case RSHIFT_EXPR:    fputs ("\n\tshr", file); break;
        default:
          gcc_unreachable ();
        }

      if (TYPE_UNSIGNED (TREE_TYPE (node)))
        fputs (".un", file);

      /* No need for conversions even in case of values with precision
         smaller than the one used on the evaluation stack,
         since for these operations the output is
         always less or equal than both operands.   */

      stack_pop (1);
      break;

    case FLOOR_DIV_EXPR:
      {
        bool is_signed0, is_signed1;

        op0 = TREE_OPERAND (node, 0);
        op1 = TREE_OPERAND (node, 1);

        gen_cil_node (file, op0);
        gen_cil_node (file, op1);

        is_signed0 = TYPE_UNSIGNED (TREE_TYPE (op0));
        is_signed1 = TYPE_UNSIGNED (TREE_TYPE (op1));
        /* If both operands are unsigned, the result is positive and thus
           rounding towards zero is identical to towards -infinity. */
        if (is_signed0 && is_signed1)
          {
            fputs ("\n\tdiv.un", file);
          }
        else
	  internal_error ("\n\nFLOOR_DIV_EXPR is not completely supported\n");

      /* No need for conversions even in case of values with precision
         smaller than the one used on the evaluation stack,
         since for these operations the output is
         always less or equal than both operands.   */

        stack_pop (1);
        break;
      }

    case NEGATE_EXPR:
    case BIT_NOT_EXPR:
      gen_cil_node (file, TREE_OPERAND (node, 0));

      switch (TREE_CODE (node))
        {
        case NEGATE_EXPR:    fputs ("\n\tneg", file); break;
        case BIT_NOT_EXPR:   fputs ("\n\tnot", file); break;
        default:
          gcc_unreachable ();
        }

      /* Values with precision smaller than the one used
         on the evaluation stack require an explicit conversion.
         Unfortunately this is true for the negation as well just
         for the case in which the operand is the smallest negative value.
         Example: 8-bit negation of -128 gives 0 and not 128.   */
      if (INTEGRAL_TYPE_P (TREE_TYPE (node)))
        gen_integral_conv (file, TREE_TYPE (node), TREE_TYPE (node));
      break;

    case INDIRECT_REF:
    case ARRAY_REF:
      gen_addr_expr (file, node);

      if (TREE_THIS_VOLATILE (node))
        fputs ("\n\tvolatile.", file);

      if (AGGREGATE_TYPE_P (TREE_TYPE (node)))
        {
          fputs ("\n\tldobj\t", file);
          dump_type (file, TREE_TYPE (node), true, false);
        }
      else if (TREE_CODE (TREE_TYPE (node)) == COMPLEX_TYPE)
        {
          fputs ("\n\tldobj ", file);
          dump_complex_type (file, TREE_TYPE (node), true);
        }
      else if (TREE_CODE (TREE_TYPE (node)) == VECTOR_TYPE)
        {
          fputs ("\n\tldobj ", file);
          dump_vector_type (file, TREE_TYPE (node), true);
        }
      else
        {
          fputs ("\n\tldind.", file);
          print_type_suffix (file, TREE_TYPE (node), true);
        }
      break;

    case CONVERT_EXPR:
    case FLOAT_EXPR:
      /* ER: if flag_trapv is set, we could generate the .ovf version? */
      /* TODO: */
    case FIX_TRUNC_EXPR:
    case NOP_EXPR:
      gen_cil_node (file, TREE_OPERAND (node, 0));
      gen_conv (file,
                (TREE_CODE (node) == NOP_EXPR),
                TREE_TYPE (node),
                TREE_TYPE (TREE_OPERAND (node, 0)));
      break;

    case LABEL_EXPR:
      op0 = TREE_OPERAND (node, 0);
      /* If this is for break or continue, don't bother printing it.  */
      if (DECL_NAME (op0))
        {
          const char *name = IDENTIFIER_POINTER (DECL_NAME (op0));
          if (strcmp (name, "break") == 0
              || strcmp (name, "continue") == 0)
            break;
        }
      fprintf (file, "\n");
      dump_label_name (file, op0);
      fprintf (file, ":");

      if (DECL_NONLOCAL (op0))
        fprintf (file, " [non-local]");

      break;

    case RETURN_EXPR:
      op0 = TREE_OPERAND (node, 0);
      if (op0)
        {
          /* dump_generic_node (file, op0); */
          if (TREE_CODE (op0) == MODIFY_EXPR || TREE_CODE (op0) == GIMPLE_MODIFY_STMT)
            op0 = GENERIC_TREE_OPERAND (op0, 1);

          gen_cil_node (file, op0);
        }

      /* Pre-C99 code may contain void-returns for non-void functions,
         but the simplification pass should already have avoided this.   */
      gcc_assert (op0
                  || TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl)))
                  == VOID_TYPE);

      fputs ("\n\tret", file);
      stack_reset ();
      break;

    case ASM_EXPR:
      {
        /* support just a simple string, no input/output/clober */
        tree asm_string = ASM_STRING (node);
        const char *str = TREE_STRING_POINTER (asm_string);

        fputs ("\n\t", file);
        fputs (str, file);
        break;
      }

    case MIN_EXPR:
    case MAX_EXPR:
      {
        tree node_type = TREE_TYPE (node);

        gcc_assert (!TARGET_EXPAND_MINMAX);

        op0 = TREE_OPERAND (node, 0);
        op1 = TREE_OPERAND (node, 1);

        gen_cil_node (file, op0);
        gen_cil_node (file, op1);

        /* emit a call */
        fputs ("\n\tcall\t", file);
        dump_type_for_builtin (file, node_type, false);
        fputs (" [gcc4net]gcc4net.Crt::__",  file);

        if (TYPE_UNSIGNED (node_type))
          fputs ("u",  file);

        if (TREE_CODE (node) == MIN_EXPR)
          fputs ("min",  file);
        else
          fputs ("max",  file);

        dump_type_eval_mode (file, node_type, false, false);
        fputs ("3(",  file);
        dump_type_for_builtin (file, TREE_TYPE (op0), false);
        fputs (", ", file);
        dump_type_for_builtin (file, TREE_TYPE (op1), false);
        fputs (")", file);
        stack_pop (1);
      }
      break;

    case ABS_EXPR:
      {
        tree node_type = TREE_TYPE (node);

        gcc_assert (!TARGET_EXPAND_ABS);

        op0 = TREE_OPERAND (node, 0);
        gen_cil_node (file, op0);

        /* emit a call */
        fputs ("\n\tcall\t", file);
        dump_type_for_builtin (file, node_type, false);
        fputs (" [gcc4net]gcc4net.Crt::__abs", file);
        dump_type_eval_mode (file, node_type, false, false);
        fputs ("2(",  file);
        dump_type_for_builtin (file, TREE_TYPE (op0), false);
        fputs (")", file);
      }
      break;

    case SSA_NAME:
      gcc_assert (0);
      break;

    case VAR_DECL:
      mark_referenced_type (TREE_TYPE (node));

      if (!DECL_FILE_SCOPE_P (node))
        {
          if (TREE_THIS_VOLATILE (node))
            {
              /* put the address of the loc on the stack */
              fputs ("\n\tldloca\t", file);
              dump_decl_name (file, node);
              /* and emit a volatile ldind or ldobj */
              fputs ("\n\tvolatile.", file);
              if (AGGREGATE_TYPE_P (TREE_TYPE (node)) ||
                  TREE_CODE (TREE_TYPE (node)) == COMPLEX_TYPE ||
                  TREE_CODE (TREE_TYPE (node)) == VECTOR_TYPE)
                {
                  fputs ("\n\tldobj\t", file);
                  dump_type (file, TREE_TYPE (node), true, false);
                }
              else
                {
                  fputs ("\n\tldind.", file);
                  print_type_suffix (file, TREE_TYPE (node), true);
                }
            }
          else
            {
              fputs ("\n\tldloc\t", file);
              dump_decl_name (file, node);
            }
        }
      else
        {
          if (TREE_THIS_VOLATILE (node))
            fputs ("\n\tvolatile.", file);
          fputs ("\n\tldsfld\t", file);
          dump_type (file, TREE_TYPE (node), true, false);
          fputs (" ", file);
          if (TARGET_EMIT_EXTERNAL_ASSEMBLY && DECL_EXTERNAL (node))
            fputs ("[ExternalAssembly]ExternalAssembly::", file);
          dump_decl_name (file, node);
        }

      stack_push (1);
      break;

    case PARM_DECL:
      mark_referenced_type (TREE_TYPE (node));
      fputs ("\n\tldarg\t", file);
      dump_decl_name (file, node);
      stack_push (1);

      /* K&R C allows declaration type to be wider than the actual type */
      if (TREE_TYPE (node) != DECL_ARG_TYPE (node))
        {
          mark_referenced_type (DECL_ARG_TYPE (node));
          gen_conv (file, true, TREE_TYPE (node), DECL_ARG_TYPE (node));
        }
      break;

    case FIELD_DECL:
    case NAMESPACE_DECL:
      fprintf (stderr, "CIL: Cannot handle FIELD_DECL or NAMESPACE_DECL: ");
      dump_decl_name (stderr, node);
      gcc_assert (0);
      break;

    case TREE_LIST:
      gcc_assert (0);
      break;

    case FUNCTION_DECL:
    case CONST_DECL:
      gcc_assert (0);
      break;

    case ADDR_EXPR:
      gen_addr_expr (file, TREE_OPERAND (node, 0));
      break;

    case COMPONENT_REF:
      {
        tree obj = TREE_OPERAND (node, 0);
        tree fld = TREE_OPERAND (node, 1);
        tree obj_type = TYPE_MAIN_VARIANT (TREE_TYPE (obj));
        tree fld_type = TREE_TYPE (fld);

        gcc_assert (TREE_CODE (fld) == FIELD_DECL);
        gcc_assert (! DECL_BIT_FIELD (fld));

        gen_addr_expr (file, obj);
        if (TREE_THIS_VOLATILE (node))
          fputs ("\n\tvolatile.", file);
        fputs ("\n\tldfld\t", file);
        dump_type (file, fld_type, true, false);
        fputs (" ", file);
        mark_referenced_type (obj_type);
        dump_valuetype_name (file, obj_type);
        fputs ("::", file);
        dump_decl_name (file, fld);
      }
      break;

    case TRUTH_NOT_EXPR:
      gen_cil_node (file, TREE_OPERAND (node, 0));
      fputs ("\n\tldc.i4.0"
             "\n\tceq", file);
      stack_push (1);
      stack_pop (1);
      break;

    case TRUTH_AND_EXPR:
    case TRUTH_OR_EXPR:
    case TRUTH_XOR_EXPR:
      op0 = TREE_OPERAND (node, 0);
      op1 = TREE_OPERAND (node, 1);

      gen_cil_node (file, op0);
      gcc_assert (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE
                  || TREE_CODE (TREE_TYPE (op0)) == BOOLEAN_TYPE);
      if (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE)
        {
          fputs ("\n\tldc.i4.0"
                 "\n\tceq"
                 "\n\tldc.i4.1"
                 "\n\txor", file);
          stack_push (1);
          stack_pop (1);
        }

      gen_cil_node (file, op1);
      gcc_assert (TREE_CODE (TREE_TYPE (op1)) == INTEGER_TYPE
                  || TREE_CODE (TREE_TYPE (op1)) == BOOLEAN_TYPE);
      if (TREE_CODE (TREE_TYPE (op1)) == INTEGER_TYPE)
        {
          fputs ("\n\tldc.i4.0"
                 "\n\tceq"
                 "\n\tldc.i4.1"
                 "\n\txor", file);
          stack_push (1);
          stack_pop (1);
        }

      if (TREE_CODE (node) == TRUTH_AND_EXPR)
        fputs ("\n\tand", file);
      else if (TREE_CODE (node) == TRUTH_OR_EXPR)
        fputs ("\n\tor", file);
      else
        fputs ("\n\txor"
               "\n\tldc.i4.1"
               "\n\tand", file);
      stack_pop (1);
      break;

    case VIEW_CONVERT_EXPR:
      {
        op0 = TREE_OPERAND (node, 0);
        gen_cil_node (file, op0);

        if (TREE_CODE (TREE_TYPE (op0)) == VECTOR_TYPE)
          {
            /* Convert a vector type to something. */
            tree vec_type = TREE_TYPE (op0);
            fputs ("\n\tcall ", file);
            dump_type (file, TREE_TYPE (node), false, false);
            fputs (" [gcc4net]gcc4net.", file);
            dump_vector_type (file, vec_type, false);
            fputs ("::", file);
            dump_vector_type (file, vec_type, false);
            fputs ("_to_", file);
            dump_type_eval_mode (file, TREE_TYPE (node), true, true);
            fputs (" (", file);
            dump_type (file, vec_type, false, false);
            fputs (")", file);
          }
        else if (TREE_CODE (TREE_TYPE (node)) == VECTOR_TYPE)
          {
            /* Convert something to a vector type. */
            tree vec_type = TREE_TYPE (node);
            fputs ("\n\tcall ", file);
            dump_type (file, vec_type, false, false);
            fputs (" [gcc4net]gcc4net.", file);
            dump_vector_type (file, vec_type, false);
            fputs ("::ctor (", file);
            dump_type (file, TREE_TYPE (op0), false, false);
            fputs (")", file);
          }
        else
          {
            internal_error ("\n\nVIEW_CONVERT_EXPR not supported on '%s'\n",
                            tree_code_name[TREE_CODE (TREE_TYPE (node))]);
          }
      }
      break;

    case REALPART_EXPR:
    case IMAGPART_EXPR:
      {
        tree cplx_type = TREE_TYPE (TREE_OPERAND (node, 0));
        op0 = TREE_OPERAND (node, 0);

        gcc_assert (TREE_CODE (cplx_type) == COMPLEX_TYPE);

        gen_cil_node (file, op0);
        fputs ("\n\tcall ", file);
        dump_type (file, TREE_TYPE (node), false, false);
        fputs (" [gcc4net]gcc4net.", file);
        dump_complex_type (file, cplx_type, false);
        fputs ("::", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("_", file);
        if (TREE_CODE (node) == REALPART_EXPR)
          fputs ("Re(", file);
        else
          fputs ("Im(", file);
        dump_complex_type(file, cplx_type, true);
        fputs (") ", file);
        stack_pop (1);
        stack_push (1);
      }
      break;

    case COMPLEX_EXPR:
      {
        tree cplx_type = TREE_TYPE (node);
        op0 = TREE_OPERAND (node, 0);
        op1 = TREE_OPERAND (node, 1);
        gen_cil_node (file, op0);
        gen_cil_node (file, op1);
        fputs ("\n\tcall ", file);
        dump_complex_type (file, cplx_type, true);
        fputs (" [gcc4net]gcc4net.", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("::", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("_ctor (", file);
        dump_type (file, TREE_TYPE (op0), false, false);
        fputs (", ", file);
        dump_type (file, TREE_TYPE (op0), false, false);
        fputs (")", file);
        stack_pop (2);
        stack_push (1);
      }
      break;

    case ENUMERAL_TYPE:
    case ARRAY_TYPE:
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
    case VOID_TYPE:
    case INTEGER_TYPE:
    case REAL_TYPE:
    case COMPLEX_TYPE:
    case VECTOR_TYPE:
    case BOOLEAN_TYPE:
    case POINTER_TYPE:
    case REFERENCE_TYPE:
      internal_error ("gen_cil_node does not support TYPE nodes,"
                      " to dump Type name use dump_type.\n");
      break;

    default:
      internal_error ("\n\nUnsupported tree in CIL generation: '%s'\n",
                      tree_code_name[TREE_CODE (node)]);
      break;
    }
}

static void
gen_cil_modify_expr (FILE *file, tree lhs, tree rhs)
{
  switch (TREE_CODE (lhs))
    {
    case SSA_NAME:
      gcc_assert (0);
      break;

    case REALPART_EXPR:
    case IMAGPART_EXPR:
      {
        tree cplx_op = TREE_OPERAND (lhs, 0);
        tree cplx_type = TREE_TYPE (cplx_op);

        gen_addr_expr (file, cplx_op);
        gen_cil_node (file, rhs);

        fputs ("\n\tcall instance void [gcc4net]gcc4net.", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("::", file);
        dump_complex_type(file, cplx_type, false);
        fputs ("_set_", file);
        if (TREE_CODE (lhs) == REALPART_EXPR)
          fputs ("Re(", file);
        else
          fputs ("Im(", file);
        dump_type (file, TREE_TYPE (lhs), false, false);
        fputs (")", file);
        stack_pop (2);
      }
      break;

    case INDIRECT_REF:
    case ARRAY_REF:
    case COMPLEX_EXPR:
      gen_addr_expr (file, lhs);
      gen_cil_node (file, rhs);

      if (TREE_THIS_VOLATILE (lhs))
        fputs ("\n\tvolatile.", file);

      if (AGGREGATE_TYPE_P (TREE_TYPE (lhs)) ||
          TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE ||
          TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE)
        {
          fputs ("\n\tstobj\t", file);
          dump_type (file, TREE_TYPE (lhs), true, false);
        }
      else
        {
          fputs ("\n\tstind.", file);
          print_type_suffix (file, TREE_TYPE (lhs), false);
        }

      stack_pop (2);
      break;

    case VAR_DECL:
      mark_referenced_type (TREE_TYPE (lhs));

      if (!DECL_FILE_SCOPE_P (lhs))
        {
          if (TREE_THIS_VOLATILE (lhs))
            {
              /* put the address of the loc on the stack */
              fputs ("\n\tldloca\t", file);
              dump_decl_name (file, lhs);
              stack_push (1);
              /* put the value */
              gen_cil_node (file, rhs);
              /* and emit a volatile stind or stobj */
              fputs ("\n\tvolatile.", file);
              if (AGGREGATE_TYPE_P (TREE_TYPE (lhs)) ||
                  TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE ||
                  TREE_CODE (TREE_TYPE (lhs)) == VECTOR_TYPE)
                {
                  fputs ("\n\tstobj\t", file);
                  dump_type (file, TREE_TYPE (lhs), true, false);
                }
              else
                {
                  fputs ("\n\tstind.", file);
                  print_type_suffix (file, TREE_TYPE (lhs), true);
                }
              stack_pop (2);
            }
          else
            {
              gen_cil_node (file, rhs);
              fputs ("\n\tstloc\t", file);
              dump_decl_name (file, lhs);
              stack_pop (1);
            }
        }
      else
        {
          gen_cil_node (file, rhs);
          if (TREE_THIS_VOLATILE (lhs))
            fputs ("\n\tvolatile.", file);
          fputs ("\n\tstsfld\t", file);
          dump_type (file, TREE_TYPE (lhs), true, false);
          fputs (" ", file);
          if (TARGET_EMIT_EXTERNAL_ASSEMBLY && DECL_EXTERNAL (lhs))
            fputs ("[ExternalAssembly]ExternalAssembly::", file);
          dump_decl_name (file, lhs);
          stack_pop (1);
        }
      break;

    case PARM_DECL:
      gen_cil_node (file, rhs);
      fputs ("\n\tstarg\t", file);
      dump_decl_name (file, lhs);
      stack_pop (1);
      break;

    case COMPONENT_REF:
      {
        tree obj = TREE_OPERAND (lhs, 0);
        tree fld = TREE_OPERAND (lhs, 1);
        tree obj_type = TYPE_MAIN_VARIANT (TREE_TYPE (obj));
        tree fld_type = TREE_TYPE (fld);

        gcc_assert (TREE_CODE (fld) == FIELD_DECL);
        gcc_assert (! DECL_BIT_FIELD (fld));

        gen_addr_expr (file, obj);
        gen_cil_node (file, rhs);
        mark_referenced_type (obj_type);
        if (TREE_THIS_VOLATILE (lhs))
          fputs ("\n\tvolatile.", file);
        fputs ("\n\tstfld\t", file);
        dump_type (file, fld_type, true, false);
        fputs (" ", file);
        dump_valuetype_name (file, obj_type);
        fputs ("::", file);
        dump_decl_name (file, fld);
        stack_pop (2);
      }
      break;

    default:
      fprintf (stderr, "CIL: Cannot handle lhs: ");
      debug_generic_expr (lhs);
      gcc_assert (0);
    }
}

/* Warning: these strings are not null-terminated */
static char *
append_string (char *str, const char *to_append,
               unsigned int *len, unsigned int *max_len)
{
  size_t i, orig_len = *len;
  size_t append_len = strlen (to_append);

  *len += append_len;

  if (*len > *max_len)
    {
      while (*len > *max_len)
        *max_len *= 2;
      str = (char *)xrealloc (str, *max_len);
    }

  for (i=0; i < append_len; ++i)
    str[orig_len + i] = to_append[i];

  return str;
}

/* Warning: these strings are not null-terminated */
static char *
append_coded_type (char *str, tree type,
                   unsigned int *len, unsigned int *max_len)
{
  enum tree_code type_code;

  if (type == NULL_TREE || type == error_mark_node)
    return str;

  type = TYPE_MAIN_VARIANT (type);

  type_code = TREE_CODE (type);

 restartswitch:
  switch (type_code)
    {
    case VOID_TYPE:
      str = append_string (str, "VOID", len, max_len);
      break;

    case INTEGER_TYPE:
      {
        int type_size = TYPE_PRECISION (type);
        char tmp_str[8] = "UI";
        char *tmp_str_ptr = tmp_str;

        snprintf (tmp_str_ptr + 2, 6, "%d", type_size);

        if (!TYPE_UNSIGNED (type))
          ++tmp_str_ptr;

        str = append_string (str, tmp_str_ptr, len, max_len);
      }
      break;

    case BOOLEAN_TYPE:
      str = append_string (str, "B", len, max_len);
      break;

    case REAL_TYPE:
      {
        int type_size = TYPE_PRECISION (type);
        char tmp_str[4] = "F";

        snprintf (tmp_str + 1, 3, "%d", type_size);

        str = append_string (str, tmp_str, len, max_len);
      }
      break;

    case POINTER_TYPE:
      if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
        {
          tree fun_type = TREE_TYPE (type);
          tree args_type = TYPE_ARG_TYPES (fun_type);
/*           bool varargs = TREE_VALUE (tree_last (args_type)) != void_type_node; */
          unsigned int nargs_base = list_length (args_type);
          unsigned int aidx;
          char tmp_str[5] = "FP";

          snprintf (tmp_str + 2, 3, "%d", nargs_base);
          str = append_string (str, tmp_str, len, max_len);

          str = append_string (str, "_", len, max_len);
          str = append_coded_type (str, TREE_TYPE (fun_type), len, max_len);
          str = append_string (str, "_", len, max_len);

          for (aidx=0;aidx<nargs_base;++aidx)
            {
              str = append_string (str, "_", len, max_len);
              str = append_coded_type (str, TREE_VALUE (args_type), len, max_len);
              args_type = TREE_CHAIN (args_type);
            }
        }
      else
        {
          str = append_string (str, "*", len, max_len);
          type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
          type_code = TREE_CODE (type);
          goto restartswitch;
        }
      break;

    case ARRAY_TYPE:
      if (TYPE_DOMAIN (type) && ! ARRAY_TYPE_VARLENGTH (type))
        {
          tree domain = TYPE_DOMAIN (type);
          tree min = TYPE_MIN_VALUE (domain);
          tree max = TYPE_MAX_VALUE (domain);

          str = append_string (str, "[", len, max_len);

          if (ARRAY_TYPE_ZEROLENGTH (type))
            str = append_string (str, "0", len, max_len);
          else if (min && max
              && integer_zerop (min)
              && host_integerp (max, 0))
            {
              unsigned int size = TREE_INT_CST_LOW (max) + 1;
              char tmp_str[32];

              snprintf (tmp_str, 32, "%d", size);
              str = append_string (str, tmp_str, len, max_len);
            }
          else
            str = append_string (str, "unk", len, max_len);

          str = append_string (str, "]", len, max_len);
        }
      else {
        type_code = POINTER_TYPE;
        goto restartswitch;
      }
      type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
      type_code = TREE_CODE (type);
      goto restartswitch;
  
      break;

    case ENUMERAL_TYPE:
    case RECORD_TYPE:
    case UNION_TYPE:
    case QUAL_UNION_TYPE:
      {
        const char *prefix;
        const char *type_str;
        tree type_name;

        /* Give the aggregate a name unless it has it already */
        if (TYPE_NAME (type) == 0)
          {
            tree type_decl = build0 (TYPE_DECL, type);
            DECL_NAME (type_decl) = make_valuetype_identifier (type);
            TYPE_NAME (type) = type_decl;
          }

        type_name = TYPE_NAME (type);

        if (TREE_CODE (type_name) == IDENTIFIER_NODE)
          type_str = IDENTIFIER_POINTER (type_name);
        else
          type_str = IDENTIFIER_POINTER (DECL_NAME (type_name));

        switch (type_code)
          {
          case ENUMERAL_TYPE:
            prefix = "E";
            break;

          case RECORD_TYPE:
            prefix = "S";
            break;

          case UNION_TYPE:
          case QUAL_UNION_TYPE:
            prefix = "UN";
            break;

          default:
            gcc_assert (0);
            prefix = "error";
          }

        str = append_string (str, prefix, len, max_len);
        str = append_string (str, type_str, len, max_len);
      }
      break;

    default:
/*       debug_tree(type); */
/*       gcc_assert (0); */
      str = append_string (str, "unknown", len, max_len);
    }

  return str;
}

/* Compute and return a compact identifier from identifier STR of size LEN.
   Memory is allocated for the compact identifier.
   Store the length of the compact identifier in COMPACT_LEN.   */

static char *
get_compact_identifier (const char *str, size_t len, size_t *compact_len)
{
  char *compact_str;
  size_t i;
  unsigned char buffer[COMPACT_ID_LENGTH / 2];

  gcc_assert (COMPACT_ID_LENGTH % 2 == 0);

  /* If the string is shorter than the length of compact strings,
     then return it unchanged.   */
  if (len <= COMPACT_ID_LENGTH)
    {
      compact_str = (char *)xmalloc (len);
      memcpy (compact_str, str, len);

      *compact_len = len;
      return compact_str;
    }

  /* Fill the buffer */
  memset (buffer, 0, COMPACT_ID_LENGTH / 2);
  for (i=0; i < len; ++i)
    {
      int j = 0;
      unsigned char c = str[i];

      while (true)
        {
          unsigned char tmp_c;

          /* Modify a position in buffer */
          buffer[(i + j) % (COMPACT_ID_LENGTH / 2)] ^= c;

          if (j == COMPACT_ID_LENGTH / 2)
            break;

          /* Rotate c 1-bit right */
          tmp_c = c >> 1;
          tmp_c |= (c & 1) << 7;
          c = tmp_c;

          ++j;
        }
    }

  /* Build the compact string */
  compact_str = (char *)xmalloc (COMPACT_ID_LENGTH);
  for (i=0; i < COMPACT_ID_LENGTH / 2; ++i)
    {
      unsigned char c1, c2;

      c1 = buffer[i] & 0xf;
      c2 = buffer[i] >> 4;

      compact_str[i * 2]     = c1 + ((c1 < 10) ? '0' : 'a' - 10);
      compact_str[i * 2 + 1] = c2 + ((c2 < 10) ? '0' : 'a' - 10);
    }

  /* Return the compact string and its length */
  *compact_len = COMPACT_ID_LENGTH;
  return compact_str;
}

static tree
make_valuetype_identifier (tree t)
{
  size_t tmp_name_max_len = 256;
  size_t tmp_name_len = 0;
  char *tmp_name;
  size_t vt_name_len = 0;
  char *vt_name;
  tree ident;

  tmp_name = (char *)xmalloc (tmp_name_max_len);

  if (TREE_CODE (t) == ENUMERAL_TYPE)
    {
      tree tmp;

      tmp_name = append_string (tmp_name, "enum?",
                                &tmp_name_len, &tmp_name_max_len);

      tmp = TYPE_VALUES (t);

      while (tmp)
        {
          tmp_name = append_string (tmp_name,
                                    IDENTIFIER_POINTER (TREE_PURPOSE (tmp)),
                                    &tmp_name_len, &tmp_name_max_len);
          tmp_name = append_string (tmp_name, "?",
                                    &tmp_name_len, &tmp_name_max_len);
          tmp = TREE_CHAIN (tmp);
        }
    }
  else if (TREE_CODE (t) == ARRAY_TYPE)
    {
      gcc_assert (TYPE_DOMAIN (t) && ! ARRAY_TYPE_VARLENGTH (t));
      tmp_name = append_string (tmp_name, "array?",
                                &tmp_name_len, &tmp_name_max_len);
      tmp_name = append_coded_type (tmp_name, t,
                                    &tmp_name_len, &tmp_name_max_len);
    }
  else
    {
      tree tmp;

      if (TREE_CODE (t) == RECORD_TYPE)
        tmp_name = append_string (tmp_name, "struct?",
                                  &tmp_name_len, &tmp_name_max_len);
      else
        tmp_name = append_string (tmp_name, "union?",
                                  &tmp_name_len, &tmp_name_max_len);

      tmp = TYPE_FIELDS (t);
      while (tmp)
        {
          tree ttype = TREE_TYPE (tmp);

          tmp_name = append_coded_type (tmp_name, ttype,
                                        &tmp_name_len, &tmp_name_max_len);
          tmp_name = append_string (tmp_name, "?",
                                    &tmp_name_len, &tmp_name_max_len);
          if (DECL_NAME (tmp) != 0)
            tmp_name = append_string (tmp_name,
                                      IDENTIFIER_POINTER (DECL_NAME (tmp)),
                                      &tmp_name_len, &tmp_name_max_len);
          else
            /* Unnamed bitfields or unions */
            tmp_name = append_string (tmp_name, "?unnamed",
                                      &tmp_name_len, &tmp_name_max_len);
          tmp_name = append_string (tmp_name, "?",
                                    &tmp_name_len, &tmp_name_max_len);
          tmp = TREE_CHAIN (tmp);
        }
    }

  vt_name = get_compact_identifier (tmp_name, tmp_name_len, &vt_name_len);
  free (tmp_name);

  ident = get_identifier_with_length (vt_name, vt_name_len);
  free (vt_name);

  return ident;
}

static void
print_enum_decl (FILE *file, tree t)
{
  gcc_assert (t != NULL_TREE && TREE_CODE (t) == ENUMERAL_TYPE);

  fputs ("\n.class ", file);

  if (TYPE_FILE_SCOPE_P (t)) fputs ("public  ", file);
  else                       fputs ("private ", file);

  fputs ("sealed serializable ansi ", file);
  dump_valuetype_name (file, t);
  fputs (" extends ['mscorlib']System.Enum\n"
         "{\n", file);

  {
    int type_size = TYPE_PRECISION (t);
    char tmp_str[8] = "int";
    char *base_type_str = tmp_str;
    tree tmp;

    snprintf (base_type_str + 3, 5, "%d", type_size);

    fputs ("\t.field public specialname rtspecialname ", file);

    if (!TYPE_UNSIGNED (t))
      fputs ("unsigned ", file);

    fprintf (file, "%s 'value__'\n", base_type_str);

    tmp = TYPE_VALUES (t);
    while (tmp)
      {
        fputs ("\t.field public static literal ", file);
        dump_type (file, t, false, false);
        fputs (" '", file);
        gcc_assert (TREE_CODE (TREE_PURPOSE (tmp)) == IDENTIFIER_NODE);
        fprintf (file, IDENTIFIER_POINTER (TREE_PURPOSE (tmp)));
        fprintf (file, "' = %s(%ld)\n",
                 base_type_str, TREE_INT_CST_LOW (TREE_VALUE (tmp)));
        tmp = TREE_CHAIN (tmp);
      }
  }

  fputs ("}\n", file);
}

static void
print_array_decl (FILE *file, tree t)
{
  fputs ("\n.class ", file);

  if (TYPE_FILE_SCOPE_P (t)) fputs ("public ", file);
  else                       fputs ("private ", file);

  fputs ("explicit sealed serializable ansi ", file);
  dump_valuetype_name (file, t);
  fputs (" extends ['mscorlib']System.ValueType\n"
         "{\n"
         "\t.custom instance "
         "void [gcc4net]gcc4net.C_Attributes.ArrayType::.ctor() "
         "= (01 00 00 00)\n", file);

  fprintf (file, "\t.size %ld\n", TREE_INT_CST_LOW (TYPE_SIZE_UNIT (t)));
  fputs ("\t.field [0] public specialname ", file);
  dump_type (file, TREE_TYPE (t), false, false);
  fputs (" 'elem__'\n"
         "}\n", file);
}

static void
print_struct_union_decl (FILE *file, tree t)
{
  tree tmp;

  fputs ("\n.class ", file);

  if (TYPE_FILE_SCOPE_P (t)) fputs ("public ", file);
  else                       fputs ("private ", file);

  fputs ("explicit sealed serializable ansi ", file);
  dump_valuetype_name (file, t);
  fputs (" extends ['mscorlib']System.ValueType\n"
         "{\n", file);

  fprintf (file, "\t.size %ld\n", TREE_INT_CST_LOW (TYPE_SIZE_UNIT (t)));

  tmp = TYPE_FIELDS (t);
  while (tmp)
    {

      if (DECL_NAME (tmp) == 0 && DECL_BIT_FIELD (tmp))
        {
          /* Skip unnamed bitfields */
        }
      else
        {
          tree type;
          unsigned int bit_offset = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (tmp));
          unsigned int byte_offset = TREE_INT_CST_LOW (DECL_FIELD_OFFSET (tmp));
          unsigned int offset;


          if (DECL_BIT_FIELD (tmp))
            {
              unsigned int type_size;

              type = DECL_BIT_FIELD_TYPE (tmp);

              gcc_assert (TREE_CODE (TREE_TYPE (tmp)) == INTEGER_TYPE
                          || TREE_CODE (TREE_TYPE (tmp)) == BOOLEAN_TYPE);
              gcc_assert (TREE_CODE (type) == INTEGER_TYPE
                          || TREE_CODE (type) == BOOLEAN_TYPE
                          || TREE_CODE (type) == ENUMERAL_TYPE);

              type_size = TREE_INT_CST_LOW (TYPE_SIZE (type));
              offset = byte_offset + (bit_offset & ~(type_size - 1)) / 8;
            }
          else
            {
              type = TREE_TYPE (tmp);
              gcc_assert (bit_offset % 8 == 0);
              offset = byte_offset + bit_offset / 8;
            }

          fprintf (file, "\t.field [%d] public ", offset);
          dump_type (file, type, false, false);
          fputs (" ", file );
          dump_decl_name (file, tmp);
          fputs ("\n", file);
        }

      tmp = TREE_CHAIN (tmp);
    }

  fputs ("}\n", file);
}

static void
print_valuetype_decl (FILE *file, tree t)
{
  if (t == NULL_TREE || t == error_mark_node)
    return;

  if (!AGGREGATE_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
    return;

  gcc_assert (file != 0);

  gcc_assert (TYPE_MAIN_VARIANT (t) == t);
  gcc_assert (TYPE_NAME (t));

  if (TREE_CODE (t) == ENUMERAL_TYPE)
    print_enum_decl (file, t);
  else if (TREE_CODE (t) == ARRAY_TYPE)
    print_array_decl (file, t);
  else /* struct or union */
    print_struct_union_decl (file, t);

}

  /* The attribute string must be less than 127 characters and
     contain only 7-bit ASCII chars.  No checks though. */
static void
gen_string_custom_attr (FILE *stream, const char* parameter)
{
  int i;
  int len = strlen (parameter);

  if (TARGET_EMIT_GIMPLE_COMMENTS)
    fprintf (stream, "\t// Custom attribute String \"%s\"\n", parameter);

  gcc_assert (len <= 127);

  fprintf (stream, "\t.custom instance void [mscorlib]System.String::.ctor(int8 *) = (01 00 %02x ", len);
  for (i=0; i < len; ++i)
    fprintf (stream, "%02x ", parameter[i]);
  fputs ("00 00)\n", stream);
}


/* Dumps the labels of a switch used for implementing a computed GOTO */

static void
gen_computed_goto (FILE *file, tree node)
{
  unsigned int i;

  if (goto_labels == NULL && taken_labels != 0)
    {
      goto_labels = XNEWVEC (tree, taken_labels);
      pointer_map_traverse (labels_map, fill_goto_labels, goto_labels);
    }

  gen_cil_node (file, node);
  fputs ("\n\tswitch (", file);

  for (i = 0; i < taken_labels; i++)
    {
      dump_label_name (file, goto_labels[i]);

      if (i + 1 < taken_labels)
	fputs (", ", file);
    }

  fputs (")", file);
  stack_pop (1);
}

static void
print_string_decl (FILE *file, tree t)
{
  const char *str;
  int len, len_type, i;

  gcc_assert (TREE_CODE (t) == STRING_CST);
  str = TREE_STRING_POINTER (t);
  len = TREE_STRING_LENGTH (t);

  len_type = TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (t)))) + 1;

  /* Emit the string in readable form as a comment. */
  fputs ("// string: \"", file);
  for (i=0; i < len-1; ++i)
    {
      switch (str[i]) {
      case '\n': fputs ("\\n",  file); break;
      case '"':  fputs ("\"",   file); break;
      default:   fputc (str[i], file); break;
      }
    }
  fputs ("\"\n", file);

  fprintf (file, ".data 'DataStr%u' = bytearray(", get_string_cst_id (t));
  for (i=0; i < len; ++i)
    fprintf (file, "%02x ", (unsigned char)str[i]);
  for (; i < len_type; ++i)
    fputs ("00 ", file);
  fputs (")\n", file);

  fputs (".field private static ", file);
  dump_string_type (file, TREE_TYPE (t));
  fputs (" ", file);
  dump_string_name (file, t);
  fprintf (file, " at 'DataStr%u'\n", get_string_cst_id (t));
}

static void
print_used_strings (FILE *file)
{
  ebitmap used_stringtypes;
  int i, n;

  used_stringtypes = ebitmap_alloc (1);

  i = 0;
  n = VARRAY_ACTIVE_SIZE (referenced_strings);
  for (; i < n; ++i)
    {
      tree str =  VARRAY_TREE (referenced_strings, i);
      unsigned int str_size = TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE(str)))) + 1;
      print_string_decl (file, str);
      ebitmap_set_bit (used_stringtypes, str_size);
    }

  {
    unsigned int str_size;
    ebitmap_iterator it;
    EXECUTE_IF_SET_IN_EBITMAP(used_stringtypes, 0, str_size, it)
      {
        fprintf (file, "\n.class public explicit sealed serializable ansi '?string_type?%d'", str_size);
        fputs (" extends ['mscorlib']System.ValueType\n"
               "{\n"
               "\t.custom instance "
               "void [gcc4net]gcc4net.C_Attributes.ConstStringType::.ctor() "
               "= (01 00 00 00)\n", file);
        fprintf (file, "\t.size %d\n", str_size);
        fputs ("\t.field [0] public specialname int8 'elem__'\n"
               "}\n", file);
      }
  }
}

static void
print_pinvoke_function (FILE *file, tree fun)
{
  tree fun_type = TREE_TYPE (fun);
  struct fnct_attr attributes;

  decode_function_attrs (fun, &attributes);

  fputs (".method ", file);

  if (TREE_PUBLIC (fun)) fputs ("public  ", file);
  else                   fputs ("private ", file);

  fprintf (file, "static pinvokeimpl(\"%s\"", attributes.pinvoke_assembly);

  if (attributes.pinvoke_fname)
    fprintf (file, " as \"%s\"", attributes.pinvoke_fname);

  fputs (") ", file);

  dump_fun_type (file, fun_type, fun, NULL, false);

  fputs (" cil managed {}\n", file);
}

static void
gen_start_function (FILE *stream)
{
  int nargs;
  tree args;
  for (nargs=0,args = DECL_ARGUMENTS (current_function_decl);
       args;
       args = TREE_CHAIN (args),++nargs)
    {
    }

  fputs ("\n.method public static void '.start'(class [mscorlib]System.String[] 'args') cil managed",
         stream);
  fputs ("\n{"
         "\n\t.entrypoint"
         "\n\t.maxstack 3"
         "\n\t.locals (int32 'argc', int8** 'argv', int8** 'env')", stream);
  /* TODO: add startup code*/
  switch (nargs)
    {
    case 0:
      fputs ("\n\tcall\tvoid [gcc4net]gcc4net.StartupHelper::Startup()"
             "\n\tcall\tint32 main()", stream);
      break;

    case 1:
      fputs ("\n\tldloca\t'argc'"
             "\n\tcall\tnative int [gcc4net]gcc4net.StartupHelper::GetArgv(int32&)"
             "\n\tpop"
             "\n\tcall\tvoid [gcc4net]gcc4net.StartupHelper::Startup()"
             "\n\tldloc\t'argc'"
             "\n\tcall\tint32 main(int32)", stream);
      break;

    case 2:
      fputs ("\n\tldloca\t'argc'"
             "\n\tcall\tnative int [gcc4net]gcc4net.StartupHelper::GetArgv(int32&)"
             "\n\tstloc\t'argv'"
             "\n\tcall\tvoid [gcc4net]gcc4net.StartupHelper::Startup()"
             "\n\tldloc\t'argc'"
             "\n\tldloc\t'argv'"
             "\n\tcall\tint32 main(int32, int8**)", stream);
      break;

    case 3:
      fputs ("\n\tldloca\t'argc'"
             "\n\tcall\tnative int [gcc4net]gcc4net.StartupHelper::GetArgv(int32&)"
             "\n\tstloc\t'argv'"
             "\n\tcall\tnative int [gcc4net]gcc4net.StartupHelper::GetEnvVars()"
             "\n\tstloc\t'env'"
             "\n\tcall\tvoid [gcc4net]gcc4net.StartupHelper::Startup()"
             "\n\tldloc\t'argc'"
             "\n\tldloc\t'argv'"
             "\n\tldloc\t'env'"
             "\n\tcall\tint32 main(int32, int8**, int8**)", stream);
      break;

    default:
      gcc_assert (0);
    }

  /* TODO: add exit code*/
  fputs ("\n\tcall\tvoid [gcc4net]gcc4net.StartupHelper::Shutdown(int32)"
         "\n\tret"
         "\n} // .start"
         "\n\n", stream);
}


/* This function is mostly a copy of the last part of 'gen_cil'. */
static void
gen_cil_vcg (FILE *vcg_stream)
{
  block_stmt_iterator bsi;
  edge_iterator ei;
  const char *fun_name = lang_hooks.decl_printable_name (current_function_decl, 1);
  edge e;
  int  i=0;

  fprintf (vcg_stream, "graph: {\n");
  fprintf (vcg_stream, "title: \"%s\"\n",
           lang_hooks.decl_printable_name (current_function_decl, 1));
  fprintf (vcg_stream, "node: { title: \"%sBB%d\" label: \"ENTRY %s\" }\n",
           fun_name, ENTRY_BLOCK, fun_name);
  fprintf (vcg_stream, "node: { title: \"%sBB%d\" label: \"EXIT\" }\n",
           fun_name, EXIT_BLOCK);
  fprintf (vcg_stream, "edge:{sourcename: \"%sBB%d\" targetname: \"%sBB%d\"}\n",
           fun_name, ENTRY_BLOCK,
           fun_name, single_succ (ENTRY_BLOCK_PTR)->index);

  FOR_EACH_BB (bb)
    {
      tree stmt = NULL_TREE;

      fprintf (vcg_stream, "node: { title: \"%sBB%d\" label: \"(BB%d, pos: %d)",
               fun_name, bb->index, bb->index, i++);

      if (bb->loop_depth)
        fprintf (vcg_stream, " LOOP DEPTH %d ", bb->loop_depth);

      for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        {
          stmt = bsi_stmt (bsi);
          if (TARGET_EMIT_GIMPLE_COMMENTS)
            {
              fprintf (vcg_stream, "\n\t [ ");
              print_generic_expr (vcg_stream, stmt, 0);
              fprintf (vcg_stream, " ]");
            }
          gcc_assert (stack == 0);

          if (TREE_CODE (stmt) != NOP_EXPR
              || TREE_CODE (TREE_OPERAND (stmt, 0)) != INTEGER_CST)
            gen_cil_node (vcg_stream, stmt);

          if (TREE_CODE (stmt) == CALL_EXPR)
            {
              tree fun_expr = CALL_EXPR_FN (stmt);
              tree fun_type = TREE_TYPE (TREE_TYPE (fun_expr));

              if (TREE_CODE (TREE_TYPE (fun_type)) != VOID_TYPE)
                {
                  fputs ("\n\tpop", vcg_stream);
                  stack_pop (1);
                }
            }
        }

      if ((!stmt || (TREE_CODE (stmt) != COND_EXPR)) && single_succ_p (bb))
        {
          basic_block succ = single_succ (bb);

          /* The last part of the test (succ != bb->next_bb) is a HACK.  It
             avoids generating a branch to the successor in case of a
             fallthrough. To be fixed when we have a proper layout of basic
             blocks.  Note that branches from COND_EXPR are still generated,
             even to a fallthrough. */
          if ((succ->index != EXIT_BLOCK) && (succ != bb->next_bb))
            {
              tree label = tree_block_label (succ);
              fputs ("\n\tbr\t", vcg_stream);
              dump_label_name (vcg_stream, label);
              gcc_assert (stack == 0);
            }
        }
      fprintf (vcg_stream, "\" }\n");  /* close 'label' clause */

      for (ei = ei_start (bb->succs); ei_cond (ei, &e); ei_next (&ei))
        {
          if (e->flags & EDGE_DFS_BACK)
            fprintf (vcg_stream, "backedge: { color: red");
          else if (e->flags & EDGE_LOOP_EXIT)
            fprintf (vcg_stream, "edge: { color: blue");
          else
            fprintf (vcg_stream, "edge: {");

          fprintf (vcg_stream, " label:\"%d", e->probability);

          if (e->flags & EDGE_LOOP_EXIT)
            fprintf (vcg_stream, " loop_exit");

          fprintf (vcg_stream, "\"");

          fprintf (vcg_stream,
                   " sourcename: \"%sBB%d\" targetname: \"%sBB%d\" }\n",
                   fun_name, bb->index, fun_name, e->dest->index);
        }
    }
  fprintf (vcg_stream, "}\n");
}


static void
gen_cil_1 (FILE *stream)
{
  block_stmt_iterator bsi;
  bool varargs = FALSE;
  tree args;

  if (!TARGET_NO_STLOC_LDLOC_REMOVAL)
    remove_stloc_ldloc ();

  FOR_EACH_BB (bb)
    {
      for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        {
          tree stmt = bsi_stmt (bsi);

          /* Record the address taken labels. */
          if (TREE_CODE (stmt) == LABEL_EXPR)
            {
              tree label = LABEL_EXPR_LABEL (stmt);
              /* Check if the label has its address taken. */
              if (FORCED_LABEL (label))
                {
		  void **slot;

		  gcc_assert (pointer_map_contains (labels_map, label) == NULL);
		  slot = pointer_map_insert (labels_map, label);
		  *slot = build_int_cst (intSI_type_node, taken_labels);
		  taken_labels++;
                }
            }
        }
    }

  /* Make sure that every bb has a label */
  FOR_EACH_BB (bb)
    {
      tree_block_label (bb);
    }

  stack_reset ();
  max_stack = 0;

  if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
    gen_start_function (stream);

  {
    tree var, cell;

    for (cell = cfun->unexpanded_var_list;
         cell;
         cell = TREE_CHAIN (cell))
      {
        var = TREE_VALUE (cell);

        if (TREE_STATIC (var) && TREE_ASM_WRITTEN (var) == 0)
          make_decl_cil (stream, var);
      }
  }

  {
    tree args_type = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));

    if (args_type != NULL)
      {
        while (TREE_CHAIN (args_type))
          args_type = TREE_CHAIN (args_type);

        if (TREE_VALUE (args_type) != void_type_node)
          varargs = TRUE;
      }
  }

  fputs ("\n.method ", stream);

  if (TREE_PUBLIC (current_function_decl))
    fputs ("public ", stream);
  else
    fputs ("private ", stream);

  fputs ("static ", stream);
  if (varargs)
    fputs ("vararg ", stream);
  dump_type (stream, TREE_TYPE (TREE_TYPE (current_function_decl)), true, false);
  fprintf (stream, " '%s' (",
           lang_hooks.decl_printable_name (current_function_decl, 1));

  args = DECL_ARGUMENTS (current_function_decl);

  if (cfun->static_chain_decl)
    {
      dump_type (stream, DECL_ARG_TYPE (cfun->static_chain_decl), true, true);
      fputs (" ", stream);
      dump_decl_name (stream, cfun->static_chain_decl);
      if (args)
        fputs (", ", stream);
    }


  while (args)
    {
      dump_type (stream, DECL_ARG_TYPE (args), true, true);
      fputs (" ", stream);
      dump_decl_name (stream, args);
      args = TREE_CHAIN (args);

      if (args)
        fputs (", ", stream);
      else  if (varargs)
        fputs (", ...", stream);
    }

  fputs (") cil managed"
         "\n{", stream);

  fputs ("\n\t.locals (", stream);
  {
    tree var, cell;
    bool first = true;

    for (cell = cfun->unexpanded_var_list;
         cell;
         cell = TREE_CHAIN (cell))
      {
        var = TREE_VALUE (cell);
        if (!TREE_STATIC (var))
          {
            if (!first)
              fputs (", ", stream);
            first = false;
            dump_type (stream, TREE_TYPE (var), true, false);
            fputs (" ", stream);
            dump_decl_name (stream, var);
          }
      }
  }
  fputs (")\n", stream);

  if (DECL_STATIC_CONSTRUCTOR (current_function_decl))
    {
      /* For the time being this attribute is a String. */
      gen_string_custom_attr (stream, "initfun");

      if (TARGET_OPENSYSTEMC)
        fputs ("\t.custom instance "
               "void ['OpenSystem.C']'OpenSystem.C'.InitializerAttribute::.ctor() "
               "= (01 00 00 00)\n", stream);
    }

  {
    struct fnct_attr attributes;
    decode_function_attrs (current_function_decl, &attributes);
    if (attributes.cusattr_string)
      gen_string_custom_attr (stream, attributes.cusattr_string);
  }

  FOR_EACH_BB (bb)
    {
      tree stmt = NULL_TREE;

      if (TARGET_EMIT_GIMPLE_COMMENTS)
        {
          fprintf (stream, "\n\n\t/* Basic block frequency: %d */",
                   bb->frequency * 100 / BB_FREQ_MAX);
        }

      for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        {
          stmt = bsi_stmt (bsi);
          if (TARGET_EMIT_GIMPLE_COMMENTS)
            {
              fprintf (stream, "\n\t/* ");
              print_generic_expr (stream, stmt, 0);
              fprintf (stream, " */");
            }
          gcc_assert (stack == 0);

          if (TREE_CODE (stmt) != NOP_EXPR
              || TREE_CODE (TREE_OPERAND (stmt, 0)) != INTEGER_CST)
            gen_cil_node (stream, stmt);

          if (TREE_CODE (stmt) == CALL_EXPR)
            {
              tree fun_expr = CALL_EXPR_FN (stmt);
              tree fun_type = TREE_TYPE (TREE_TYPE (fun_expr));

              if (TREE_CODE (TREE_TYPE (fun_type)) != VOID_TYPE)
                {
                  fputs ("\n\tpop", stream);
                  stack_pop (1);
                }
            }
        }

      if ((!stmt || (TREE_CODE (stmt) != COND_EXPR)) && single_succ_p (bb))
        {
          basic_block succ = single_succ (bb);

          /* The last part of the test (succ != bb->next_bb) is a HACK.  It
             avoids generating a branch to the successor in case of a
             fallthrough. To be fixed when we have a proper layout of basic
             blocks.   */
          if ((succ->index != EXIT_BLOCK) && (succ != bb->next_bb))
            {
              tree label = tree_block_label (succ);
              fputs ("\n\tbr\t", stream);
              dump_label_name (stream, label);
              gcc_assert (stack == 0);
            }
        }

      if (TARGET_EMIT_GIMPLE_COMMENTS)
        {
          edge e;
          edge_iterator ei;

          fputs ("\n\t/* Edge probabilities: ", stream);
          FOR_EACH_EDGE (e, ei, bb->succs)
            {
              dump_entry_label_name (stream, e->dest);
              fprintf (stream, ": %d ", e->probability * 100 / REG_BR_PROB_BASE);
            }
          fputs ("*/", stream);
        }
    }

  if (TARGET_EMIT_JIT_COMPILATION_HINTS)
    {
      basic_block_frequency_emit (stream);
      branch_probability_emit_and_reset (stream);
    }

  fprintf (stream, "\n\t.maxstack %d\n", max_stack);
  fprintf (stream, "\n} // %s\n",
           lang_hooks.decl_printable_name (current_function_decl, 1));
  TREE_ASM_WRITTEN (current_function_decl) = 1;
}

static void
create_init_method (void)
{
  struct function *current_cfun = cfun;
  tree fun_type;
  tree fun_decl;
  tree init_expr = NULL;
  tree result;

  fun_type = build_function_type (void_type_node, void_list_node);
  fun_decl = build_decl (FUNCTION_DECL, get_identifier ("COBJ?init"), fun_type);

  result = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
  DECL_ARTIFICIAL (result) = 1;
  DECL_IGNORED_P (result) = 1;
  DECL_RESULT (fun_decl) = result;

  /* Allocate memory for the function structure.  The call to
     allocate_struct_function clobbers CFUN, so we need to restore
     it afterward.  */
  allocate_struct_function (fun_decl);
/*   DECL_SOURCE_LOCATION (fun_decl) = DECL_SOURCE_LOCATION (decl); */
/*   cfun->function_end_locus = DECL_SOURCE_LOCATION (decl); */


  TREE_STATIC (fun_decl) = 1;
  TREE_USED (fun_decl) = 1;
  DECL_ARTIFICIAL (fun_decl) = 1;
  DECL_IGNORED_P (fun_decl) = 0;
  TREE_PUBLIC (fun_decl) = 0;
  DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fun_decl) = 1;
  DECL_UNINLINABLE (fun_decl) = 1;
  DECL_EXTERNAL (fun_decl) = 0;
  DECL_STATIC_CONSTRUCTOR (fun_decl) = 1;
  DECL_CONTEXT (fun_decl) = NULL_TREE;
  DECL_INITIAL (fun_decl) = make_node (BLOCK);

  {
    int i, n;

    i = 0;
    n = VARRAY_ACTIVE_SIZE (pending_ctors);
    while (i<n)
      {
        for (; i < n; ++i)
          {
            tree decl = VARRAY_TREE (pending_ctors, i);
            tree init = DECL_INITIAL (decl);

            DECL_INITIAL (decl) = NULL_TREE;

            expand_init_to_stmt_list (decl, init, &init_expr);

          }
        n = VARRAY_ACTIVE_SIZE (pending_ctors);
      }
  }
  DECL_SAVED_TREE (fun_decl) = init_expr;

  gimplify_function_tree (fun_decl);
  tree_lowering_passes (fun_decl);
  tree_rest_of_compilation (fun_decl);

  /* Restore the current function */
  cfun = current_cfun;
}

void
make_decl_cil (FILE *stream, tree decl)
{
  if (TREE_CODE (decl) == VAR_DECL && (TREE_STATIC (decl) || TREE_PUBLIC (decl)))
    {
      tree init = DECL_INITIAL (decl);

      fputs ("\n.field ", stream);

      if (TREE_PUBLIC (decl))
        fputs ("public  ", stream);
      else
        fputs ("private ", stream);

      fputs ("static ", stream);
      dump_type (stream, TREE_TYPE (decl), true, false);
      fputs (" ", stream);
      dump_decl_name (stream, decl);
      fputs ("\n", stream);

      if (init && init != error_mark_node)
        VARRAY_PUSH_TREE (pending_ctors, decl);

      TREE_ASM_WRITTEN (decl) = 1;
    }
}

void
gen_cil_init (void)
{
  FILE *stream = asm_out_file;

  fputs (".assembly extern gcc4net {}\n", stream);
  if (TARGET_EMIT_EXTERNAL_ASSEMBLY)
    fputs (".assembly '_C_MONO_ASSEMBLY' {}\n", stream);
  fputs (".module '<Module>'\n", stream);

  if (TARGET_OPENSYSTEMC)
    fputs (".custom instance "
           "void ['OpenSystem.C']'OpenSystem.C'.ModuleAttribute::.ctor() "
           "= (01 00 00 00)\n", stream);

  referenced_types = pointer_set_create ();
  VARRAY_TREE_INIT (referenced_strings, 32, "strings used in current unit");
  referenced_string_ptrs = pointer_set_create ();
  referenced_pinvoke = pointer_set_create ();
  VARRAY_TREE_INIT (pending_ctors, 32, "pending ctors");

  /* Allocate hash table for pointer ids */
  pointer_id_htable = htab_create (256,
                                   pointer_id_data_hash,
                                   pointer_id_data_eq,
                                   free);

  labels_map = pointer_map_create ();
  taken_labels = 0;

  if (TARGET_EMIT_VCG)
    fprintf (stdout, "graph: {\ndisplay_edge_labels: yes\n");
}

void
gen_cil_fini (void)
{
  FILE *stream = asm_out_file;
  struct pointer_set_iter_t it;

  if (VARRAY_ACTIVE_SIZE (pending_ctors) > 0)
    {
      create_init_method ();
    }
  VARRAY_CLEAR (pending_ctors);

  if (VARRAY_ACTIVE_SIZE (referenced_strings) > 0)
    {
      print_used_strings (stream);
    }
  VARRAY_CLEAR (referenced_strings);
  pointer_set_destroy (referenced_string_ptrs);

  /* There may be distinct tree types that correspond to identical types.
     In order not to slow down mark_referenced_type(...) function (which
     may typically be called several times for the same type), insertion
     of types in the mark set makes only sure that the same tree type
     pointer is not inserted twice. As a consequence, there may still be
     distinct tree types that correspond to identical types in the
     reference type set.
     Hence, before emitting a type, make sure no type with the same name
     has already been emitted.  */

  {
    struct pointer_set_t *emitted_types = pointer_set_create ();

    it = pointer_set_begin (referenced_types);
    while (!POINTER_SET_ITER_IS_END (it))
      {
        tree type = (tree)POINTER_SET_ITER_ELEM (it);

        if (COMPLETE_TYPE_P (type))
          {
            tree type_name = TYPE_NAME (type);
            gcc_assert (DECL_P (type_name)
                        || TREE_CODE (type_name) == IDENTIFIER_NODE);
            
            if (TREE_CODE (type_name) != IDENTIFIER_NODE)
              type_name = DECL_NAME (type_name);
            
            if (!pointer_set_contains (emitted_types, type_name))
              {
                print_valuetype_decl (stream, type);
                pointer_set_insert (emitted_types, type_name);
              }
          }
        
        it = pointer_set_next (referenced_types, it);
      }
    pointer_set_destroy (referenced_types);
    pointer_set_destroy (emitted_types);
  }

  it = pointer_set_begin (referenced_pinvoke);
  while (!POINTER_SET_ITER_IS_END (it))
    {
      print_pinvoke_function (stream, (tree)POINTER_SET_ITER_ELEM (it));
      it = pointer_set_next (referenced_pinvoke, it);
    }
  pointer_set_destroy (referenced_pinvoke);

  /* Delete hash table for pointer ids */
  htab_delete (pointer_id_htable);

  pointer_map_destroy (labels_map);

  if (goto_labels != NULL)
    XDELETEVEC (goto_labels);

  if (TARGET_EMIT_VCG)
    fprintf (stdout, "}\n");
}

static bool
gen_cil_gate (void)
{
  return current_function_decl != NULL;
}

static unsigned int
gen_cil (void)
{
  gen_cil_1 (asm_out_file);

  if (TARGET_EMIT_VCG)
    gen_cil_vcg(stdout);

  return 0;
}

/* Define the parameters of the gen-CIL pass.  */

struct tree_opt_pass pass_gen_cil =
{
  "cil",                                /* name */
  gen_cil_gate,                         /* gate */
  gen_cil,                              /* execute */
  NULL,                                 /* sub */
  NULL,                                 /* next */
  0,                                    /* static_pass_number */
  TV_REST_OF_COMPILATION,               /* tv_id */
  PROP_cfg,                             /* properties_required */
  0,                                    /* properties_provided */
  /* ??? If TER is enabled, we also kill gimple.  */
  0,                                    /* properties_destroyed */
  0,
  0,
  0                                     /* letter */
};

#include "gt-gen-cil.h"

/*
 * Local variables:
 * eval: (c-set-style "gnu")
 * End:
 */