summaryrefslogtreecommitdiff
path: root/cgsas.c
blob: 9f60c7eb68c090b02ffffcd74d9f6aae4f7cf8f1 (plain) (blame)
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
/*
	File:		cgsas.c
	Author:		John van Groningen
	Machine:	Sun 4
	At:			University of Nijmegen
*/

#include <stdio.h>
#include <string.h>

#define ELF_TARGET_SPARC
#include <elf.h>

#define ELF
#undef ALIGN_REAL_ARRAYS

#include "cgport.h"
#include "cgrconst.h"
#include "cgtypes.h"
#include "cg.h"
#include "cgiconst.h"
#include "cgcode.h"
#include "cgswas.h"

#ifdef ALIGN_REAL_ARRAYS
# define LOAD_STORE_ALIGNED_REAL 4
#endif

#define FUNCTION_LEVEL_LINKING

#define for_l(v,l,n) for(v=(l);v!=NULL;v=v->n)

#define U4(s,v1,v2,v3,v4) s->v1;s->v2;s->v3;s->v4
#define U5(s,v1,v2,v3,v4,v5) s->v1;s->v2;s->v3;s->v4;s->v5

#define IO_BUFFER_SIZE 16384
#define BUFFER_SIZE 4096

struct object_buffer {
	struct object_buffer *	next;
	int						size;
	unsigned char			data [BUFFER_SIZE];
};

#define BRANCH_RELOCATION 0
#define CALL_RELOCATION 1
#define LONG_WORD_RELOCATION 2
#define HI22_RELOCATION 3
#define LO12_RELOCATION 4
#ifdef FUNCTION_LEVEL_LINKING
# define DUMMY_BRANCH_RELOCATION 5
#endif

#ifdef FUNCTION_LEVEL_LINKING
# define TEXT_LABEL_ID (0x7fff-2)
# define DATA_LABEL_ID (0x7fff-3)
#else
# define TEXT_LABEL_ID 1
# define DATA_LABEL_ID 2
#endif

#define CODE_CONTROL_SECTION 0
#define DATA_CONTROL_SECTION 1
#define IMPORTED_LABEL 2
#define EXPORTED_CODE_LABEL 3
#define EXPORTED_DATA_LABEL 4

struct object_label {
	struct object_label *	next;
	union {
		unsigned long		offset;			/* CODE_CONTROL_SECTION,DATA_CONTROL_SECTION */
		struct label *		label;			/* IMPORTED_LABEL,EXPORTED_CODE_LABEL */
	} object_label_u1;
	union {
		unsigned long		length;			/* CODE_CONTROL_SECTION,DATA_CONTROL_SECTION */
		unsigned long		string_offset;	/* IMPORTED_LABEL,EXPORTED_CODE_LABEL */
	} object_label_u2;
	int						object_label_number;
#ifdef FUNCTION_LEVEL_LINKING
	int						object_label_n_relocations;	/* CODE_CONTROL_SECTION,DATA_CONTROL_SECTION */
	short					object_label_section_n;		/* CODE_CONTROL_SECTION,DATA_CONTROL_SECTION */
#endif
	unsigned char			object_label_kind;
	unsigned char			object_section_align8;
};

#define object_label_offset object_label_u1.offset
#define object_label_label object_label_u1.label

#define object_label_length object_label_u2.length
#define object_label_string_offset object_label_u2.string_offset

struct relocation {
	struct relocation *		next;
	unsigned long			relocation_offset;
	struct label *			relocation_label;
	long					relocation_addend;
#ifdef FUNCTION_LEVEL_LINKING
	struct object_label	*	relocation_object_label;	/* for BRANCH_RELOCATION, CALL_RELOCATION and DUMMY_BRANCH_RELOCATION */
#endif
	short					relocation_kind;
};

static FILE *output_file;

static int n_code_relocations,n_data_relocations;
static struct object_label *code_object_label,*data_object_label;

static struct relocation *first_code_relocation,**last_code_relocation_l;
static struct relocation *first_data_relocation,**last_data_relocation_l;

static struct object_buffer *first_code_buffer,*current_code_buffer;
static int code_buffer_free,code_buffer_offset;
static unsigned int *code_buffer_p;

static struct object_buffer *first_data_buffer,*current_data_buffer;
static int data_buffer_free,data_buffer_offset;
static unsigned int *data_buffer_p;

static void initialize_buffers (void)
{
	struct object_buffer *new_code_buffer,*new_data_buffer;
	
	new_code_buffer=memory_allocate_type (struct object_buffer);
	
	new_code_buffer->size=0;
	new_code_buffer->next=NULL;
	
	first_code_buffer=new_code_buffer;
	current_code_buffer=new_code_buffer;
	code_buffer_offset=0;
	
	code_buffer_free=BUFFER_SIZE;
	code_buffer_p=(unsigned int*)new_code_buffer->data;

	new_data_buffer=memory_allocate_type (struct object_buffer);
	
	new_data_buffer->size=0;
	new_data_buffer->next=NULL;
	
	first_data_buffer=new_data_buffer;
	current_data_buffer=new_data_buffer;
	data_buffer_offset=0;
	
	data_buffer_free=BUFFER_SIZE;
	data_buffer_p=(unsigned int*)new_data_buffer->data;
}

static void store_instruction2 (int c)
{
	struct object_buffer *new_buffer;

	current_code_buffer->size=BUFFER_SIZE;

	new_buffer=memory_allocate_type (struct object_buffer);

	new_buffer->size=0;
	new_buffer->next=NULL;

	current_code_buffer->next=new_buffer;
	current_code_buffer=new_buffer;
	code_buffer_offset+=BUFFER_SIZE;

	code_buffer_free=BUFFER_SIZE-4;
	code_buffer_p=(unsigned int*)new_buffer->data;

	*code_buffer_p++=c;
}

static void store_instruction (int c)
{
	if (code_buffer_free>=4){
		code_buffer_free-=4;
		*code_buffer_p++=c;
	} else
		store_instruction2 (c);
}

static void store_long_word_in_data_section2 (ULONG c)
{
	struct object_buffer *new_buffer;

	current_data_buffer->size=BUFFER_SIZE;

	new_buffer=memory_allocate_type (struct object_buffer);

	new_buffer->size=0;
	new_buffer->next=NULL;

	current_data_buffer->next=new_buffer;
	current_data_buffer=new_buffer;
	data_buffer_offset+=BUFFER_SIZE;

	data_buffer_free=BUFFER_SIZE-4;
	data_buffer_p=(unsigned int*)new_buffer->data;

	*data_buffer_p++=c;
}

void store_long_word_in_data_section (ULONG c)
{
	if (data_buffer_free>=4){
		data_buffer_free-=4;
		*data_buffer_p++=c;
	} else
		store_long_word_in_data_section2 (c);
}

void store_2_words_in_data_section (UWORD w1,UWORD w2)
{
	store_long_word_in_data_section ((w1<<16) | ((UWORD)w2));
}

static void flush_code_buffer (void)
{
	current_code_buffer->size=BUFFER_SIZE-code_buffer_free;
	code_buffer_offset+=BUFFER_SIZE-code_buffer_free;
}

static void flush_data_buffer (void)
{
	current_data_buffer->size=BUFFER_SIZE-data_buffer_free;
	data_buffer_offset+=BUFFER_SIZE-data_buffer_free;
}

static void write_buffers_and_release_memory (struct object_buffer **first_buffer_l)
{
	struct object_buffer *buffer,*next_buffer;
	
	for (buffer=*first_buffer_l; buffer!=NULL; buffer=next_buffer){
		int size;
		
		size=buffer->size;
		
		if (fwrite (buffer->data,1,size,output_file)!=size)
			error ("Write error");
		
		next_buffer=buffer->next;
		
		memory_free (buffer);
	}
	
	*first_buffer_l=NULL;
}

void store_abc_string_in_data_section (char *string,int length)
{
	unsigned char *string_p;
	
	string_p=(unsigned char*)string;
	store_long_word_in_data_section (length);
	
	while (length>=4){
		store_long_word_in_data_section (*(ULONG*)string_p);
		string_p+=4;
		length-=4;
	}
	
	if (length>0){
		ULONG d;
		int shift;
				
		d=0;
		shift=24;
		while (length>0){
			d |= string_p[0]<<shift;
			shift-=8;
			--length;
			++string_p;
		}
		store_long_word_in_data_section (d);
	}
} 

void store_c_string_in_data_section (char *string,int length)
{
	unsigned char *string_p;
	ULONG d;
	int shift;
	
	string_p=(unsigned char*)string;
	
	while (length>=4){
		store_long_word_in_data_section (*(ULONG*)string_p);
		string_p+=4;
		length-=4;
	}
			
	d=0;
	shift=24;
	while (length>0){
		d |= string_p[0]<<shift;
		shift-=8;
		--length;
		++string_p;
	}
	store_long_word_in_data_section (d);
}

#define CURRENT_CODE_OFFSET (code_buffer_offset+((unsigned char*)code_buffer_p-current_code_buffer->data))
#define CURRENT_DATA_OFFSET (data_buffer_offset+((unsigned char*)data_buffer_p-current_data_buffer->data))

static struct object_label *first_object_label,**last_object_label_l;
#ifdef FUNCTION_LEVEL_LINKING
static int n_code_sections,n_data_sections;
#endif

#ifdef FUNCTION_LEVEL_LINKING
void as_new_data_module (void)
{
	struct object_label *new_object_label;
	unsigned long current_data_offset;
	int data_section_label_number;
	
	new_object_label=fast_memory_allocate_type (struct object_label);
	data_object_label=new_object_label;

	data_section_label_number=0;
	current_data_offset=CURRENT_DATA_OFFSET;

	*last_object_label_l=new_object_label;
	last_object_label_l=&new_object_label->next;
	new_object_label->next=NULL;
	
	new_object_label->object_label_offset=current_data_offset;
	new_object_label->object_label_number=data_section_label_number;
	new_object_label->object_label_section_n=n_data_sections;
	++n_data_sections;
	new_object_label->object_label_length=0;
	new_object_label->object_label_kind=DATA_CONTROL_SECTION;
	new_object_label->object_section_align8=0;
}

static void as_new_code_module (void)
{
	struct object_label *new_object_label;
	unsigned long current_code_offset;
	int code_section_label_number;
	
	new_object_label=fast_memory_allocate_type (struct object_label);
	code_object_label=new_object_label;

	code_section_label_number=0;
	current_code_offset=CURRENT_CODE_OFFSET;

	*last_object_label_l=new_object_label;
	last_object_label_l=&new_object_label->next;
	new_object_label->next=NULL;
	
	new_object_label->object_label_offset=current_code_offset;
	new_object_label->object_label_number=code_section_label_number;
	new_object_label->object_label_section_n=n_code_sections;
	++n_code_sections;
	new_object_label->object_label_length=0;
	new_object_label->object_label_kind=CODE_CONTROL_SECTION;
}
#endif

static void store_label_plus_offset_in_data_section (LABEL *label,int offset)
{
	struct relocation *new_relocation;

	store_long_word_in_data_section (0);

	new_relocation=fast_memory_allocate_type (struct relocation);
	++n_data_relocations;
	
	*last_data_relocation_l=new_relocation;
	last_data_relocation_l=&new_relocation->next;
	new_relocation->next=NULL;
	
	new_relocation->relocation_label=label;
	new_relocation->relocation_offset=CURRENT_DATA_OFFSET-4;
	new_relocation->relocation_kind=LONG_WORD_RELOCATION;
	new_relocation->relocation_addend=offset;
}

static int n_object_labels;

static unsigned long string_table_offset;

void define_data_label (LABEL *label)
{
	label->label_id=DATA_LABEL_ID;
#ifdef FUNCTION_LEVEL_LINKING
	label->label_object_label=data_object_label;
#endif
	label->label_offset=CURRENT_DATA_OFFSET;	

	if (label->label_flags & EXPORT_LABEL){
		struct object_label *new_object_label;
		int string_length;
		
		new_object_label=fast_memory_allocate_type (struct object_label);
		*last_object_label_l=new_object_label;
		last_object_label_l=&new_object_label->next;
		new_object_label->next=NULL;
		
		new_object_label->object_label_label=label;
#if defined (RELOCATIONS_RELATIVE_TO_EXPORTED_DATA_LABEL) && defined (FUNCTION_LEVEL_LINKING)
		new_object_label->object_label_number = n_object_labels;
#endif 

		++n_object_labels;

		string_length=strlen (label->label_name);
		new_object_label->object_label_string_offset=string_table_offset;
		string_table_offset+=string_length+1;

#if defined (RELOCATIONS_RELATIVE_TO_EXPORTED_DATA_LABEL) && defined (FUNCTION_LEVEL_LINKING)
		label->label_object_label=new_object_label;	
		new_object_label->object_label_section_n = data_object_label->object_label_section_n;
#endif

		new_object_label->object_label_kind=EXPORTED_DATA_LABEL;
	}
}

static void as_labels (struct block_label *labels)
{
	for (; labels!=NULL; labels=labels->block_label_next)
#if 0
		if (labels->block_label_label->label_number==0)
#endif
		{
			LABEL *label;
			
			label=labels->block_label_label;

			label->label_id=TEXT_LABEL_ID;			
#ifdef FUNCTION_LEVEL_LINKING
			label->label_object_label=code_object_label;
#endif
			label->label_offset=CURRENT_CODE_OFFSET;
			
			if (label->label_flags & EXPORT_LABEL){
				struct object_label *new_object_label;
				int string_length;
								
				new_object_label=fast_memory_allocate_type (struct object_label);
				*last_object_label_l=new_object_label;
				last_object_label_l=&new_object_label->next;
				new_object_label->next=NULL;
				
				new_object_label->object_label_label=label;
				new_object_label->object_label_number=n_object_labels;
				++n_object_labels;
		
				string_length=strlen (label->label_name);
				new_object_label->object_label_string_offset=string_table_offset;
				string_table_offset+=string_length+1;
				new_object_label->object_label_kind=EXPORTED_CODE_LABEL;				
			}
		}
}

