1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
|
#include "rtt.h"
#define NotId 0 /* declarator is not simple identifier */
#define IsId 1 /* declarator is simple identifier */
#define OrdFunc -1 /* indicates ordinary C function - non-token value */
/*
* VArgAlwnc - allowance for the variable part of an argument list in the
* most general version of an operation. If it is too small, storage must
* be malloced. 3 was chosen because over 90 percent of all writes have
* 3 or fewer arguments. It is possible that 4 would be a better number,
* but 5 is probably overkill.
*/
#define VArgAlwnc 3
/*
* Prototypes for static functions.
*/
static void cnv_fnc (struct token *t, int typcd,
struct node *src, struct node *dflt,
struct node *dest, int indent);
static void chk_conj (struct node *n);
static void chk_nl (int indent);
static void chk_rsltblk (int indent);
static void comp_def (struct node *n);
static int does_call (struct node *expr);
static void failure (int indent, int brace);
static void interp_def (struct node *n);
static int len_sel (struct node *sel,
struct parminfo *strt_prms,
struct parminfo *end_prms, int indent);
static void line_dir (int nxt_line, char *new_fname);
static int only_proto (struct node *n);
static void parm_locs (struct sym_entry *op_params);
static void parm_tnd (struct sym_entry *sym);
static void prt_runerr (struct token *t, struct node *num,
struct node *val, int indent);
static void prt_tok (struct token *t, int indent);
static void prt_var (struct node *n, int indent);
static int real_def (struct node *n);
static int retval_dcltor (struct node *dcltor, int indent);
static void ret_value (struct token *t, struct node *n,
int indent);
static void ret_1_arg (struct token *t, struct node *args,
int typcd, char *vwrd_asgn, char *arg_rep,
int indent);
static int rt_walk (struct node *n, int indent, int brace);
static void spcl_start (struct sym_entry *op_params);
static int tdef_or_extr (struct node *n);
static void tend_ary (int n);
static void tend_init (void);
static void tnd_var (struct sym_entry *sym, char *strct_ptr, char *access, int indent);
static void tok_line (struct token *t, int indent);
static void typ_asrt (int typcd, struct node *desc,
struct token *tok, int indent);
static int typ_case (struct node *var, struct node *slct_lst,
struct node *dflt,
int (*walk)(struct node *n, int xindent,
int brace), int maybe_var, int indent);
static void untend (int indent);
extern char *progname;
int op_type = OrdFunc; /* type of operation */
char lc_letter; /* f = function, o = operator, k = keyword */
char uc_letter; /* F = function, O = operator, K = keyword */
char prfx1; /* 1st char of unique prefix for operation */
char prfx2; /* 2nd char of unique prefix for operation */
char *fname = ""; /* current source file name */
int line = 0; /* current source line number */
int nxt_sbuf; /* next string buffer index */
int nxt_cbuf; /* next cset buffer index */
int abs_ret = SomeType; /* type from abstract return(s) */
int nl = 0; /* flag indicating the a new-line should be output */
static int no_nl = 0; /* flag to suppress line directives */
static int ntend; /* number of tended descriptor needed */
static char *tendstrct; /* expression to access struct of tended descriptors */
static char *rslt_loc; /* expression to access result location */
static int varargs = 0; /* flag: operation takes variable number of arguments */
static int no_ret_val; /* function has return statement with no value */
static struct node *fnc_head; /* header of function being "copied" to output */
/*
* chk_nl - if a new-line is required, output it and indent the next line.
*/
static void chk_nl(indent)
int indent;
{
int col;
if (nl) {
/*
* new-line required.
*/
putc('\n', out_file);
++line;
for (col = 0; col < indent; ++col)
putc(' ', out_file);
nl = 0;
}
}
/*
* line_dir - Output a line directive.
*/
static void line_dir(nxt_line, new_fname)
int nxt_line;
char *new_fname;
{
char *s;
/*
* Make sure line directives are desired in the output. Normally,
* blank lines surround the directive for readability. However,`
* a preceding blank line is suppressed at the beginning of the
* output file. In addition, a blank line is suppressed after
* the directive if it would force the line number on the directive
* to be 0.
*/
if (line_cntrl) {
fprintf(out_file, "\n");
if (line != 0)
fprintf(out_file, "\n");
if (nxt_line == 1)
fprintf(out_file, "#line %d \"", nxt_line);
else
fprintf(out_file, "#line %d \"", nxt_line - 1);
for (s = new_fname; *s != '\0'; ++s) {
if (*s == '"' || *s == '\\')
putc('\\', out_file);
putc(*s, out_file);
}
if (nxt_line == 1)
fprintf(out_file, "\"");
else
fprintf(out_file, "\"\n");
nl = 1;
--nxt_line;
}
else if ((nxt_line > line || fname != new_fname) && line != 0) {
/*
* Line directives are disabled, but we are in a situation where
* one or two new-lines are desirable.
*/
if (nxt_line > line + 1 || fname != new_fname)
fprintf(out_file, "\n");
nl = 1;
--nxt_line;
}
line = nxt_line;
fname = new_fname;
}
/*
* prt_str - print a string to the output file, possibly preceded by
* a new-line and indenting.
*/
void prt_str(s, indent)
char *s;
int indent;
{
chk_nl(indent);
fprintf(out_file, "%s", s);
}
/*
* tok_line - determine if a line directive is needed to synchronize the
* output file name and line number with an input token.
*/
static void tok_line(t, indent)
struct token *t;
int indent;
{
int nxt_line;
/*
* Line directives may be suppressed at certain points during code
* output. This is done either by rtt itself using the no_nl flag, or
* for macros, by the preprocessor using a flag in the token.
*/
if (no_nl)
return;
if (t->flag & LineChk) {
/*
* If blank lines can be used in place of a line directive and no
* more than 3 are needed, use them. If the line number and file
* name are correct, but we need a new-line, we must output a
* line directive so the line number is reset after the "new-line".
*/
nxt_line = t->line;
if (fname != t->fname || line > nxt_line || line + 2 < nxt_line)
line_dir(nxt_line, t->fname);
else if (nl && line == nxt_line)
line_dir(nxt_line, t->fname);
else if (line != nxt_line) {
nl = 1;
--nxt_line;
while (line < nxt_line) { /* above condition limits # interactions */
putc('\n', out_file);
++line;
}
}
}
chk_nl(indent);
}
/*
* prt_tok - print a token.
*/
static void prt_tok(t, indent)
struct token *t;
int indent;
{
char *s;
tok_line(t, indent); /* synchronize file name and line number */
/*
* Most tokens contain a string of their exact image. However, string
* and character literals lack the surrounding quotes.
*/
s = t->image;
switch (t->tok_id) {
case StrLit:
fprintf(out_file, "\"%s\"", s);
break;
case LStrLit:
fprintf(out_file, "L\"%s\"", s);
break;
case CharConst:
fprintf(out_file, "'%s'", s);
break;
case LCharConst:
fprintf(out_file, "L'%s'", s);
break;
default:
fprintf(out_file, "%s", s);
}
}
/*
* untend - output code to removed the tended descriptors in this
* function from the global tended list.
*/
static void untend(indent)
int indent;
{
ForceNl();
prt_str("tend = ", indent);
fprintf(out_file, "%s.previous;", tendstrct);
ForceNl();
/*
* For varargs operations, the tended structure might have been
* malloced. If so, it must be freed.
*/
if (varargs) {
prt_str("if (r_tendp != (struct tend_desc *)&r_tend)", indent);
ForceNl();
prt_str("free((pointer)r_tendp);", 2 * indent);
}
}
/*
* tnd_var - output an expression to accessed a tended variable.
*/
static void tnd_var(sym, strct_ptr, access, indent)
struct sym_entry *sym;
char *strct_ptr;
char *access;
int indent;
{
/*
* A variable that is a specific block pointer type must be cast
* to that pointer type in such a way that it can be used as either
* an lvalue or an rvalue: *(struct b_??? **)&???.vword.bptr
*/
if (strct_ptr != NULL) {
prt_str("(*(struct ", indent);
prt_str(strct_ptr, indent);
prt_str("**)&", indent);
}
if (sym->id_type & ByRef) {
/*
* The tended variable is being accessed indirectly through
* a pointer (that is, it is accessed as the argument to a body
* function); dereference its identifier.
*/
prt_str("(*", indent);
prt_str(sym->image, indent);
prt_str(")", indent);
}
else {
if (sym->t_indx >= 0) {
/*
* The variable is accessed directly as part of the tended structure.
*/
prt_str(tendstrct, indent);
fprintf(out_file, ".d[%d]", sym->t_indx);
}
else {
/*
* This is a direct access to an operation parameter.
*/
prt_str("r_args[", indent);
fprintf(out_file, "%d]", sym->u.param_info.param_num + 1);
}
}
prt_str(access, indent); /* access the vword for tended pointers */
if (strct_ptr != NULL)
prt_str(")", indent);
}
/*
* prt_var - print a variable.
*/
static void prt_var(n, indent)
struct node *n;
int indent;
{
struct token *t;
struct sym_entry *sym;
t = n->tok;
tok_line(t, indent); /* synchronize file name and line nuber */
sym = n->u[0].sym;
switch (sym->id_type & ~ByRef) {
case TndDesc:
/*
* Simple tended descriptor.
*/
tnd_var(sym, NULL, "", indent);
break;
case TndStr:
/*
* Tended character pointer.
*/
tnd_var(sym, NULL, ".vword.sptr", indent);
break;
case TndBlk:
/*
* Tended block pointer.
*/
tnd_var(sym, sym->u.tnd_var.blk_name, ".vword.bptr",
indent);
break;
case RtParm:
case DrfPrm:
switch (sym->u.param_info.cur_loc) {
case PrmTend:
/*
* Simple tended parameter.
*/
tnd_var(sym, NULL, "", indent);
break;
case PrmCStr:
/*
* Parameter converted to a (tended) string.
*/
tnd_var(sym, NULL, ".vword.sptr", indent);
break;
case PrmInt:
/*
* Parameter converted to a C integer.
*/
chk_nl(indent);
fprintf(out_file, "r_i%d", sym->u.param_info.param_num);
break;
case PrmDbl:
/*
* Parameter converted to a C double.
*/
chk_nl(indent);
fprintf(out_file, "r_d%d", sym->u.param_info.param_num);
break;
default:
errt2(t, "Conflicting conversions for: ", t->image);
}
break;
case RtParm | VarPrm:
case DrfPrm | VarPrm:
/*
* Parameter representing variable part of argument list.
*/
prt_str("(&", indent);
if (sym->t_indx >= 0)
fprintf(out_file, "%s.d[%d])", tendstrct, sym->t_indx);
else
fprintf(out_file, "r_args[%d])", sym->u.param_info.param_num + 1);
break;
case VArgLen:
/*
* Length of variable part of argument list.
*/
prt_str("(r_nargs - ", indent);
fprintf(out_file, "%d)", params->u.param_info.param_num);
break;
case RsltLoc:
/*
* "result" the result location of the operation.
*/
prt_str(rslt_loc, indent);
break;
case Label:
/*
* Statement label.
*/
prt_str(sym->image, indent);
break;
case OtherDcl:
/*
* Some other type of variable: accessed by identifier. If this
* is a body function, it may be passed by reference and need
* a level of pointer dereferencing.
*/
if (sym->id_type & ByRef)
prt_str("(*",indent);
prt_str(sym->image, indent);
if (sym->id_type & ByRef)
prt_str(")",indent);
break;
}
}
/*
* does_call - determine if an expression contains a function call by
* walking its syntax tree.
*/
static int does_call(expr)
struct node *expr;
{
int n_subs;
int i;
if (expr == NULL)
return 0;
if (expr->nd_id == BinryNd && expr->tok->tok_id == ')')
return 1; /* found a function call */
switch (expr->nd_id) {
case ExactCnv: case PrimryNd: case SymNd:
n_subs = 0;
break;
case CompNd:
/*
* Check field 0 below, field 1 is not a subtree, check field 2 here.
*/
n_subs = 1;
if (does_call(expr->u[2].child))
return 1;
break;
case IcnTypNd: case PstfxNd: case PreSpcNd: case PrefxNd:
n_subs = 1;
break;
case AbstrNd: case BinryNd: case CommaNd: case ConCatNd: case LstNd:
case StrDclNd:
n_subs = 2;
break;
case TrnryNd:
n_subs = 3;
break;
case QuadNd:
n_subs = 4;
break;
default:
fprintf(stdout, "rtt internal error: unknown node type\n");
exit(EXIT_FAILURE);
}
for (i = 0; i < n_subs; ++i)
if (does_call(expr->u[i].child))
return 1;
return 0;
}
/*
* prt_runerr - print code to implement runerr().
*/
static void prt_runerr(t, num, val, indent)
struct token *t;
struct node *num;
struct node *val;
int indent;
{
if (op_type == OrdFunc)
errt1(t, "'runerr' may not be used in an ordinary C function");
tok_line(t, indent); /* synchronize file name and line number */
prt_str("{", indent);
ForceNl();
prt_str("err_msg(", indent);
c_walk(num, indent, 0); /* error number */
if (val == NULL)
prt_str(", NULL);", indent); /* no offending value */
else {
prt_str(", &(", indent);
c_walk(val, indent, 0); /* offending value */
prt_str("));", indent);
}
/*
* Handle error conversion. Indicate that operation may fail because
* of error conversion and produce the necessary code.
*/
cur_impl->ret_flag |= DoesEFail;
failure(indent, 1);
prt_str("}", indent);
ForceNl();
}
/*
* typ_name - convert a type code to a string that can be used to
* output "T_" or "D_" type codes.
*/
char *typ_name(typcd, tok)
int typcd;
struct token *tok;
{
if (typcd == Empty_type)
errt1(tok, "it is meaningless to assert a type of empty_type");
else if (typcd == Any_value)
errt1(tok, "it is useless to assert a type of any_value");
else if (typcd < 0 || typcd == str_typ)
return NULL;
else
return icontypes[typcd].cap_id;
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* Produce a C conditional expression to check a descriptor for a
* particular type.
*/
static void typ_asrt(typcd, desc, tok, indent)
int typcd;
struct node *desc;
struct token *tok;
int indent;
{
tok_line(tok, indent);
if (typcd == str_typ) {
/*
* Check dword for the absense of a "not qualifier" flag.
*/
prt_str("(!((", indent);
c_walk(desc, indent, 0);
prt_str(").dword & F_Nqual))", indent);
}
else if (typcd == TypVar) {
/*
* Check dword for the presense of a "variable" flag.
*/
prt_str("(((", indent);
c_walk(desc, indent, 0);
prt_str(").dword & D_Var) == D_Var)", indent);
}
else if (typcd == int_typ) {
/*
* If large integers are supported, an integer can be either
* an ordinary integer or a large integer.
*/
ForceNl();
prt_str("(((", indent);
c_walk(desc, indent, 0);
prt_str(").dword == D_Integer) || ((", indent);
c_walk(desc, indent, 0);
prt_str(").dword == D_Lrgint))", indent);
ForceNl();
}
else {
/*
* Check dword for a specific type code.
*/
prt_str("((", indent);
c_walk(desc, indent, 0);
prt_str(").dword == D_", indent);
prt_str(typ_name(typcd, tok), indent);
prt_str(")", indent);
}
}
/*
* retval_dcltor - convert the "declarator" part of function declaration
* into a declarator for the variable "r_retval" of the same type
* as the function result type, outputing the new declarator. This
* variable is a temporary location to store the result of the argument
* to a C return statement.
*/
static int retval_dcltor(dcltor, indent)
struct node *dcltor;
int indent;
{
int flag;
switch (dcltor->nd_id) {
case ConCatNd:
c_walk(dcltor->u[0].child, indent, 0);
retval_dcltor(dcltor->u[1].child, indent);
return NotId;
case PrimryNd:
/*
* We have reached the function name. Replace it with "r_retval"
* and tell caller we have found it.
*/
prt_str("r_retval", indent);
return IsId;
case PrefxNd:
/*
* (...)
*/
prt_str("(", indent);
flag = retval_dcltor(dcltor->u[0].child, indent);
prt_str(")", indent);
return flag;
case BinryNd:
if (dcltor->tok->tok_id == ')') {
/*
* Function declaration. If this is the declarator that actually
* defines the function being processed, discard the paramater
* list including parentheses.
*/
if (retval_dcltor(dcltor->u[0].child, indent) == NotId) {
prt_str("(", indent);
c_walk(dcltor->u[1].child, indent, 0);
prt_str(")", indent);
}
}
else {
/*
* Array.
*/
retval_dcltor(dcltor->u[0].child, indent);
prt_str("[", indent);
c_walk(dcltor->u[1].child, indent, 0);
prt_str("]", indent);
}
return NotId;
}
err1("rtt internal error detected in function retval_dcltor()");
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* cnv_fnc - produce code to handle RTT cnv: and def: constructs.
*/
static void cnv_fnc(t, typcd, src, dflt, dest, indent)
struct token *t;
int typcd;
struct node *src;
struct node *dflt;
struct node *dest;
int indent;
{
int dflt_to_ptr;
int loc;
int is_cstr;
if (src->nd_id == SymNd && src->u[0].sym->id_type & VarPrm)
errt1(t, "converting entire variable part of param list not supported");
tok_line(t, indent); /* synchronize file name and line number */
/*
* Initial assumptions: result of conversion is a tended location
* and is not tended C string.
*/
loc = PrmTend;
is_cstr = 0;
/*
* Print the name of the conversion function. If it is a conversion
* with a default value, determine (through dflt_to_prt) if the
* default value is passed by-reference instead of by-value.
*/
prt_str(cnv_name(typcd, dflt, &dflt_to_ptr), indent);
prt_str("(", indent);
/*
* Determine what parameter scope, if any, is established by this
* conversion. If the conversion needs a buffer, allocate it and
* put it in the argument list.
*/
switch (typcd) {
case TypCInt:
case TypECInt:
loc = PrmInt;
break;
case TypCDbl:
loc = PrmDbl;
break;
case TypCStr:
is_cstr = 1;
break;
case TypTStr:
fprintf(out_file, "r_sbuf[%d], ", nxt_sbuf++);
break;
case TypTCset:
fprintf(out_file, "&r_cbuf[%d], ", nxt_cbuf++);
break;
}
/*
* Output source of conversion.
*/
prt_str("&(", indent);
c_walk(src, indent, 0);
prt_str("), ", indent);
/*
* If there is a default value, output it, taking its address if necessary.
*/
if (dflt != NULL) {
if (dflt_to_ptr)
prt_str("&(", indent);
c_walk(dflt, indent, 0);
if (dflt_to_ptr)
prt_str("), ", indent);
else
prt_str(", ", indent);
}
/*
* Output the destination of the conversion. This may or may not be
* the same as the source.
*/
prt_str("&(", indent);
if (dest == NULL) {
/*
* Convert "in place", changing the location of a paramater if needed.
*/
if (src->nd_id == SymNd && src->u[0].sym->id_type & (RtParm | DrfPrm)) {
if (src->u[0].sym->id_type & DrfPrm)
src->u[0].sym->u.param_info.cur_loc = loc;
else
errt1(t, "only dereferenced parameter can be converted in-place");
}
else if ((loc != PrmTend) | is_cstr)
errt1(t,
"only ordinary parameters can be converted in-place to C values");
c_walk(src, indent, 0);
if (is_cstr) {
/*
* The parameter must be accessed as a tended C string, but only
* now, after the "destination" code has been produced as a full
* descriptor.
*/
src->u[0].sym->u.param_info.cur_loc = PrmCStr;
}
}
else {
/*
* Convert to an explicit destination.
*/
if (is_cstr) {
/*
* Access the destination as a full descriptor even though it
* must be declared as a tended C string.
*/
if (dest->nd_id != SymNd || (dest->u[0].sym->id_type != TndStr &&
dest->u[0].sym->id_type != TndDesc))
errt1(t,
"dest. of C_string conv. must be tended descriptor or char *");
tnd_var(dest->u[0].sym, NULL, "", indent);
}
else
c_walk(dest, indent, 0);
}
prt_str("))", indent);
}
/*
* cnv_name - produce name of conversion routine. Warning, name is
* constructed in a static buffer. Also determine if a default
* must be passed "by reference".
*/
char *cnv_name(typcd, dflt, dflt_to_ptr)
int typcd;
struct node *dflt;
int *dflt_to_ptr;
{
static char buf[15];
int by_ref;
/*
* The names of simple conversion and defaulting conversions have
* the same suffixes, but different prefixes.
*/
if (dflt == NULL)
strcpy(buf , "cnv_");
else
strcpy(buf, "def_");
by_ref = 0;
switch (typcd) {
case TypCInt:
strcat(buf, "c_int");
break;
case TypCDbl:
strcat(buf, "c_dbl");
break;
case TypCStr:
strcat(buf, "c_str");
break;
case TypTStr:
strcat(buf, "tstr");
by_ref = 1;
break;
case TypTCset:
strcat(buf, "tcset");
by_ref = 1;
break;
case TypEInt:
strcat(buf, "eint");
break;
case TypECInt:
strcat(buf, "ec_int");
break;
default:
if (typcd == cset_typ) {
strcat(buf, "cset");
by_ref = 1;
}
else if (typcd == int_typ)
strcat(buf, "int");
else if (typcd == real_typ)
strcat(buf, "real");
else if (typcd == str_typ) {
strcat(buf, "str");
by_ref = 1;
}
}
if (dflt_to_ptr != NULL)
*dflt_to_ptr = by_ref;
return buf;
}
/*
* ret_value - produce code to set the result location of an operation
* using the expression on a return or suspend.
*/
static void ret_value(t, n, indent)
struct token *t;
struct node *n;
int indent;
{
struct node *caller;
struct node *args;
int typcd;
if (n == NULL)
errt1(t, "there is no default return value for run-time operations");
if (n->nd_id == SymNd && n->u[0].sym->id_type == RsltLoc) {
/*
* return/suspend result;
*
* result already where it needs to be.
*/
return;
}
if (n->nd_id == PrefxNd && n->tok != NULL) {
switch (n->tok->tok_id) {
case C_Integer:
/*
* return/suspend C_integer <expr>;
*/
prt_str(rslt_loc, indent);
prt_str(".vword.integr = ", indent);
c_walk(n->u[0].child, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = D_Integer;", indent);
chkabsret(t, int_typ); /* compare return with abstract return */
return;
case C_Double:
/*
* return/suspend C_double <expr>;
*/
prt_str(rslt_loc, indent);
prt_str(".vword.bptr = (union block *)alcreal(", indent);
c_walk(n->u[0].child, indent + IndentInc, 0);
prt_str(");", indent + IndentInc);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = D_Real;", indent);
/*
* The allocation of the real block may fail.
*/
chk_rsltblk(indent);
chkabsret(t, real_typ); /* compare return with abstract return */
return;
case C_String:
/*
* return/suspend C_string <expr>;
*/
prt_str(rslt_loc, indent);
prt_str(".vword.sptr = ", indent);
c_walk(n->u[0].child, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = strlen(", indent);
prt_str(rslt_loc, indent);
prt_str(".vword.sptr);", indent);
chkabsret(t, str_typ); /* compare return with abstract return */
return;
}
}
else if (n->nd_id == BinryNd && n->tok->tok_id == ')') {
/*
* Return value is in form of function call, see if it is really
* a descriptor constructor.
*/
caller = n->u[0].child;
args = n->u[1].child;
if (caller->nd_id == SymNd) {
switch (caller->tok->tok_id) {
case IconType:
typcd = caller->u[0].sym->u.typ_indx;
switch (icontypes[typcd].rtl_ret) {
case TRetBlkP:
/*
* return/suspend <type>(<block-pntr>);
*/
ret_1_arg(t, args, typcd, ".vword.bptr = (union block *)",
"(bp)", indent);
break;
case TRetDescP:
/*
* return/suspend <type>(<desc-pntr>);
*/
ret_1_arg(t, args, typcd, ".vword.descptr = (dptr)",
"(dp)", indent);
break;
case TRetCharP:
/*
* return/suspend <type>(<char-pntr>);
*/
ret_1_arg(t, args, typcd, ".vword.sptr = (char *)",
"(s)", indent);
break;
case TRetCInt:
/*
* return/suspend <type>(<integer>);
*/
ret_1_arg(t, args, typcd, ".vword.integr = (word)",
"(i)", indent);
break;
case TRetSpcl:
if (typcd == str_typ) {
/*
* return/suspend string(<len>, <char-pntr>);
*/
if (args == NULL || args->nd_id != CommaNd ||
args->u[0].child->nd_id == CommaNd)
errt1(t, "wrong no. of args for string(n, s)");
prt_str(rslt_loc, indent);
prt_str(".vword.sptr = ", indent);
c_walk(args->u[1].child, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = ", indent);
c_walk(args->u[0].child, indent + IndentInc, 0);
prt_str(";", indent);
}
else if (typcd == stv_typ) {
/*
* return/suspend tvsubs(<desc-pntr>, <start>, <len>);
*/
if (args == NULL || args->nd_id != CommaNd ||
args->u[0].child->nd_id != CommaNd ||
args->u[0].child->u[0].child->nd_id == CommaNd)
errt1(t, "wrong no. of args for tvsubs(dp, i, j)");
no_nl = 1;
prt_str("SubStr(&", indent);
prt_str(rslt_loc, indent);
prt_str(", ", indent);
c_walk(args->u[0].child->u[0].child, indent + IndentInc,
0);
prt_str(", ", indent + IndentInc);
c_walk(args->u[1].child, indent + IndentInc, 0);
prt_str(", ", indent + IndentInc);
c_walk(args->u[0].child->u[1].child, indent + IndentInc,
0);
prt_str(");", indent + IndentInc);
no_nl = 0;
/*
* The allocation of the substring trapped variable
* block may fail.
*/
chk_rsltblk(indent);
chkabsret(t, stv_typ); /* compare to abstract return */
}
break;
}
chkabsret(t, typcd); /* compare return with abstract return */
return;
case Named_var:
/*
* return/suspend named_var(<desc-pntr>);
*/
if (args == NULL || args->nd_id == CommaNd)
errt1(t, "wrong no. of args for named_var(dp)");
prt_str(rslt_loc, indent);
prt_str(".vword.descptr = ", indent);
c_walk(args, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = D_Var;", indent);
chkabsret(t, TypVar); /* compare return with abstract return */
return;
case Struct_var:
/*
* return/suspend struct_var(<desc-pntr>, <block_pntr>);
*/
if (args == NULL || args->nd_id != CommaNd ||
args->u[0].child->nd_id == CommaNd)
errt1(t, "wrong no. of args for struct_var(dp, bp)");
prt_str(rslt_loc, indent);
prt_str(".vword.descptr = (dptr)", indent);
c_walk(args->u[1].child, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
prt_str(rslt_loc, indent);
prt_str(".dword = D_Var + ((word *)", indent);
c_walk(args->u[0].child, indent + IndentInc, 0);
prt_str(" - (word *)", indent+IndentInc);
prt_str(rslt_loc, indent);
prt_str(".vword.descptr);", indent+IndentInc);
ForceNl();
chkabsret(t, TypVar); /* compare return with abstract return */
return;
}
}
}
/*
* If it is not one of the special returns, it is just a return of
* a descriptor.
*/
prt_str(rslt_loc, indent);
prt_str(" = ", indent);
c_walk(n, indent + IndentInc, 0);
prt_str(";", indent);
chkabsret(t, SomeType); /* check for preceding abstract return */
}
/*
* ret_1_arg - produce code for a special return/suspend with one argument.
*/
static void ret_1_arg(t, args, typcd, vwrd_asgn, arg_rep, indent)
struct token *t;
struct node *args;
int typcd;
char *vwrd_asgn;
char *arg_rep;
int indent;
{
if (args == NULL || args->nd_id == CommaNd)
errt3(t, "wrong no. of args for", icontypes[typcd].id, arg_rep);
/*
* Assignment to vword of result descriptor.
*/
prt_str(rslt_loc, indent);
prt_str(vwrd_asgn, indent);
c_walk(args, indent + IndentInc, 0);
prt_str(";", indent);
ForceNl();
/*
* Assignment to dword of result descriptor.
*/
prt_str(rslt_loc, indent);
prt_str(".dword = D_", indent);
prt_str(icontypes[typcd].cap_id, indent);
prt_str(";", indent);
}
/*
* chk_rsltblk - the result value contains an allocated block, make sure
* the allocation succeeded.
*/
static void chk_rsltblk(indent)
int indent;
{
ForceNl();
prt_str("if (", indent);
prt_str(rslt_loc, indent);
prt_str(".vword.bptr == NULL) {", indent);
ForceNl();
prt_str("err_msg(307, NULL);", indent + IndentInc);
ForceNl();
/*
* Handle error conversion. Indicate that operation may fail because
* of error conversion and produce the necessary code.
*/
cur_impl->ret_flag |= DoesEFail;
failure(indent + IndentInc, 1);
prt_str("}", indent + IndentInc);
ForceNl();
}
/*
* failure - produce code for fail or efail.
*/
static void failure(indent, brace)
int indent;
int brace;
{
/*
* If there are tended variables, they must be removed from the tended
* list. The C function may or may not return an explicit signal.
*/
ForceNl();
if (ntend != 0) {
if (!brace)
prt_str("{", indent);
untend(indent);
ForceNl();
if (fnc_ret == RetSig)
prt_str("return A_Resume;", indent);
else
prt_str("return;", indent);
if (!brace) {
ForceNl();
prt_str("}", indent);
}
}
else
if (fnc_ret == RetSig)
prt_str("return A_Resume;", indent);
else
prt_str("return;", indent);
ForceNl();
}
/*
* c_walk - walk the syntax tree for extended C code and output the
* corresponding ordinary C. Return and indication of whether execution
* falls through the code.
*/
int c_walk(n, indent, brace)
struct node *n;
int indent;
int brace;
{
struct token *t;
struct node *n1;
struct sym_entry *sym;
int fall_thru;
int save_break;
static int does_break = 0;
static int may_brnchto; /* may reach end of code by branching into middle */
if (n == NULL)
return 1;
t = n->tok;
switch (n->nd_id) {
case PrimryNd:
switch (t->tok_id) {
case Fail:
if (op_type == OrdFunc)
errt1(t, "'fail' may not be used in an ordinary C function");
cur_impl->ret_flag |= DoesFail;
failure(indent, brace);
chkabsret(t, SomeType); /* check preceding abstract return */
return 0;
case Errorfail:
if (op_type == OrdFunc)
errt1(t,
"'errorfail' may not be used in an ordinary C function");
cur_impl->ret_flag |= DoesEFail;
failure(indent, brace);
return 0;
case Break:
prt_tok(t, indent);
prt_str(";", indent);
does_break = 1;
return 0;
default:
/*
* Other "primary" expressions are just their token image,
* possibly followed by a semicolon.
*/
prt_tok(t, indent);
if (t->tok_id == Continue)
prt_str(";", indent);
return 1;
}
case PrefxNd:
switch (t->tok_id) {
case Sizeof:
prt_tok(t, indent); /* sizeof */
prt_str("(", indent);
c_walk(n->u[0].child, indent, 0);
prt_str(")", indent);
return 1;
case '{':
/*
* Initializer list.
*/
prt_tok(t, indent + IndentInc); /* { */
c_walk(n->u[0].child, indent + IndentInc, 0);
prt_str("}", indent + IndentInc);
return 1;
case Default:
prt_tok(t, indent - IndentInc); /* default (un-indented) */
prt_str(": ", indent - IndentInc);
fall_thru = c_walk(n->u[0].child, indent, 0);
may_brnchto = 1;
return fall_thru;
case Goto:
prt_tok(t, indent); /* goto */
prt_str(" ", indent);
c_walk(n->u[0].child, indent, 0);
prt_str(";", indent);
return 0;
case Return:
if (n->u[0].child != NULL)
no_ret_val = 0; /* note that return statement has no value */
if (op_type == OrdFunc || fnc_ret == RetInt ||
fnc_ret == RetDbl) {
/*
* ordinary C return: ignore C_integer, C_double, and
* C_string qualifiers on return expression (the first
* two may legally occur when fnc_ret is RetInt or RetDbl).
*/
n1 = n->u[0].child;
if (n1 != NULL && n1->nd_id == PrefxNd && n1->tok != NULL) {
switch (n1->tok->tok_id) {
case C_Integer:
case C_Double:
case C_String:
n1 = n1->u[0].child;
}
}
if (ntend != 0) {
/*
* There are tended variables that must be removed from
* the tended list.
*/
if (!brace)
prt_str("{", indent);
if (does_call(n1)) {
/*
* The return expression contains a function call;
* the variables must remain tended while it is
* computed, so compute it into a temporary variable
* named r_retval.Output a declaration for r_retval;
* its type must match the return type of the C
* function.
*/
ForceNl();
prt_str("register ", indent);
if (op_type == OrdFunc) {
no_nl = 1;
just_type(fnc_head->u[0].child, indent, 0);
prt_str(" ", indent);
retval_dcltor(fnc_head->u[1].child, indent);
prt_str(";", indent);
no_nl = 0;
}
else if (fnc_ret == RetInt)
prt_str("C_integer r_retval;", indent);
else /* fnc_ret == RetDbl */
prt_str("double r_retval;", indent);
ForceNl();
/*
* Output code to compute the return value, untend
* the variable, then return the value.
*/
prt_str("r_retval = ", indent);
c_walk(n1, indent + IndentInc, 0);
prt_str(";", indent);
untend(indent);
ForceNl();
prt_str("return r_retval;", indent);
}
else {
/*
* It is safe to untend the variables and return
* the result value directly with a return
* statement.
*/
untend(indent);
ForceNl();
prt_tok(t, indent); /* return */
prt_str(" ", indent);
c_walk(n1, indent, 0);
prt_str(";", indent);
}
if (!brace) {
ForceNl();
prt_str("}", indent);
}
ForceNl();
}
else {
/*
* There are no tended variable, just output the
* return expression.
*/
prt_tok(t, indent); /* return */
prt_str(" ", indent);
c_walk(n1, indent, 0);
prt_str(";", indent);
}
/*
* If this is a body function, check the return against
* preceding abstract returns.
*/
if (fnc_ret == RetInt)
chkabsret(n->tok, int_typ);
else if (fnc_ret == RetDbl)
chkabsret(n->tok, real_typ);
}
else {
/*
* Return from Icon operation. Indicate that the operation
* returns, compute the value into the result location,
* untend variables if necessary, and return a signal
* if the function requires one.
*/
cur_impl->ret_flag |= DoesRet;
ForceNl();
if (!brace) {
prt_str("{", indent);
ForceNl();
}
ret_value(t, n->u[0].child, indent);
if (ntend != 0)
untend(indent);
ForceNl();
if (fnc_ret == RetSig)
prt_str("return A_Continue;", indent);
else if (fnc_ret == RetNoVal)
prt_str("return;", indent);
ForceNl();
if (!brace) {
prt_str("}", indent);
ForceNl();
}
}
return 0;
case Suspend:
if (op_type == OrdFunc)
errt1(t, "'suspend' may not be used in an ordinary C function"
);
cur_impl->ret_flag |= DoesSusp; /* note suspension */
ForceNl();
if (!brace) {
prt_str("{", indent);
ForceNl();
}
prt_str("register int signal;", indent + IndentInc);
ForceNl();
ret_value(t, n->u[0].child, indent);
ForceNl();
/*
* The operator suspends by calling the success continuation
* if there is one or just returns if there is none. For
* the interpreter, interp() is the success continuation.
* A non-A_Resume signal from the success continuation must
* returned to the caller. If there are tended variables
* they must be removed from the tended list before a signal
* is returned.
*/
if (iconx_flg) {
prt_str(
"if ((signal = interp(G_Csusp, r_args)) != A_Resume) {",
indent);
}
else {
prt_str("if (r_s_cont == (continuation)NULL) {", indent);
if (ntend != 0)
untend(indent + IndentInc);
ForceNl();
prt_str("return A_Continue;", indent + IndentInc);
ForceNl();
prt_str("}", indent + IndentInc);
ForceNl();
prt_str("else if ((signal = (*r_s_cont)()) != A_Resume) {",
indent);
}
ForceNl();
if (ntend != 0)
untend(indent + IndentInc);
ForceNl();
prt_str("return signal;", indent + IndentInc);
ForceNl();
prt_str("}", indent + IndentInc);
if (!brace) {
prt_str("}", indent);
ForceNl();
}
return 1;
case '(':
/*
* Parenthesized expression.
*/
prt_tok(t, indent); /* ( */
fall_thru = c_walk(n->u[0].child, indent, 0);
prt_str(")", indent);
return fall_thru;
default:
/*
* All other prefix expressions are printed as the token
* image of the operation followed by the operand.
*/
prt_tok(t, indent);
c_walk(n->u[0].child, indent, 0);
return 1;
}
case PstfxNd:
/*
* All postfix expressions are printed as the operand followed
* by the token image of the operation.
*/
fall_thru = c_walk(n->u[0].child, indent, 0);
prt_tok(t, indent);
return fall_thru;
case PreSpcNd:
/*
* This prefix expression (pointer indication in a declaration) needs
* a space after it.
*/
prt_tok(t, indent);
c_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
return 1;
case SymNd:
/*
* Identifier.
*/
prt_var(n, indent);
return 1;
case BinryNd:
switch (t->tok_id) {
case '[':
/*
* subscripting expression or declaration: <expr> [ <expr> ]
*/
n1 = n->u[0].child;
c_walk(n->u[0].child, indent, 0);
prt_str("[", indent);
c_walk(n->u[1].child, indent, 0);
prt_str("]", indent);
return 1;
case '(':
/*
* cast: ( <type> ) <expr>
*/
prt_tok(t, indent); /* ) */
c_walk(n->u[0].child, indent, 0);
prt_str(")", indent);
c_walk(n->u[1].child, indent, 0);
return 1;
case ')':
/*
* function call or declaration: <expr> ( <expr-list> )
*/
c_walk(n->u[0].child, indent, 0);
prt_str("(", indent);
c_walk(n->u[1].child, indent, 0);
prt_tok(t, indent); /* ) */
return call_ret(n->u[0].child);
case Struct:
case Union:
/*
* struct/union <ident>
* struct/union <opt-ident> { <field-list> }
*/
prt_tok(t, indent); /* struct or union */
prt_str(" ", indent);
c_walk(n->u[0].child, indent, 0);
if (n->u[1].child != NULL) {
/*
* Field declaration list.
*/
prt_str(" {", indent);
c_walk(n->u[1].child, indent + IndentInc, 0);
ForceNl();
prt_str("}", indent);
}
return 1;
case TokEnum:
/*
* enum <ident>
* enum <opt-ident> { <enum-list> }
*/
prt_tok(t, indent); /* enum */
prt_str(" ", indent);
c_walk(n->u[0].child, indent, 0);
if (n->u[1].child != NULL) {
/*
* enumerator list.
*/
prt_str(" {", indent);
c_walk(n->u[1].child, indent + IndentInc, 0);
prt_str("}", indent);
}
return 1;
case ';':
/*
* <type-specs> <declarator> ;
*/
c_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
c_walk(n->u[1].child, indent, 0);
prt_tok(t, indent); /* ; */
return 1;
case ':':
/*
* <label> : <statement>
*/
c_walk(n->u[0].child, indent, 0);
prt_tok(t, indent); /* : */
prt_str(" ", indent);
fall_thru = c_walk(n->u[1].child, indent, 0);
may_brnchto = 1;
return fall_thru;
case Case:
/*
* case <expr> : <statement>
*/
prt_tok(t, indent - IndentInc); /* case (un-indented) */
prt_str(" ", indent);
c_walk(n->u[0].child, indent - IndentInc, 0);
prt_str(": ", indent - IndentInc);
fall_thru = c_walk(n->u[1].child, indent, 0);
may_brnchto = 1;
return fall_thru;
case Switch:
/*
* switch ( <expr> ) <statement>
*
* <statement> is double indented so that case and default
* statements can be un-indented and come out indented 1
* with respect to the switch. Statements that are not
* "labeled" with case or default are indented one more
* than those that are labeled.
*/
prt_tok(t, indent); /* switch */
prt_str(" (", indent);
c_walk(n->u[0].child, indent, 0);
prt_str(")", indent);
prt_str(" ", indent);
save_break = does_break;
fall_thru = c_walk(n->u[1].child, indent + 2 * IndentInc, 0);
fall_thru |= does_break;
does_break = save_break;
return fall_thru;
case While: {
struct node *n0;
/*
* While ( <expr> ) <statement>
*/
n0 = n->u[0].child;
prt_tok(t, indent); /* while */
prt_str(" (", indent);
c_walk(n0, indent, 0);
prt_str(")", indent);
prt_str(" ", indent);
save_break = does_break;
c_walk(n->u[1].child, indent + IndentInc, 0);
/*
* check for an infinite loop, while (1) ... :
* a condition consisting of an IntConst with image=="1"
* and no breaks in the body.
*/
if (n0->nd_id == PrimryNd && n0->tok->tok_id == IntConst &&
!strcmp(n0->tok->image,"1") && !does_break)
fall_thru = 0;
else
fall_thru = 1;
does_break = save_break;
return fall_thru;
}
case Do:
/*
* do <statement> <while> ( <expr> )
*/
prt_tok(t, indent); /* do */
prt_str(" ", indent);
c_walk(n->u[0].child, indent + IndentInc, 0);
ForceNl();
prt_str("while (", indent);
save_break = does_break;
c_walk(n->u[1].child, indent, 0);
does_break = save_break;
prt_str(");", indent);
return 1;
case '.':
case Arrow:
/*
* Field access: <expr> . <expr> and <expr> -> <expr>
*/
c_walk(n->u[0].child, indent, 0);
prt_tok(t, indent); /* . or -> */
c_walk(n->u[1].child, indent, 0);
return 1;
case Runerr:
/*
* runerr ( <error-number> )
* runerr ( <error-number> , <offending-value> )
*/
prt_runerr(t, n->u[0].child, n->u[1].child, indent);
return 0;
case Is:
/*
* is : <type> ( <expr> )
*/
typ_asrt(icn_typ(n->u[0].child), n->u[1].child,
n->u[0].child->tok, indent);
return 1;
default:
/*
* All other binary expressions are infix notation and
* are printed with spaces around the operator.
*/
c_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
prt_tok(t, indent);
prt_str(" ", indent);
c_walk(n->u[1].child, indent, 0);
return 1;
}
case LstNd:
/*
* <declaration-part> <declaration-part>
*
* Need space between parts
*/
c_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
c_walk(n->u[1].child, indent, 0);
return 1;
case ConCatNd:
/*
* <some-code> <some-code>
*
* Various lists of code parts that do not need space between them.
*/
if (c_walk(n->u[0].child, indent, 0))
return c_walk(n->u[1].child, indent, 0);
else {
/*
* Cannot directly reach the second piece of code, see if
* it is possible to branch into it.
*/
may_brnchto = 0;
fall_thru = c_walk(n->u[1].child, indent, 0);
return may_brnchto & fall_thru;
}
case CommaNd:
/*
* <expr> , <expr>
*/
c_walk(n->u[0].child, indent, 0);
prt_tok(t, indent);
prt_str(" ", indent);
return c_walk(n->u[1].child, indent, 0);
case StrDclNd:
/*
* Structure field declaration. Bit field declarations have
* a semicolon and a field width.
*/
c_walk(n->u[0].child, indent, 0);
if (n->u[1].child != NULL) {
prt_str(": ", indent);
c_walk(n->u[1].child, indent, 0);
}
return 1;
case CompNd:
/*
* Compound statement.
*/
if (brace)
tok_line(t, indent); /* just synch. file name and line number */
else
prt_tok(t, indent); /* { */
c_walk(n->u[0].child, indent, 0);
/*
* we are in an inner block. tended locations may need to
* be set to values from declaration initializations.
*/
for (sym = n->u[1].sym; sym!= NULL; sym = sym->u.tnd_var.next) {
if (sym->u.tnd_var.init != NULL) {
prt_str(tendstrct, IndentInc);
fprintf(out_file, ".d[%d]", sym->t_indx);
switch (sym->id_type) {
case TndDesc:
prt_str(" = ", IndentInc);
break;
case TndStr:
prt_str(".vword.sptr = ", IndentInc);
break;
case TndBlk:
prt_str(".vword.bptr = (union block *)",
IndentInc);
break;
}
c_walk(sym->u.tnd_var.init, 2 * IndentInc, 0);
prt_str(";", 2 * IndentInc);
ForceNl();
}
}
/*
* If there are no declarations, suppress braces that
* may be required for a one-statement body; we already
* have a set.
*/
if (n->u[0].child == NULL && n->u[1].sym == NULL)
fall_thru = c_walk(n->u[2].child, indent, 1);
else
fall_thru = c_walk(n->u[2].child, indent, 0);
if (!brace) {
ForceNl();
prt_str("}", indent);
}
return fall_thru;
case TrnryNd:
switch (t->tok_id) {
case '?':
/*
* <expr> ? <expr> : <expr>
*/
c_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
prt_tok(t, indent); /* ? */
prt_str(" ", indent);
c_walk(n->u[1].child, indent, 0);
prt_str(" : ", indent);
c_walk(n->u[2].child, indent, 0);
return 1;
case If:
/*
* if ( <expr> ) <statement>
* if ( <expr> ) <statement> else <statement>
*/
prt_tok(t, indent); /* if */
prt_str(" (", indent);
c_walk(n->u[0].child, indent + IndentInc, 0);
prt_str(") ", indent);
fall_thru = c_walk(n->u[1].child, indent + IndentInc, 0);
n1 = n->u[2].child;
if (n1 == NULL)
fall_thru = 1;
else {
/*
* There is an else statement. Don't indent an
* "else if"
*/
ForceNl();
prt_str("else ", indent);
if (n1->nd_id == TrnryNd && n1->tok->tok_id == If)
fall_thru |= c_walk(n1, indent, 0);
else
fall_thru |= c_walk(n1, indent + IndentInc, 0);
}
return fall_thru;
case Type_case:
/*
* type_case <expr> of { <section-list> }
* type_case <expr> of { <section-list> <default-clause> }
*/
return typ_case(n->u[0].child, n->u[1].child, n->u[2].child,
c_walk, 1, indent);
case Cnv:
/*
* cnv : <type> ( <source> , <destination> )
*/
cnv_fnc(t, icn_typ(n->u[0].child), n->u[1].child, NULL,
n->u[2].child,
indent);
return 1;
}
case QuadNd:
switch (t->tok_id) {
case For:
/*
* for ( <expr> ; <expr> ; <expr> ) <statement>
*/
prt_tok(t, indent); /* for */
prt_str(" (", indent);
c_walk(n->u[0].child, indent, 0);
prt_str("; ", indent);
c_walk(n->u[1].child, indent, 0);
prt_str("; ", indent);
c_walk(n->u[2].child, indent, 0);
prt_str(") ", indent);
save_break = does_break;
c_walk(n->u[3].child, indent + IndentInc, 0);
if (n->u[1].child == NULL && !does_break)
fall_thru = 0;
else
fall_thru = 1;
does_break = save_break;
return fall_thru;
case Def:
/*
* def : <type> ( <source> , <default> , <destination> )
*/
cnv_fnc(t, icn_typ(n->u[0].child), n->u[1].child, n->u[2].child,
n->u[3].child, indent);
return 1;
}
}
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* call_ret - decide whether a function being called might return.
*/
int call_ret(n)
struct node *n;
{
/*
* Assume functions return except for c_exit(), fatalerr(), and syserr().
*/
if (n->tok != NULL &&
(strcmp("c_exit", n->tok->image) == 0 ||
strcmp("fatalerr", n->tok->image) == 0 ||
strcmp("syserr", n->tok->image) == 0))
return 0;
else
return 1;
}
/*
* new_prmloc - allocate an array large enough to hold a flag for every
* parameter of the current operation. This flag indicates where
* the parameter is in terms of scopes created by conversions.
*/
struct parminfo *new_prmloc()
{
struct parminfo *parminfo;
int nparams;
int i;
if (params == NULL)
return NULL;
nparams = params->u.param_info.param_num + 1;
parminfo = alloc(nparams * sizeof(struct parminfo));
for (i = 0; i < nparams; ++i) {
parminfo[i].cur_loc = 0;
parminfo [i].parm_mod = 0;
}
return parminfo;
}
/*
* ld_prmloc - load parameter location information that has been
* saved in an arrary into the symbol table.
*/
void ld_prmloc(parminfo)
struct parminfo *parminfo;
{
struct sym_entry *sym;
int param_num;
for (sym = params; sym != NULL; sym = sym->u.param_info.next) {
param_num = sym->u.param_info.param_num;
if (sym->id_type & DrfPrm) {
sym->u.param_info.cur_loc = parminfo[param_num].cur_loc;
sym->u.param_info.parm_mod = parminfo[param_num].parm_mod;
}
}
}
/*
* sv_prmloc - save parameter location information from the the symbol table
* into an array.
*/
void sv_prmloc(parminfo)
struct parminfo *parminfo;
{
struct sym_entry *sym;
int param_num;
for (sym = params; sym != NULL; sym = sym->u.param_info.next) {
param_num = sym->u.param_info.param_num;
if (sym->id_type & DrfPrm) {
parminfo[param_num].cur_loc = sym->u.param_info.cur_loc;
parminfo[param_num].parm_mod = sym->u.param_info.parm_mod;
}
}
}
/*
* mrg_prmloc - merge parameter location information in the symbol table
* with other information already saved in an array. This may result
* in conflicting location information, but conflicts are only detected
* when a parameter is actually used.
*/
void mrg_prmloc(parminfo)
struct parminfo *parminfo;
{
struct sym_entry *sym;
int param_num;
for (sym = params; sym != NULL; sym = sym->u.param_info.next) {
param_num = sym->u.param_info.param_num;
if (sym->id_type & DrfPrm) {
parminfo[param_num].cur_loc |= sym->u.param_info.cur_loc;
parminfo[param_num].parm_mod |= sym->u.param_info.parm_mod;
}
}
}
/*
* clr_prmloc - indicate that this execution path contributes nothing
* to the location of parameters.
*/
void clr_prmloc()
{
struct sym_entry *sym;
for (sym = params; sym != NULL; sym = sym->u.param_info.next) {
if (sym->id_type & DrfPrm) {
sym->u.param_info.cur_loc = 0;
sym->u.param_info.parm_mod = 0;
}
}
}
/*
* typ_case - translate a type_case statement into C. This is called
* while walking a syntax tree of either RTL code or C code; the parameter
* "walk" is a function used to process the subtrees within the type_case
* statement.
*/
static int typ_case(var, slct_lst, dflt, walk, maybe_var, indent)
struct node *var;
struct node *slct_lst;
struct node *dflt;
int (*walk)(struct node *n, int xindent, int brace);
int maybe_var;
int indent;
{
struct node *lst;
struct node *select;
struct node *slctor;
struct parminfo *strt_prms;
struct parminfo *end_prms;
int remaining;
int first;
int fnd_slctrs;
int maybe_str = 1;
int dflt_lbl;
int typcd;
int fall_thru;
char *s;
/*
* This statement involves multiple paths that may establish new
* scopes for parameters. Remember the starting scope information
* and initialize an array in which to compute the final information.
*/
strt_prms = new_prmloc();
sv_prmloc(strt_prms);
end_prms = new_prmloc();
/*
* First look for cases that must be checked with "if" statements.
* These include string qualifiers and variables.
*/
remaining = 0; /* number of cases skipped in first pass */
first = 1; /* next case to be output is the first */
if (dflt == NULL)
fall_thru = 1;
else
fall_thru = 0;
for (lst = slct_lst; lst != NULL; lst = lst->u[0].child) {
select = lst->u[1].child;
fnd_slctrs = 0; /* flag: found type selections for clause for this pass */
/*
* A selection clause may include several types.
*/
for (slctor = select->u[0].child; slctor != NULL; slctor =
slctor->u[0].child) {
typcd = icn_typ(slctor->u[1].child);
if(typ_name(typcd, slctor->u[1].child->tok) == NULL) {
/*
* This type must be checked with the "if". Is this the
* first condition checked for this clause? Is this the
* first clause output?
*/
if (fnd_slctrs)
prt_str(" || ", indent);
else {
if (first)
first = 0;
else {
ForceNl();
prt_str("else ", indent);
}
prt_str("if (", indent);
fnd_slctrs = 1;
}
/*
* Output type check
*/
typ_asrt(typcd, var, slctor->u[1].child->tok, indent + IndentInc);
if (typcd == str_typ)
maybe_str = 0; /* string has been taken care of */
else if (typcd == Variable)
maybe_var = 0; /* variable has been taken care of */
}
else
++remaining;
}
if (fnd_slctrs) {
/*
* We have found and output type selections for this clause;
* output the body of the clause. Remember any changes to
* paramter locations caused by type conversions within the
* clause.
*/
prt_str(") {", indent + IndentInc);
ForceNl();
if ((*walk)(select->u[1].child, indent + IndentInc, 1)) {
fall_thru |= 1;
mrg_prmloc(end_prms);
}
prt_str("}", indent + IndentInc);
ForceNl();
ld_prmloc(strt_prms);
}
}
/*
* The rest of the cases can be checked with a "switch" statement, look
* for them..
*/
if (remaining == 0) {
if (dflt != NULL) {
/*
* There are no cases to handle with a switch statement, but there
* is a default clause; handle it with an "else".
*/
prt_str("else {", indent);
ForceNl();
fall_thru |= (*walk)(dflt, indent + IndentInc, 1);
ForceNl();
prt_str("}", indent + IndentInc);
ForceNl();
}
}
else {
/*
* If an "if" statement was output, the "switch" must be in its "else"
* clause.
*/
if (!first)
prt_str("else ", indent);
/*
* A switch statement cannot handle types that are not simple type
* codes. If these have not taken care of, output code to check them.
* This will either branch around the switch statement or into
* its default clause.
*/
if (maybe_str || maybe_var) {
dflt_lbl = lbl_num++; /* allocate a label number */
prt_str("{", indent);
ForceNl();
prt_str("if (((", indent);
c_walk(var, indent + IndentInc, 0);
prt_str(").dword & D_Typecode) != D_Typecode) ", indent);
ForceNl();
prt_str("goto L", indent + IndentInc);
fprintf(out_file, "%d; /* default */ ", dflt_lbl);
ForceNl();
}
no_nl = 1; /* suppress #line directives */
prt_str("switch (Type(", indent);
c_walk(var, indent + IndentInc, 0);
prt_str(")) {", indent + IndentInc);
no_nl = 0;
ForceNl();
/*
* Loop through the case clauses producing code for them.
*/
for (lst = slct_lst; lst != NULL; lst = lst->u[0].child) {
select = lst->u[1].child;
fnd_slctrs = 0;
/*
* A selection clause may include several types.
*/
for (slctor = select->u[0].child; slctor != NULL; slctor =
slctor->u[0].child) {
typcd = icn_typ(slctor->u[1].child);
s = typ_name(typcd, slctor->u[1].child->tok);
if (s != NULL) {
/*
* A type selection has been found that can be checked
* in the switch statement. Note that large integers
* require special handling.
*/
fnd_slctrs = 1;
if (typcd == int_typ) {
ForceNl();
prt_str("case T_Lrgint: ", indent + IndentInc);
ForceNl();
}
prt_str("case T_", indent + IndentInc);
prt_str(s, indent + IndentInc);
prt_str(": ", indent + IndentInc);
}
}
if (fnd_slctrs) {
/*
* We have found and output type selections for this clause;
* output the body of the clause. Remember any changes to
* paramter locations caused by type conversions within the
* clause.
*/
ForceNl();
if ((*walk)(select->u[1].child, indent + 2 * IndentInc, 0)) {
fall_thru |= 1;
ForceNl();
prt_str("break;", indent + 2 * IndentInc);
mrg_prmloc(end_prms);
}
ForceNl();
ld_prmloc(strt_prms);
}
}
if (dflt != NULL) {
/*
* This type_case statement has a default clause. If there is
* a branch into this clause, output the label. Remember any
* changes to paramter locations caused by type conversions
* within the clause.
*/
ForceNl();
prt_str("default:", indent + 1 * IndentInc);
ForceNl();
if (maybe_str || maybe_var) {
prt_str("L", 0);
fprintf(out_file, "%d: ; /* default */", dflt_lbl);
ForceNl();
}
if ((*walk)(dflt, indent + 2 * IndentInc, 0)) {
fall_thru |= 1;
mrg_prmloc(end_prms);
}
ForceNl();
ld_prmloc(strt_prms);
}
prt_str("}", indent + IndentInc);
if (maybe_str || maybe_var) {
if (dflt == NULL) {
/*
* There is a branch around the switch statement. Output
* the label.
*/
ForceNl();
prt_str("L", 0);
fprintf(out_file, "%d: ; /* default */", dflt_lbl);
}
ForceNl();
prt_str("}", indent + IndentInc);
}
ForceNl();
}
/*
* Put ending parameter locations into effect.
*/
mrg_prmloc(end_prms);
ld_prmloc(end_prms);
if (strt_prms != NULL)
free(strt_prms);
if (end_prms != NULL)
free(end_prms);
return fall_thru;
}
/*
* chk_conj - see if the left argument of a conjunction is an in-place
* conversion of a parameter other than a conversion to C_integer or
* C_double. If so issue a warning.
*/
static void chk_conj(n)
struct node *n;
{
struct node *cnv_type;
struct node *src;
struct node *dest;
int typcd;
if (n->nd_id == BinryNd && n->tok->tok_id == And)
n = n->u[1].child;
switch (n->nd_id) {
case TrnryNd:
/*
* Must be Cnv.
*/
cnv_type = n->u[0].child;
src = n->u[1].child;
dest = n->u[2].child;
break;
case QuadNd:
/*
* Must be Def.
*/
cnv_type = n->u[0].child;
src = n->u[1].child;
dest = n->u[3].child;
break;
default:
return; /* not a conversion */
}
/*
* A conversion has been found. See if it meets the criteria for
* issuing a warning.
*/
if (src->nd_id != SymNd || !(src->u[0].sym->id_type & DrfPrm))
return; /* not a dereferenced parameter */
typcd = icn_typ(cnv_type);
switch (typcd) {
case TypCInt:
case TypCDbl:
case TypECInt:
return;
}
if (dest != NULL)
return; /* not an in-place convertion */
fprintf(stderr,
"%s: file %s, line %d, warning: in-place conversion may or may not be\n",
progname, cnv_type->tok->fname, cnv_type->tok->line);
fprintf(stderr, "\tundone on subsequent failure.\n");
}
/*
* len_sel - translate a clause form a len_case statement into a C case
* clause. Return an indication of whether execution falls through the
* clause.
*/
static int len_sel(sel, strt_prms, end_prms, indent)
struct node *sel;
struct parminfo *strt_prms;
struct parminfo *end_prms;
int indent;
{
int fall_thru;
prt_str("case ", indent);
prt_tok(sel->tok, indent + IndentInc); /* integer selection */
prt_str(":", indent + IndentInc);
fall_thru = rt_walk(sel->u[0].child, indent + IndentInc, 0);/* clause body */
ForceNl();
if (fall_thru) {
prt_str("break;", indent + IndentInc);
ForceNl();
/*
* Remember any changes to paramter locations caused by type conversions
* within the clause.
*/
mrg_prmloc(end_prms);
}
ld_prmloc(strt_prms);
return fall_thru;
}
/*
* rt_walk - walk the part of the syntax tree containing rtt code, producing
* code for the most-general version of the routine.
*/
static int rt_walk(n, indent, brace)
struct node *n;
int indent;
int brace;
{
struct token *t, *t1;
struct node *n1, *errnum;
int fall_thru;
if (n == NULL)
return 1;
t = n->tok;
switch (n->nd_id) {
case PrefxNd:
switch (t->tok_id) {
case '{':
/*
* RTL code: { <actions> }
*/
if (brace)
tok_line(t, indent); /* just synch file name and line num */
else
prt_tok(t, indent); /* { */
fall_thru = rt_walk(n->u[0].child, indent, 1);
if (!brace)
prt_str("}", indent);
return fall_thru;
case '!':
/*
* RTL type-checking and conversions: ! <simple-type-check>
*/
prt_tok(t, indent);
rt_walk(n->u[0].child, indent, 0);
return 1;
case Body:
case Inline:
/*
* RTL code: body { <c-code> }
* inline { <c-code> }
*/
fall_thru = c_walk(n->u[0].child, indent, brace);
if (!fall_thru)
clr_prmloc();
return fall_thru;
}
break;
case BinryNd:
switch (t->tok_id) {
case Runerr:
/*
* RTL code: runerr( <message-number> )
* runerr( <message-number>, <descriptor> )
*/
prt_runerr(t, n->u[0].child, n->u[1].child, indent);
/*
* Execution cannot continue on this execution path.
*/
clr_prmloc();
return 0;
case And:
/*
* RTL type-checking and conversions:
* <type-check> && <type_check>
*/
chk_conj(n->u[0].child); /* is a warning needed? */
rt_walk(n->u[0].child, indent, 0);
prt_str(" ", indent);
prt_tok(t, indent); /* && */
prt_str(" ", indent);
rt_walk(n->u[1].child, indent, 0);
return 1;
case Is:
/*
* RTL type-checking and conversions:
* is: <icon-type> ( <variable> )
*/
typ_asrt(icn_typ(n->u[0].child), n->u[1].child,
n->u[0].child->tok, indent);
return 1;
}
break;
case ConCatNd:
/*
* "Glue" for two constructs.
*/
fall_thru = rt_walk(n->u[0].child, indent, 0);
return fall_thru & rt_walk(n->u[1].child, indent, 0);
case AbstrNd:
/*
* Ignore abstract type computations while producing C code
* for library routines.
*/
return 1;
case TrnryNd:
switch (t->tok_id) {
case If: {
/*
* RTL code for "if" statements:
* if <type-check> then <action>
* if <type-check> then <action> else <action>
*
* <type-check> may include parameter conversions that create
* new scoping. It is necessary to keep track of paramter
* types and locations along success and failure paths of
* these conversions. The "then" and "else" actions may
* also establish new scopes.
*/
struct parminfo *then_prms = NULL;
struct parminfo *else_prms;
/*
* Save the current parameter locations. These are in
* effect on the failure path of any type conversions
* in the condition of the "if".
*/
else_prms = new_prmloc();
sv_prmloc(else_prms);
prt_tok(t, indent); /* if */
prt_str(" (", indent);
n1 = n->u[0].child;
rt_walk(n1, indent + IndentInc, 0); /* type check */
prt_str(") {", indent);
/*
* If the condition is negated, the failure path is to the "then"
* and the success path is to the "else".
*/
if (n1->nd_id == PrefxNd && n1->tok->tok_id == '!') {
then_prms = else_prms;
else_prms = new_prmloc();
sv_prmloc(else_prms);
ld_prmloc(then_prms);
}
/*
* Then Clause.
*/
fall_thru = rt_walk(n->u[1].child, indent + IndentInc, 1);
ForceNl();
prt_str("}", indent + IndentInc);
/*
* Determine if there is an else clause and merge parameter
* location information from the alternate paths through
* the statement.
*/
n1 = n->u[2].child;
if (n1 == NULL) {
if (fall_thru)
mrg_prmloc(else_prms);
ld_prmloc(else_prms);
fall_thru = 1;
}
else {
if (then_prms == NULL)
then_prms = new_prmloc();
if (fall_thru)
sv_prmloc(then_prms);
ld_prmloc(else_prms);
ForceNl();
prt_str("else {", indent);
if (rt_walk(n1, indent + IndentInc, 1)) { /* else clause */
fall_thru = 1;
mrg_prmloc(then_prms);
}
ForceNl();
prt_str("}", indent + IndentInc);
ld_prmloc(then_prms);
}
ForceNl();
if (then_prms != NULL)
free(then_prms);
if (else_prms != NULL)
free(else_prms);
}
return fall_thru;
case Len_case: {
/*
* RTL code:
* len_case <variable> of {
* <integer>: <action>
* ...
* default: <action>
* }
*/
struct parminfo *strt_prms;
struct parminfo *end_prms;
/*
* A case may contain parameter conversions that create new
* scopes. Remember the parameter locations at the start
* of the len_case statement.
*/
strt_prms = new_prmloc();
sv_prmloc(strt_prms);
end_prms = new_prmloc();
n1 = n->u[0].child;
if (!(n1->u[0].sym->id_type & VArgLen))
errt1(t, "len_case must select on length of vararg");
/*
* The len_case statement is implemented as a C switch
* statement.
*/
prt_str("switch (", indent);
prt_var(n1, indent);
prt_str(") {", indent);
ForceNl();
fall_thru = 0;
for (n1 = n->u[1].child; n1->nd_id == ConCatNd;
n1 = n1->u[0].child)
fall_thru |= len_sel(n1->u[1].child, strt_prms, end_prms,
indent + IndentInc);
fall_thru |= len_sel(n1, strt_prms, end_prms,
indent + IndentInc);
/*
* Handle default clause.
*/
prt_str("default:", indent + IndentInc);
ForceNl();
fall_thru |= rt_walk(n->u[2].child, indent + 2 * IndentInc, 0);
ForceNl();
prt_str("}", indent + IndentInc);
ForceNl();
/*
* Put into effect the location of parameters at the end
* of the len_case statement.
*/
mrg_prmloc(end_prms);
ld_prmloc(end_prms);
if (strt_prms != NULL)
free(strt_prms);
if (end_prms != NULL)
free(end_prms);
}
return fall_thru;
case Type_case: {
/*
* RTL code:
* type_case <variable> of {
* <icon_type> : ... <icon_type> : <action>
* ...
* }
*
* last clause may be: default: <action>
*/
int maybe_var;
struct node *var;
struct sym_entry *sym;
/*
* If we can determine that the value being checked is
* not a variable reference, we don't have to produce code
* to check for that possibility.
*/
maybe_var = 1;
var = n->u[0].child;
if (var->nd_id == SymNd) {
sym = var->u[0].sym;
switch(sym->id_type) {
case DrfPrm:
case OtherDcl:
case TndDesc:
case TndStr:
case RsltLoc:
if (sym->nest_lvl > 1) {
/*
* The thing being tested is either a
* dereferenced parameter or a local
* descriptor which could only have been
* set by a conversion which does not
* produce a variable reference.
*/
maybe_var = 0;
}
}
}
return typ_case(var, n->u[1].child, n->u[2].child, rt_walk,
maybe_var, indent);
}
case Cnv:
/*
* RTL code: cnv: <type> ( <source> )
* cnv: <type> ( <source> , <destination> )
*/
cnv_fnc(t, icn_typ(n->u[0].child), n->u[1].child, NULL,
n->u[2].child, indent);
return 1;
case Arith_case: {
/*
* arith_case (<variable>, <variable>) of {
* C_integer: <statement>
* integer: <statement>
* C_double: <statement>
* }
*
* This construct does type conversions and provides
* alternate execution paths. It is necessary to keep
* track of parameter locations.
*/
struct parminfo *strt_prms;
struct parminfo *end_prms;
struct parminfo *tmp_prms;
strt_prms = new_prmloc();
sv_prmloc(strt_prms);
end_prms = new_prmloc();
tmp_prms = new_prmloc();
fall_thru = 0;
n1 = n->u[2].child; /* contains actions for the 3 cases */
/*
* Set up an error number node for use in runerr().
*/
t1 = copy_t(t);
t1->tok_id = IntConst;
t1->image = "102";
errnum = node0(PrimryNd, t1);
/*
* Try converting both arguments to a C_integer.
*/
tok_line(t, indent);
prt_str("if (", indent);
cnv_fnc(t, TypECInt, n->u[0].child, NULL, NULL, indent);
prt_str(" && ", indent);
cnv_fnc(t, TypECInt, n->u[1].child, NULL, NULL, indent);
prt_str(") ", indent);
ForceNl();
if (rt_walk(n1->u[0].child, indent + IndentInc, 0)) {
fall_thru |= 1;
mrg_prmloc(end_prms);
}
ForceNl();
/*
* Try converting both arguments to an integer.
*/
ld_prmloc(strt_prms);
tok_line(t, indent);
prt_str("else if (", indent);
cnv_fnc(t, TypEInt, n->u[0].child, NULL, NULL, indent);
prt_str(" && ", indent);
cnv_fnc(t, TypEInt, n->u[1].child, NULL, NULL, indent);
prt_str(") ", indent);
ForceNl();
if (rt_walk(n1->u[1].child, indent + IndentInc, 0)) {
fall_thru |= 1;
mrg_prmloc(end_prms);
}
ForceNl();
/*
* Try converting both arguments to a C_double
*/
ld_prmloc(strt_prms);
prt_str("else {", indent);
ForceNl();
tok_line(t, indent + IndentInc);
prt_str("if (!", indent + IndentInc);
cnv_fnc(t, TypCDbl, n->u[0].child, NULL, NULL,
indent + IndentInc);
prt_str(")", indent + IndentInc);
ForceNl();
sv_prmloc(tmp_prms); /* use original parm locs for error */
ld_prmloc(strt_prms);
prt_runerr(t, errnum, n->u[0].child, indent + 2 * IndentInc);
ld_prmloc(tmp_prms);
tok_line(t, indent + IndentInc);
prt_str("if (!", indent + IndentInc);
cnv_fnc(t, TypCDbl, n->u[1].child, NULL, NULL,
indent + IndentInc);
prt_str(") ", indent + IndentInc);
ForceNl();
sv_prmloc(tmp_prms); /* use original parm locs for error */
ld_prmloc(strt_prms);
prt_runerr(t, errnum, n->u[1].child, indent + 2 * IndentInc);
ld_prmloc(tmp_prms);
if (rt_walk(n1->u[2].child, indent + IndentInc, 0)) {
fall_thru |= 1;
mrg_prmloc(end_prms);
}
ForceNl();
prt_str("}", indent + IndentInc);
ForceNl();
ld_prmloc(end_prms);
free(strt_prms);
free(end_prms);
free(tmp_prms);
free_tree(errnum);
return fall_thru;
}
}
case QuadNd:
/*
* RTL code: def: <type> ( <source> , <default>)
* def: <type> ( <source> , <default> , <destination> )
*/
cnv_fnc(t, icn_typ(n->u[0].child), n->u[1].child, n->u[2].child,
n->u[3].child, indent);
return 1;
}
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* spcl_dcls - print special declarations for tended variables, parameter
* conversions, and buffers.
*/
void spcl_dcls(op_params)
struct sym_entry *op_params; /* operation parameters or NULL */
{
register struct sym_entry *sym;
struct sym_entry *sym1;
/*
* Output declarations for buffers and locations to hold conversions
* to C values.
*/
spcl_start(op_params);
/*
* Determine if this operation takes a variable number of arguments.
* Use that information in deciding how large a tended array to
* declare.
*/
varargs = (op_params != NULL && op_params->id_type & VarPrm);
if (varargs)
tend_ary(ntend + VArgAlwnc - 1);
else
tend_ary(ntend);
if (varargs) {
/*
* This operation takes a variable number of arguments. A declaration
* for a tended array has been made that will usually hold them, but
* sometimes it is necessary to malloc() a tended array at run
* time. Produce code to check for this.
*/
cur_impl->ret_flag |= DoesEFail; /* error conversion from allocation */
prt_str("struct tend_desc *r_tendp;", IndentInc);
ForceNl();
prt_str("int r_n;\n", IndentInc);
++line;
ForceNl();
prt_str("if (r_nargs <= ", IndentInc);
fprintf(out_file, "%d)", op_params->u.param_info.param_num + VArgAlwnc);
ForceNl();
prt_str("r_tendp = (struct tend_desc *)&r_tend;", 2 * IndentInc);
ForceNl();
prt_str("else {", IndentInc);
ForceNl();
prt_str(
"r_tendp = (struct tend_desc *)malloc((sizeof(struct tend_desc)",
2 * IndentInc);
ForceNl();
prt_str("", 3 * IndentInc);
fprintf(out_file, "+ (r_nargs + %d) * sizeof(struct descrip)));",
ntend - 2 - op_params->u.param_info.param_num);
ForceNl();
prt_str("if (r_tendp == NULL) {", 2 * IndentInc);
ForceNl();
prt_str("err_msg(305, NULL);", 3 * IndentInc);
ForceNl();
prt_str("return A_Resume;", 3 * IndentInc);
ForceNl();
prt_str("}", 3 * IndentInc);
ForceNl();
prt_str("}", 2 * IndentInc);
ForceNl();
tendstrct = "(*r_tendp)";
}
else
tendstrct = "r_tend";
/*
* Produce code to initialize the tended array. These are for tended
* declarations and parameters.
*/
tend_init(); /* initializations for tended declarations. */
if (varargs) {
/*
* This operation takes a variable number of arguments. Produce code
* to dereference or copy this into its portion of the tended
* array.
*/
prt_str("for (r_n = ", IndentInc);
fprintf(out_file, "%d; r_n < r_nargs; ++r_n)",
op_params->u.param_info.param_num);
ForceNl();
if (op_params->id_type & DrfPrm) {
prt_str("deref(&r_args[r_n], &", IndentInc * 2);
fprintf(out_file, "%s.d[r_n + %d]);", tendstrct, ntend - 1 -
op_params->u.param_info.param_num);
}
else {
prt_str(tendstrct, IndentInc * 2);
fprintf(out_file, ".d[r_n + %d] = r_args[r_n];", ntend - 1 -
op_params->u.param_info.param_num);
}
ForceNl();
sym = op_params->u.param_info.next;
}
else
sym = op_params; /* no variable part of arg list */
/*
* Go through the fixed part of the parameter list, producing code
* to copy/dereference parameters into the tended array.
*/
while (sym != NULL) {
/*
* A there may be identifiers for dereferenced and/or undereferenced
* versions of a paramater. If there are both, sym1 references the
* second identifier.
*/
sym1 = sym->u.param_info.next;
if (sym1 != NULL && sym->u.param_info.param_num !=
sym1->u.param_info.param_num)
sym1 = NULL; /* the next entry is not for the same parameter */
/*
* If there are not enough arguments to supply a value for this
* parameter, set it to the null value.
*/
prt_str("if (", IndentInc);
fprintf(out_file, "r_nargs > %d) {", sym->u.param_info.param_num);
ForceNl();
parm_tnd(sym);
if (sym1 != NULL) {
ForceNl();
parm_tnd(sym1);
}
ForceNl();
prt_str("} else {", IndentInc);
ForceNl();
prt_str(tendstrct, IndentInc * 2);
fprintf(out_file, ".d[%d].dword = D_Null;", sym->t_indx);
if (sym1 != NULL) {
ForceNl();
prt_str(tendstrct, IndentInc * 2);
fprintf(out_file, ".d[%d].dword = D_Null;", sym1->t_indx);
}
ForceNl();
prt_str("}", 2 * IndentInc);
ForceNl();
if (sym1 == NULL)
sym = sym->u.param_info.next;
else
sym = sym1->u.param_info.next;
}
/*
* Finish setting up the tended array structure and link it into the tended
* list.
*/
if (ntend != 0) {
prt_str(tendstrct, IndentInc);
if (varargs)
fprintf(out_file, ".num = %d + Max(r_nargs - %d, 0);", ntend - 1,
op_params->u.param_info.param_num);
else
fprintf(out_file, ".num = %d;", ntend);
ForceNl();
prt_str(tendstrct, IndentInc);
prt_str(".previous = tend;", IndentInc);
ForceNl();
prt_str("tend = (struct tend_desc *)&", IndentInc);
fprintf(out_file, "%s;", tendstrct);
ForceNl();
}
}
/*
* spcl_start - do initial work for outputing special declarations. Output
* declarations for buffers and locations to hold conversions to C values.
* Determine what tended locations are needed for parameters.
*/
static void spcl_start(op_params)
struct sym_entry *op_params;
{
ForceNl();
if (n_tmp_str > 0) {
prt_str("char r_sbuf[", IndentInc);
fprintf(out_file, "%d][MaxCvtLen];", n_tmp_str);
ForceNl();
}
if (n_tmp_cset > 0) {
prt_str("struct b_cset r_cbuf[", IndentInc);
fprintf(out_file, "%d];", n_tmp_cset);
ForceNl();
}
if (tend_lst == NULL)
ntend = 0;
else
ntend = tend_lst->t_indx + 1;
parm_locs(op_params); /* see what parameter conversion there are */
}
/*
* tend_ary - write struct containing array of tended descriptors.
*/
static void tend_ary(n)
int n;
{
if (n == 0)
return;
prt_str("struct {", IndentInc);
ForceNl();
prt_str("struct tend_desc *previous;", 2 * IndentInc);
ForceNl();
prt_str("int num;", 2 * IndentInc);
ForceNl();
prt_str("struct descrip d[", 2 * IndentInc);
fprintf(out_file, "%d];", n);
ForceNl();
prt_str("} r_tend;\n", 2 * IndentInc);
++line;
ForceNl();
}
/*
* tend_init - produce code to initialize entries in the tended array
* corresponding to tended declarations. Default initializations are
* supplied when there is none in the declaration.
*/
static void tend_init()
{
register struct init_tend *tnd;
for (tnd = tend_lst; tnd != NULL; tnd = tnd->next) {
switch (tnd->init_typ) {
case TndDesc:
/*
* Simple tended declaration.
*/
prt_str(tendstrct, IndentInc);
if (tnd->init == NULL)
fprintf(out_file, ".d[%d].dword = D_Null;", tnd->t_indx);
else {
fprintf(out_file, ".d[%d] = ", tnd->t_indx);
c_walk(tnd->init, 2 * IndentInc, 0);
prt_str(";", 2 * IndentInc);
}
break;
case TndStr:
/*
* Tended character pointer.
*/
prt_str(tendstrct, IndentInc);
if (tnd->init == NULL)
fprintf(out_file, ".d[%d] = emptystr;", tnd->t_indx);
else {
fprintf(out_file, ".d[%d].dword = 0;", tnd->t_indx);
ForceNl();
prt_str(tendstrct, IndentInc);
fprintf(out_file, ".d[%d].vword.sptr = ", tnd->t_indx);
c_walk(tnd->init, 2 * IndentInc, 0);
prt_str(";", 2 * IndentInc);
}
break;
case TndBlk:
/*
* A tended block pointer of some kind.
*/
prt_str(tendstrct, IndentInc);
if (tnd->init == NULL)
fprintf(out_file, ".d[%d] = nullptr;", tnd->t_indx);
else {
fprintf(out_file, ".d[%d].dword = F_Ptr | F_Nqual;",tnd->t_indx);
ForceNl();
prt_str(tendstrct, IndentInc);
fprintf(out_file, ".d[%d].vword.bptr = (union block *)",
tnd->t_indx);
c_walk(tnd->init, 2 * IndentInc, 0);
prt_str(";", 2 * IndentInc);
}
break;
}
ForceNl();
}
}
/*
* parm_tnd - produce code to put a parameter in its tended location.
*/
static void parm_tnd(sym)
struct sym_entry *sym;
{
/*
* A parameter may either be dereferenced into its tended location
* or copied.
*/
if (sym->id_type & DrfPrm) {
prt_str("deref(&r_args[", IndentInc * 2);
fprintf(out_file, "%d], &%s.d[%d]);", sym->u.param_info.param_num,
tendstrct, sym->t_indx);
}
else {
prt_str(tendstrct, IndentInc * 2);
fprintf(out_file, ".d[%d] = r_args[%d];", sym->t_indx,
sym->u.param_info.param_num);
}
}
/*
* parm_locs - determine what locations are needed to hold parameters and
* their conversions. Produce declarations for the C_integer and C_double
* locations.
*/
static void parm_locs(op_params)
struct sym_entry *op_params;
{
struct sym_entry *next_parm;
/*
* Parameters are stored in reverse order: Recurse down the list
* and perform processing on the way back.
*/
if (op_params == NULL)
return;
next_parm = op_params->u.param_info.next;
parm_locs(next_parm);
/*
* For interpreter routines, extra tended descriptors are only needed
* when both dereferenced and undereferenced values are requested.
*/
if (iconx_flg && (next_parm == NULL ||
op_params->u.param_info.param_num != next_parm->u.param_info.param_num))
op_params->t_indx = -1;
else
op_params->t_indx = ntend++;
if (op_params->u.param_info.non_tend & PrmInt) {
prt_str("C_integer r_i", IndentInc);
fprintf(out_file, "%d;", op_params->u.param_info.param_num);
ForceNl();
}
if (op_params->u.param_info.non_tend & PrmDbl) {
prt_str("double r_d", IndentInc);
fprintf(out_file, "%d;", op_params->u.param_info.param_num);
ForceNl();
}
}
/*
* real_def - see if a declaration really defines storage.
*/
static int real_def(n)
struct node *n;
{
struct node *dcl_lst;
dcl_lst = n->u[1].child;
/*
* If no variables are being defined this must be a tag declaration.
*/
if (dcl_lst == NULL)
return 0;
if (only_proto(dcl_lst))
return 0;
if (tdef_or_extr(n->u[0].child))
return 0;
return 1;
}
/*
* only_proto - see if this declarator list contains only function prototypes.
*/
static int only_proto(n)
struct node *n;
{
switch (n->nd_id) {
case CommaNd:
return only_proto(n->u[0].child) & only_proto(n->u[1].child);
case ConCatNd:
/*
* Optional pointer.
*/
return only_proto(n->u[1].child);
case BinryNd:
switch (n->tok->tok_id) {
case '=':
return only_proto(n->u[0].child);
case '[':
/*
* At this point, assume array declarator is not part of
* prototype.
*/
return 0;
case ')':
/*
* Prototype (or forward declaration).
*/
return 1;
}
case PrefxNd:
/*
* Parenthesized.
*/
return only_proto(n->u[0].child);
case PrimryNd:
/*
* At this point, assume it is not a prototype.
*/
return 0;
}
err1("rtt internal error detected in function only_proto()");
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* tdef_or_extr - see if this is a typedef or extern.
*/
static int tdef_or_extr(n)
struct node *n;
{
switch (n->nd_id) {
case LstNd:
return tdef_or_extr(n->u[0].child) | tdef_or_extr(n->u[1].child);
case BinryNd:
/*
* struct, union, or enum.
*/
return 0;
case PrimryNd:
if (n->tok->tok_id == Extern || n->tok->tok_id == Typedef)
return 1;
else
return 0;
}
err1("rtt internal error detected in function tdef_or_extr()");
/*NOTREACHED*/
return 0; /* avoid gcc warning */
}
/*
* dclout - output an ordinary global C declaration.
*/
void dclout(n)
struct node *n;
{
if (!enable_out)
return; /* output disabled */
if (real_def(n))
def_fnd = 1; /* this declaration defines a run-time object */
c_walk(n, 0, 0);
free_tree(n);
}
/*
* fncout - output code for a C function.
*/
void fncout(head, prm_dcl, block)
struct node *head;
struct node *prm_dcl;
struct node *block;
{
if (!enable_out)
return; /* output disabled */
def_fnd = 1; /* this declaration defines a run-time object */
nxt_sbuf = 0; /* clear number of string buffers */
nxt_cbuf = 0; /* clear number of cset buffers */
/*
* Output the function header and the parameter declarations.
*/
fnc_head = head;
c_walk(head, 0, 0);
prt_str(" ", 0);
c_walk(prm_dcl, 0, 0);
prt_str(" ", 0);
/*
* Handle outer block.
*/
prt_tok(block->tok, IndentInc); /* { */
c_walk(block->u[0].child, IndentInc, 0); /* non-tended declarations */
spcl_dcls(NULL); /* tended declarations */
no_ret_val = 1;
c_walk(block->u[2].child, IndentInc, 0); /* statement list */
if (ntend != 0 && no_ret_val) {
/*
* This function contains no return statements with values, assume
* that the programmer is using the implicit return at the end
* of the function and update the tending of descriptors.
*/
untend(IndentInc);
}
ForceNl();
prt_str("}", IndentInc);
ForceNl();
/*
* free storage.
*/
free_tree(head);
free_tree(prm_dcl);
free_tree(block);
pop_cntxt();
clr_def();
}
/*
* defout - output operation definitions (except for constant keywords)
*/
void defout(n)
struct node *n;
{
struct sym_entry *sym, *sym1;
if (!enable_out)
return; /* output disabled */
nxt_sbuf = 0;
nxt_cbuf = 0;
/*
* Somewhat different code is produced for the interpreter and compiler.
*/
if (iconx_flg)
interp_def(n);
else
comp_def(n);
free_tree(n);
/*
* The declarations for the declare statement are not associated with
* any compound statement and must be freed here.
*/
sym = dcl_stk->tended;
while (sym != NULL) {
sym1 = sym;
sym = sym->u.tnd_var.next;
free_sym(sym1);
}
while (decl_lst != NULL) {
sym1 = decl_lst;
decl_lst = decl_lst->u.declare_var.next;
free_sym(sym1);
}
op_type = OrdFunc;
pop_cntxt();
clr_def();
}
/*
* comp_def - output code for the compiler for operation definitions.
*/
static void comp_def(n)
struct node *n;
{
#ifdef Rttx
fprintf(stdout,
"rtt was compiled to only support the interpreter, use -x\n");
exit(EXIT_FAILURE);
#else /* Rttx */
struct sym_entry *sym;
struct node *n1;
FILE *f_save;
char buf1[5];
char buf[MaxPath];
char *cname;
long min_result;
long max_result;
int ret_flag;
int resume;
char *name;
char *s;
f_save = out_file;
/*
* Note if the result location is explicitly referenced and note
* how it is accessed in the generated code.
*/
cur_impl->use_rslt = sym_lkup(str_rslt)->u.referenced;
rslt_loc = "(*r_rslt)";
/*
* In several contexts, letters are used to distinguish kinds of operations.
*/
switch (op_type) {
case TokFunction:
lc_letter = 'f';
uc_letter = 'F';
break;
case Keyword:
lc_letter = 'k';
uc_letter = 'K';
break;
case Operator:
lc_letter = 'o';
uc_letter = 'O';
}
prfx1 = cur_impl->prefix[0];
prfx2 = cur_impl->prefix[1];
if (op_type != Keyword) {
/*
* First pass through the operation: produce most general routine.
*/
fnc_ret = RetSig; /* most general routine always returns a signal */
/*
* Compute the file name in which to output the function.
*/
sprintf(buf1, "%c_%c%c", lc_letter, prfx1, prfx2);
cname = salloc(makename(buf, SourceDir, buf1, CSuffix));
if ((out_file = fopen(cname, "w")) == NULL)
err2("cannot open output file", cname);
else
addrmlst(cname, out_file);
prologue(); /* output standard comments and preprocessor directives */
/*
* Output function header that corresponds to standard calling
* convensions. The function name is constructed from the letter
* for the operation type, the prefix that makes the function
* name unique, and the name of the operation.
*/
fprintf(out_file, "int %c%c%c_%s(r_nargs, r_args, r_rslt, r_s_cont)\n",
uc_letter, prfx1, prfx2, cur_impl->name);
fprintf(out_file, "int r_nargs;\n");
fprintf(out_file, "dptr r_args;\n");
fprintf(out_file, "dptr r_rslt;\n");
fprintf(out_file, "continuation r_s_cont;");
fname = cname;
line = 12;
ForceNl();
prt_str("{", IndentInc);
ForceNl();
/*
* Output ordinary declarations from declare clause.
*/
for (sym = decl_lst; sym != NULL; sym = sym->u.declare_var.next) {
c_walk(sym->u.declare_var.tqual, IndentInc, 0);
prt_str(" ", IndentInc);
c_walk(sym->u.declare_var.dcltor, IndentInc, 0);
if ((n1 = sym->u.declare_var.init) != NULL) {
prt_str(" = ", IndentInc);
c_walk(n1, IndentInc, 0);
}
prt_str(";", IndentInc);
}
/*
* Output code for special declarations along with code to initial
* them. This includes buffers and tended locations for parameters
* and tended variables.
*/
spcl_dcls(params);
if (rt_walk(n, IndentInc, 0)) { /* body of operation */
if (n->nd_id == ConCatNd)
s = n->u[1].child->tok->fname;
else
s = n->tok->fname;
fprintf(stderr, "%s: file %s, warning: ", progname, s);
fprintf(stderr, "execution may fall off end of operation \"%s\"\n",
cur_impl->name);
}
ForceNl();
prt_str("}\n", IndentInc);
if (fclose(out_file) != 0)
err2("cannot close ", cname);
put_c_fl(cname, 1); /* note name of output file for operation */
}
/*
* Second pass through operation: produce in-line code and special purpose
* routines.
*/
for (sym = params; sym != NULL; sym = sym->u.param_info.next)
if (sym->id_type & DrfPrm)
sym->u.param_info.cur_loc = PrmTend; /* reset location of parameter */
in_line(n);
/*
* Insure that the fail/return/suspend statements are consistent
* with the result sequence indicated.
*/
min_result = cur_impl->min_result;
max_result = cur_impl->max_result;
ret_flag = cur_impl->ret_flag;
resume = cur_impl->resume;
name = cur_impl->name;
if (min_result == NoRsltSeq && ret_flag & (DoesFail|DoesRet|DoesSusp))
err2(name,
": result sequence of {}, but fail, return, or suspend present");
if (min_result != NoRsltSeq && ret_flag == 0)
err2(name,
": result sequence indicated, no fail, return, or suspend present");
if (max_result != NoRsltSeq) {
if (max_result == 0 && ret_flag & (DoesRet|DoesSusp))
err2(name,
": result sequence of 0 length, but return or suspend present");
if (max_result != 0 && !(ret_flag & (DoesRet | DoesSusp)))
err2(name,
": result sequence length > 0, but no return or suspend present");
if ((max_result == UnbndSeq || max_result > 1 || resume) &&
!(ret_flag & DoesSusp))
err2(name,
": result sequence indicates suspension, but no suspend present");
if ((max_result != UnbndSeq && max_result <= 1 && !resume) &&
ret_flag & DoesSusp)
err2(name,
": result sequence indicates no suspension, but suspend present");
}
if (min_result != NoRsltSeq && max_result != UnbndSeq &&
min_result > max_result)
err2(name, ": minimum result sequence length greater than maximum");
out_file = f_save;
#endif /* Rttx */
}
/*
* interp_def - output code for the interpreter for operation definitions.
*/
static void interp_def(n)
struct node *n;
{
struct sym_entry *sym;
struct node *n1;
int nparms;
int has_underef;
char letter;
char *name;
char *s;
/*
* Note how result location is accessed in generated code.
*/
rslt_loc = "r_args[0]";
/*
* Determine if the operation has any undereferenced parameters.
*/
has_underef = 0;
for (sym = params; sym != NULL; sym = sym->u.param_info.next)
if (sym->id_type & RtParm) {
has_underef = 1;
break;
}
/*
* Determine the nuber of parameters. A negative value is used
* to indicate an operation that takes a variable number of
* arguments.
*/
if (params == NULL)
nparms = 0;
else {
nparms = params->u.param_info.param_num + 1;
if (params->id_type & VarPrm)
nparms = -nparms;
}
fnc_ret = RetSig; /* interpreter routine always returns a signal */
name = cur_impl->name;
/*
* Determine what letter is used to prefix the operation name.
*/
switch (op_type) {
case TokFunction:
letter = 'Z';
break;
case Keyword:
letter = 'K';
break;
case Operator:
letter = 'O';
}
fprintf(out_file, "\n");
if (op_type != Keyword) {
/*
* Output prototype. Operations taking a variable number of arguments
* have an extra parameter: the number of arguments.
*/
fprintf(out_file, "int %c%s (", letter, name);
if (params != NULL && (params->id_type & VarPrm))
fprintf(out_file, "int r_nargs, ");
fprintf(out_file, "dptr r_args);\n");
++line;
/*
* Output procedure block.
*/
switch (op_type) {
case TokFunction:
fprintf(out_file, "FncBlock(%s, %d, %d)\n\n", name, nparms,
(has_underef ? -1 : 0));
++line;
break;
case Operator:
if (strcmp(cur_impl->op,"\\") == 0)
fprintf(out_file, "OpBlock(%s, %d, \"%s\", 0)\n\n", name, nparms,
"\\\\");
else
fprintf(out_file, "OpBlock(%s, %d, \"%s\", 0)\n\n", name, nparms,
cur_impl->op);
++line;
}
}
/*
* Output function header. Operations taking a variable number of arguments
* have an extra parameter: the number of arguments.
*/
fprintf(out_file, "int %c%s(", letter, name);
if (params != NULL && (params->id_type & VarPrm))
fprintf(out_file, "r_nargs, ");
fprintf(out_file, "r_args)\n");
++line;
if (params != NULL && (params->id_type & VarPrm)) {
fprintf(out_file, "int r_nargs;\n");
++line;
}
fprintf(out_file, "dptr r_args;");
++line;
ForceNl();
prt_str("{", IndentInc);
/*
* Output ordinary declarations from the declare clause.
*/
ForceNl();
for (sym = decl_lst; sym != NULL; sym = sym->u.declare_var.next) {
c_walk(sym->u.declare_var.tqual, IndentInc, 0);
prt_str(" ", IndentInc);
c_walk(sym->u.declare_var.dcltor, IndentInc, 0);
if ((n1 = sym->u.declare_var.init) != NULL) {
prt_str(" = ", IndentInc);
c_walk(n1, IndentInc, 0);
}
prt_str(";", IndentInc);
}
/*
* Output special declarations and initial processing.
*/
tendstrct = "r_tend";
spcl_start(params);
tend_ary(ntend);
if (has_underef && params != NULL && params->id_type == (VarPrm | DrfPrm))
prt_str("int r_n;\n", IndentInc);
tend_init();
/*
* See which parameters need to be dereferenced. If all are dereferenced,
* it is done by before the routine is called.
*/
if (has_underef) {
sym = params;
if (sym != NULL && sym->id_type & VarPrm) {
if (sym->id_type & DrfPrm) {
/*
* There is a variable part of the parameter list and it
* must be dereferenced.
*/
prt_str("for (r_n = ", IndentInc);
fprintf(out_file, "%d; r_n <= r_nargs; ++r_n)",
sym->u.param_info.param_num + 1);
ForceNl();
prt_str("Deref(r_args[r_n]);", IndentInc * 2);
ForceNl();
}
sym = sym->u.param_info.next;
}
/*
* Produce code to dereference any fixed parameters that need to be.
*/
while (sym != NULL) {
if (sym->id_type & DrfPrm) {
/*
* Tended index of -1 indicates that the parameter can be
* dereferened in-place (this is the usual case).
*/
if (sym->t_indx == -1) {
prt_str("Deref(r_args[", IndentInc * 2);
fprintf(out_file, "%d]);", sym->u.param_info.param_num + 1);
}
else {
prt_str("deref(&r_args[", IndentInc * 2);
fprintf(out_file, "%d], &r_tend.d[%d]);",
sym->u.param_info.param_num + 1, sym->t_indx);
}
}
ForceNl();
sym = sym->u.param_info.next;
}
}
/*
* Finish setting up the tended array structure and link it into the tended
* list.
*/
if (ntend != 0) {
prt_str("r_tend.num = ", IndentInc);
fprintf(out_file, "%d;", ntend);
ForceNl();
prt_str("r_tend.previous = tend;", IndentInc);
ForceNl();
prt_str("tend = (struct tend_desc *)&r_tend;", IndentInc);
ForceNl();
}
if (rt_walk(n, IndentInc, 0)) { /* body of operation */
if (n->nd_id == ConCatNd)
s = n->u[1].child->tok->fname;
else
s = n->tok->fname;
fprintf(stderr, "%s: file %s, warning: ", progname, s);
fprintf(stderr, "execution may fall off end of operation \"%s\"\n",
cur_impl->name);
}
ForceNl();
prt_str("}\n", IndentInc);
}
/*
* keyconst - produce code for a constant keyword.
*/
void keyconst(t)
struct token *t;
{
struct il_code *il;
int n;
if (iconx_flg) {
/*
* For the interpreter, output a C function implementing the keyword.
*/
rslt_loc = "r_args[0]"; /* result location */
fprintf(out_file, "\n");
fprintf(out_file, "int K%s(r_args)\n", cur_impl->name);
fprintf(out_file, "dptr r_args;");
line += 2;
ForceNl();
prt_str("{", IndentInc);
ForceNl();
switch (t->tok_id) {
case StrLit:
prt_str(rslt_loc, IndentInc);
prt_str(".vword.sptr = \"", IndentInc);
n = prt_i_str(out_file, t->image, (int)strlen(t->image));
prt_str("\";", IndentInc);
ForceNl();
prt_str(rslt_loc, IndentInc);
fprintf(out_file, ".dword = %d;", n);
break;
case CharConst:
prt_str("static struct b_cset cset_blk = ", IndentInc);
cset_init(out_file, bitvect(t->image, (int)strlen(t->image)));
ForceNl();
prt_str(rslt_loc, IndentInc);
prt_str(".dword = D_Cset;", IndentInc);
ForceNl();
prt_str(rslt_loc, IndentInc);
prt_str(".vword.bptr = (union block *)&cset_blk;", IndentInc);
break;
case DblConst:
prt_str("static struct b_real real_blk = {T_Real, ", IndentInc);
fprintf(out_file, "%s};", t->image);
ForceNl();
prt_str(rslt_loc, IndentInc);
prt_str(".dword = D_Real;", IndentInc);
ForceNl();
prt_str(rslt_loc, IndentInc);
prt_str(".vword.bptr = (union block *)&real_blk;", IndentInc);
break;
case IntConst:
prt_str(rslt_loc, IndentInc);
prt_str(".dword = D_Integer;", IndentInc);
ForceNl();
prt_str(rslt_loc, IndentInc);
prt_str(".vword.integr = ", IndentInc);
prt_str(t->image, IndentInc);
prt_str(";", IndentInc);
break;
}
ForceNl();
prt_str("return A_Continue;", IndentInc);
ForceNl();
prt_str("}\n", IndentInc);
++line;
ForceNl();
}
else {
/*
* For the compiler, make an entry in the data base for the keyword.
*/
cur_impl->use_rslt = 0;
il = new_il(IL_Const, 2);
switch (t->tok_id) {
case StrLit:
il->u[0].n = str_typ;
il->u[1].s = alloc(strlen(t->image) + 3);
sprintf(il->u[1].s, "\"%s\"", t->image);
break;
case CharConst:
il->u[0].n = cset_typ;
il->u[1].s = alloc(strlen(t->image) + 3);
sprintf(il->u[1].s, "'%s'", t->image);
break;
case DblConst:
il->u[0].n = real_typ;
il->u[1].s = t->image;
break;
case IntConst:
il->u[0].n = int_typ;
il->u[1].s = t->image;
break;
}
cur_impl->in_line = il;
}
/*
* Reset the translator and free storage.
*/
op_type = OrdFunc;
free_t(t);
pop_cntxt();
clr_def();
}
/*
* keepdir - A preprocessor directive to be kept has been encountered.
* If it is #passthru, print just the body of the directive, otherwise
* print the whole thing.
*/
void keepdir(t)
struct token *t;
{
char *s;
tok_line(t, 0);
s = t->image;
if (strncmp(s, "#passthru", 9) == 0)
s = s + 10;
fprintf(out_file, "%s\n", s);
line += 1;
}
/*
* prologue - print standard comments and preprocessor directives at the
* start of an output file.
*/
void prologue()
{
id_comment(out_file);
fprintf(out_file, "%s", compiler_def);
fprintf(out_file, "#include \"%s\"\n\n", inclname);
}
|