summaryrefslogtreecommitdiff
path: root/compiler/aasmtai.pas
blob: 4b1781566264b48a757e0ca134cda5f8229ed8dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
{
    Copyright (c) 1998-2006 by Florian Klaempfl

    This unit implements an abstract asmoutput class for all processor types

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

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

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
{ @abstract(This unit implements an abstract asm output class for all processor types)
  This unit implements an abstract assembler output class for all processors, these
  are then overridden for each assembler writer to actually write the data in these
  classes to an assembler file.
}

unit aasmtai;

{$i fpcdefs.inc}

interface

    uses
       cutils,cclasses,
       globtype,systems,
       cpuinfo,cpubase,
{$ifdef llvm}
       { overrides max_operands }
       llvmbase,
{$endif llvm}
       cgbase,cgutils,
       symtype,
       aasmbase,aasmdata,ogbase
{$ifdef jvm}
       ,widestr
{$endif jvm}
       ;

    type
       { keep the number of elements in this enumeration less or equal than 32 as long
         as FPC knows only 4 byte and 32 byte sets (FK) }
       taitype = (
          ait_none,
          ait_align,
          ait_section,
          ait_comment,
          ait_string,
          ait_instruction,
          ait_datablock,
          ait_symbol,
          { needed to calc the size of a symbol }
          ait_symbol_end,
          ait_directive,
          ait_label,
          ait_const,
          ait_real_32bit,
          ait_real_64bit,
          ait_real_80bit,
          ait_comp_64bit,
          ait_real_128bit,
          ait_stab,
          ait_force_line,
          ait_function_name,
{$ifdef alpha}
          { the follow is for the DEC Alpha }
          ait_frame,
{$endif alpha}
{$ifdef ia64}
          ait_bundle,
          ait_stop,
{$endif ia64}
{$ifdef m68k}
          ait_labeled_instruction,
{$endif m68k}
{$ifdef arm}
          ait_thumb_func,
          ait_thumb_set,
{$endif arm}
          ait_set,
          ait_weak,
          { used to split into tiny assembler files }
          ait_cutobject,
          ait_regalloc,
          ait_tempalloc,
          { used to mark assembler blocks and inlined functions }
          ait_marker,
          { used to describe a new location of a variable }
          ait_varloc,
{$ifdef JVM}
          { JVM only }
          ait_jvar,    { debug information for a local variable }
          ait_jcatch,  { exception catch clause }
{$endif JVM}
{$ifdef llvm}
          ait_llvmins, { llvm instruction }
          ait_llvmalias, { alias for a symbol }
          ait_llvmdecl, { llvm symbol declaration (global/external variable, external procdef) }
{$endif}
          { SEH directives used in ARM,MIPS and x86_64 COFF targets }
          ait_seh_directive
          );

        taiconst_type = (
          aitconst_128bit,
          aitconst_64bit,
          aitconst_32bit,
          aitconst_16bit,
          aitconst_8bit,
          aitconst_sleb128bit,
          aitconst_uleb128bit,
          { win32 only }
          aitconst_rva_symbol,
          aitconst_secrel32_symbol,
          { darwin only }
          { From gcc/config/darwin.c (darwin_asm_output_dwarf_delta):
            ***
            Output a difference of two labels that will be an assembly time
            constant if the two labels are local.  (.long lab1-lab2 will be
            very different if lab1 is at the boundary between two sections; it
            will be relocated according to the second section, not the first,
            so one ends up with a difference between labels in different
            sections, which is bad in the dwarf2 eh context for instance.)
            ***
            We cannot use this everywhere, because older versions of the
            darwin assembler don't support the construct used for these
            relsyms (nor do they support dwarf, for that matter)
          }
          aitconst_darwin_dwarf_delta64,
          aitconst_darwin_dwarf_delta32,
          { ARM Thumb-2 only }
          aitconst_half16bit, { used for table jumps. The actual value is the 16bit value shifted left once }
          { for use by dwarf debugger information }
          aitconst_16bit_unaligned,
          aitconst_32bit_unaligned,
          aitconst_64bit_unaligned,
          { i8086 far pointer; emits: 'DW symbol, SEG symbol' }
          aitconst_farptr,
          { offset of symbol's GOT slot in GOT }
          aitconst_got,
          { offset of symbol itself from GOT }
          aitconst_gotoff_symbol
        );

    const
{$if defined(cpu64bitaddr)}
       aitconst_ptr = aitconst_64bit;
       aitconst_ptr_unaligned = aitconst_64bit_unaligned;
{$elseif defined(cpu32bitaddr)}
       aitconst_ptr = aitconst_32bit;
       aitconst_ptr_unaligned = aitconst_32bit_unaligned;
{$elseif defined(cpu16bitaddr)}
       aitconst_ptr = aitconst_16bit;
       aitconst_ptr_unaligned = aitconst_16bit_unaligned;
{$endif}

{$if defined(cpu64bitalu)}
       aitconst_aint = aitconst_64bit;
{$elseif defined(cpu32bitalu)}
       aitconst_aint = aitconst_32bit;
{$elseif defined(cpu16bitalu)}
       aitconst_aint = aitconst_16bit;
{$elseif defined(cpu8bitalu)}
       aitconst_aint = aitconst_8bit;
{$endif}

       taitypestr : array[taitype] of string[24] = (
          '<none>',
          'align',
          'section',
          'comment',
          'string',
          'instruction',
          'datablock',
          'symbol',
          'symbol_end',
          'symbol_directive',
          'label',
          'const',
          'real_32bit',
          'real_64bit',
          'real_80bit',
          'comp_64bit',
          'real_128bit',
          'stab',
          'force_line',
          'function_name',
{$ifdef alpha}
          { the follow is for the DEC Alpha }
          'frame',
{$endif alpha}
{$ifdef ia64}
          'bundle',
          'stop',
{$endif ia64}
{$ifdef m68k}
          'labeled_instr',
{$endif m68k}
{$ifdef arm}
          'thumb_func',
          'thumb_set',
{$endif arm}
          'set',
          'weak',
          'cut',
          'regalloc',
          'tempalloc',
          'marker',
          'varloc',
{$ifdef JVM}
          'jvar',
          'jcatch',
{$endif JVM}
{$ifdef llvm}
          'llvmins',
          'llvmalias',
          'llvmdecl',
{$endif}
          'seh_directive'
          );

    type
      { Types of operand }
      toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
{$ifdef arm}
       { ARM only }
       ,top_regset
       ,top_conditioncode
       ,top_modeflags
       ,top_specialreg
{$endif arm}
{$if defined(arm) or defined(aarch64)}
       ,top_shifterop
{$endif defined(arm) or defined(aarch64)}
{$ifdef m68k}
       { m68k only }
       ,top_regset
{$endif m68k}
{$ifdef jvm}
       { jvm only}
       ,top_single
       ,top_double
       ,top_string
       ,top_wstring
{$endif jvm}
{$ifdef llvm}
       { llvm only }
       ,top_single
       ,top_double
{$ifdef cpuextended}
       ,top_extended80
{$endif cpuextended}
       ,top_def
       ,top_fpcond
       ,top_cond
       ,top_para
{$endif llvm}
       );

      { kinds of operations that an instruction can perform on an operand }
      topertype = (operand_read,operand_write,operand_readwrite);

      tlocaloper = record
        localsym : pointer;
        localsymderef : tderef;
        localsymofs : longint;
        localindexreg : tregister;
        localscale : byte;
        localgetoffset,
        localforceref : boolean
      end;
      plocaloper = ^tlocaloper;

      { please keep the size of this record <=12 bytes and keep it properly aligned }
      toper = record
        ot : longint;
        case typ : toptype of
          top_none   : ();
          top_reg    : (reg:tregister);
          top_ref    : (ref:preference);
          top_const  : (val:tcgint);
          top_bool   : (b:boolean);
          { local varsym that will be inserted in pass_generate_code }
          top_local  : (localoper:plocaloper);
      {$ifdef arm}
          top_regset : (regset:^tcpuregisterset; regtyp: tregistertype; subreg: tsubregister; usermode: boolean);
          top_conditioncode : (cc : TAsmCond);
          top_modeflags : (modeflags : tcpumodeflags);
          top_specialreg : (specialreg:tregister; specialflags:tspecialregflags);
      {$endif arm}
      {$if defined(arm) or defined(aarch64)}
          top_shifterop : (shifterop : pshifterop);
      {$endif defined(arm) or defined(aarch64)}
      {$ifdef m68k}
          top_regset : (dataregset,addrregset:^tcpuregisterset);
      {$endif m68k}
      {$ifdef jvm}
          top_single : (sval:single);
          top_double : (dval:double);
          top_string : (pcvallen: aint; pcval: pchar);
          top_wstring : (pwstrval: pcompilerwidestring);
      {$endif jvm}
      {$ifdef llvm}
          top_single : (sval:single);
          top_double : (dval:double);
        {$ifdef cpuextended}
          top_extended80 : (eval:extended);
        {$endif cpuextended}
          top_def    : (def: tdef);
          top_cond   : (cond: topcmp);
          top_fpcond : (fpcond: tllvmfpcmp);
          top_para   : (paras: tfplist);
      {$endif llvm}
      end;
      poper=^toper;

    const
      { ait_* types which don't result in executable code or which don't influence
        the way the program runs/behaves, but which may be encountered by the
        optimizer (= if it's sometimes added to the exprasm list). Update if you add
        a new ait type!                                                              }
      SkipInstr = [ait_comment, ait_symbol,ait_section
                   ,ait_stab, ait_function_name, ait_force_line
                   ,ait_regalloc, ait_tempalloc, ait_symbol_end
                   ,ait_directive
                   ,ait_varloc,
{$ifdef JVM}
                   ait_jvar, ait_jcatch,
{$endif JVM}
                   ait_seh_directive];

      { ait_* types which do not have line information (and hence which are of type
        tai, otherwise, they are of type tailineinfo }
      SkipLineInfo =[ait_label,
                     ait_regalloc,ait_tempalloc,
                     ait_stab,ait_function_name,
                     ait_cutobject,ait_marker,ait_varloc,ait_align,ait_section,ait_comment,
                     ait_const,ait_directive,
{$ifdef arm}
                     ait_thumb_func,
                     ait_thumb_set,
{$endif arm}
                     ait_set,ait_weak,
                     ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
                     ait_symbol,
{$ifdef JVM}
                     ait_jvar, ait_jcatch,
{$endif JVM}
{$ifdef llvm}
                     ait_llvmdecl,
{$endif llvm}
                     ait_seh_directive
                    ];


    type
      { cut type, required for alphanumeric ordering of the assembler filenames }
      TCutPlace=(cut_normal,cut_begin,cut_end);

      TAsmMarker = (
        mark_NoPropInfoStart,mark_NoPropInfoEnd,
        mark_AsmBlockStart,mark_AsmBlockEnd,
        mark_NoLineInfoStart,mark_NoLineInfoEnd,mark_BlockStart,
        mark_Position
      );

      TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);

      TStabType = (stab_stabs,stab_stabn,stab_stabd,
                   { AIX/XCOFF stab types }
                   stab_stabx,
                   { begin/end include file }
                   stabx_bi,stabx_ei,
                   { begin/end function }
                   stabx_bf, stabx_ef,
                   { begin/end static data block }
                   stabx_bs, stabx_es,
                   { line spec, function start/end label }
                   stabx_line, stabx_function);

      TAsmDirective=(
        asd_indirect_symbol,
        asd_extern,asd_nasm_import, asd_toc_entry,
        asd_reference,asd_no_dead_strip,asd_weak_reference,asd_lazy_reference,
        asd_weak_definition,
        { for Jasmin }
        asd_jclass,asd_jinterface,asd_jsuper,asd_jfield,asd_jlimit,asd_jline,
        { .ent/.end for MIPS and Alpha }
        asd_ent,asd_ent_end
      );

      TAsmSehDirective=(
          ash_proc,ash_endproc,
          ash_endprologue,ash_handler,ash_handlerdata,
          ash_eh,ash_32,ash_no32,
          ash_setframe,ash_stackalloc,ash_pushreg,
          ash_savereg,ash_savexmm,ash_pushframe
        );


    const
      regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
      tempallocstr : array[boolean] of string[10]=('released','allocated');
      stabtypestr : array[TStabType] of string[8]=(
        'stabs','stabn','stabd',
        'stabx',
        'bi','ei',
        'bf','ef',
        'bs','es',
        'line','function');
      directivestr : array[TAsmDirective] of string[23]=(
        'indirect_symbol',
        'extern','nasm_import', 'tc', 'reference',
        'no_dead_strip','weak_reference','lazy_reference','weak_definition',
        { for Jasmin }
        'class','interface','super','field','limit','line',
        { .ent/.end for MIPS and Alpha }
        'ent','end'
      );
      sehdirectivestr : array[TAsmSehDirective] of string[16]=(
        '.seh_proc','.seh_endproc',
        '.seh_endprologue','.seh_handler','.seh_handlerdata',
        '.seh_eh','.seh_32','seh_no32',
        '.seh_setframe','.seh_stackalloc','.seh_pushreg',
        '.seh_savereg','.seh_savexmm','.seh_pushframe'
      );

    type
       { abstract assembler item }
       tai = class(TLinkedListItem)
{$ifndef NOOPT}
          { pointer to record with optimizer info about this tai object }
          optinfo  : pointer;
{$endif NOOPT}
          typ      : taitype;
          constructor Create;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
          procedure ppuwrite(ppufile:tcompilerppufile);virtual;
          procedure buildderefimpl;virtual;
          procedure derefimpl;virtual;
       end;

       { abstract assembler item with line information }
       tailineinfo = class(tai)
        fileinfo : tfileposinfo;
        constructor Create;
        constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
        procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       tai_simple = class(tai)
         constructor create(_typ : taitype);
       end;

       taiclass = class of tai;

       taiclassarray = array[taitype] of taiclass;

       { Generates an assembler string }
       tai_string = class(tailineinfo)
          str : pchar;
          { extra len so the string can contain an \0 }
          len : longint;
          constructor Create(const _str : string);
          constructor Create_pchar(_str : pchar;length : longint);
          destructor Destroy;override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          function getcopy:tlinkedlistitem;override;
       end;

       { Generates a common label }
       tai_symbol = class(tai)
          sym       : tasmsymbol;
          value     : puint;
          size      : longint;
          is_global,
          has_value : boolean;
          constructor Create(_sym:tasmsymbol;siz:longint);
          constructor Create_Global(_sym:tasmsymbol;siz:longint);
          constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
          constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
          constructor Createname_global_value(const _name : string;_symtyp:Tasmsymtype;siz:longint;val:ptruint);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure derefimpl;override;
       end;

       tai_symbol_end = class(tailineinfo)
          sym : tasmsymbol;
          constructor Create(_sym:tasmsymbol);
          constructor Createname(const _name : string);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure derefimpl;override;
       end;

       tai_directive = class(tailineinfo)
          name : ansistring;
          directive : TAsmDirective;
          constructor Create(_directive:TAsmDirective;const _name:ansistring);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       { Generates an assembler label }
       tai_label = class(tai)
          labsym    : tasmlabel;
{$ifdef arm}
          { set to true when the label has been moved by insertpcrelativedata to the correct location
            so one label can be used multiple times }
          moved     : boolean;
          { true, if a label has been already inserted, this is important for arm thumb where no negative
            pc relative offsets are allowed }
          inserted  : boolean;
{$endif arm}
          constructor Create(_labsym : tasmlabel);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure derefimpl;override;
       end;

       { Generates an assembler comment }
       tai_comment = class(tai)
          str : pchar;
          constructor Create(_str : pchar);
          destructor Destroy; override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          function getcopy:tlinkedlistitem;override;
       end;


       { Generates a section / segment directive }
       tai_section = class(tai)
          sectype  : TAsmSectiontype;
          secorder : TasmSectionorder;
          secalign : byte;
          name     : pshortstring;
          sec      : TObjSection; { used in binary writer }
          destructor Destroy;override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
{$push}{$warnings off}
         private
          { this constructor is made private on purpose }
          { because sections should be created via new_section() }
          constructor Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
{$pop}
       end;


       { Generates an uninitializised data block }
       tai_datablock = class(tailineinfo)
          is_global : boolean;
          sym       : tasmsymbol;
          size      : asizeint;
          constructor Create(const _name : string;_size : aint);
          constructor Create_global(const _name : string;_size : asizeint);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure derefimpl;override;
       end;


       { Generates an integer const }

       { tai_const }

       tai_const = class(tai)
          sym,
          endsym  : tasmsymbol;
          { if symbols and offset are provided the symofs is used,
            the value is calculated during assembling }
          symofs,
          value   : int64;
          consttype : taiconst_type;
          { we use for the 128bit int64/qword for now because I can't imagine a
            case where we need 128 bit now (FK) }
          constructor Create(_typ:taiconst_type;_value : int64);
          constructor Create_128bit(_value : int64);
          constructor Create_64bit(_value : int64);
          constructor Create_32bit(_value : longint);
          constructor Create_16bit(_value : word);
          constructor Create_64bit_unaligned(_value : int64);
          constructor Create_32bit_unaligned(_value : longint);
          constructor Create_16bit_unaligned(_value : word);
          constructor Create_8bit(_value : byte);
          constructor Create_char(size: integer; _value: dword);
          constructor Create_sleb128bit(_value : int64);
          constructor Create_uleb128bit(_value : qword);
          constructor Create_aint(_value : aint);
          constructor Create_pint(_value : pint);
          constructor Create_pint_unaligned(_value : pint);
          constructor Create_sym(_sym:tasmsymbol);
{$ifdef i8086}
          constructor Create_sym_near(_sym:tasmsymbol);
          constructor Create_sym_far(_sym:tasmsymbol);
{$endif i8086}
          constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
          constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
          constructor Create_type_sym_offset(_typ:taiconst_type;_sym:tasmsymbol;ofs:aint);
          constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
          constructor Create_rel_sym_offset(_typ : taiconst_type; _sym,_endsym : tasmsymbol; _ofs : int64);
          constructor Create_rva_sym(_sym:tasmsymbol);
          constructor Createname(const name:string;ofs:aint);
          constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
          constructor Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
          constructor Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:aint);
          constructor Create_nil_codeptr;
          constructor Create_nil_dataptr;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure derefimpl;override;
          function getcopy:tlinkedlistitem;override;
          function size:longint;
       end;

       { Generates a single float (32 bit real) }
       tai_real_32bit = class(tai)
          value : ts32real;
          constructor Create(_value : ts32real);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       tformatoptions = (fo_none,fo_hiloswapped);

       { Generates a double float (64 bit real) }
       tai_real_64bit = class(tai)
          value : ts64real;
{$ifdef ARM}
          formatoptions : tformatoptions;
          constructor Create_hiloswapped(_value : ts64real);
{$endif ARM}
          constructor Create(_value : ts64real);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;


       { Generates an extended float (80 bit real) }
       tai_real_80bit = class(tai)
          value : ts80real;
          savesize : byte;
          constructor Create(_value : ts80real; _savesize: byte);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;


       { Generates an float128 (128 bit real) }
       tai_real_128bit = class(tai)
          value : ts128real;
          constructor Create(_value : ts128real);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       { Generates a comp int (integer over 64 bits)

          This is Intel 80x86 specific, and is not
          really supported on other processors.
       }
       tai_comp_64bit = class(tai)
          value : ts64comp;
          constructor Create(_value : ts64comp);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       { tai_stab }

       tai_stab = class(tai)
          str : pchar;
          stabtype : TStabType;
          constructor Create(_stabtype:TStabType;_str : pchar);
          constructor Create_str(_stabtype:TStabType;const s:string);
          constructor create_ansistr(_stabtype: TStabType; const s: ansistring);
          destructor Destroy;override;
       end;

       tai_force_line = class(tailineinfo)
          constructor Create;
       end;

       tai_function_name = class(tai)
          funcname : pshortstring;
          constructor create(const s:string);
          destructor destroy;override;
       end;

       { Insert a cut to split assembler into several smaller files }
       tai_cutobject = class(tai)
          place : tcutplace;
          constructor Create;
          constructor Create_begin;
          constructor Create_end;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       { Insert a marker for assembler and inline blocks }
       tai_marker = class(tai)
          Kind: TAsmMarker;
          Constructor Create(_Kind: TAsmMarker);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       tai_tempalloc = class(tai)
          allocation : boolean;
{$ifdef EXTDEBUG}
          problem : pshortstring;
{$endif EXTDEBUG}
          temppos,
          tempsize   : longint;
          constructor alloc(pos,size:longint);
          constructor dealloc(pos,size:longint);
{$ifdef EXTDEBUG}
          constructor allocinfo(pos,size:longint;const st:string);
{$endif EXTDEBUG}
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          destructor destroy;override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       tai_regalloc = class(tai)
          reg     : tregister;
          ratype  : TRegAllocType;
          { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
          keep    : boolean;
          { reg(de)alloc belongs to this instruction, this
            is only used for automatic inserted (de)alloc for
            imaginary register and required for spilling code }
          instr   : tai;
          constructor alloc(r : tregister;ainstr:tai);
          constructor dealloc(r : tregister;ainstr:tai);
          constructor sync(r : tregister);
          constructor resize(r : tregister);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
       end;

       tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;

        { Class template for assembler instructions
        }
        tai_cpu_abstract = class(tailineinfo)
        protected
           procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
           procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
           procedure ppubuildderefimploper(var o:toper);virtual;abstract;
           procedure ppuderefoper(var o:toper);virtual;abstract;
        public
           { Condition flags for instruction }
           condition : TAsmCond;
           { Number of operands to instruction }
           ops       : byte;
           { Number of allocate oper structures }
           opercnt   : byte;
           { Operands of instruction }
           oper      : array[0..max_operands-1] of poper;
           { Actual opcode of instruction }
           opcode    : tasmop;
{$ifdef x86}
           segprefix : tregister;
{$endif x86}
           { true if instruction is a jmp }
           is_jmp    : boolean; { is this instruction a jump? (needed for optimizer) }
           Constructor Create(op : tasmop);virtual;
           Destructor Destroy;override;
           function getcopy:TLinkedListItem;override;
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure buildderefimpl;override;
           procedure derefimpl;override;
           procedure SetCondition(const c:TAsmCond);
           procedure allocate_oper(opers:longint);
           procedure loadconst(opidx:longint;l:aint);
           procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
           procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
           procedure loadref(opidx:longint;const r:treference);
           procedure loadreg(opidx:longint;r:tregister);
           procedure loadoper(opidx:longint;o:toper);
           procedure clearop(opidx:longint);
           procedure freeop(opidx:longint);
           { register allocator }
           function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
           function spilling_get_operation_type(opnr: longint): topertype;virtual;
           function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;

           function  Pass1(objdata:TObjData):longint;virtual;
           procedure Pass2(objdata:TObjData);virtual;

           procedure resetpass1; virtual;
           procedure resetpass2; virtual;
        end;
        tai_cpu_class = class of tai_cpu_abstract;

        { Buffer type used for alignment }
        tfillbuffer = array[0..63] of char;

        { alignment for operator }
        tai_align_abstract = class(tai)
           aligntype : byte;   { 1 = no align, 2 = word align, 4 = dword align }
           fillsize  : byte;   { real size to fill }
           fillop    : byte;   { value to fill with - optional }
           use_op    : boolean;
           constructor Create(b:byte);virtual;
           constructor Create_op(b: byte; _op: byte);virtual;
           constructor Create_zeros(b:byte);
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           function calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;virtual;
        end;
        tai_align_class = class of tai_align_abstract;

        tai_varloc = class(tai)
           oldlocation,
           oldlocationhi,
           newlocation,
           newlocationhi : tregister;
           varsym : tsym;
           constructor create(sym : tsym;loc : tregister);
           constructor create64(sym : tsym;loc,lochi : tregister);
{$ifdef cpu64bitalu}
           constructor create128(sym : tsym;loc,lochi : tregister);
{$endif cpu64bitalu}
           constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
           procedure ppuwrite(ppufile:tcompilerppufile);override;
           procedure buildderefimpl;override;
           procedure derefimpl;override;
        end;

        TSehDirectiveDatatype=(sd_none,sd_string,sd_reg,sd_offset,sd_regoffset);

        TSehDirectiveData=record
        case typ: TSehDirectiveDatatype of
          sd_none: ();
          sd_string: (name:pshortstring;flags:byte);
          sd_reg,sd_offset,sd_regoffset: (reg:TRegister;offset:dword);
        end;

        tai_seh_directive = class(tai)
          kind: TAsmSehDirective;
          data: TSehDirectiveData;
          constructor create(_kind:TAsmSehDirective);
          constructor create_name(_kind:TAsmSehDirective;const _name: string);
          constructor create_reg(_kind:TAsmSehDirective;r:TRegister);
          constructor create_offset(_kind:TAsmSehDirective;ofs:dword);
          constructor create_reg_offset(_kind:TAsmSehDirective;r:TRegister;ofs:dword);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          destructor destroy;override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          procedure generate_code(objdata:TObjData);virtual;
          property datatype: TSehDirectiveDatatype read data.typ;
        end;
        tai_seh_directive_class=class of tai_seh_directive;

{$ifdef JVM}
        { JVM variable live range description }
        tai_jvar = class(tai)
          stackslot: longint;
          desc: pshortstring;
          startlab,stoplab: tasmsymbol;

          constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
          destructor destroy;override;
        end;
        tai_jvar_class = class of tai_jvar;

        { JVM exception catch description }
        tai_jcatch = class(tai)
          name: pshortstring;
          startlab,stoplab,handlerlab: tasmsymbol;

          constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
          destructor destroy;override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
        end;
        tai_jcatch_class = class of tai_jcatch;
{$endif JVM}

        tai_set = class(tai)
          sym,
          value: pshortstring;
          constructor create(const asym, avalue: string);
          destructor destroy;override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
        end;

{$ifdef arm}
        tai_thumb_set = class(tai_set)
          constructor create(const asym, avalue: string);
        end;
{$endif arm}

        tai_weak = class(tai)
          sym: pshortstring;
          constructor create(const asym: string);
          destructor destroy;override;
          constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
          procedure ppuwrite(ppufile:tcompilerppufile);override;
        end;

    var
      { array with all class types for tais }
      aiclass : taiclassarray;

      { target specific tais, possibly overwritten in target specific aasmcpu }
      cai_align : tai_align_class = tai_align_abstract;
      cai_cpu   : tai_cpu_class = tai_cpu_abstract;
      cai_seh_directive: tai_seh_directive_class = tai_seh_directive;

      { hook to notify uses of registers }
      add_reg_instruction_hook : tadd_reg_instruction_proc;

    procedure maybe_new_object_file(list:TAsmList);
    procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
    procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
                                   Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
    procedure section_symbol_end(list:TAsmList;const Aname:string);

    function ppuloadai(ppufile:tcompilerppufile):tai;
    procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);


implementation

    uses
      SysUtils,
      verbose,
      globals;

    const
      pputaimarker = 254;


{****************************************************************************
                                 Helpers
 ****************************************************************************}

    procedure maybe_new_object_file(list:TAsmList);
      begin
        if create_smartlink_library then
          list.concat(tai_cutobject.create);
      end;


    procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
      begin
        list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
        list.concat(cai_align.create(Aalign));
      end;


    procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
                                   Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
      begin
        maybe_new_object_file(list);
        new_section(list,Asectype,Aname,Aalign);
        if Aglobal or
           create_smartlink then
          list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
        else
          list.concat(tai_symbol.createname(Aname,Asymtyp,0));
      end;


    procedure section_symbol_end(list:TAsmList;const Aname:string);
      begin
        list.concat(tai_symbol_end.createname(Aname));
      end;


    function ppuloadai(ppufile:tcompilerppufile):tai;
      var
        b : byte;
        t : taitype;
      begin
        { marker }
        b:=ppufile.getbyte;
        if b<>pputaimarker then
          internalerror(200208181);
        { load nodetype }
        t:=taitype(ppufile.getbyte);
        if t<>ait_none then
         begin
           if t>high(taitype) then
             internalerror(200208182);
           if not assigned(aiclass[t]) then
             internalerror(200208183);
           {writeln('taiload: ',taitypestr[t]);}
           { generate tai of the correct class }
           ppuloadai:=aiclass[t].ppuload(t,ppufile);
         end
        else
         ppuloadai:=nil;
      end;


    procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
      begin
        { marker, read by ppuloadnode }
        ppufile.putbyte(pputaimarker);
        if assigned(n) then
         begin
           { type, read by ppuloadnode }
           ppufile.putbyte(byte(n.typ));
           {writeln('taiwrite: ',taitypestr[n.typ]);}
           n.ppuwrite(ppufile);
         end
        else
         ppufile.putbyte(byte(ait_none));
      end;


    constructor tai_weak.create(const asym: string);
      begin
        inherited create;
        typ:=ait_weak;
        sym:=stringdup(asym);
      end;

    destructor tai_weak.destroy;
      begin
        stringdispose(sym);
        inherited destroy;
      end;

    constructor tai_weak.ppuload(t: taitype; ppufile: tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        sym:=stringdup(ppufile.getstring);
      end;

    procedure tai_weak.ppuwrite(ppufile: tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putstring(sym^);
      end;

{$ifdef arm}
    constructor tai_thumb_set.create(const asym, avalue: string);
      begin
        inherited create(asym, avalue);
        typ:=ait_thumb_set;
      end;
{$endif arm}

    constructor tai_set.create(const asym, avalue: string);
      begin
        inherited create;
        typ:=ait_set;
        sym:=stringdup(asym);
        value:=stringdup(avalue);
      end;

    destructor tai_set.destroy;
      begin
        stringdispose(sym);
        stringdispose(value);
        inherited destroy;
      end;

    constructor tai_set.ppuload(t: taitype; ppufile: tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        sym:=stringdup(ppufile.getstring);
        value:=stringdup(ppufile.getstring);
      end;

    procedure tai_set.ppuwrite(ppufile: tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putstring(sym^);
        ppufile.putstring(value^);
      end;


    constructor tai_varloc.create(sym: tsym; loc: tregister);
      begin
        inherited Create;
        typ:=ait_varloc;
        newlocation:=loc;
        newlocationhi:=NR_NO;
        varsym:=sym;
        oldlocationhi:=NR_NO;
      end;


    constructor tai_varloc.create64(sym: tsym; loc, lochi: tregister);
      begin
        inherited Create;
        typ:=ait_varloc;
        newlocation:=loc;
        newlocationhi:=lochi;
        varsym:=sym;
      end;


{$ifdef cpu64bitalu}
    constructor tai_varloc.create128(sym: tsym; loc, lochi: tregister);
      begin
        inherited Create;
        typ:=ait_varloc;
        newlocation:=loc;
        newlocationhi:=lochi;
        varsym:=sym;
      end;
{$endif cpu64bitalu}


    constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
      begin
        inherited ppuload(t, ppufile);
      end;


    procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
      end;


    procedure tai_varloc.buildderefimpl;
      begin
        inherited buildderefimpl;
      end;


    procedure tai_varloc.derefimpl;
      begin
        inherited derefimpl;
      end;


{****************************************************************************
                             TAI
 ****************************************************************************}

    constructor tai.Create;
      begin
{$ifndef NOOPT}
        optinfo:=nil;
{$endif NOOPT}
      end;


    constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        typ:=t;
{$ifndef NOOPT}
        optinfo:=nil;
{$endif}
      end;


    procedure tai.ppuwrite(ppufile:tcompilerppufile);
      begin
      end;


    procedure tai.buildderefimpl;
      begin
      end;


    procedure tai.derefimpl;
      begin
      end;


{****************************************************************************
                              TAILINEINFO
 ****************************************************************************}

    constructor tailineinfo.create;
     begin
       inherited create;
       fileinfo:=current_filepos;
     end;


    constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        ppufile.getposinfo(fileinfo);
      end;


    procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putposinfo(fileinfo);
      end;


{****************************************************************************
                              TAI_SIMPLE
 ****************************************************************************}

    constructor tai_simple.create(_typ : taitype);
      begin
        inherited create;
        typ:=_typ;
      end;


{****************************************************************************
                             TAI_SECTION
 ****************************************************************************}

    constructor tai_section.Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
      begin
        inherited Create;
        typ:=ait_section;
        sectype:=asectype;
        secalign:=Aalign;
        secorder:=Asecorder;
        name:=stringdup(Aname);
        sec:=nil;
      end;


    constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        sectype:=TAsmSectiontype(ppufile.getbyte);
        secalign:=ppufile.getbyte;
        name:=stringdup(ppufile.getstring);
        sec:=nil;
      end;


    destructor tai_section.Destroy;
      begin
        stringdispose(name);
      end;


    procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(byte(sectype));
        ppufile.putbyte(secalign);
        ppufile.putstring(name^);
      end;


{****************************************************************************
                             TAI_DATABLOCK
 ****************************************************************************}

    constructor tai_datablock.Create(const _name : string;_size : aint);

      begin
         inherited Create;
         typ:=ait_datablock;
         sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
         { keep things aligned }
         if _size<=0 then
           _size:=sizeof(aint);
         size:=_size;
         is_global:=false;
      end;


    constructor tai_datablock.Create_global(const _name : string;_size : asizeint);
      begin
         inherited Create;
         typ:=ait_datablock;
         sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
         { keep things aligned }
         if _size<=0 then
           _size:=sizeof(aint);
         size:=_size;
         is_global:=true;
      end;


    constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited Create;
        sym:=ppufile.getasmsymbol;
        size:=ppufile.getaint;
        is_global:=boolean(ppufile.getbyte);
      end;


    procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putasmsymbol(sym);
        ppufile.putaint(size);
        ppufile.putbyte(byte(is_global));
      end;


    procedure tai_datablock.derefimpl;
      begin
      end;


{****************************************************************************
                               TAI_SYMBOL
 ****************************************************************************}

    constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
      begin
         inherited Create;
         typ:=ait_symbol;
         sym:=_sym;
         size:=siz;
         { don't redefine global/external symbols as local, as code to access
           such symbols is different on some platforms }
         if not(sym.bind in [AB_NONE,AB_LOCAL]) then
           internalerror(2013081601);
         sym.bind:=AB_LOCAL;
         is_global:=false;
      end;


    constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
      begin
         inherited Create;
         typ:=ait_symbol;
         sym:=_sym;
         size:=siz;
         { don't override PRIVATE_EXTERN with GLOBAL }
         if not(sym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]) then
           sym.bind:=AB_GLOBAL;
         is_global:=true;
      end;


    constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
      begin
         inherited Create;
         typ:=ait_symbol;
         sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
         size:=siz;
         is_global:=false;
      end;


    constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
      begin
         inherited Create;
         typ:=ait_symbol;
         sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
         size:=siz;
         is_global:=true;
      end;


    constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint);
      begin
        Createname_global(_name,_symtyp,siz);
        value:=val;
        has_value:=true;
      end;


    constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        sym:=ppufile.getasmsymbol;
        size:=ppufile.getlongint;
        is_global:=boolean(ppufile.getbyte);
      end;


    procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putasmsymbol(sym);
        ppufile.putlongint(size);
        ppufile.putbyte(byte(is_global));
      end;


    procedure tai_symbol.derefimpl;
      begin
      end;


{****************************************************************************
                               TAI_SYMBOL_END
 ****************************************************************************}

    constructor tai_symbol_end.Create(_sym:tasmsymbol);
      begin
         inherited Create;
         typ:=ait_symbol_end;
         sym:=_sym;
      end;


    constructor tai_symbol_end.Createname(const _name : string);
      begin
         inherited Create;
         typ:=ait_symbol_end;
         sym:=current_asmdata.GetAsmSymbol(_name);
         if not assigned(sym) then
           internalerror(2013080301);
      end;


    constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        sym:=ppufile.getasmsymbol;
      end;


    procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putasmsymbol(sym);
      end;


    procedure tai_symbol_end.derefimpl;
      begin
      end;


{****************************************************************************
                               TAI_SYMBOL_END
 ****************************************************************************}

    constructor tai_directive.Create(_directive:TAsmDirective;const _name:ansistring);
      begin
         inherited Create;
         typ:=ait_directive;
         name:=_name;
         directive:=_directive;
      end;


    constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        name:=ppufile.getansistring;
        directive:=TAsmDirective(ppufile.getbyte);
      end;


    procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putansistring(name);
        ppufile.putbyte(byte(directive));
      end;


{****************************************************************************
                               TAI_CONST
 ****************************************************************************}

    constructor tai_const.Create(_typ:taiconst_type;_value : int64);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=_typ;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_128bit(_value : int64);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_128bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_64bit(_value : int64);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_64bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_32bit(_value : longint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_32bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_16bit(_value : word);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_16bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;

    constructor tai_const.Create_64bit_unaligned(_value : int64);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_64bit_unaligned;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_32bit_unaligned(_value : longint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_32bit_unaligned;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_16bit_unaligned(_value : word);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_16bit_unaligned;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_8bit(_value : byte);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_8bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_char(size: integer; _value: dword);
      begin
         inherited Create;
         typ:=ait_const;
         case size of
            1:
              begin
                consttype:=aitconst_8bit;
                value:=byte(_value)
              end;
             2:
               begin
                 consttype:=aitconst_16bit;
                 value:=word(_value)
               end
             else
               InternalError(2010030701)
         end
      end;


    constructor tai_const.Create_sleb128bit(_value : int64);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_sleb128bit;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_uleb128bit(_value : qword);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_uleb128bit;
         value:=int64(_value);
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_aint(_value : aint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_aint;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_pint(_value : pint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_ptr;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_pint_unaligned(_value: pint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=aitconst_ptr_unaligned;
         value:=_value;
         sym:=nil;
         endsym:=nil;
      end;


    constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=_typ;
         sym:=_sym;
         endsym:=nil;
         value:=0;
         { update sym info }
         if assigned(sym) then
           sym.increfs;
      end;


    constructor tai_const.Create_sym(_sym:tasmsymbol);
      begin
         self.create_sym_offset(_sym,0);
      end;


{$ifdef i8086}
    constructor tai_const.Create_sym_near(_sym: tasmsymbol);
      begin
         self.create_sym(_sym);
         consttype:=aitconst_ptr;
      end;

    constructor tai_const.Create_sym_far(_sym: tasmsymbol);
      begin
        self.create_sym(_sym);
        consttype:=aitconst_farptr;
      end;
{$endif i8086}


    constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
      begin
         inherited Create;
         typ:=ait_const;
{$ifdef i8086}
         if assigned(_sym) and (_sym.typ=AT_DATA) then
           begin
             if current_settings.x86memorymodel in x86_far_data_models then
               consttype:=aitconst_farptr
             else
               consttype:=aitconst_ptr;
           end
         else
           begin
             if current_settings.x86memorymodel in x86_far_code_models then
               consttype:=aitconst_farptr
             else
               consttype:=aitconst_ptr;
           end;
{$else i8086}
         consttype:=aitconst_ptr;
{$endif i8086}
         { sym is allowed to be nil, this is used to write nil pointers }
         sym:=_sym;
         endsym:=nil;
         { store the original offset in symofs so that we can recalculate the
           value field in the assembler }
         symofs:=ofs;
         value:=ofs;
         { update sym info }
         if assigned(sym) then
           sym.increfs;
      end;


    constructor tai_const.Create_type_sym_offset(_typ : taiconst_type;_sym : tasmsymbol; ofs : aint);
      begin
         inherited Create;
         typ:=ait_const;
         consttype:=_typ;
         { sym is allowed to be nil, this is used to write nil pointers }
         sym:=_sym;
         endsym:=nil;
         { store the original offset in symofs so that we can recalculate the
           value field in the assembler }
         symofs:=ofs;
         value:=ofs;
         { update sym info }
         if assigned(sym) then
           sym.increfs;
      end;


    constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
      begin
         self.create_sym_offset(_sym,0);
         consttype:=_typ;
         endsym:=_endsym;
         endsym.increfs;
      end;


    constructor tai_const.Create_rel_sym_offset(_typ: taiconst_type; _sym,_endsym: tasmsymbol; _ofs: int64);
       begin
         self.create_sym_offset(_sym,_ofs);
         consttype:=_typ;
         endsym:=_endsym;
         endsym.increfs;
       end;


    constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
      begin
         self.create_sym_offset(_sym,0);
         consttype:=aitconst_rva_symbol;
      end;


    constructor tai_const.Createname(const name:string;ofs:aint);
      begin
         self.Createname(name,AT_NONE,ofs);
      end;


    constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
      begin
         self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
      end;


    constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
      begin
         self.Create_type_name(_typ,name,AT_NONE,ofs);
      end;


    constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:aint);
      begin
         self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
         consttype:=_typ;
      end;


    constructor tai_const.Create_nil_codeptr;
      begin
        inherited Create;
        typ:=ait_const;
{$ifdef i8086}
        if current_settings.x86memorymodel in x86_far_code_models then
          consttype:=aitconst_farptr
        else
{$endif i8086}
          consttype:=aitconst_ptr;
        sym:=nil;
        endsym:=nil;
        symofs:=0;
        value:=0;
      end;


    constructor tai_const.Create_nil_dataptr;
      begin
        inherited Create;
        typ:=ait_const;
{$ifdef i8086}
        if current_settings.x86memorymodel in x86_far_data_models then
          consttype:=aitconst_farptr
        else
{$endif i8086}
          consttype:=aitconst_ptr;
        sym:=nil;
        endsym:=nil;
        symofs:=0;
        value:=0;
      end;


    constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        consttype:=taiconst_type(ppufile.getbyte);
        sym:=ppufile.getasmsymbol;
        endsym:=ppufile.getasmsymbol;
        value:=ppufile.getint64;
      end;


    procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(byte(consttype));
        ppufile.putasmsymbol(sym);
        ppufile.putasmsymbol(endsym);
        ppufile.putint64(value);
      end;


    procedure tai_const.derefimpl;
      begin
      end;


    function tai_const.getcopy:tlinkedlistitem;
      begin
        getcopy:=inherited getcopy;
        { we need to increase the reference number }
        if assigned(sym) then
          sym.increfs;
        if assigned(endsym) then
          endsym.increfs;
      end;


    function tai_const.size:longint;
      begin
        case consttype of
          aitconst_8bit :
            result:=1;
          aitconst_16bit,aitconst_16bit_unaligned :
            result:=2;
          aitconst_32bit,aitconst_darwin_dwarf_delta32,
	  aitconst_32bit_unaligned:
            result:=4;
          aitconst_64bit,aitconst_darwin_dwarf_delta64,
	  aitconst_64bit_unaligned:
            result:=8;
          aitconst_secrel32_symbol,
          aitconst_rva_symbol :
            if target_info.system=system_x86_64_win64 then
              result:=sizeof(longint)
            else
              result:=sizeof(pint);
          aitconst_uleb128bit :
            result:=LengthUleb128(qword(value));
          aitconst_sleb128bit :
            result:=LengthSleb128(value);
          aitconst_half16bit:
            result:=2;
          aitconst_gotoff_symbol:
            result:=4;
          else
            internalerror(200603253);
        end;
      end;


{****************************************************************************
                               TAI_real_32bit
 ****************************************************************************}

    constructor tai_real_32bit.Create(_value : ts32real);

      begin
         inherited Create;
         typ:=ait_real_32bit;
         value:=_value;
      end;

    constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        value:=ppufile.getreal;
      end;


    procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putreal(value);
      end;


{****************************************************************************
                               TAI_real_64bit
 ****************************************************************************}

    constructor tai_real_64bit.Create(_value : ts64real);

      begin
         inherited Create;
         typ:=ait_real_64bit;
         value:=_value;
      end;


{$ifdef ARM}
    constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);

      begin
         inherited Create;
         typ:=ait_real_64bit;
         value:=_value;
         formatoptions:=fo_hiloswapped;
      end;
{$endif ARM}

    constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        value:=ppufile.getreal;
{$ifdef ARM}
        formatoptions:=tformatoptions(ppufile.getbyte);
{$endif ARM}
      end;


    procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putreal(value);
{$ifdef ARM}
        ppufile.putbyte(byte(formatoptions));
{$endif ARM}
      end;


{****************************************************************************
                               TAI_real_80bit
 ****************************************************************************}

    constructor tai_real_80bit.Create(_value : ts80real; _savesize: byte);

      begin
         inherited Create;
         typ:=ait_real_80bit;
         value:=_value;
         savesize:=_savesize;
      end;


    constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        value:=ppufile.getreal;
        savesize:=ppufile.getbyte;
      end;


    procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putreal(value);
        ppufile.putbyte(savesize);
      end;


{****************************************************************************
                               TAI_real_80bit
 ****************************************************************************}

    constructor tai_real_128bit.Create(_value : ts128real);

      begin
         inherited Create;
         typ:=ait_real_128bit;
         value:=_value;
      end;


    constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        value:=ppufile.getreal;
      end;


    procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putreal(value);
      end;


{****************************************************************************
                               Tai_comp_64bit
 ****************************************************************************}

    constructor tai_comp_64bit.Create(_value : ts64comp);

      begin
         inherited Create;
         typ:=ait_comp_64bit;
         value:=_value;
      end;


    constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        ppufile.putdata(value,sizeof(value));
      end;


    procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.getdata(value,sizeof(value));
      end;


{****************************************************************************
                               TAI_STRING
 ****************************************************************************}

     constructor tai_string.Create(const _str : string);
       begin
          inherited Create;
          typ:=ait_string;
          len:=length(_str);
          getmem(str,len+1);
          move(_str[1],str^,len);
          str[len]:=#0;
       end;


    constructor tai_string.Create_pchar(_str : pchar;length : longint);
       begin
          inherited Create;
          typ:=ait_string;
          str:=_str;
          len:=length;
       end;


    destructor tai_string.destroy;
      begin
         if str<>nil then
           freemem(str);
         inherited Destroy;
      end;


    constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        len:=ppufile.getlongint;
        getmem(str,len);
        ppufile.getdata(str^,len);
      end;


    procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putlongint(len);
        ppufile.putdata(str^,len);
      end;


    function tai_string.getcopy : tlinkedlistitem;
      var
        p : tlinkedlistitem;
      begin
        p:=inherited getcopy;
        getmem(tai_string(p).str,len);
        move(str^,tai_string(p).str^,len);
        getcopy:=p;
      end;


{****************************************************************************
                               TAI_LABEL
 ****************************************************************************}

    constructor tai_label.Create(_labsym : tasmlabel);
      begin
        inherited Create;
        typ:=ait_label;
        labsym:=_labsym;
        labsym.is_set:=true;
      end;


    constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        labsym:=tasmlabel(ppufile.getasmsymbol);
        ppufile.getbyte; { was is_global flag, now unused }
      end;


    procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putasmsymbol(labsym);
        ppufile.putbyte(0); { was is_global flag, now unused }
      end;


    procedure tai_label.derefimpl;
      begin
        labsym.is_set:=true;
      end;

{****************************************************************************
          tai_comment  comment to be inserted in the assembler file
 ****************************************************************************}

     constructor tai_comment.Create(_str : pchar);

       begin
          inherited Create;
          typ:=ait_comment;
          str:=_str;
       end;

    destructor tai_comment.destroy;

      begin
         freemem(str);
         inherited Destroy;
      end;

    constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
      var
        len : longint;
      begin
        inherited ppuload(t,ppufile);
        len:=ppufile.getlongint;
        getmem(str,len+1);
        ppufile.getdata(str^,len);
        str[len]:=#0;
      end;


    procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
      var
        len : longint;
      begin
        inherited ppuwrite(ppufile);
        len:=strlen(str);
        ppufile.putlongint(len);
        ppufile.putdata(str^,len);
      end;


    function tai_comment.getcopy : tlinkedlistitem;
      var
        p : tlinkedlistitem;
      begin
        p:=inherited getcopy;
        getmem(tai_comment(p).str,strlen(str)+1);
        move(str^,tai_comment(p).str^,strlen(str)+1);
        getcopy:=p;
      end;


{****************************************************************************
                              TAI_STABS
 ****************************************************************************}

    constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
      begin
         inherited create;
         typ:=ait_stab;
         str:=_str;
         stabtype:=_stabtype;
      end;

    constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
      begin
         self.create(_stabtype,strpnew(s));
      end;

    constructor tai_stab.create_ansistr(_stabtype:TStabType;const s:ansistring);
      begin
         inherited create;
         typ:=ait_stab;
         stabtype:=_stabtype;
         getmem(str,length(s)+1);
         move(s[1],str^,length(s)+1);
      end;

    destructor tai_stab.destroy;
      begin
         freemem(str);
         inherited destroy;
      end;


{****************************************************************************
                            TAI_FORCE_LINE
 ****************************************************************************}

    constructor tai_force_line.create;
      begin
         inherited create;
         typ:=ait_force_line;
      end;


{****************************************************************************
                              TAI_FUNCTION_NAME
 ****************************************************************************}

    constructor tai_function_name.create(const s:string);
      begin
         inherited create;
         typ:=ait_function_name;
         funcname:=stringdup(s);
      end;

    destructor tai_function_name.destroy;
      begin
         stringdispose(funcname);
         inherited destroy;
      end;


{****************************************************************************
                              TAI_CUTOBJECT
 ****************************************************************************}

     constructor tai_cutobject.Create;
       begin
          inherited Create;
          typ:=ait_cutobject;
          place:=cut_normal;
       end;


     constructor tai_cutobject.Create_begin;
       begin
          inherited Create;
          typ:=ait_cutobject;
          place:=cut_begin;
       end;


     constructor tai_cutobject.Create_end;
       begin
          inherited Create;
          typ:=ait_cutobject;
          place:=cut_end;
       end;


    constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        place:=TCutPlace(ppufile.getbyte);
      end;


    procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(byte(place));
      end;


{****************************************************************************
                             Tai_Marker
 ****************************************************************************}

    constructor Tai_Marker.Create(_Kind: TAsmMarker);
      begin
        Inherited Create;
        typ := ait_marker;
        Kind := _Kind;
      end;


    constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        kind:=TAsmMarker(ppufile.getbyte);
      end;


    procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(byte(kind));
      end;


{*****************************************************************************
                                tai_tempalloc
*****************************************************************************}

    constructor tai_tempalloc.alloc(pos,size:longint);
      begin
        inherited Create;
        typ:=ait_tempalloc;
        allocation:=true;
        temppos:=pos;
        tempsize:=size;
{$ifdef EXTDEBUG}
        problem:=nil;
{$endif EXTDEBUG}
      end;


    destructor tai_tempalloc.destroy;
      begin
{$ifdef EXTDEBUG}
        stringdispose(problem);
{$endif EXTDEBUG}
        inherited destroy;
      end;


    constructor tai_tempalloc.dealloc(pos,size:longint);
      begin
        inherited Create;
        typ:=ait_tempalloc;
        allocation:=false;
        temppos:=pos;
        tempsize:=size;
{$ifdef EXTDEBUG}
        problem:=nil;
{$endif EXTDEBUG}
      end;


{$ifdef EXTDEBUG}
    constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
      begin
        inherited Create;
        typ:=ait_tempalloc;
        allocation:=false;
        temppos:=pos;
        tempsize:=size;
        problem:=stringdup(st);
      end;
{$endif EXTDEBUG}


    constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        temppos:=ppufile.getlongint;
        tempsize:=ppufile.getlongint;
        allocation:=boolean(ppufile.getbyte);
{$ifdef EXTDEBUG}
        problem:=nil;
{$endif EXTDEBUG}
      end;


    procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putlongint(temppos);
        ppufile.putlongint(tempsize);
        ppufile.putbyte(byte(allocation));
      end;


{*****************************************************************************
                                 tai_regalloc
*****************************************************************************}

    constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
      begin
        inherited create;
        typ:=ait_regalloc;
        ratype:=ra_alloc;
        reg:=r;
        { ainstr must be an instruction }
        if assigned(ainstr) and
           (ainstr.typ<>ait_instruction) then
          internalerror(200411011);
        instr:=ainstr;
      end;


    constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
      begin
        inherited create;
        typ:=ait_regalloc;
        ratype:=ra_dealloc;
        reg:=r;
        { ainstr must be an instruction }
        if assigned(ainstr) and
           (ainstr.typ<>ait_instruction) then
          internalerror(200411012);
        instr:=ainstr;
      end;


    constructor tai_regalloc.sync(r : tregister);
      begin
        inherited create;
        typ:=ait_regalloc;
        ratype:=ra_sync;
        reg:=r;
      end;


    constructor tai_regalloc.resize(r : tregister);
      begin
        inherited create;
        typ:=ait_regalloc;
        ratype:=ra_resize;
        reg:=r;
      end;


    constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        ppufile.getdata(reg,sizeof(Tregister));
        ratype:=tregalloctype(ppufile.getbyte);
        keep:=boolean(ppufile.getbyte);
      end;


    procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putdata(reg,sizeof(Tregister));
        ppufile.putbyte(byte(ratype));
        ppufile.putbyte(byte(keep));
      end;


{*****************************************************************************
                               TaiInstruction
*****************************************************************************}

    constructor tai_cpu_abstract.Create(op : tasmop);

      begin
         inherited create;
         typ:=ait_instruction;
         is_jmp:=false;
         opcode:=op;
         ops:=0;
      end;


    destructor tai_cpu_abstract.Destroy;
      var
        i : integer;
      begin
        for i:=0 to opercnt-1 do
          freeop(i);
        inherited destroy;
      end;


{ ---------------------------------------------------------------------
    Loading of operands.
  ---------------------------------------------------------------------}

    procedure tai_cpu_abstract.allocate_oper(opers:longint);
      begin
        while (opers>opercnt) do
          begin
            new(oper[opercnt]);
            fillchar(oper[opercnt]^,sizeof(toper),0);
            inc(opercnt);
          end;
      end;


    procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
      begin
        allocate_oper(opidx+1);
        with oper[opidx]^ do
         begin
           if typ<>top_const then
             clearop(opidx);
           val:=l;
           typ:=top_const;
         end;
      end;


    procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
      var
        r : treference;
      begin
        reference_reset_symbol(r,s,sofs,1);
        r.refaddr:=addr_full;
        loadref(opidx,r);
      end;


    procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
      begin
        if not assigned(s) then
         internalerror(200204251);
        allocate_oper(opidx+1);
        with oper[opidx]^ do
         begin
           if typ<>top_local then
             begin
               clearop(opidx);
               new(localoper);
             end;
           with oper[opidx]^.localoper^ do
             begin
               localsym:=s;
               localsymofs:=sofs;
               localindexreg:=indexreg;
               localscale:=scale;
               localgetoffset:=getoffset;
               localforceref:=forceref;
             end;
           typ:=top_local;
         end;
      end;


    procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
      begin
        allocate_oper(opidx+1);
        with oper[opidx]^ do
          begin
            if typ<>top_ref then
              begin
                clearop(opidx);
                new(ref);
              end;

            ref^:=r;
{$ifdef x86}
            { We allow this exception for x86, since overloading this would be
              too much of a a speed penalty}
            if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
              segprefix:=ref^.segment;
{$endif}
{$ifndef llvm}
            if (cs_create_pic in current_settings.moduleswitches) and
              assigned(r.symbol) and
              not assigned(r.relsymbol) and
              (r.refaddr=addr_no)
{$ifdef ARM}
              and not(r.base=NR_R15)
{$endif ARM}
              then
              internalerror(200502052);
{$endif not llvm}
            typ:=top_ref;
            if assigned(add_reg_instruction_hook) then
              begin
                add_reg_instruction_hook(self,ref^.base);
                add_reg_instruction_hook(self,ref^.index);
              end;
            { mark symbol as used }
            if assigned(ref^.symbol) then
              ref^.symbol.increfs;
            if assigned(ref^.relsymbol) then
              ref^.relsymbol.increfs;
          end;
      end;


    procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
      begin
        allocate_oper(opidx+1);
        with oper[opidx]^ do
         begin
           if typ<>top_reg then
             clearop(opidx);
           reg:=r;
           typ:=top_reg;
         end;
        if assigned(add_reg_instruction_hook) then
          add_reg_instruction_hook(self,r);
{$ifdef ARM}
        { R15 is the PC on the ARM thus moves to R15 are jumps.
          Due to speed considerations we don't use a virtual overridden method here.
          Because the pc/r15 isn't handled by the reg. allocator this should never cause
          problems with iregs getting r15.
        }
        is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
{$endif ARM}
      end;


    procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
      begin
        allocate_oper(opidx+1);
        clearop(opidx);
        oper[opidx]^:=o;
        { copy also the reference }
        with oper[opidx]^ do
          begin
            case typ of
              top_reg:
                begin
                  if assigned(add_reg_instruction_hook) then
                    add_reg_instruction_hook(self,reg);
                end;
              top_ref:
                begin
                  new(ref);
                  ref^:=o.ref^;
{$ifdef x86}
                  if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
                    segprefix:=ref^.segment;
{$endif x86}
                  if assigned(add_reg_instruction_hook) then
                    begin
                      add_reg_instruction_hook(self,ref^.base);
                      add_reg_instruction_hook(self,ref^.index);
                    end;
                end;
{$ifdef ARM}
              top_shifterop:
                begin
                  new(shifterop);
                  shifterop^:=o.shifterop^;
                  if assigned(add_reg_instruction_hook) then
                    add_reg_instruction_hook(self,shifterop^.rs);
                end;
{$endif ARM}
             end;
          end;
      end;

    procedure tai_cpu_abstract.clearop(opidx:longint);
      begin
        with oper[opidx]^ do
          begin
            case typ of
              top_ref:
                dispose(ref);
              top_local:
                dispose(localoper);
{$ifdef ARM}
              top_shifterop:
                dispose(shifterop);
              top_regset:
                dispose(regset);
{$endif ARM}
{$ifdef m68k}
              top_regset:
                begin
                  dispose(dataregset);
                  dispose(addrregset);
                end;
{$endif m68k}
{$ifdef jvm}
              top_string:
                freemem(pcval);
              top_wstring:
                donewidestring(pwstrval);
{$endif jvm}
{$ifdef llvm}
              top_para:
                paras.free;
{$endif llvm}
            end;
            typ:=top_none;
          end;
      end;


    procedure tai_cpu_abstract.freeop(opidx:longint);
      begin
        clearop(opidx);
        dispose(oper[opidx]);
      end;


{ ---------------------------------------------------------------------
    Miscellaneous methods.
  ---------------------------------------------------------------------}

    procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
      begin
         condition:=c;
      end;


    Function tai_cpu_abstract.getcopy:TLinkedListItem;
      var
        i : longint;
        p : tai_cpu_abstract;
      begin
        p:=tai_cpu_abstract(inherited getcopy);
        { make a copy of the references }
        p.opercnt:=0;
        p.allocate_oper(ops);
        for i:=0 to ops-1 do
          begin
            p.oper[i]^:=oper[i]^;
            case oper[i]^.typ of
              top_local :
                begin
                  new(p.oper[i]^.localoper);
                  p.oper[i]^.localoper^:=oper[i]^.localoper^;
                end;
              top_ref :
                begin
                  new(p.oper[i]^.ref);
                  p.oper[i]^.ref^:=oper[i]^.ref^;
                end;
{$ifdef ARM}
              top_shifterop:
                begin
                  new(p.oper[i]^.shifterop);
                  p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
                end;
{$endif ARM}
            end;
          end;
        getcopy:=p;
      end;


    function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
      begin
        { When the generic RA is used this needs to be overridden, we don't use
          virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
          when tai_cpu is created (PFV) }
        internalerror(2004040901);
        result:=false;
      end;


    function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
      begin
        internalerror(2004040902);
        result:=operand_readwrite;
      end;


    function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
      begin
        result := operand_read;
      end;


    constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
      var
        i : integer;
      begin
        inherited ppuload(t,ppufile);
        { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
        ppufile.getdata(condition,sizeof(tasmcond));
        allocate_oper(ppufile.getbyte);
        for i:=0 to ops-1 do
          ppuloadoper(ppufile,oper[i]^);
        opcode:=tasmop(ppufile.getword);
{$ifdef x86}
        ppufile.getdata(segprefix,sizeof(Tregister));
{$endif x86}
        is_jmp:=boolean(ppufile.getbyte);
      end;


    procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
      var
        i : integer;
      begin
        inherited ppuwrite(ppufile);
        ppufile.putdata(condition,sizeof(tasmcond));
        ppufile.putbyte(ops);
        for i:=0 to ops-1 do
          ppuwriteoper(ppufile,oper[i]^);
        ppufile.putword(word(opcode));
{$ifdef x86}
        ppufile.putdata(segprefix,sizeof(Tregister));
{$endif x86}
        ppufile.putbyte(byte(is_jmp));
      end;


    procedure tai_cpu_abstract.buildderefimpl;
      var
        i : integer;
      begin
        for i:=0 to ops-1 do
          ppubuildderefimploper(oper[i]^);
      end;


    procedure tai_cpu_abstract.derefimpl;
      var
        i : integer;
      begin
        for i:=0 to ops-1 do
          ppuderefoper(oper[i]^);
      end;


    procedure tai_cpu_abstract.resetpass1;
      begin
      end;


    procedure tai_cpu_abstract.resetpass2;
      begin
      end;


   function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
      begin
        result:=0;
      end;


    procedure tai_cpu_abstract.Pass2(objdata:TObjData);
      begin
      end;


    procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
      begin
        o.typ:=toptype(ppufile.getbyte);
        o.ot:=ppufile.getlongint;
        case o.typ of
          top_reg :
            ppufile.getdata(o.reg,sizeof(Tregister));
          top_ref :
            begin
              new(o.ref);
{$ifdef x86}
              ppufile.getdata(o.ref^.segment,sizeof(Tregister));
{$endif x86}
              ppufile.getdata(o.ref^.base,sizeof(Tregister));
              ppufile.getdata(o.ref^.index,sizeof(Tregister));
              ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
              o.ref^.scalefactor:=ppufile.getbyte;
              o.ref^.offset:=ppufile.getaint;
              o.ref^.symbol:=ppufile.getasmsymbol;
              o.ref^.relsymbol:=ppufile.getasmsymbol;
            end;
          top_const :
            o.val:=ppufile.getaint;
          top_local :
            begin
              new(o.localoper);
              with o.localoper^ do
                begin
                  ppufile.getderef(localsymderef);
                  localsymofs:=ppufile.getaint;
                  localindexreg:=tregister(ppufile.getlongint);
                  localscale:=ppufile.getbyte;
                  localgetoffset:=(ppufile.getbyte<>0);
                end;
            end;
          else
            internalerror(2007010210);
        end;
      end;


    procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
      begin
        ppufile.putbyte(byte(o.typ));
        ppufile.putlongint(o.ot);
        case o.typ of
          top_reg :
            ppufile.putdata(o.reg,sizeof(Tregister));
          top_ref :
            begin
{$ifdef x86}
              ppufile.putdata(o.ref^.segment,sizeof(Tregister));
{$endif x86}
              ppufile.putdata(o.ref^.base,sizeof(Tregister));
              ppufile.putdata(o.ref^.index,sizeof(Tregister));
              ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
              ppufile.putbyte(o.ref^.scalefactor);
              ppufile.putaint(o.ref^.offset);
              ppufile.putasmsymbol(o.ref^.symbol);
              ppufile.putasmsymbol(o.ref^.relsymbol);
            end;
          top_const :
            ppufile.putaint(o.val);
          top_local :
            begin
              with o.localoper^ do
                begin
                  ppufile.putderef(localsymderef);
                  ppufile.putaint(localsymofs);
                  ppufile.putlongint(longint(localindexreg));
                  ppufile.putbyte(localscale);
                  ppufile.putbyte(byte(localgetoffset));
                end;
            end;
          else
            internalerror(2007010211);
        end;
      end;

{****************************************************************************
                              tai_align_abstract
 ****************************************************************************}

     constructor tai_align_abstract.Create(b: byte);
       begin
          inherited Create;
          typ:=ait_align;
{$ifdef EXTDEBUG}
          if upper(classname)='TAI_ALIGN_ABSTRACT' then
            internalerror(200709191);
{$endif EXTDEBUG}
          if b in [1,2,4,8,16,32] then
            aligntype := b
          else
            aligntype := 1;
          fillsize:=0;
          fillop:=0;
          use_op:=false;
       end;


     constructor tai_align_abstract.Create_op(b: byte; _op: byte);
       begin
          inherited Create;
          typ:=ait_align;
          if b in [1,2,4,8,16,32] then
            aligntype := b
          else
            aligntype := 1;
          fillsize:=0;
          fillop:=_op;
          use_op:=true;
       end;


     constructor tai_align_abstract.Create_zeros(b: byte);
       begin
          inherited Create;
          typ:=ait_align;
          if b in [1,2,4,8,16,32] then
            aligntype := b
          else
            aligntype := 1;
         use_op:=true;
         fillsize:=0;
         fillop:=0;
       end;


     function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
       begin
         if fillsize>sizeof(buf) then
           internalerror(200404293);
         fillchar(buf,high(buf),fillop);
         calculatefillbuf:=pchar(@buf);
       end;


    constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t,ppufile);
        aligntype:=ppufile.getbyte;
        fillsize:=0;
        fillop:=ppufile.getbyte;
        use_op:=boolean(ppufile.getbyte);
      end;


    procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(aligntype);
        ppufile.putbyte(fillop);
        ppufile.putbyte(byte(use_op));
      end;


{****************************************************************************
                              tai_seh_directive
 ****************************************************************************}

    const
      datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
        sd_string,     { proc }
        sd_none,       { endproc }
        sd_none,       { endprologue }
        sd_string,     { handler }
        sd_none,       { handlerdata }
        sd_none,sd_none,sd_none,  { eh, 32, no32 }
        sd_regoffset,  { setframe }
        sd_offset,     { stackalloc }
        sd_reg,        { pushreg }
        sd_regoffset,  { savereg }
        sd_regoffset,  { savexmm }
        sd_none        { pushframe }
      );

    constructor tai_seh_directive.create(_kind:TAsmSehDirective);
      begin
        inherited Create;
        typ:=ait_seh_directive;
        kind:=_kind;
        data.typ:=datatypemap[_kind];
      end;

    constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
      begin
        create(_kind);
        data.name:=stringdup(_name);
      end;

    constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
      begin
        create(_kind);
        data.reg:=r;
      end;

    constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
      begin
        create(_kind);
        data.offset:=ofs;
      end;

    constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
      r:TRegister;ofs:dword);
      begin
        create(_kind);
        data.offset:=ofs;
        data.reg:=r;
      end;

    constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
      begin
        inherited ppuload(t, ppufile);
        kind:=TAsmSehDirective(ppufile.getbyte);
        data.typ:=datatypemap[kind];
        case data.typ of
          sd_none: ;
          sd_string:
            begin
              data.name:=stringdup(ppufile.getstring);
              data.flags:=ppufile.getbyte;
            end;

          sd_reg,sd_offset,sd_regoffset:
            begin
              ppufile.getdata(data.reg,sizeof(TRegister));
              data.offset:=ppufile.getdword;
            end;
        else
          InternalError(2011091201);
        end;
      end;

    destructor tai_seh_directive.destroy;
      begin
        if data.typ=sd_string then
          stringdispose(data.name);
        inherited destroy;
      end;

    procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putbyte(ord(kind));
        case data.typ of
          sd_none: ;
          sd_string:
            begin
              ppufile.putstring(data.name^);
              ppufile.putbyte(data.flags);
            end;

          sd_reg,sd_offset,sd_regoffset:
            begin
              ppufile.putdata(data.reg,sizeof(TRegister));
              ppufile.putdword(data.offset);
            end;
        else
          InternalError(2011091202);
        end;
      end;

    procedure tai_seh_directive.generate_code(objdata:TObjData);
      begin
      end;

{$ifdef JVM}

{****************************************************************************
                              tai_jvar
 ****************************************************************************}

    constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
      begin
        Inherited create;
        typ:=ait_jvar;
        stackslot:=_stackslot;
        desc:=stringdup(_desc);
        startlab:=_startlab;
        stoplab:=_stoplab;
      end;


    constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
      begin
        inherited ppuload(t, ppufile);
        stackslot:=ppufile.getlongint;
        desc:=stringdup(ppufile.getstring);
        startlab:=ppufile.getasmsymbol;
        stoplab:=ppufile.getasmsymbol;
      end;


    procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putlongint(stackslot);
        ppufile.putstring(desc^);
        ppufile.putasmsymbol(startlab);
        ppufile.putasmsymbol(stoplab);
      end;


    destructor tai_jvar.destroy;
      begin
        stringdispose(desc);
        inherited destroy;
      end;


{****************************************************************************
                              tai_jcatch
 ****************************************************************************}

    constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
      begin
        Inherited create;
        typ:=ait_jcatch;
        name:=stringdup(_name);
        startlab:=_startlab;
        startlab.increfs;
        stoplab:=_stoplab;
        stoplab.increfs;
        handlerlab:=_handlerlab;
        handlerlab.increfs;
      end;


    destructor tai_jcatch.destroy;
      begin
        stringdispose(name);
        inherited destroy;
      end;


    constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
      begin
        inherited ppuload(t, ppufile);
        name:=stringdup(ppufile.getstring);
        startlab:=ppufile.getasmsymbol;
        startlab.increfs;
        stoplab:=ppufile.getasmsymbol;
        stoplab.increfs;
        handlerlab:=ppufile.getasmsymbol;
        handlerlab.increfs;
      end;


    procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
      begin
        inherited ppuwrite(ppufile);
        ppufile.putstring(name^);
        ppufile.putasmsymbol(startlab);
        ppufile.putasmsymbol(stoplab);
        ppufile.putasmsymbol(handlerlab);
      end;

{$endif JVM}

begin
{$push}{$warnings off}
  { taitype should fit into a 4 byte set for speed reasons }
  if ord(high(taitype))>31 then
    internalerror(201108181);
{$pop}
end.