void store_label_in_data_section (LABEL *label)
{
	store_label_plus_offset_in_data_section (label,0);
}

void store_descriptor_in_data_section (LABEL *label)
{
	store_label_plus_offset_in_data_section (label,2);
}

void store_descriptor_string_in_data_section (char *string,int length,LABEL *string_label)
{
	define_data_label (string_label);
	store_abc_string_in_data_section (string,length);
}

static void as_branch_label (struct label *label,int relocation_kind)
{
	struct relocation *new_relocation;

	new_relocation=fast_memory_allocate_type (struct relocation);
	++n_code_relocations;
	
	*last_code_relocation_l=new_relocation;
	last_code_relocation_l=&new_relocation->next;
	new_relocation->next=NULL;
	
	new_relocation->relocation_label=label;
	new_relocation->relocation_offset=CURRENT_CODE_OFFSET-4;
#ifdef FUNCTION_LEVEL_LINKING
	new_relocation->relocation_object_label=code_object_label;
#endif
	new_relocation->relocation_kind=relocation_kind;
	new_relocation->relocation_addend=0;
}

static void as_hi_or_lo_label (struct label *label,int offset,int relocation_kind)
{
	struct relocation *new_relocation;

	new_relocation=fast_memory_allocate_type (struct relocation);
	++n_code_relocations;
	
	*last_code_relocation_l=new_relocation;
	last_code_relocation_l=&new_relocation->next;
	new_relocation->next=NULL;
	
	new_relocation->relocation_label=label;
	new_relocation->relocation_offset=CURRENT_CODE_OFFSET-4;
	new_relocation->relocation_kind=relocation_kind;
	new_relocation->relocation_addend=offset;
}

static void store_label_in_code_section (struct label *label)
{
	struct toc_label *t_label;
	struct relocation *new_relocation;

	store_instruction (0);

	new_relocation=fast_memory_allocate_type (struct relocation);
	++n_code_relocations;
	
	*last_code_relocation_l=new_relocation;
	last_code_relocation_l=&new_relocation->next;
	new_relocation->next=NULL;
	
	new_relocation->relocation_offset=CURRENT_CODE_OFFSET-4;

	new_relocation->relocation_label=label;
	new_relocation->relocation_kind=LONG_WORD_RELOCATION;
	new_relocation->relocation_addend=0;
}

#define REGISTER_G0 (-16)
#define REGISTER_I6 (-10)
#define REGISTER_O0 8
#define REGISTER_O1 9
#define REGISTER_O7 15

/*
static char register_type  [32]="ggggggiiggiiiiiilllllllloooooooo";
static char register_number[32]="01234767565432100123456701234567";
*/

static unsigned char real_reg_num [32] =
{
	0,1,2,3,4,7,30,31,
	5,6,29,28,27,26,25,24,
	16,17,18,19,20,21,22,23,
	8,9,10,11,12,13,14,15
};

#define reg_num(r) (real_reg_num[(r)+16])

#define as_i_id0(i,rd) store_instruction(0x1000000|(reg_num(rd)<<25)|((i)&0x3fffff))
#define as_i_bic(i,cond) store_instruction((cond<<25)|(2<<22)|((i)&0x3fffffff))
#define as_i_bica(i,cond) store_instruction((1<<29)|(cond<<25)|(2<<22)|(i)&0x3fffffff)
#define as_i_call(i) store_instruction((1<<30)|i)
#define as_i_fbic(i,cond) store_instruction((cond<<25)|(6<<22)|i)
#define as_i_fbica(i,cond) store_instruction((1<<29)|(cond<<25)|(6<<22)|i)
#define as_i_abd2(ra,rb,rd,op) store_instruction(0x80000000|((op)<<19)|(reg_num(rd)<<25)|(reg_num(ra)<<14)|reg_num(rb))
#define as_i_fb2(fa,fb,op,opf) store_instruction(0x80000000|((op)<<19)|((fa)<<14)|((opf)<<5)|(fb))
#define as_i_ff2(ra,rd,op,opf) store_instruction(0x80000000|((op)<<19)|((rd)<<25)|((opf)<<5)|(ra))
#define as_i_fff2(ra,rb,rd,op,opf) store_instruction(0x80000000|((op)<<19)|((rd)<<25)|((ra)<<14)|((opf)<<5)|(rb))
#define as_i_aid2(ra,i,rd,op) store_instruction(0x80000000|((op)<<19)|(reg_num(rd)<<25)|(reg_num(ra)<<14)|0x2000|((i)&0x1fff))
#define as_i_abd3(ra,rb,rd,op) store_instruction(0xc0000000|((op)<<19)|(reg_num(rd)<<25)|(reg_num(ra)<<14)|reg_num(rb))
#define as_i_aod3(ra,o,rd,op) store_instruction(0xc0000000|((op)<<19)|(reg_num(rd)<<25)|(reg_num(ra)<<14)|0x2000|((o)&0x1fff))
#define as_i_foa3(fa,o,ra,op) store_instruction(0xc0000000|((op)<<19)|((fa)<<25)|((reg_num(ra))<<14)|0x2000|((o)&0x1fff))
#define as_i_fab3(fa,ra,rb,op) store_instruction(0xc0000000|((op)<<19)|((fa)<<25)|((reg_num(ra))<<14)|(reg_num(rb)))

#define LD_OP 0
#define LDUB_OP 1
#define LDUH_OP 2
#define LDSB_OP 9
#define LDSH_OP 10
#define ST_OP 4
#define STB_OP 5
#define STH_OP 6

#define LDF_OP 0x20
#define LDDF_OP 0x23
#define	STF_OP 0x24
#define STDF_OP 0x27

#define AND_OP 1
#define OR_OP 2
#define XOR_OP 3
#define SLL_OP 0x25
#define SRL_OP 0x26
#define SRA_OP 0x27

#define FADDD_OP 0x42
#define FDIVD_OP 0x4e
#define FMULD_OP 0x4a
#define FSUBD_OP 0x46

#define A_COND 0x8
#define E_COND 0x1
#define GE_COND 0xb
#define G_COND 0xa
#define L_COND 0x3
#define LE_COND 0x2
#define NE_COND 0x9
#define CS_COND 0x5
#define VC_COND 0xf
#define VS_COND 0x7

#define FE_COND 0x9
#define FGE_COND 0xb
#define FG_COND 0x6
#define FLE_COND 0xd
#define FL_COND 0x4
#define FNE_COND 0x1

#define as_add(ra,rb,rd) as_i_abd2(ra,rb,rd,0)
#define as_addcc(ra,rb,rd) as_i_abd2(ra,rb,rd,0x10)
#define as_addcci(ra,i,rd) as_i_aid2(ra,i,rd,0x10)
#define as_addi(ra,i,rd) as_i_aid2(ra,i,rd,0)
#define as_andcci(ra,i,rd) as_i_aid2(ra,i,rd,0x11)
#define as_faddd(fa,fb,fd) as_i_fff2(fa,fb,fd,0x34,FADDD_OP)
#define as_fcmpd(fa,fb) as_i_fb2(fa,fb,0x35,0x52)
#define as_fdtoi(fa,fd) as_i_ff2(fa,fd,0x34,0xd2)
#define as_fitod(fa,fd) as_i_ff2(fa,fd,0x34,0xc8)
#define as_fdivd(fa,fb,fd) as_i_fff2(fa,fb,fd,0x34,FDIVD_OP)
#define as_fmuld(fa,fb,fd) as_i_fff2(fa,fb,fd,0x34,FMULD_OP)
#define as_fsqrtd(fa,fd) as_i_ff2(fa,fd,0x34,0x2a)
#define as_fsubd(fa,fb,fd) as_i_fff2(fa,fb,fd,0x34,FSUBD_OP)
#define as_jmpli(i,ra,rd) as_i_aid2(ra,i,rd,0x38)
#define as_ld(o,ra,rd) as_i_aod3(ra,o,rd,LD_OP)
#define as_lddf(o,ra,fd) as_i_foa3(fd,o,ra,LDDF_OP)
#define as_lddf_x(ra,rb,fd) as_i_fab3(fd,ra,rb,LDDF_OP)
#define as_ldf(o,ra,fd) as_i_foa3(fd,o,ra,LDF_OP)
#define as_ldf_x(ra,rb,fd) as_i_fab3(fd,ra,rb,LDF_OP)
#define as_ldsh(o,ra,rd) as_i_aod3(ra,o,rd,LDSH_OP)
#define as_ldsh_x(ra,rb,rd) as_i_abd3(ra,rb,rd,LDSH_OP)
#define as_ld_x(ra,rb,rd) as_i_abd3(ra,rb,rd,LD_OP)
#define as_fmovs(fa,fd) as_i_ff2(fa,fd,0x34,1);
#define as_fnegs(fa,fd) as_i_ff2(fa,fd,0x34,5);
#define as_fabss(fa,fd) as_i_ff2(fa,fd,0x34,9);
#define as_or(ra,rb,rd) as_i_abd2(ra,rb,rd,OR_OP)
#define as_orcc(ra,rb,rd) as_i_abd2(ra,rb,rd,0x12)
#define as_ori(ra,i,rd) as_i_aid2(ra,i,rd,OR_OP)
#define as_sethi(i,rd) as_i_id0(i,rd)
#define as_slli(ra,i,rd) as_i_aid2(ra,i,rd,SLL_OP)
#define as_stdf(fa,o,rd) as_i_foa3(fa,o,rd,STDF_OP)
#define as_stdf_x(fa,ra,rb) as_i_fab3(fa,ra,rb,STDF_OP)
#define as_stf(fa,o,rd) as_i_foa3(fa,o,rd,STF_OP)
#define as_sub(ra,rb,rd) as_i_abd2(ra,rb,rd,4)
#define as_subcc(ra,rb,rd) as_i_abd2(ra,rb,rd,0x14)
#define as_subcci(ra,i,rd) as_i_aid2(ra,i,rd,0x14)

#define as_btst(i,ra) as_i_aid2(ra,i,REGISTER_G0,0x11)
#define as_clr(rd) as_or(REGISTER_G0,REGISTER_G0,rd)
#define as_cmp(ra,rb) as_subcc(ra,rb,REGISTER_G0)
#define as_cmpi(ra,i) as_subcci(ra,i,REGISTER_G0)
#define as_dec(i,rd) as_i_aid2(rd,i,rd,4)
#define as_deccc(i,rd) as_i_aid2(rd,i,rd,0x14)
#define as_inc(i,rd) as_i_aid2(rd,i,rd,0)
#define as_inccc(i,rd) as_i_aid2(rd,i,rd,0x10)
#define as_mov(ra,rd) as_or(REGISTER_G0,ra,rd)
#define as_movi(i,rd) as_ori(REGISTER_G0,i,rd)
#define as_nop() as_sethi(0,REGISTER_G0)
#define as_retl() as_jmpli(8,REGISTER_O7,REGISTER_G0)
#define as_tst(ra) as_orcc(REGISTER_G0,ra,REGISTER_G0)
#define as_load(op,o,ra,rd) as_i_aod3(ra,o,rd,op)
#define as_load_x(op,ra,rb,rd) as_i_abd3(ra,rb,rd,op)
#define as_store(op,rd,o,ra) as_i_aod3(ra,o,rd,op)
#define as_store_x(op,rd,ra,rb) as_i_abd3(ra,rb,rd,op)

#define as_st(rd,o,ra) as_store(ST_OP,rd,o,ra)

static void as_set (int i,int rd)
{
	if (i>=-4096 && i<=4095)
		as_movi (i,rd);
	else {
		as_sethi (i>>10,rd);
		if ((i & 1023)!=0)
			as_ori (rd,i & 1023,rd);
	}
}

enum { SIZE_LONG, SIZE_WORD, SIZE_BYTE };

static void as_ld_parameter (struct parameter *parameter,int rd)
{
	if (parameter->parameter_type==P_INDIRECT)
		as_ld (parameter->parameter_offset,parameter->parameter_data.reg.r,rd);
	else if (parameter->parameter_type==P_INDEXED && parameter->parameter_offset==0)
		as_ld_x (parameter->parameter_data.ir->a_reg.r,parameter->parameter_data.ir->d_reg.r,rd);
	else
		internal_error_in_function ("as_ld_parameter");
}

static void as_ldsh_parameter (struct parameter *parameter,int rd)
{
	if (parameter->parameter_type==P_INDIRECT)
		as_ldsh (parameter->parameter_offset,parameter->parameter_data.reg.r,rd);
	else if (parameter->parameter_type==P_INDEXED && parameter->parameter_offset==0)
		as_ldsh_x (parameter->parameter_data.ir->a_reg.r,parameter->parameter_data.ir->d_reg.r,rd);
	else
		internal_error_in_function ("as_ldsh_parameter");
}

static struct parameter as_register_parameter (struct parameter parameter,int size_flag)
{
	switch (parameter.parameter_type){
		case P_DESCRIPTOR_NUMBER:
			as_sethi (0,REGISTER_O0);
			as_hi_or_lo_label (parameter.parameter_data.l,2+(parameter.parameter_offset<<3),HI22_RELOCATION);

			as_ori (REGISTER_O0,0,REGISTER_O0);
			as_hi_or_lo_label (parameter.parameter_data.l,2+(parameter.parameter_offset<<3),LO12_RELOCATION);

			parameter.parameter_type=P_REGISTER;
			parameter.parameter_data.reg.r=REGISTER_O0;
			break;
		case P_IMMEDIATE:
			if (parameter.parameter_data.i==0){
				parameter.parameter_type=P_REGISTER;
				parameter.parameter_data.reg.r=REGISTER_G0;
			} else {
				as_set (parameter.parameter_data.i,REGISTER_O0);

				parameter.parameter_type=P_REGISTER;
				parameter.parameter_data.reg.r=REGISTER_O0;
			}
			break;
		case P_REGISTER:
			break;
		case P_INDIRECT:
			as_load (size_flag==SIZE_LONG ? LD_OP : size_flag==SIZE_WORD ? LDSH_OP : LDUB_OP,
					 parameter.parameter_offset,parameter.parameter_data.reg.r,REGISTER_O0);

			parameter.parameter_type=P_REGISTER;
			parameter.parameter_data.reg.r=REGISTER_O0;
			break;
		case P_INDEXED:
			if (parameter.parameter_offset!=0)
				internal_error_in_function ("as_register_parameter");
			
			as_load_x (size_flag==SIZE_LONG ? LD_OP : size_flag==SIZE_WORD ? LDSH_OP : LDUB_OP,
					   parameter.parameter_data.ir->a_reg.r,parameter.parameter_data.ir->d_reg.r,REGISTER_O0);

			parameter.parameter_type=P_REGISTER;
			parameter.parameter_data.reg.r=REGISTER_O0;
			break;
		default:
			internal_error_in_function ("as_register_parameter");
	}
	return parameter;
}

static void as_move_instruction (struct instruction *instruction,int size_flag)
{
	switch (instruction->instruction_parameters[1].parameter_type){
		case P_REGISTER:
			switch (instruction->instruction_parameters[0].parameter_type){
				case P_DESCRIPTOR_NUMBER:
					as_sethi (0,instruction->instruction_parameters[1].parameter_data.reg.r);
					as_hi_or_lo_label (	instruction->instruction_parameters[0].parameter_data.l,
										2+(instruction->instruction_parameters[0].parameter_offset<<3),HI22_RELOCATION);

					as_ori (instruction->instruction_parameters[1].parameter_data.reg.r,0,
							instruction->instruction_parameters[1].parameter_data.reg.r);
					as_hi_or_lo_label (	instruction->instruction_parameters[0].parameter_data.l,
										2+(instruction->instruction_parameters[0].parameter_offset<<3),LO12_RELOCATION);
					break;
				case P_IMMEDIATE:
					as_set (instruction->instruction_parameters[0].parameter_data.i,
							instruction->instruction_parameters[1].parameter_data.reg.r);
					break;
				case P_REGISTER:
					as_mov (instruction->instruction_parameters[0].parameter_data.reg.r,
							instruction->instruction_parameters[1].parameter_data.reg.r);
					return;
				case P_INDIRECT:
					as_load (size_flag==SIZE_LONG ? LD_OP : size_flag==SIZE_WORD ? LDSH_OP : LDUB_OP,
							 instruction->instruction_parameters[0].parameter_offset,
							 instruction->instruction_parameters[0].parameter_data.reg.r,
							 instruction->instruction_parameters[1].parameter_data.reg.r);
					break;
				case P_INDEXED:
					if (instruction->instruction_parameters[0].parameter_offset!=0)
						internal_error_in_function ("as_move_instruction");
						
					as_load_x (size_flag==SIZE_LONG ? LD_OP : size_flag==SIZE_WORD ? LDSH_OP : LDUB_OP,
							   instruction->instruction_parameters[0].parameter_data.ir->a_reg.r,
							   instruction->instruction_parameters[0].parameter_data.ir->d_reg.r,
							   instruction->instruction_parameters[1].parameter_data.reg.r);
					break;
				default:
					internal_error_in_function ("as_move_instruction");
					return;
			}
			return;
		case P_INDIRECT:
		{
			struct parameter parameter_0;
			int offset;

			parameter_0=as_register_parameter (instruction->instruction_parameters[0],size_flag);

			offset=instruction->instruction_parameters[1].parameter_offset;

			if (((offset << (32-13)) >> (32-13))==offset){
				as_store (size_flag==SIZE_LONG ? ST_OP : size_flag==SIZE_WORD ? STH_OP : STB_OP,
						  parameter_0.parameter_data.reg.r,offset,instruction->instruction_parameters[1].parameter_data.reg.r);
			} else {
				as_sethi (offset>>10,REGISTER_O1);
		
				as_add (REGISTER_O1,instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O1);

				as_store (size_flag==SIZE_LONG ? ST_OP : size_flag==SIZE_WORD ? STH_OP : STB_OP,
						  parameter_0.parameter_data.reg.r,offset & 1023,REGISTER_O1);
			}

			return;
		}
		case P_INDEXED:
		{
			struct parameter parameter_0;

			if (instruction->instruction_parameters[1].parameter_offset!=0)
				internal_error_in_function ("as_move_instruction");
			
			parameter_0=as_register_parameter (instruction->instruction_parameters[0],size_flag);

			as_store_x (size_flag==SIZE_LONG ? ST_OP : size_flag==SIZE_WORD ? STH_OP : STB_OP,
						parameter_0.parameter_data.reg.r,instruction->instruction_parameters[1].parameter_data.ir->a_reg.r,
						instruction->instruction_parameters[1].parameter_data.ir->d_reg.r);
			return;
		}
		default:
			internal_error_in_function ("as_move_instruction");
	}
}

static void as_lea_instruction (struct instruction *instruction)
{
	if (instruction->instruction_parameters[1].parameter_type==P_REGISTER)
		switch (instruction->instruction_parameters[0].parameter_type){
			case P_LABEL:
				as_sethi (0,instruction->instruction_parameters[1].parameter_data.reg.r);
				as_hi_or_lo_label (	instruction->instruction_parameters[0].parameter_data.l,
									instruction->instruction_parameters[0].parameter_offset,HI22_RELOCATION);

				as_ori (instruction->instruction_parameters[1].parameter_data.reg.r,0,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				as_hi_or_lo_label (	instruction->instruction_parameters[0].parameter_data.l,
									instruction->instruction_parameters[0].parameter_offset,LO12_RELOCATION);
				return;
			case P_INDIRECT:
				as_addi (instruction->instruction_parameters[0].parameter_data.reg.r,
						 instruction->instruction_parameters[0].parameter_offset,
						 instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			case P_INDEXED:
				as_add (instruction->instruction_parameters[0].parameter_data.ir->a_reg.r,
						instruction->instruction_parameters[0].parameter_data.ir->d_reg.r,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
		}

	internal_error_in_function ("as_lea_instruction");
}

static void as_sll_instruction (struct instruction *instruction)
{
	as_slli (	instruction->instruction_parameters[0].parameter_data.reg.r,
				instruction->instruction_parameters[2].parameter_data.i,
				instruction->instruction_parameters[1].parameter_data.reg.r);
}

static void as_logical_or_shift_instruction (struct instruction *instruction,int opcode)
{
	struct parameter parameter;

	parameter=instruction->instruction_parameters[0];

	switch (parameter.parameter_type){
		case P_IMMEDIATE:
			if ((unsigned)(parameter.parameter_data.i+4096)>=(unsigned)8192){
				as_set (parameter.parameter_data.i,REGISTER_O0);

				parameter.parameter_type=P_REGISTER;
				parameter.parameter_data.reg.r=REGISTER_O0;
			} else {
				as_i_aid2 ( instruction->instruction_parameters[1].parameter_data.reg.r,
							parameter.parameter_data.i,
							instruction->instruction_parameters[1].parameter_data.reg.r,opcode);
				return;
			}
			break;
		case P_INDIRECT:
			as_ld (parameter.parameter_offset,parameter.parameter_data.reg.r,REGISTER_O0);

			parameter.parameter_type=P_REGISTER;
			parameter.parameter_data.reg.r=REGISTER_O0;
			break;
		case P_INDEXED:
			if (parameter.parameter_offset!=0)
				internal_error_in_function ("as_tryadic_instruction");

			as_ld_x (parameter.parameter_data.ir->a_reg.r,parameter.parameter_data.ir->d_reg.r,REGISTER_O0);

			parameter.parameter_type=P_REGISTER;
			parameter.parameter_data.reg.r=REGISTER_O0;			
	}

	as_i_abd2 (	instruction->instruction_parameters[1].parameter_data.reg.r,
				parameter.parameter_data.reg.r,
				instruction->instruction_parameters[1].parameter_data.reg.r,opcode);
}

static void as_add_instruction (struct instruction *instruction)
{
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_add (instruction->instruction_parameters[1].parameter_data.reg.r,
					instruction->instruction_parameters[0].parameter_data.reg.r,
					instruction->instruction_parameters[1].parameter_data.reg.r);
			return;
		case P_IMMEDIATE:
			if ((unsigned)(instruction->instruction_parameters[0].parameter_data.i+4096)<(unsigned)8192){
				as_inc (instruction->instruction_parameters[0].parameter_data.i,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			} else {
				as_set (instruction->instruction_parameters[0].parameter_data.i,REGISTER_O0);

				as_add (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			}
		default:
			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O0);

			as_add (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
					instruction->instruction_parameters[1].parameter_data.reg.r);
	}
}

static void as_add_o_instruction (struct instruction *instruction)
{
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_addcc (	instruction->instruction_parameters[1].parameter_data.reg.r,
						instruction->instruction_parameters[0].parameter_data.reg.r,
						instruction->instruction_parameters[1].parameter_data.reg.r);
			return;
		case P_IMMEDIATE:
			if ((unsigned)(instruction->instruction_parameters[0].parameter_data.i+4096)<(unsigned)8192){
				as_inccc (	instruction->instruction_parameters[0].parameter_data.i,
							instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			} else {
				as_set (instruction->instruction_parameters[0].parameter_data.i,REGISTER_O0);
				
				as_addcc (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
						  instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			}
		default:
			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O0);

			as_addcc (	instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
						instruction->instruction_parameters[1].parameter_data.reg.r);
	}
}

static void as_sub_instruction (struct instruction *instruction)
{
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_sub (instruction->instruction_parameters[1].parameter_data.reg.r,
					instruction->instruction_parameters[0].parameter_data.reg.r,
					instruction->instruction_parameters[1].parameter_data.reg.r);
			return;
		case P_IMMEDIATE:
			if ((unsigned)(instruction->instruction_parameters[0].parameter_data.i+4096)<(unsigned)8192){
				as_dec (instruction->instruction_parameters[0].parameter_data.i,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			} else {
				as_set (instruction->instruction_parameters[0].parameter_data.i,REGISTER_O0);

				as_sub (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
						instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			}
		default:
			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O0);

			as_sub (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
					instruction->instruction_parameters[1].parameter_data.reg.r);
	}
}

static void as_sub_o_instruction (struct instruction *instruction)
{
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_subcc (instruction->instruction_parameters[1].parameter_data.reg.r,
					  instruction->instruction_parameters[0].parameter_data.reg.r,
					  instruction->instruction_parameters[1].parameter_data.reg.r);
			return;
		case P_IMMEDIATE:
			if ((unsigned)(instruction->instruction_parameters[0].parameter_data.i+4096)<(unsigned)8192){
				as_deccc (instruction->instruction_parameters[0].parameter_data.i,
						  instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			} else {
				as_set (instruction->instruction_parameters[0].parameter_data.i,REGISTER_O0);

				as_subcc (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
						  instruction->instruction_parameters[1].parameter_data.reg.r);
				return;
			}
		default:
			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O0);

			as_subcc (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0,
					  instruction->instruction_parameters[1].parameter_data.reg.r);
	}
}

static void as_cmp_instruction (struct instruction *instruction)
{
	struct parameter parameter_0,parameter_1;

	parameter_0=instruction->instruction_parameters[0];
	parameter_1=instruction->instruction_parameters[1];

	if (parameter_1.parameter_type==P_INDIRECT){
		as_ld (parameter_1.parameter_offset,parameter_1.parameter_data.reg.r,REGISTER_O1);

		parameter_1.parameter_type=P_REGISTER;
		parameter_1.parameter_data.reg.r=REGISTER_O1;
	} else if (parameter_1.parameter_type==P_INDEXED){
		if (parameter_1.parameter_offset!=0)
			internal_error_in_function ("as_cmp_instruction");
		
		as_ld_x (parameter_1.parameter_data.ir->a_reg.r,parameter_1.parameter_data.ir->d_reg.r,REGISTER_O1);

		parameter_1.parameter_type=P_REGISTER;
		parameter_1.parameter_data.reg.r=REGISTER_O1;
	}

	switch (parameter_0.parameter_type){
		case P_DESCRIPTOR_NUMBER:
			as_sethi (0,REGISTER_O0);
			as_hi_or_lo_label (parameter_0.parameter_data.l,2+(parameter_0.parameter_offset<<3),HI22_RELOCATION);

			as_ori (REGISTER_O0,0,REGISTER_O0);
			as_hi_or_lo_label (parameter_0.parameter_data.l,2+(parameter_0.parameter_offset<<3),LO12_RELOCATION);

			parameter_0.parameter_type=P_REGISTER;
			parameter_0.parameter_data.reg.r=REGISTER_O0;
			break;
		case P_IMMEDIATE:
			if ((unsigned)(parameter_0.parameter_data.i+4096)>=(unsigned)8192){
				as_set (parameter_0.parameter_data.i,REGISTER_O0);

				parameter_0.parameter_type=P_REGISTER;
				parameter_0.parameter_data.reg.r=REGISTER_O0;
			} else {
				as_cmpi (parameter_1.parameter_data.reg.r,parameter_0.parameter_data.i);
				return;
			}
			break;
		case P_REGISTER:
			break;
		default:
			as_ld_parameter (&parameter_0,REGISTER_O0);

			parameter_0.parameter_type=P_REGISTER;
			parameter_0.parameter_data.reg.r=REGISTER_O0;
	}

	as_cmp (parameter_1.parameter_data.reg.r,parameter_0.parameter_data.reg.r);
}

#if 0
static void as_cmpw_instruction (struct instruction *instruction)
{
	struct parameter parameter_0,parameter_1;

	parameter_0=instruction->instruction_parameters[0];
	parameter_1=instruction->instruction_parameters[1];

	if (parameter_1.parameter_type==P_INDIRECT){
		as_ldsh (parameter_1.parameter_offset,parameter_1.parameter_data.reg.r,REGISTER_O1);

		parameter_1.parameter_type=P_REGISTER;
		parameter_1.parameter_data.reg.r=REGISTER_O1;
	} else if (parameter_1.parameter_type==P_INDEXED){
		if (parameter_1.parameter_offset!=0)
			internal_error_in_function ("as_cmpw_instruction");

		as_ldsh_x (parameter_1.parameter_data.ir->a_reg.r,parameter_1.parameter_data.ir->d_reg.r,REGISTER_O1);

		parameter_1.parameter_type=P_REGISTER;
		parameter_1.parameter_data.reg.r=REGISTER_O1;
	}

	switch (parameter_0.parameter_type){
		case P_DESCRIPTOR_NUMBER:
			as_sethi (0,REGISTER_O0);
			as_hi_or_lo_label (parameter_0.parameter_data.l,2+(parameter_0.parameter_offset<<3),HI22_RELOCATION);

			as_ori (REGISTER_O0,0,REGISTER_O0);
			as_hi_or_lo_label (parameter_0.parameter_data.l,2+(parameter_0.parameter_offset<<3),LO12_RELOCATION);

			parameter_0.parameter_type=P_REGISTER;
			parameter_0.parameter_data.reg.r=REGISTER_O0;
			break;
		case P_IMMEDIATE:
			if ((unsigned)(parameter_0.parameter_data.i+4096)>=(unsigned)8192){
				as_set (parameter_0.parameter_data.i,REGISTER_O0);

				parameter_0.parameter_type=P_REGISTER;
				parameter_0.parameter_data.reg.r=REGISTER_O0;
			} else {
				as_cmpi (parameter_1.parameter_data.reg.r,parameter_0.parameter_data.i);
				return;
			}
			break;
		case P_REGISTER:
			break;
		default:
			as_ldsh_parameter (&parameter_0,REGISTER_O0);

			parameter_0.parameter_type=P_REGISTER;
			parameter_0.parameter_data.reg.r=REGISTER_O0;
	}

	as_cmp (parameter_1.parameter_data.reg.r,parameter_0.parameter_data.reg.r);
}
#endif

static void as_tst_instruction (struct instruction *instruction,int size_flag)
{
	struct parameter parameter_0;

	if (size_flag!=SIZE_LONG)
		internal_error_in_function ("as_tst_instruction");

	parameter_0=as_register_parameter (instruction->instruction_parameters[0],size_flag);

	as_tst (parameter_0.parameter_data.reg.r);
}

static void as_btst_instruction (struct instruction *instruction)
{
	as_btst (instruction->instruction_parameters[0].parameter_data.i,
			 instruction->instruction_parameters[1].parameter_data.reg.r);
}

void as_jmp_instruction (struct instruction *instruction)
{
	if (instruction->instruction_parameters[0].parameter_type==P_LABEL){
		if (instruction->instruction_parameters[0].parameter_data.l->label_flags & LOCAL_LABEL){
			as_i_bica (0,A_COND);
			as_branch_label (instruction->instruction_parameters[0].parameter_data.l,BRANCH_RELOCATION);
			return;
		} else {
			as_i_call (0);
			as_branch_label (instruction->instruction_parameters[0].parameter_data.l,CALL_RELOCATION);

			as_nop();
		}
	} else if (instruction->instruction_parameters[0].parameter_type==P_INDIRECT){
		as_jmpli (	instruction->instruction_parameters[0].parameter_offset,
					instruction->instruction_parameters[0].parameter_data.reg.r,REGISTER_G0);

		as_nop();
	} else
		internal_error_in_function ("as_jmp_instruction");
}

static void as_branch_instruction (struct instruction *instruction,int condition)
{
	as_i_bic (0,condition);
	as_branch_label (instruction->instruction_parameters[0].parameter_data.l,BRANCH_RELOCATION);

	as_nop();
}

static void as_index_error_branch_instruction (struct instruction *instruction)
{
	as_i_bic (12>>2,CS_COND);
	
	as_nop();

	as_i_bica (0,A_COND);
	as_branch_label (instruction->instruction_parameters[0].parameter_data.l,BRANCH_RELOCATION);
}

static void as_float_branch_instruction (struct instruction *instruction,int condition)
{
	as_nop();

	as_i_fbic (0,condition);
	as_branch_label (instruction->instruction_parameters[0].parameter_data.l,BRANCH_RELOCATION);

	as_nop();
}

static void as_jsr_instruction (struct instruction *instruction)
{
	if (instruction->instruction_parameters[0].parameter_type==P_LABEL){
		as_i_call (0);
		as_branch_label (instruction->instruction_parameters[0].parameter_data.l,CALL_RELOCATION);

		if (instruction->instruction_parameters[1].parameter_type==P_INDIRECT)
			as_st (REGISTER_O7,instruction->instruction_parameters[1].parameter_data.i,B_STACK_POINTER);
		else
			as_nop();
	} else if (instruction->instruction_parameters[1].parameter_type==P_INDIRECT){
		as_jmpli (	instruction->instruction_parameters[0].parameter_offset,
					instruction->instruction_parameters[0].parameter_data.reg.r,REGISTER_O7);


		as_st (REGISTER_O7,instruction->instruction_parameters[1].parameter_data.i,B_STACK_POINTER);
	} else
		internal_error_in_function ("as_jsr_instruction");		
}

static void as_rts_instruction (struct instruction *instruction)
{
	int b_offset;
	
	as_ld (instruction->instruction_parameters[0].parameter_offset,B_STACK_POINTER,REGISTER_O7);

	as_retl();

	b_offset=instruction->instruction_parameters[1].parameter_data.i;
	if (b_offset==0)
		as_nop();
	else {
		if (b_offset<0)
			as_dec (-b_offset,B_STACK_POINTER);
		else
			as_inc (b_offset,B_STACK_POINTER);
	}
}

static void as_set_condition_instruction (struct instruction *instruction,int condition)
{
	as_clr (instruction->instruction_parameters[0].parameter_data.reg.r);

	as_i_bica (2-1,condition);

	as_movi (-1,instruction->instruction_parameters[0].parameter_data.reg.r);
}

static void as_set_float_condition_instruction (struct instruction *instruction,int condition)
{
	as_nop();

	as_clr (instruction->instruction_parameters[0].parameter_data.reg.r);

	as_i_fbica (2-1,condition);

	as_movi (-1,instruction->instruction_parameters[0].parameter_data.reg.r);
}

extern struct label *dot_rem_label,*dot_div_label,*dot_mul_label;

static void w_as_mod_instruction (struct instruction *instruction)
{
	as_mov (instruction->instruction_parameters[2].parameter_data.reg.r,REGISTER_O0);

	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_i_call (0);
			as_branch_label (dot_rem_label,CALL_RELOCATION);

			as_mov (instruction->instruction_parameters[0].parameter_data.reg.r,REGISTER_O1);
			break;
		case P_IMMEDIATE:
		{
			long v;
			
			v=instruction->instruction_parameters[0].parameter_data.i;

			if ((unsigned)(v+4096) < (unsigned)8192){
				as_i_call (0);
				as_branch_label (dot_rem_label,CALL_RELOCATION);

				as_movi (v,REGISTER_O1);
			} else {
				as_sethi (v>>10,REGISTER_O1);

				as_i_call (0);
				as_branch_label (dot_rem_label,CALL_RELOCATION);
			
				as_ori (REGISTER_O1,v & 1023,REGISTER_O1);
			}
			break;
		}
		default:
			as_i_call (0);
			as_branch_label (dot_rem_label,CALL_RELOCATION);

			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O1);
	}

	as_mov (REGISTER_O0,instruction->instruction_parameters[1].parameter_data.reg.r);
}

static void w_as_mul_or_div_instruction (struct instruction *instruction,struct label *mul_or_div_label)
{
	as_mov (instruction->instruction_parameters[1].parameter_data.reg.r,REGISTER_O0);

	switch (instruction->instruction_parameters[0].parameter_type){
		case P_REGISTER:
			as_i_call (0);
			as_branch_label (mul_or_div_label,CALL_RELOCATION);

			as_mov (instruction->instruction_parameters[0].parameter_data.reg.r,REGISTER_O1);
			break;
		case P_IMMEDIATE:
		{
			long v;
			
			v=instruction->instruction_parameters[0].parameter_data.i;

			if ((unsigned)(v+4096) < (unsigned)8192){
				as_i_call (0);
				as_branch_label (mul_or_div_label,CALL_RELOCATION);
	
				as_movi (v,REGISTER_O1);
			} else {
				as_sethi (v>>10,REGISTER_O1);

				as_i_call (0);
				as_branch_label (mul_or_div_label,CALL_RELOCATION);

				as_ori (REGISTER_O1,v & 1023,REGISTER_O1);
			}
			break;
		}
		default:
			as_i_call (0);
			as_branch_label (mul_or_div_label,CALL_RELOCATION);

			as_ld_parameter (&instruction->instruction_parameters[0],REGISTER_O1);
	}

	as_mov (REGISTER_O0,instruction->instruction_parameters[1].parameter_data.reg.r);
}

static void as_neg_instruction (struct instruction *instruction)
{
	as_sub (REGISTER_G0,instruction->instruction_parameters[0].parameter_data.reg.r,instruction->instruction_parameters[0].parameter_data.reg.r);
}

#ifndef FUNCTION_LEVEL_LINKING
static int data_section_alignment_mask;
#endif

static void as_load_float_immediate (double float_value,int fp_reg)
{
	struct label *new_label;

	new_label=allocate_memory_from_heap_type (struct label);

	new_label->label_flags=DATA_LABEL;
	new_label->label_id=DATA_LABEL_ID;
#ifdef FUNCTION_LEVEL_LINKING
	new_label->label_object_label=data_object_label;
	
	data_object_label->object_section_align8=1;
#else
	data_section_alignment_mask |= 7;
#endif

#ifdef FUNCTION_LEVEL_LINKING
	if ((((unsigned char*)data_buffer_p-current_data_buffer->data)-data_object_label->object_label_offset) & 4)
#else
	if ((((unsigned char*)data_buffer_p-current_data_buffer->data) & 4)!=0)
#endif
		store_long_word_in_data_section (0);

	new_label->label_offset=CURRENT_DATA_OFFSET;
	
	new_label->label_number=next_label_id++;

	store_long_word_in_data_section (((ULONG*)&float_value)[0]);
	store_long_word_in_data_section (((ULONG*)&float_value)[1]);

	as_sethi (0,REGISTER_O0);
	as_hi_or_lo_label (new_label,0,HI22_RELOCATION);

	as_lddf (0,REGISTER_O0,fp_reg<<1);
	as_hi_or_lo_label (new_label,0,LO12_RELOCATION);
}

static void as_load_float_indirect (struct parameter *parameter_p,int f_reg)
{
#ifdef ALIGN_REAL_ARRAYS
	if (parameter_p->parameter_flags & LOAD_STORE_ALIGNED_REAL)
		as_lddf (parameter_p->parameter_offset,parameter_p->parameter_data.reg.r,f_reg<<1);						
	else {
#endif
	as_ldf (parameter_p->parameter_offset,parameter_p->parameter_data.reg.r,f_reg<<1);
	as_ldf (parameter_p->parameter_offset+4,parameter_p->parameter_data.reg.r,(f_reg<<1)+1);
#ifdef ALIGN_REAL_ARRAYS
	}
#endif
}

static void as_load_float_indexed (struct parameter *parameter_p,int f_reg)
{
	int offset;
	
	offset=parameter_p->parameter_offset>>2;
	
#ifdef ALIGN_REAL_ARRAYS
	if (parameter_p->parameter_flags & LOAD_STORE_ALIGNED_REAL){
		if (offset==0)
			as_lddf_x (parameter_p->parameter_data.ir->a_reg.r,parameter_p->parameter_data.ir->d_reg.r,f_reg<<1);
		else {
			as_add (parameter_p->parameter_data.ir->a_reg.r,parameter_p->parameter_data.ir->d_reg.r,REGISTER_O0);
			as_lddf (offset,REGISTER_O0,f_reg<<1);
		}
	} else {
#endif
	as_add (parameter_p->parameter_data.ir->a_reg.r,parameter_p->parameter_data.ir->d_reg.r,REGISTER_O0);
	as_ldf (offset,REGISTER_O0,f_reg<<1);
	as_ldf (offset+4,REGISTER_O0,(f_reg<<1)+1);
#ifdef ALIGN_REAL_ARRAYS
	}
#endif
}

static int as_float_parameter (struct parameter parameter)
{
	switch (parameter.parameter_type){
		case P_F_IMMEDIATE:
			as_load_float_immediate (*parameter.parameter_data.r,15);
			return 15;
		case P_INDIRECT:
#ifdef ALIGN_REAL_ARRAYS
			if (parameter.parameter_flags & LOAD_STORE_ALIGNED_REAL)
				as_lddf (parameter.parameter_offset,parameter.parameter_data.reg.r,30);
			else {
#endif
			as_ldf (parameter.parameter_offset,parameter.parameter_data.reg.r,30);
			as_ldf (parameter.parameter_offset+4,parameter.parameter_data.reg.r,31);
#ifdef ALIGN_REAL_ARRAYS
			}
#endif
			return 15;
		case P_INDEXED:
		{
			int offset;
			
			offset=parameter.parameter_offset>>2;
			
#ifdef ALIGN_REAL_ARRAYS
			if (parameter.parameter_flags & LOAD_STORE_ALIGNED_REAL){
				if (offset==0)
					as_lddf_x (parameter.parameter_data.ir->a_reg.r,parameter.parameter_data.ir->d_reg.r,30);
				else {
					as_add (parameter.parameter_data.ir->a_reg.r,parameter.parameter_data.ir->d_reg.r,REGISTER_O0);

					as_lddf (offset,REGISTER_O0,30);
				}
			} else {
#endif
			as_add (parameter.parameter_data.ir->a_reg.r,parameter.parameter_data.ir->d_reg.r,REGISTER_O0);

			as_ldf (offset,REGISTER_O0,30);
			as_ldf (offset+4,REGISTER_O0,31);
#ifdef ALIGN_REAL_ARRAYS
			}
#endif
			return 15;
		}
		case P_F_REGISTER:
			return parameter.parameter_data.reg.r;
	}
	internal_error_in_function ("as_float_parameter");
	return 0;
}

static void as_compare_float_instruction (struct instruction *instruction)
{
	int f_reg;

	f_reg=as_float_parameter (instruction->instruction_parameters[0]);

	as_fcmpd (instruction->instruction_parameters[1].parameter_data.reg.r<<1,f_reg<<1);
}

static void as_sqrt_float_instruction (struct instruction *instruction)
{
	int f_reg;

	f_reg=as_float_parameter (instruction->instruction_parameters[0]);

	as_fsqrtd (f_reg<<1,instruction->instruction_parameters[1].parameter_data.reg.r<<1);
}

static void as_neg_float_instruction (struct instruction *instruction)
{
	int freg1,freg2;

	freg2=instruction->instruction_parameters[1].parameter_data.reg.r;
	
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_INDIRECT:
			as_load_float_indirect (&instruction->instruction_parameters[0],freg2);
			freg1=freg2;
			break;
		case P_INDEXED:
			as_load_float_indexed (&instruction->instruction_parameters[0],freg2);
			freg1=freg2;
			break;
		default:
			freg1=as_float_parameter (instruction->instruction_parameters[0]);
	}

	as_fnegs (freg1<<1,freg2<<1);

	if (freg1!=freg2)
		as_fmovs ((freg1<<1)+1,(freg2<<1)+1);
}

static void as_abs_float_instruction (struct instruction *instruction)
{
	int freg1,freg2;

	freg2=instruction->instruction_parameters[1].parameter_data.reg.r;
	
	switch (instruction->instruction_parameters[0].parameter_type){
		case P_INDIRECT:
			as_load_float_indirect (&instruction->instruction_parameters[0],freg2);
			freg1=freg2;
			break;
		case P_INDEXED:
			as_load_float_indexed (&instruction->instruction_parameters[0],freg2);
			freg1=freg2;
			break;
		default:
			freg1=as_float_parameter (instruction->instruction_parameters[0]);
	}

	as_fabss (freg1<<1,freg2<<1);

	if (freg1!=freg2)
		as_fmovs ((freg1<<1)+1,(freg2<<1)+1);
}

static void as_tryadic_float_instruction (struct instruction *instruction,int opcode)
{
	int f_reg;

	f_reg=as_float_parameter (instruction->instruction_parameters[0]);

	as_i_fff2 (instruction->instruction_parameters[1].parameter_data.reg.r<<1,f_reg<<1,
			   instruction->instruction_parameters[1].parameter_data.reg.r<<1,
			   0x34,opcode);
}

static struct instruction *as_fmove_instruction (struct instruction *instruction)
{
	switch (instruction->instruction_parameters[1].parameter_type){
		case P_F_REGISTER:
			switch (instruction->instruction_parameters[0].parameter_type){
				case P_F_REGISTER:
				{
					struct instruction *next_instruction;
					int reg0,reg1;
					
					reg0=instruction->instruction_parameters[0].parameter_data.reg.r;
					reg1=instruction->instruction_parameters[1].parameter_data.reg.r;
					
					next_instruction=instruction->instruction_next;
					if (next_instruction)
						switch (next_instruction->instruction_icode){
							case IFADD: case IFSUB: case IFMUL: case IFDIV:
								if (next_instruction->instruction_parameters[1].parameter_data.reg.r==reg1)
								{
									int reg_s;

									reg_s=as_float_parameter (next_instruction->instruction_parameters[0]);

									if (reg_s==reg1)
										reg_s=reg0;
									
									switch (next_instruction->instruction_icode){
										case IFADD:
											as_faddd (reg0<<1,reg_s<<1,reg1<<1);
											break;
										case IFSUB:
											as_fsubd (reg0<<1,reg_s<<1,reg1<<1);
											break;
										case IFMUL:
											as_fmuld (reg0<<1,reg_s<<1,reg1<<1);
											break;
										case IFDIV:
											as_fdivd (reg0<<1,reg_s<<1,reg1<<1);
											break;
									}
									
									return next_instruction;
								}
						}

					as_fmovs (reg0<<1,reg1<<1);
					as_fmovs ((reg0<<1)+1,(reg1<<1)+1);
				
					return instruction;
				}
				case P_INDIRECT:
					as_load_float_indirect (&instruction->instruction_parameters[0],instruction->instruction_parameters[1].parameter_data.reg.r);
					return instruction;
				case P_INDEXED:
					as_load_float_indexed (&instruction->instruction_parameters[0],instruction->instruction_parameters[1].parameter_data.reg.r);
					return instruction;
				case P_F_IMMEDIATE:
					as_load_float_immediate (*instruction->instruction_parameters[0].parameter_data.r,instruction->instruction_parameters[1].parameter_data.reg.r);
					return instruction;
			}
			break;
		case P_INDIRECT:
			if (instruction->instruction_parameters[0].parameter_type==P_F_REGISTER){
#ifdef ALIGN_REAL_ARRAYS
				if (instruction->instruction_parameters[1].parameter_flags & LOAD_STORE_ALIGNED_REAL){
					as_stdf (instruction->instruction_parameters[0].parameter_data.reg.r<<1,
							 instruction->instruction_parameters[1].parameter_offset,
							 instruction->instruction_parameters[1].parameter_data.reg.r);
				} else {
#endif
				as_stf (instruction->instruction_parameters[0].parameter_data.reg.r<<1,
						instruction->instruction_parameters[1].parameter_offset,
						instruction->instruction_parameters[1].parameter_data.reg.r);

				as_stf ((instruction->instruction_parameters[0].parameter_data.reg.r<<1)+1,
						instruction->instruction_parameters[1].parameter_offset+4,
						instruction->instruction_parameters[1].parameter_data.reg.r);
#ifdef ALIGN_REAL_ARRAYS
				}
#endif
				return instruction;
			}
			break;
		case P_INDEXED:
			if (instruction->instruction_parameters[0].parameter_type==P_F_REGISTER){
				int offset;
				
				offset=instruction->instruction_parameters[1].parameter_offset>>2;
#ifdef ALIGN_REAL_ARRAYS
				if (instruction->instruction_parameters[1].parameter_flags & LOAD_STORE_ALIGNED_REAL){
					if (offset==0)
						as_stdf_x (instruction->instruction_parameters[0].parameter_data.reg.r<<1,
								   instruction->instruction_parameters[1].parameter_data.ir->a_reg.r,
								   instruction->instruction_parameters[1].parameter_data.ir->d_reg.r);	
					else {
						as_add (instruction->instruction_parameters[1].parameter_data.ir->a_reg.r,
								instruction->instruction_parameters[1].parameter_data.ir->d_reg.r,REGISTER_O0);

						as_stdf (instruction->instruction_parameters[0].parameter_data.reg.r<<1,offset,REGISTER_O0);			
					}
				} else {
#endif
				as_add (instruction->instruction_parameters[1].parameter_data.ir->a_reg.r,
						instruction->instruction_parameters[1].parameter_data.ir->d_reg.r,REGISTER_O0);

				as_stf (instruction->instruction_parameters[0].parameter_data.reg.r<<1,offset,REGISTER_O0);
				as_stf ((instruction->instruction_parameters[0].parameter_data.reg.r<<1)+1,offset+4,REGISTER_O0);
#ifdef ALIGN_REAL_ARRAYS
				}
#endif
				return instruction;
			}
	}
	internal_error_in_function ("as_fmove_instruction");
	return instruction;
}

static void as_fmove_hl_instruction (struct instruction *instruction)
{
	if (instruction->instruction_parameters[0].parameter_type==P_INDIRECT
		&&	instruction->instruction_parameters[1].parameter_type==P_F_REGISTER)
	{
		if (instruction->instruction_icode==IFMOVEHI)
			as_ldf (instruction->instruction_parameters[0].parameter_offset,
					instruction->instruction_parameters[0].parameter_data.reg.r,
					instruction->instruction_parameters[1].parameter_data.reg.r<<1);
		else
			as_ldf (instruction->instruction_parameters[0].parameter_offset,
					instruction->instruction_parameters[0].parameter_data.reg.r,
					(instruction->instruction_parameters[1].parameter_data.reg.r<<1)+1);
		return;
	}
	
	internal_error_in_function ("as_fmove_hl_instruction");
}

static void as_fmovel_instruction (struct instruction *instruction)
{
	if (instruction->instruction_parameters[0].parameter_type==P_F_REGISTER){
		if (instruction->instruction_parameters[1].parameter_type!=P_REGISTER)
			internal_error_in_function ("as_fmovel_instruction");

		as_fdtoi (instruction->instruction_parameters[0].parameter_data.reg.r<<1,31);

		as_stf (31,-4,REGISTER_I6);

		as_ld (-4,REGISTER_I6,instruction->instruction_parameters[1].parameter_data.reg.r);
	} else {
		switch (instruction->instruction_parameters[0].parameter_type){
			case P_REGISTER:
				as_st (instruction->instruction_parameters[0].parameter_data.reg.r,-4,REGISTER_I6);

				as_ldf (-4,REGISTER_I6,31);
				break;
			case P_INDIRECT:
				as_ldf (instruction->instruction_parameters[0].parameter_offset,
						instruction->instruction_parameters[0].parameter_data.reg.r,31);
				break;
			case P_INDEXED:
				if (instruction->instruction_parameters[0].parameter_offset!=0)
					internal_error_in_function ("as_movel_instruction");

				as_ldf_x (instruction->instruction_parameters[0].parameter_data.ir->a_reg.r,
						  instruction->instruction_parameters[0].parameter_data.ir->d_reg.r,31);
				break;
			case P_IMMEDIATE:
				as_set (instruction->instruction_parameters[0].parameter_data.i,REGISTER_O0);

				as_st (REGISTER_O0,-4,REGISTER_I6);

				as_ldf (-4,REGISTER_I6,31);
				break;			
			default:
				internal_error_in_function ("as_fmovel_instruction");
		}

		as_fitod (31,instruction->instruction_parameters[1].parameter_data.reg.r<<1);
	}
}

static void as_instructions (register struct instruction *instruction)
{
	while (instruction!=NULL){
		switch (instruction->instruction_icode){
			case IMOVE:
				as_move_instruction (instruction,SIZE_LONG);
				break;
			case ILEA:
				as_lea_instruction (instruction);
				break;
			case IADD:
				as_add_instruction (instruction);
				break;
			case IADDI:
				as_addi (instruction->instruction_parameters[0].parameter_data.reg.r,
						 instruction->instruction_parameters[2].parameter_data.i,
						 instruction->instruction_parameters[1].parameter_data.reg.r);
				break;
			case ISUB:
				as_sub_instruction (instruction);
				break;
			case ICMP:
				as_cmp_instruction (instruction);
				break;
			case IJMP:
				as_jmp_instruction (instruction);
				break;
			case IJSR:
				as_jsr_instruction (instruction);
				break;
			case IRTS:
				as_rts_instruction (instruction);
				break;
			case IBEQ:
				as_branch_instruction (instruction,E_COND);
				break;
			case IBGE:
				as_branch_instruction (instruction,GE_COND);
				break;
			case IBGT:
				as_branch_instruction (instruction,G_COND);
				break;
			case IBHS:
				as_index_error_branch_instruction (instruction);
				break;
			case IBLE:
				as_branch_instruction (instruction,LE_COND);
				break;
			case IBLT:
				as_branch_instruction (instruction,L_COND);
				break;
			case IBNE:
				as_branch_instruction (instruction,NE_COND);
				break;
			case IBNO:
				as_branch_instruction (instruction,VC_COND);
				break;
			case IBO:
				as_branch_instruction (instruction,VS_COND);
				break;
			case ILSLI:
				as_sll_instruction (instruction);
				break;
			case ILSL:
				as_logical_or_shift_instruction (instruction,SLL_OP);
				break;
			case ILSR:
				as_logical_or_shift_instruction (instruction,SRL_OP);
				break;
			case IASR:
				as_logical_or_shift_instruction (instruction,SRA_OP);
				break;
			case IMUL:
				w_as_mul_or_div_instruction (instruction,dot_mul_label);
				break;
			case IDIV:
				w_as_mul_or_div_instruction (instruction,dot_div_label);
				break;
			case IMOD:
				w_as_mod_instruction (instruction);
				break;
			case IAND:
				as_logical_or_shift_instruction (instruction,AND_OP);
				break;
			case IOR:
				as_logical_or_shift_instruction (instruction,OR_OP);
				break;
			case IEOR:
				as_logical_or_shift_instruction (instruction,XOR_OP);
				break;
			case ISEQ:
				as_set_condition_instruction (instruction,E_COND);
				break;
			case ISGE:
				as_set_condition_instruction (instruction,GE_COND);
				break;
			case ISGT:
				as_set_condition_instruction (instruction,G_COND);
				break;
			case ISLE:
				as_set_condition_instruction (instruction,LE_COND);
				break;
			case ISLT:
				as_set_condition_instruction (instruction,L_COND);
				break;
			case ISNE:
				as_set_condition_instruction (instruction,NE_COND);
				break;
			case ISNO:
				as_set_condition_instruction (instruction,VC_COND);
				break;
			case ISO:
				as_set_condition_instruction (instruction,VS_COND);
				break;			
#if 0
			case ICMPW:
				as_cmpw_instruction (instruction);
				break;
#endif
			case ITST:
				as_tst_instruction (instruction,SIZE_LONG);
				break;
			case IBTST:
				as_btst_instruction (instruction);
				break;
			case IMOVEW:
				as_move_instruction (instruction,SIZE_WORD);
				break;
			case IMOVEB:
				as_move_instruction (instruction,SIZE_BYTE);
				break;
			case INEG:
				as_neg_instruction (instruction);
				break;
			case IFMOVE:
				instruction=as_fmove_instruction (instruction);
				break;
			case IFMOVEHI:
			case IFMOVELO:
				as_fmove_hl_instruction (instruction);
				break;
			case IFADD:
				as_tryadic_float_instruction (instruction,FADDD_OP);
				break;
			case IFSUB:
				as_tryadic_float_instruction (instruction,FSUBD_OP);
				break;
			case IFCMP:
				as_compare_float_instruction (instruction);
				break;
			case IFDIV:
				as_tryadic_float_instruction (instruction,FDIVD_OP);
				break;
			case IFMUL:
				as_tryadic_float_instruction (instruction,FMULD_OP);
				break;
			case IFBEQ:
				as_float_branch_instruction (instruction,FE_COND);
				break;
			case IFBGE:
				as_float_branch_instruction (instruction,FGE_COND);
				break;
			case IFBGT:
				as_float_branch_instruction (instruction,FG_COND);
				break;
			case IFBLE:
				as_float_branch_instruction (instruction,FLE_COND);
				break;
			case IFBLT:
				as_float_branch_instruction (instruction,FL_COND);
				break;
			case IFBNE:
				as_float_branch_instruction (instruction,FNE_COND);
				break;
			case IFMOVEL:
				as_fmovel_instruction (instruction);
				break;
			case IFSQRT:
				as_sqrt_float_instruction (instruction);
				break;
			case IFNEG:
				as_neg_float_instruction (instruction);
				break;
			case IFABS:
				as_abs_float_instruction (instruction);
				break;
			case IFSEQ:
				as_set_float_condition_instruction (instruction,FE_COND);
				break;
			case IFSGE:
				as_set_float_condition_instruction (instruction,FGE_COND);
				break;
			case IFSGT:
				as_set_float_condition_instruction (instruction,FG_COND);
				break;
			case IFSLE:
				as_set_float_condition_instruction (instruction,FLE_COND);
				break;
			case IFSLT:
				as_set_float_condition_instruction (instruction,FL_COND);
				break;
			case IFSNE:
				as_set_float_condition_instruction (instruction,FNE_COND);
				break;
			case IWORD:
				store_instruction (instruction->instruction_parameters[0].parameter_data.i);
				break;
			case IADDO:
				as_add_o_instruction (instruction);
				break;
			case ISUBO:
				as_sub_o_instruction (instruction);
				break;
			case IFTST:
			default:
				internal_error_in_function ("as_instructions");
		}
		instruction=instruction->instruction_next;
	}
}

static void as_number_of_arguments (int n_node_arguments)
{
	store_instruction (n_node_arguments);
}

struct call_and_jump {
	struct call_and_jump *	cj_next;
	struct label *			cj_call_label;
	struct label			cj_label;
	struct label			cj_jump_label;
};

static struct call_and_jump *first_call_and_jump,*last_call_and_jump;

static void as_garbage_collect_test (struct basic_block *block)
{
	LONG n_cells;
	struct call_and_jump *new_call_and_jump;
	
	new_call_and_jump=allocate_memory_from_heap (sizeof (struct call_and_jump));

	new_call_and_jump->cj_next=NULL;
	new_call_and_jump->cj_label.label_flags=0;
	
	switch (block->block_n_begin_a_parameter_registers){
		case 0:		new_call_and_jump->cj_call_label=collect_0_label;	break;
		case 1:		new_call_and_jump->cj_call_label=collect_1_label;	break;
		case 2:		new_call_and_jump->cj_call_label=collect_2_label;	break;
		case 3:		new_call_and_jump->cj_call_label=collect_3_label;	break;
		default:	internal_error_in_function ("as_garbage_collect_test");
	}

	if (first_call_and_jump!=NULL)
		last_call_and_jump->cj_next=new_call_and_jump;
	else
		first_call_and_jump=new_call_and_jump;
	last_call_and_jump=new_call_and_jump;
	
	n_cells=block->block_n_new_heap_cells;	

	if (n_cells<4096)
		as_deccc (n_cells,REGISTER_D7);
	else {
		as_set (n_cells,REGISTER_O0);
		as_subcc (REGISTER_D7,REGISTER_O0,REGISTER_D7);
	}

	as_i_bica (0,CS_COND);
	as_branch_label (&new_call_and_jump->cj_label,BRANCH_RELOCATION);

	as_dec (4,B_STACK_POINTER);
	
	new_call_and_jump->cj_jump_label.label_flags=0;
	new_call_and_jump->cj_jump_label.label_id=TEXT_LABEL_ID;
#ifdef FUNCTION_LEVEL_LINKING
	new_call_and_jump->cj_jump_label.label_object_label=code_object_label;
#endif
	new_call_and_jump->cj_jump_label.label_offset=CURRENT_CODE_OFFSET;
}

static void as_call_and_jump (struct call_and_jump *call_and_jump)
{
	call_and_jump->cj_label.label_id=TEXT_LABEL_ID;			
#ifdef FUNCTION_LEVEL_LINKING
	call_and_jump->cj_label.label_object_label=code_object_label;
#endif
	call_and_jump->cj_label.label_offset=CURRENT_CODE_OFFSET;

	as_i_call (0);
	as_branch_label (call_and_jump->cj_call_label,CALL_RELOCATION);

	as_st (REGISTER_O7,0,B_STACK_POINTER);
	
	as_i_bica (0,A_COND);
	as_branch_label (&call_and_jump->cj_jump_label,BRANCH_RELOCATION);
}

void initialize_assembler (FILE *output_file_d)
{
	output_file=output_file_d;
	setvbuf (output_file,NULL,_IOFBF,IO_BUFFER_SIZE);

	n_object_labels=1;
	
	first_object_label=NULL;
	last_object_label_l=&first_object_label;
	
	first_code_relocation=NULL;
	first_data_relocation=NULL;
	last_code_relocation_l=&first_code_relocation;
	last_data_relocation_l=&first_data_relocation;
	n_code_relocations=0;
	n_data_relocations=0;
#ifndef FUNCTION_LEVEL_LINKING
	data_section_alignment_mask=3;
#endif

	string_table_offset=1;
	initialize_buffers();

#ifdef FUNCTION_LEVEL_LINKING
	code_object_label=NULL;
	n_code_sections=0;
	
	data_object_label=NULL;
	n_data_sections=0;
#else	
	code_object_label=fast_memory_allocate_type (struct object_label);
	++n_object_labels;
	*last_object_label_l=code_object_label;
	last_object_label_l=&code_object_label->next;
	code_object_label->next=NULL;
	
	code_object_label->object_label_offset=0;
	code_object_label->object_label_length=0;
	code_object_label->object_label_kind=CODE_CONTROL_SECTION;

	data_object_label=fast_memory_allocate_type (struct object_label);
	++n_object_labels;
	*last_object_label_l=data_object_label;
	last_object_label_l=&data_object_label->next;
	data_object_label->next=NULL;
	
	data_object_label->object_label_offset=0;
	data_object_label->object_label_length=0;
	data_object_label->object_label_kind=DATA_CONTROL_SECTION;
	data_object_label->object_section_align8=0;
#endif
}

static void as_indirect_node_entry_jump (LABEL *label)
{
	long new_label_offset;
	struct label *new_label;

#ifdef FUNCTION_LEVEL_LINKING
	as_new_code_module();
#endif

	if (label->label_flags & EA_LABEL){
		int label_arity;
		extern LABEL *eval_fill_label,*eval_upd_labels[];

		label_arity=label->label_arity;
		
		if (label_arity<-2)
			label_arity=1;

		if (label_arity>=0 && label->label_ea_label!=eval_fill_label){
			as_sethi (0,REGISTER_A2);
			as_hi_or_lo_label (label->label_ea_label,0,HI22_RELOCATION);

			as_i_call (0);
			as_branch_label (eval_upd_labels[label_arity],CALL_RELOCATION);

			as_ori (REGISTER_A2,0,REGISTER_A2);
			as_hi_or_lo_label (label->label_ea_label,0,LO12_RELOCATION);
		} else {
			as_i_call (0);
			as_branch_label (label->label_ea_label,CALL_RELOCATION);
		
			as_nop();
			as_nop();
		}
		
		if (label->label_arity<0 || parallel_flag){
			LABEL *descriptor_label;

			descriptor_label=label->label_descriptor;

			if (descriptor_label->label_id<0)
				descriptor_label->label_id=next_label_id++;

			store_label_in_code_section (descriptor_label);
		} else
			as_number_of_arguments (0);
	} else
		if (label->label_arity<0 || parallel_flag){
			LABEL *descriptor_label;

			descriptor_label=label->label_descriptor;

			if (descriptor_label->label_id<0)
				descriptor_label->label_id=next_label_id++;

			store_label_in_code_section (descriptor_label);
		}

	as_number_of_arguments (label->label_arity);
		
	new_label_offset = CURRENT_CODE_OFFSET;
		
	new_label=allocate_memory_from_heap_type (struct label);
	*new_label=*label;

	as_i_call (0);
	as_branch_label (new_label,CALL_RELOCATION);

	label->label_id=TEXT_LABEL_ID;
#ifdef FUNCTION_LEVEL_LINKING
	label->label_object_label=code_object_label;
#endif
	label->label_offset=new_label_offset;
	
	as_nop();
}

static void as_import_labels (struct label_node *label_node)
{
	LABEL *label;
	
	if (label_node==NULL)
		return;
	
	label=&label_node->label_node_label;
	
	if (!(label->label_flags & LOCAL_LABEL) && label->label_number==0){
		struct object_label *new_object_label;
		int string_length;
		
		new_object_label=fast_memory_allocate_type (struct object_label);
		*last_object_label_l=new_object_label;
		last_object_label_l=&new_object_label->next;
		new_object_label->next=NULL;
		
		new_object_label->object_label_label=label;

		label->label_id=n_object_labels;
		++n_object_labels;

		label->label_offset=0;

		string_length=strlen (label->label_name);
		new_object_label->object_label_string_offset=string_table_offset;
		string_table_offset+=string_length+1;

		new_object_label->object_label_kind=IMPORTED_LABEL;
	}
	
	as_import_labels (label_node->label_node_left);
	as_import_labels (label_node->label_node_right);
}

static void write_c (int c)
{
	fputc (c,output_file);
}

static void write_w (int c)
{
	fputc (c>>8,output_file);
	fputc (c,output_file);
}

static void write_l (int c)
{
	fputc (c>>24,output_file);
	fputc (c>>16,output_file);
	fputc (c>>8,output_file);
	fputc (c,output_file);
}

static void write_zstring (char *string)
{
    char c;

    do {
        c=*string++;
        write_c (c);
    } while (c!='\0');
}

#ifdef FUNCTION_LEVEL_LINKING
static int compute_section_strings_size (int string_size_without_digits,int n_sections)
{
	int section_strings_size,max_n_digits,power10_max_n_digits;

	section_strings_size=0;
	max_n_digits=1;
	power10_max_n_digits=10;
	while (n_sections>power10_max_n_digits){
		section_strings_size-=power10_max_n_digits;
		++max_n_digits;
		power10_max_n_digits*=10;
	}
	section_strings_size+=(string_size_without_digits+max_n_digits+1)*n_sections;

	return section_strings_size;
}

static int n_digits (int n)
{
	int i,power10;

	i=1;
	power10=10;

	while (n>=power10){
		++i;
		power10*=10;
	}

	return i;
}

static int n_sections;
#endif

static void write_file_header_and_section_headers (void)
{
	unsigned int offset;

#ifdef FUNCTION_LEVEL_LINKING
	int n_code_relocation_sections,n_data_relocation_sections;
	int section_strings_size;

	n_sections=n_code_sections+n_data_sections;

	{
		struct object_label *object_label,*previous_code_object_label,*previous_data_object_label;
		struct relocation *code_relocation,*data_relocation;
		int code_offset,data_offset;

		code_relocation=first_code_relocation;		
		code_offset=0;
		n_code_relocation_sections=0;
		previous_code_object_label=NULL;

		data_relocation=first_data_relocation;		
		data_offset=0;
		n_data_relocation_sections=0;
		previous_data_object_label=NULL;

		section_strings_size=0;

		for_l (object_label,first_object_label,next){
			if (object_label->object_label_kind==CODE_CONTROL_SECTION){
				if (previous_code_object_label!=NULL){
					int code_section_length,n_code_relocations_in_section;
					
					code_section_length=object_label->object_label_offset-code_offset;
					
					n_code_relocations_in_section=0;
					while (code_relocation!=NULL && 
						(code_relocation->relocation_offset < code_offset+code_section_length
						|| (code_relocation->relocation_offset==code_offset+code_section_length && code_relocation->relocation_kind==DUMMY_BRANCH_RELOCATION)))
					{
						code_relocation->relocation_offset-=code_offset;
						++n_code_relocations_in_section;
						
						code_relocation=code_relocation->next;
					}
					
					previous_code_object_label->object_label_length=code_section_length;
					previous_code_object_label->object_label_n_relocations=n_code_relocations_in_section;
					
					code_offset+=code_section_length;
					if (n_code_relocations_in_section>0){
						section_strings_size+=13+n_digits (previous_code_object_label->object_label_section_n);
						++n_code_relocation_sections;
					}
				}
				
				previous_code_object_label=object_label;
			} else if (object_label->object_label_kind==DATA_CONTROL_SECTION){
				if (previous_data_object_label!=NULL){
					int data_section_length,n_data_relocations_in_section;
					
					data_section_length=object_label->object_label_offset-data_offset;
					
					n_data_relocations_in_section=0;
					while (data_relocation!=NULL && data_relocation->relocation_offset < data_offset+data_section_length){
						data_relocation->relocation_offset-=data_offset;
						++n_data_relocations_in_section;
						
						data_relocation=data_relocation->next;
					}
					
					previous_data_object_label->object_label_length=data_section_length;
					previous_data_object_label->object_label_n_relocations=n_data_relocations_in_section;
					
					data_offset+=data_section_length;
					if (n_data_relocations_in_section>0){
						section_strings_size+=13+n_digits (previous_data_object_label->object_label_section_n);
						++n_data_relocation_sections;
					}
				}
				
				previous_data_object_label=object_label;
			}
		}

		if (previous_code_object_label!=NULL){
			int code_section_length,n_code_relocations_in_section;
			
			code_section_length=code_buffer_offset-code_offset;
			
			n_code_relocations_in_section=0;
			while (code_relocation!=NULL){
				code_relocation->relocation_offset-=code_offset;
				++n_code_relocations_in_section;
							
				code_relocation=code_relocation->next;
			}

			previous_code_object_label->object_label_n_relocations=n_code_relocations_in_section;
			previous_code_object_label->object_label_length=code_section_length;

			if (n_code_relocations_in_section>0){
				section_strings_size+=13+n_digits (previous_code_object_label->object_label_section_n);
				++n_code_relocation_sections;
			}
		}

		if (previous_data_object_label!=NULL){
			int data_section_length,n_data_relocations_in_section;
			
			data_section_length=data_buffer_offset-data_offset;
			
			n_data_relocations_in_section=0;
			while (data_relocation!=NULL){
				data_relocation->relocation_offset-=data_offset;
				++n_data_relocations_in_section;
							
				data_relocation=data_relocation->next;
			}

			previous_data_object_label->object_label_n_relocations=n_data_relocations_in_section;
			previous_data_object_label->object_label_length=data_section_length;

			if (n_data_relocations_in_section>0){
				section_strings_size+=13+n_digits (previous_data_object_label->object_label_section_n);
				++n_data_relocation_sections;
			}
		}
	}
	
	section_strings_size+=compute_section_strings_size (7,n_code_sections)+
						  compute_section_strings_size (7,n_data_sections);
#endif

    /* header: */
    write_l (0x7f454c46);
    write_l (0x01020100);
    write_l (0);
    write_l (0);
    write_l (0x00010002);
    write_l (1);
    write_l (0);
    write_l (0);
    write_l (0x34);
    write_l (0);
    write_l (0x00340000);
    write_l (0x00000028);
#ifdef FUNCTION_LEVEL_LINKING
	write_l (0x00000001 | ((n_sections+n_code_relocation_sections+n_data_relocation_sections+4)<<16));
#else
    write_l (0x00080001);
#endif

    /* offet 0x34: section header 0 */
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);
    write_l (0);

#ifdef FUNCTION_LEVEL_LINKING
	offset=0xd4+40*(n_sections+n_code_relocation_sections+n_data_relocation_sections);
#else
	offset=0x174;
#endif

    /* offset 0x5c: section header 1 */
    write_l (1);     /* .shstrtab offset */
    write_l (SHT_STRTAB);
    write_l (0);
    write_l (0);
    write_l (offset); /* offset */
#ifdef FUNCTION_LEVEL_LINKING
	write_l ((27+section_strings_size+3) & -4);
#else
    write_l (64);    /* size */
#endif
    write_l (0);
    write_l (0);
    write_l (1);     /* align */
    write_l (0);
#ifdef FUNCTION_LEVEL_LINKING
	offset+=(27+section_strings_size+3) & -4;
#else
	offset+=64;
#endif

#ifdef FUNCTION_LEVEL_LINKING
	{
		struct object_label *object_label;
		int code_offset,data_offset,code_relocations_offset,data_relocations_offset,section_string_offset;

		code_offset=0;
		section_string_offset=11;
	
		for_l (object_label,first_object_label,next){
			if (object_label->object_label_kind==CODE_CONTROL_SECTION){
				int code_section_length;
				
				code_section_length=object_label->object_label_length;
					
				write_l (section_string_offset);
				write_l (SHT_PROGBITS);
				write_l (SHF_ALLOC | SHF_EXECINSTR);
				write_l (0);
				write_l (offset+code_offset);
				write_l (code_section_length);
				write_l (0);
				write_l (0);
				write_l (4);
				write_l (0);

				section_string_offset+=8+n_digits (object_label->object_label_section_n);
				code_offset+=code_section_length;
			}
		}
		offset+=(code_offset+3) & -4;

		data_offset=0;

		for_l (object_label,first_object_label,next){
			if (object_label->object_label_kind==DATA_CONTROL_SECTION){
				int data_section_length;
	
				data_section_length=object_label->object_label_length;
					
				write_l (section_string_offset);
				write_l (SHT_PROGBITS);
				write_l (SHF_ALLOC | SHF_WRITE);
				write_l (0);
				write_l (offset+data_offset);
				write_l (data_section_length);
				write_l (0);
				write_l (0);
				write_l (object_label->object_section_align8 ? 8 : 4);
				write_l (0);
				
				section_string_offset+=8+n_digits (object_label->object_label_section_n);
				data_offset+=data_section_length;
			}
		}

		offset+=(data_offset+3) & -4;

		code_relocations_offset=0;
	
		for_l (object_label,first_object_label,next){
			if (object_label->object_label_kind==CODE_CONTROL_SECTION){
				int n_code_relocations_in_section;
			
				n_code_relocations_in_section=object_label->object_label_n_relocations;
				
				if (n_code_relocations_in_section>0){
					write_l (section_string_offset);
					write_l (SHT_RELA);
					write_l (0);
					write_l (0);
					write_l (offset+code_relocations_offset);
					write_l (12*n_code_relocations_in_section);
					write_l (n_sections+n_code_relocation_sections+n_data_relocation_sections+2);
					write_l (2+object_label->object_label_section_n);
					write_l (4);
					write_l (12);
					section_string_offset+=13+n_digits (object_label->object_label_section_n);
					code_relocations_offset+=12*n_code_relocations_in_section;
				}
			}
		}
		offset+=12*n_code_relocations;

		data_relocations_offset=0;
	
		for_l (object_label,first_object_label,next){
			if (object_label->object_label_kind==DATA_CONTROL_SECTION){
				int n_data_relocations_in_section;
			
				n_data_relocations_in_section=object_label->object_label_n_relocations;
				
				if (n_data_relocations_in_section>0){
					write_l (section_string_offset);
					write_l (SHT_RELA);
					write_l (0);
					write_l (0);
					write_l (offset+data_relocations_offset);
					write_l (12*n_data_relocations_in_section);
					write_l (n_sections+n_code_relocation_sections+n_data_relocation_sections+2);
					write_l (2+n_code_sections+object_label->object_label_section_n);
					write_l (4);
					write_l (12);
					section_string_offset+=13+n_digits (object_label->object_label_section_n);
					data_relocations_offset+=12*n_data_relocations_in_section;
				}
			}
		}
		offset+=12*n_data_relocations;
	}
#else
    /* offset 0x84: section header 2 */
    write_l (11);					/* .text offset */
    write_l (SHT_PROGBITS);
    write_l (SHF_ALLOC | SHF_EXECINSTR);
    write_l (0);
    write_l (offset);
    write_l (code_buffer_offset);   /* size */
    write_l (0);
    write_l (0);
    write_l (4);					/* align */
    write_l (0);
	offset+=code_buffer_offset;
    /* offset 0xac: section header 3 */
    write_l (17);  						/* .data offset */
    write_l (SHT_PROGBITS);
    write_l (SHF_ALLOC | SHF_WRITE);
    write_l (0);
    write_l (offset);
    write_l (data_buffer_offset);	     /* size */
    write_l (0);
    write_l (0);
    write_l (data_section_alignment_mask+1);	/* align */
    write_l (0);
	offset+=data_buffer_offset;
    /* offet 0xd4: section header 4 */
    write_l (23); 					 	/* .rela.text offset */
    write_l (SHT_RELA);
    write_l (0);
    write_l (0);
    write_l (offset);
    write_l (12*n_code_relocations);	/* size */
    write_l (6);						/* symbol table index */
    write_l (2);						/* text section index */
    write_l (4);    					/* align */
    write_l (12);
	offset+=12*n_code_relocations;
    /* offset 0xfc: section header 5 */
    write_l (34);  						/* .rela.data offset */
    write_l (SHT_RELA);
    write_l (0);
    write_l (0);
    write_l (offset);
    write_l (12*n_data_relocations);	/* size */
    write_l (6);						/* symbol table index */
    write_l (3);						/* data section index */
    write_l (4);  						/* align */
    write_l (12);
	offset+=12*n_data_relocations;
#endif

    /* offset 0x124: section header 6 */
#ifdef FUNCTION_LEVEL_LINKING
	write_l (11+section_strings_size);
#else
    write_l (45);   /* .symtab offset */
#endif
    write_l (SHT_SYMTAB);
    write_l (0);
    write_l (0);
    write_l (offset);
	write_l (16*(n_object_labels+n_sections));
#ifdef FUNCTION_LEVEL_LINKING
	write_l (n_sections+n_code_relocation_sections+n_data_relocation_sections+3);
	write_l (1+n_sections);
#else
    write_l (7);						/* string table index */
    write_l (3);
#endif
    write_l (4); 						/* align */
    write_l (16);
	offset+=16*(n_object_labels+n_sections);
    /* offset 0x14c: section header 7 */
#ifdef FUNCTION_LEVEL_LINKING
	write_l (19+section_strings_size);
#else
    write_l (53);  						/* .strtab offset */
#endif
    write_l (SHT_STRTAB);
    write_l (0);
    write_l (0);
    write_l (offset);
    write_l (string_table_offset);	 	/* size */
    write_l (0);
    write_l (0);
    write_l (0);  						/* align */
    write_l (0);

    /* offset 0x174: section 1 */
    write_c (0);
    write_zstring (".shstrtab"); /* 1 */
#ifdef FUNCTION_LEVEL_LINKING
	{
		struct object_label *object_label;
		int section_n;
		char section_name[20];

		for (section_n=0; section_n<n_code_sections; ++section_n){
			sprintf (section_name,".text.m%d",section_n);
			write_zstring (section_name);
		}

		for (section_n=0; section_n<n_data_sections; ++section_n){
			sprintf (section_name,".data.m%d",section_n);
			write_zstring (section_name);
		}

		for_l (object_label,first_object_label,next)
			if (object_label->object_label_kind==CODE_CONTROL_SECTION && object_label->object_label_n_relocations>0){ 
				sprintf (section_name,".rela.text.m%d",object_label->object_label_section_n);
				write_zstring (section_name);
			}
	
		for_l (object_label,first_object_label,next)
			if (object_label->object_label_kind==DATA_CONTROL_SECTION && object_label->object_label_n_relocations>0){ 
				sprintf (section_name,".rela.data.m%d",object_label->object_label_section_n);
				write_zstring (section_name);
			}
	}
#else
    write_zstring (".text");     /* 11 */
    write_zstring (".data");     /* 17 */
    write_zstring (".rela.text");/* 23 */
    write_zstring (".rela.data");/* 34 */
#endif
    write_zstring (".symtab");   /* 45 */
    write_zstring (".strtab");   /* 53 */
                                 /* 61 */
#ifdef FUNCTION_LEVEL_LINKING
	if (((27+section_strings_size) & 3)!=0){
		int n;

		n=4-((27+section_strings_size) & 3);
		do {
			write_c (0);
		} while (--n);
	}
#else
	write_c (0);
	write_c (0);
	write_c (0);
	/* offset 0x1b4 */
#endif
}

static void as_indirect_node_entry_jumps (struct label_node *label_node)
{
	LABEL *label;
	
	if (label_node==NULL)
		return;
	
	label=&label_node->label_node_label;
	
	if (!(label->label_flags & LOCAL_LABEL) && label->label_number==0)
		if (label->label_flags & NODE_ENTRY_LABEL)
			as_indirect_node_entry_jump (label);
	
	as_indirect_node_entry_jumps (label_node->label_node_left);
	as_indirect_node_entry_jumps (label_node->label_node_right);
}

#ifdef NEW_APPLY
extern LABEL *add_empty_node_labels[];

static void as_apply_update_entry (struct basic_block *block)
{
	if (block->block_n_node_arguments==-200){
		as_i_bica (0,A_COND);
		as_branch_label (block->block_ea_label,BRANCH_RELOCATION);
		as_nop();
		as_nop();
		as_nop();
	} else {
		as_dec (4,B_STACK_POINTER);
		as_i_call (0);
		as_branch_label (add_empty_node_labels[block->block_n_node_arguments+200],CALL_RELOCATION);
		as_st (REGISTER_O7,0,B_STACK_POINTER);
		as_i_bica (0,A_COND);
		as_branch_label (block->block_ea_label,BRANCH_RELOCATION);
	}
}
#endif

void write_code (void)
{
	struct basic_block *block;
	struct call_and_jump *call_and_jump;

	first_call_and_jump=NULL;

	as_indirect_node_entry_jumps (labels);

#ifdef FUNCTION_LEVEL_LINKING
	if (first_block!=NULL && !(first_block->block_begin_module && !first_block->block_link_module))
		first_block->block_begin_module=1;
#endif

	for_l (block,first_block,block_next){
#ifdef FUNCTION_LEVEL_LINKING
		if (block->block_begin_module){
			if (block->block_link_module){
				if (code_object_label!=NULL && CURRENT_CODE_OFFSET!=code_object_label->object_label_offset && block->block_labels){
					struct relocation *new_relocation;
					
					new_relocation=fast_memory_allocate_type (struct relocation);
					++n_code_relocations;
					
					*last_code_relocation_l=new_relocation;
					last_code_relocation_l=&new_relocation->next;
					new_relocation->next=NULL;
					
					U5 (new_relocation,
						relocation_label=block->block_labels->block_label_label,
						relocation_offset=CURRENT_CODE_OFFSET,
						relocation_object_label=code_object_label,
						relocation_kind=DUMMY_BRANCH_RELOCATION,
						relocation_addend=0);

					as_new_code_module();
				}
			} else
				as_new_code_module();
		}
#endif

		if (block->block_n_node_arguments>-100){
			if (block->block_ea_label!=NULL){
				int n_node_arguments;
				extern LABEL *eval_fill_label,*eval_upd_labels[];
				
				n_node_arguments=block->block_n_node_arguments;
				
				if (n_node_arguments<-2)
					n_node_arguments=1;
				
				if (n_node_arguments>=0 && block->block_ea_label!=eval_fill_label){
					as_sethi (0,REGISTER_A2);
					as_hi_or_lo_label (block->block_ea_label,0,HI22_RELOCATION);

					as_i_call (0);
					as_branch_label (eval_upd_labels[n_node_arguments],CALL_RELOCATION);

					as_ori (REGISTER_A2,0,REGISTER_A2);
					as_hi_or_lo_label (block->block_ea_label,0,LO12_RELOCATION);
				} else {
					as_i_call (0);
					as_branch_label (block->block_ea_label,CALL_RELOCATION);
					
					as_nop();
					as_nop();
				}
				
				if (block->block_descriptor!=NULL && (block->block_n_node_arguments<0 || parallel_flag)){
					store_label_in_code_section (block->block_descriptor);
				} else
					as_number_of_arguments (0);
			} else
				if (block->block_descriptor!=NULL)
					store_label_in_code_section (block->block_descriptor);
				else
					as_number_of_arguments (0);

			as_number_of_arguments (block->block_n_node_arguments);
		}
#ifdef NEW_APPLY
		else if (block->block_n_node_arguments<-100)
			as_apply_update_entry (block);
#endif

		as_labels (block->block_labels);

		if (block->block_n_new_heap_cells>0)
			as_garbage_collect_test (block);
		
		as_instructions (block->block_instructions);
	}
	
	for (call_and_jump=first_call_and_jump; call_and_jump!=NULL; call_and_jump=call_and_jump->cj_next){
#ifdef FUNCTION_LEVEL_LINKING
		as_new_code_module();
#endif
		as_call_and_jump (call_and_jump);
	}

#ifndef FUNCTION_LEVEL_LINKING
	as_nop();
#endif
}

static void relocate_code (void)
{
	struct relocation *relocation,**relocation_p;
	struct object_buffer *object_buffer;
	int buffer_offset;
	struct label *label;
	int instruction_offset;
	ULONG *instruction_p;
	
	object_buffer=first_code_buffer;
	buffer_offset=0;
	
	relocation_p=&first_code_relocation;
	
	while (relocation=*relocation_p,relocation!=NULL){
		label=relocation->relocation_label;

		switch (relocation->relocation_kind){
			case BRANCH_RELOCATION:
				if (label->label_id==TEXT_LABEL_ID
#ifdef FUNCTION_LEVEL_LINKING
					&& label->label_object_label==relocation->relocation_object_label
#endif
				){
					instruction_offset=relocation->relocation_offset;
					while (instruction_offset >= buffer_offset+BUFFER_SIZE){
						object_buffer=object_buffer->next;
						buffer_offset+=BUFFER_SIZE;
					}

					instruction_p=(ULONG*)((char*)(object_buffer->data)+(instruction_offset-buffer_offset));

					*instruction_p= ((*instruction_p)& 0xffc00000) | (((label->label_offset-instruction_offset+relocation->relocation_addend)>>2) & 0x3fffff);

					*relocation_p=relocation->next;
					--n_code_relocations;
					continue;
				}
#ifdef FUNCTION_LEVEL_LINKING
				else if (label->label_id==TEXT_LABEL_ID || label->label_id==DATA_LABEL_ID){
					if (label->label_object_label==NULL)
						internal_error_in_function ("relocate_code");
					
					relocation->relocation_addend -= label->label_object_label->object_label_offset;
				}
#endif
				break;
			case CALL_RELOCATION:
				if (label->label_id==TEXT_LABEL_ID
#ifdef FUNCTION_LEVEL_LINKING
					&& label->label_object_label==relocation->relocation_object_label
#endif
				){
					instruction_offset=relocation->relocation_offset;
					while (instruction_offset >= buffer_offset+BUFFER_SIZE){
						object_buffer=object_buffer->next;
						buffer_offset+=BUFFER_SIZE;
					}

					instruction_p=(ULONG*)((char*)(object_buffer->data)+(instruction_offset-buffer_offset));

					*instruction_p= ((*instruction_p)& 0xc0000000) | (((label->label_offset-instruction_offset+relocation->relocation_addend)>>2) & 0x3fffffff);					

					*relocation_p=relocation->next;
					--n_code_relocations;
					continue;
				}
#ifdef FUNCTION_LEVEL_LINKING
				else if (label->label_id==TEXT_LABEL_ID || label->label_id==DATA_LABEL_ID){
					if (label->label_object_label==NULL)
						internal_error_in_function ("relocate_code");
					
					relocation->relocation_addend -= label->label_object_label->object_label_offset;
				}
#endif
				break;
#ifdef FUNCTION_LEVEL_LINKING
			case HI22_RELOCATION:
			case LO12_RELOCATION:
			case LONG_WORD_RELOCATION:
				if (label->label_id==TEXT_LABEL_ID || label->label_id==DATA_LABEL_ID){
					if (label->label_object_label==NULL)
						internal_error_in_function ("relocate_code");
						
					relocation->relocation_addend -= label->label_object_label->object_label_offset;
				}
				break;
			case DUMMY_BRANCH_RELOCATION:
				if (label->label_id==TEXT_LABEL_ID){
					if (label->label_object_label!=relocation->relocation_object_label){
						relocation->relocation_addend -= label->label_object_label->object_label_offset;
						relocation_p=&relocation->next;
					} else {
						*relocation_p=relocation->next;
						--n_code_relocations;
					}
					continue;
				} else {
					internal_error_in_function ("relocate_code");
					*relocation_p=relocation->next;
				}
#endif
		}

		relocation_p=&relocation->next;
	}
}

static void relocate_data (void)
{
#ifdef FUNCTION_LEVEL_LINKING
	struct relocation *relocation;

	for_l (relocation,first_data_relocation,next){
		switch (relocation->relocation_kind){
			case LONG_WORD_RELOCATION:
			{
				struct label *label;
			
				label=relocation->relocation_label;
				
				if (label->label_id==TEXT_LABEL_ID || label->label_id==DATA_LABEL_ID){
					if (label->label_object_label==NULL)
						internal_error_in_function ("relocate_data");
		
					relocation->relocation_addend -= label->label_object_label->object_label_offset;
				}
			}
		}
	}
#endif
}

#ifdef FUNCTION_LEVEL_LINKING
static int elf_label_number (struct label *label)
{
	int label_n;
					
	label_n=label->label_id;
	if (label_n==TEXT_LABEL_ID){
		label_n=label->label_object_label->object_label_number;
		if (label_n==0)
			return 1+label->label_object_label->object_label_section_n;
		else
			return label_n+n_sections;
	} else if (label_n==DATA_LABEL_ID){
		label_n=label->label_object_label->object_label_number;
		if (label_n==0)
			return 1+n_code_sections+label->label_object_label->object_label_section_n;
		else
			return label_n+n_sections;
	} else {
		if (label_n==-1)
			internal_error_in_function ("elf_label_number");
		return label_n+n_sections;
	}
}
#endif

static void write_code_relocations (void)
{
	struct relocation *relocation;
	
	for_l (relocation,first_code_relocation,next){
		struct label *label;
		
		label=relocation->relocation_label;

		switch (relocation->relocation_kind){
			case BRANCH_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_WDISP22));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_WDISP22));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			case CALL_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_WDISP30));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_WDISP30));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			case HI22_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_HI22));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_HI22));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			case LO12_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_LO10));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_LO10));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			case LONG_WORD_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_32));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_32));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			case DUMMY_BRANCH_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_NONE));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_NONE));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			default:
				internal_error_in_function ("write_code_relocations");
		}
	}
}

static void write_data_relocations (void)
{
	struct relocation *relocation;
	
	for_l (relocation,first_data_relocation,next){
		struct label *label;
		
		label=relocation->relocation_label;
		switch (relocation->relocation_kind){
			case LONG_WORD_RELOCATION:
				write_l (relocation->relocation_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (ELF32_R_INFO (elf_label_number (label),R_SPARC_32));
#else
				write_l (ELF32_R_INFO (label->label_id,R_SPARC_32));
#endif
				write_l (relocation->relocation_addend+label->label_offset);
				break;
			default:
				internal_error_in_function ("write_data_relocations");
		}
	}
}

static void write_object_labels (void)
{
	struct object_label *object_label;
	int code_section_number,data_section_number;
#if defined (RELOCATIONS_RELATIVE_TO_EXPORTED_DATA_LABEL) && defined (FUNCTION_LEVEL_LINKING)
	struct object_label *current_text_or_data_object_label;

	current_text_or_data_object_label=NULL;
#endif

	code_section_number=0;
	data_section_number=0;

	write_l (0);
	write_l (0);
	write_l (0);
	write_l (0);
# ifndef FUNCTION_LEVEL_LINKING
	write_l (0);
	write_l (0);
	write_l (0);
	write_c (ELF32_ST_INFO (STB_LOCAL,STT_SECTION));
	write_c (0);
	write_w (2);

	write_l (0);
	write_l (0);
	write_l (0);
	write_c (ELF32_ST_INFO (STB_LOCAL,STT_SECTION));
	write_c (0);
	write_w (3);
#else
	{
		int section_n;

		for (section_n=0; section_n<n_code_sections; ++section_n){
			write_l (0);
			write_l (0);
			write_l (0);
			write_c (ELF32_ST_INFO (STB_LOCAL,STT_SECTION));
			write_c (0);
			write_w (2+section_n);
		}

		for (section_n=0; section_n<n_data_sections; ++section_n){
			write_l (0);
			write_l (0);
			write_l (0);
			write_c (ELF32_ST_INFO (STB_LOCAL,STT_SECTION));
			write_c (0);
			write_w (2+n_code_sections+section_n);
		}
	}
# endif

	for_l (object_label,first_object_label,next){
		switch (object_label->object_label_kind){
			case CODE_CONTROL_SECTION:
				break;
			case DATA_CONTROL_SECTION:
#if defined (RELOCATIONS_RELATIVE_TO_EXPORTED_DATA_LABEL) && defined (FUNCTION_LEVEL_LINKING)
				current_text_or_data_object_label=object_label;
#endif
				break;
			case IMPORTED_LABEL:
				write_l (object_label->object_label_string_offset);
				write_l (0);
				write_l (0);
				write_c (ELF32_ST_INFO (STB_GLOBAL,STT_NOTYPE));
				write_c (0);
				write_w (0);
				break;
			case EXPORTED_CODE_LABEL:
			{
				struct label *label;
				
				label=object_label->object_label_label;

				write_l (object_label->object_label_string_offset);
#ifdef FUNCTION_LEVEL_LINKING
				write_l (label->label_offset - label->label_object_label->object_label_offset);
#else
				write_l (label->label_offset);
#endif
				write_l (0);
				write_c (ELF32_ST_INFO (STB_GLOBAL,STT_FUNC));
				write_c (0);
#ifdef FUNCTION_LEVEL_LINKING
				write_w (2+label->label_object_label->object_label_section_n);
#else
				write_w (2);
#endif
				break;
			}
			case EXPORTED_DATA_LABEL:
			{
				struct label *label;
				
				label=object_label->object_label_label;

				write_l (object_label->object_label_string_offset);
#ifdef FUNCTION_LEVEL_LINKING
# ifdef RELOCATIONS_RELATIVE_TO_EXPORTED_DATA_LABEL
				write_l (label->label_offset - current_text_or_data_object_label->object_label_offset);
# else
				write_l (label->label_offset - label->label_object_label->object_label_offset);
#endif
#else
				write_l (label->label_offset);
#endif
				write_l (0);
				write_c (ELF32_ST_INFO (STB_GLOBAL,STT_OBJECT));
				write_c (0);
#ifdef FUNCTION_LEVEL_LINKING
				write_w (2+n_code_sections+label->label_object_label->object_label_section_n);
#else
				write_w (3);
#endif
				break;
			}
			default:
				internal_error_in_function ("write_object_labels");
		}
	}
}

static void write_string_table (void)
{
	struct object_label *object_label;

	write_c (0);

	for_l (object_label,first_object_label,next){
		int object_label_kind;
		
		object_label_kind=object_label->object_label_kind;
		
		if ((object_label_kind==IMPORTED_LABEL || object_label_kind==EXPORTED_CODE_LABEL || object_label_kind==EXPORTED_DATA_LABEL)
			&& object_label->object_label_string_offset!=0)
		{
			char *s,c;
				
			s=object_label->object_label_label->label_name;

			do {
				c=*s++;
				write_c (c);
			} while (c!='\0');
		}
	}
}

void assemble_code (void)
{
	as_import_labels (labels);

	write_code();

	flush_data_buffer();
	flush_code_buffer();

#ifndef FUNCTION_LEVEL_LINKING
	code_object_label->object_label_length=code_buffer_offset;
	data_object_label->object_label_length=data_buffer_offset;
#endif

	relocate_code();
	relocate_data();

	write_file_header_and_section_headers();

	write_buffers_and_release_memory (&first_code_buffer);
	write_buffers_and_release_memory (&first_data_buffer);
	
	write_code_relocations();
	write_data_relocations();
	
	write_object_labels();

	write_string_table();
}