Source

gdc / d / d-lang.cc

Full commit
   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
/* GDC -- D front-end for GCC
   Copyright (C) 2004 David Friedman

   Modified by
    Michael Parrott, (C) 2009, 2010
    Iain Buclaw, (C) 2010, 2011

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

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

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/*
  dc-lang.cc: implementation of back-end callbacks and data structures
*/

#include "root.h"
#include "mtype.h"
#include "id.h"
#include "module.h"
#include "cond.h"
#include "mars.h"

#include "async.h"
#include "json.h"

#include "d-gcc-includes.h"
#include "options.h"
#include "cppdefault.h"

#include "d-lang.h"
#include "d-codegen.h"
#include "d-gcc-real.h"
#include "d-confdefs.h"

static char lang_name[6] = "GNU D";

/* Lang Hooks */
#undef LANG_HOOKS_NAME
#undef LANG_HOOKS_INIT
#undef LANG_HOOKS_INIT_OPTIONS
#undef LANG_HOOKS_HANDLE_OPTION
#undef LANG_HOOKS_POST_OPTIONS
#undef LANG_HOOKS_PARSE_FILE
#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
#undef LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE
#undef LANG_HOOKS_TYPES_COMPATIBLE_P
#undef LANG_HOOKS_BUILTIN_FUNCTION
#undef LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE
#undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
#undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
#undef LANG_HOOKS_GIMPLIFY_EXPR
#undef LANG_HOOKS_EH_PERSONALITY
#undef LANG_HOOKS_EH_RUNTIME_TYPE

#define LANG_HOOKS_NAME                     lang_name
#define LANG_HOOKS_INIT                     d_init
#define LANG_HOOKS_INIT_OPTIONS             d_init_options
#define LANG_HOOKS_HANDLE_OPTION            d_handle_option
#define LANG_HOOKS_POST_OPTIONS             d_post_options
#define LANG_HOOKS_PARSE_FILE               d_parse_file
#define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE   d_common_attribute_table
#define LANG_HOOKS_FORMAT_ATTRIBUTE_TABLE   d_common_format_attribute_table
#define LANG_HOOKS_TYPES_COMPATIBLE_P       d_types_compatible_p
#define LANG_HOOKS_BUILTIN_FUNCTION         d_builtin_function
#define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE d_builtin_function
#define LANG_HOOKS_REGISTER_BUILTIN_TYPE    d_register_builtin_type
#define LANG_HOOKS_FINISH_INCOMPLETE_DECL   d_finish_incomplete_decl
#define LANG_HOOKS_GIMPLIFY_EXPR            d_gimplify_expr
#define LANG_HOOKS_EH_PERSONALITY           d_eh_personality
#define LANG_HOOKS_EH_RUNTIME_TYPE          d_build_eh_type_type

#if D_GCC_VER >= 46
#undef LANG_HOOKS_OPTION_LANG_MASK
#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
#define LANG_HOOKS_OPTION_LANG_MASK         d_option_lang_mask
#define LANG_HOOKS_INIT_OPTIONS_STRUCT      d_init_options_struct
#endif

/* Lang Hooks for decls */
#undef LANG_HOOKS_WRITE_GLOBALS
#define LANG_HOOKS_WRITE_GLOBALS            d_write_global_declarations

/* Lang Hooks for types */
#undef LANG_HOOKS_TYPE_FOR_MODE
#undef LANG_HOOKS_TYPE_FOR_SIZE
#undef LANG_HOOKS_TYPE_PROMOTES_TO

#define LANG_HOOKS_TYPE_FOR_MODE            d_type_for_mode
#define LANG_HOOKS_TYPE_FOR_SIZE            d_type_for_size
#define LANG_HOOKS_TYPE_PROMOTES_TO         d_type_promotes_to


static tree d_signed_or_unsigned_type(int, tree);

static const char * fonly_arg;
// Because of PR16888, on x86 platforms, GCC clears unused reg names.
// As this doesn't affect us, need a way to restore them.
static const char *saved_reg_names[FIRST_PSEUDO_REGISTER];

#if D_GCC_VER >= 46
/* Common initialization before calling option handlers.  */
static void
d_init_options (unsigned int, struct cl_decoded_option *decoded_options)
{
    // Set default values
    global.params.argv0 = xstrdup(decoded_options[0].arg);
    global.params.link = 1;
    global.params.useAssert = 1;
    global.params.useInvariants = 1;
    global.params.useIn = 1;
    global.params.useOut = 1;
    global.params.useArrayBounds = 2;
    global.params.useSwitchError = 1;
    global.params.useInline = 0;
    global.params.warnings = 0;
    global.params.obj = 1;
    global.params.Dversion = 2;
    global.params.quiet = 1;

    global.params.linkswitches = new Strings();
    global.params.libfiles = new Strings();
    global.params.objfiles = new Strings();
    global.params.ddocfiles = new Strings();

    global.params.imppath = new Strings();
    global.params.fileImppath = new Strings();

    // extra D-specific options
    gen.splitDynArrayVarArgs = true;
    gen.emitTemplates = TEnormal;
    gen.useInlineAsm = false;
    gen.useBuiltins = true;
    std_inc = true;
}

/* Initialize options structure OPTS.  */
static void
d_init_options_struct (struct gcc_options *opts)
{
    // GCC options
    opts->x_flag_exceptions = 1;

    // Avoid range issues for complex multiply and divide.
    opts->x_flag_complex_method = 2;

    // Unlike C, there is no global 'errno' variable.
    opts->x_flag_errno_math = 0;
    opts->frontend_set_flag_errno_math = true;

    // Keep in synch with existing -fbounds-check flag.
    opts->x_flag_bounds_check = global.params.useArrayBounds;

    // Honour left to right code evaluation.
    opts->x_flag_evaluation_order = 1;
#if V2
    // Default to using strict aliasing.
    opts->x_flag_strict_aliasing = 1;
#endif
}

/* Return language mask for option parsing.  */
static unsigned int
d_option_lang_mask (void)
{
    return CL_D;
}

#else
static unsigned int
d_init_options (unsigned int, const char ** argv)
{
    // Set default values
    global.params.argv0 = xstrdup(argv[0]);
    global.params.link = 1;
    global.params.useAssert = 1;
    global.params.useInvariants = 1;
    global.params.useIn = 1;
    global.params.useOut = 1;
    global.params.useArrayBounds = 2;
    global.params.useSwitchError = 1;
    global.params.useInline = 0;
    global.params.warnings = 0;
    global.params.obj = 1;
    global.params.Dversion = 2;
    global.params.quiet = 1;

    global.params.linkswitches = new Strings();
    global.params.libfiles = new Strings();
    global.params.objfiles = new Strings();
    global.params.ddocfiles = new Strings();

    global.params.imppath = new Strings();
    global.params.fileImppath = new Strings();

    // GCC options
    flag_exceptions = 1;

    // Avoid range issues for complex multiply and divide.
    flag_complex_method = 2;

    // Unlike C, there is no global 'errno' variable.
    flag_errno_math = 0;

    // keep in synch with existing -fbounds-check flag
    flag_bounds_check = global.params.useArrayBounds;

    // Honour left to right code evaluation.
    flag_evaluation_order = 1;
#if V2
    // Default to using strict aliasing.
    flag_strict_aliasing = 1;
#endif
    // extra D-specific options
    gen.splitDynArrayVarArgs = true;
    gen.emitTemplates = TEnormal;
    gen.useInlineAsm = false;
    gen.useBuiltins = true;
    std_inc = true;

    return CL_D;
}
#endif

#ifdef D_OS_VERSYM
const char * cygwin_d_os_versym = D_OS_VERSYM;
#undef D_OS_VERSYM
#define D_OS_VERSYM cygwin_d_os_versym
#endif

static void
maybe_fixup_os_versym()
{
#ifdef D_OS_VERSYM
    char * env = getenv("GCC_CYGWIN_MINGW");

    if (!strcmp(D_OS_VERSYM, "Cygwin") && env && *env == '1')
    {
        cygwin_d_os_versym = "Win32";
    }
#endif
}

static bool is_target_win32 = false;

bool
d_gcc_is_target_win32()
{
    return is_target_win32;
}

static bool
d_init ()
{
    const char * cpu_versym = NULL;

    /* Restore register names if any were cleared during backend init */
    if (memcmp (reg_names, saved_reg_names, sizeof reg_names))
        memcpy (reg_names, saved_reg_names, sizeof reg_names);

    /* Currently, is64bit indicates a 64-bit target in general and is not
       Intel-specific. */
#ifdef TARGET_64BIT
    global.params.is64bit = TARGET_64BIT ? 1 : 0;
#else
    /* TARGET_64BIT is only defined on biarched archs defaulted to 64-bit
     * (as amd64 or s390x) so for full 64-bit archs (as ia64 or alpha) we
     * need to test it more. */
#  ifdef D_CPU_VERSYM64
    /* We are "defaulting" to 32-bit, which mean that if both D_CPU_VERSYM
     * and D_CPU_VERSYM64 are defined, and not TARGET_64BIT, we will use
     * 32 bits. This will be overidden for full 64-bit archs */
    global.params.is64bit = 0;
#    ifndef D_CPU_VERSYM
    /* So this is typically for alpha and ia64 */
    global.params.is64bit = 1;
#    endif
#  else
#    ifdef D_CPU_VERSYM /* D_CPU_VERSYM is defined and D_CPU_VERSYM64 is not. */
    global.params.is64bit = 0;
#    else
    /* If none of D_CPU_VERSYM and D_CPU_VERSYM64 defined check size_t
     * length instead. */
    switch (sizeof(size_t))
    {
        case 4:
            global.params.is64bit = 0;
            break;
        case 8:
            global.params.is64bit = 1;
            break;
    }
#    endif
#  endif
#endif

    Type::init();
    Id::initialize();
    Module::init();
    initPrecedence();
    gcc_d_backend_init();
    real_t::init();

    maybe_fixup_os_versym();

    VersionCondition::addPredefinedGlobalIdent("GNU");
#if V2
    VersionCondition::addPredefinedGlobalIdent("D_Version2");
#endif
#ifdef D_CPU_VERSYM64
    if (global.params.is64bit == 1)
        cpu_versym = D_CPU_VERSYM64;
#  ifdef D_CPU_VERSYM
    else
        cpu_versym = D_CPU_VERSYM;
#  endif
#else
#  ifdef D_CPU_VERSYM
    cpu_versym = D_CPU_VERSYM;
#  endif
#endif
    if (cpu_versym)
        VersionCondition::addPredefinedGlobalIdent(cpu_versym);
#ifdef D_OS_VERSYM
    if (strcmp(D_OS_VERSYM, "Win64") == 0 && !TARGET_64BIT)
    {
        // -m32 should set up for Win32.
        VersionCondition::addPredefinedGlobalIdent("Win32");
        is_target_win32 = true;
    }
    else
        VersionCondition::addPredefinedGlobalIdent(D_OS_VERSYM);

    if (strcmp(D_OS_VERSYM, "darwin") == 0)
        VersionCondition::addPredefinedGlobalIdent("OSX");
    if (strcmp(D_OS_VERSYM, "Win32") == 0)
        is_target_win32 = true;
#endif
#ifdef D_OS_VERSYM2
    VersionCondition::addPredefinedGlobalIdent(D_OS_VERSYM2);
    
    if (strncmp(D_OS_VERSYM2, "MinGW", 5) == 0)
    {
        // Should MinGW exist? Rationale:  Windows, Win32 and Win64.
        VersionCondition::addPredefinedGlobalIdent("MinGW");
    }
    if (strcmp(D_OS_VERSYM2, "Win32") == 0)
        is_target_win32 = true;
#endif
#ifdef D_VENDOR_VERSYM
    VersionCondition::addPredefinedGlobalIdent(D_VENDOR_VERSYM);
#endif

#ifdef TARGET_THUMB
    if (TARGET_THUMB)
        VersionCondition::addPredefinedGlobalIdent("Thumb");
    else
        VersionCondition::addPredefinedGlobalIdent("Arm");
#endif

    if (BYTES_BIG_ENDIAN)
        VersionCondition::addPredefinedGlobalIdent("BigEndian");
    else
        VersionCondition::addPredefinedGlobalIdent("LittleEndian");

#if D_GCC_VER >= 46
    if (targetm.except_unwind_info(&global_options) == UI_SJLJ)
        VersionCondition::addPredefinedGlobalIdent("GNU_SjLj_Exceptions");
#else
    if (USING_SJLJ_EXCEPTIONS)
        VersionCondition::addPredefinedGlobalIdent("GNU_SjLj_Exceptions");
#endif

#ifdef TARGET_LONG_DOUBLE_128
    if (TARGET_LONG_DOUBLE_128)
        VersionCondition::addPredefinedGlobalIdent("GNU_LongDouble128");
#endif

#ifdef STACK_GROWS_DOWNWARD
    VersionCondition::addPredefinedGlobalIdent("GNU_StackGrowsDown");
#endif

    if (gen.useInlineAsm)
    {
        VersionCondition::addPredefinedGlobalIdent("D_InlineAsm");

        if (d_have_inline_asm() && cpu_versym)
        {
            if (strcmp(cpu_versym, "X86") == 0)
                VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86");
            else if (strcmp(cpu_versym, "X86_64") == 0)
                VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86_64");
        }
    }
    /* Should define this anyway to set us apart from the competition. */
    VersionCondition::addPredefinedGlobalIdent("GNU_InlineAsm");

    /* Logic copied from cppbuiltins for LP64 targets. */
    if (TYPE_PRECISION (long_integer_type_node) == 64
        && TYPE_PRECISION (integer_type_node) == 32 && POINTER_SIZE == 64)
    {
        VersionCondition::addPredefinedGlobalIdent("D_LP64");
    }

    /* Setting global.params.cov forces module info generation which is
       not needed for thee GCC coverage implementation.  Instead, just
       test flag_test_coverage while leaving global.params.cov unset. */
    //if (global.params.cov)
    if (flag_test_coverage)
        VersionCondition::addPredefinedGlobalIdent("D_Coverage");
    if (flag_pic)
        VersionCondition::addPredefinedGlobalIdent("D_PIC");
    if (global.params.doDocComments)
        VersionCondition::addPredefinedGlobalIdent("D_Ddoc");
    if (global.params.useUnitTests)
        VersionCondition::addPredefinedGlobalIdent("unittest");

    VersionCondition::addPredefinedGlobalIdent("all");

    register_import_chains();

    {
        char * path = FileName::searchPath(global.path, "phobos-ver-syms", 1);
        if (path)
        {
            FILE * f = fopen(path, "r");
            char buf[256];
            char *p, *q;
            if (f)
            {
                while ( ! feof(f) && fgets(buf, 256, f) )
                {
                    p = buf;
                    while (*p && ISSPACE(*p))
                        p++;
                    q = p;
                    while (*q && ! ISSPACE(*q))
                        q++;
                    *q = 0;
                    if (p != q)
                    {   /* Needs to be predefined because we define
                           Unix/Windows this way. */
                        VersionCondition::addPredefinedGlobalIdent(xstrdup(p));
                    }
                }
                fclose(f);
            }
            else
            {
                //printf("failed\n");
            }
        }
        else
        {
            //printf("no p-v-s found\n");
        }
    }

    return 1;
}

static bool
parse_int (const char * arg, int * value_ret)
{
    long v;
    char * err;
    errno = 0;
    v = strtol(arg, & err, 10);
    if (*err || errno || v > INT_MAX)
        return false;
    * value_ret = v;
    return true;
}

#if D_GCC_VER >= 46
static bool
d_handle_option (size_t scode, const char *arg, int value,
                 int kind, location_t loc,
                 const struct cl_option_handlers *handlers)
#else
static int
d_handle_option (size_t scode, const char *arg, int value)
#endif
{
    enum opt_code code = (enum opt_code) scode;
    int level;

    switch (code)
    {
        case OPT_fassert:
            global.params.useAssert = value;
            break;

#if V2
        case OPT_fbounds_check:
            global.params.noboundscheck = ! value;
            break;
#endif
        case OPT_fbuiltin:
            gen.useBuiltins = value;
            break;

        case OPT_fdebug:
            global.params.debuglevel = value ? 1 : 0;
            break;

        case OPT_fdebug_:
            if (ISDIGIT(arg[0]))
            {
                if (! parse_int(arg, & level))
                    goto Lerror_d;
                DebugCondition::setGlobalLevel(level);
            }
            else if (Lexer::isValidIdentifier(CONST_CAST(char*, arg)))
                DebugCondition::addGlobalIdent(xstrdup(arg));
            else
            {
              Lerror_d:
                error("bad argument for -fdebug");
            }
            break;

        case OPT_fdebug_c:
            strcpy(lang_name, value ? "GNU C" : "GNU D");
            break;

        case OPT_fdeprecated:
            global.params.useDeprecated = value;
            break;

        case OPT_fdeps_:
            global.params.moduleDepsFile = xstrdup(arg);
            if (!global.params.moduleDepsFile[0])
                error("bad argument for -fdeps");
            global.params.moduleDeps = new OutBuffer;
            break;

        case OPT_fdoc:
            global.params.doDocComments = value;
            break;

        case OPT_fdoc_dir_:
            global.params.doDocComments = 1;
            global.params.docdir = xstrdup(arg);
            break;

        case OPT_fdoc_file_:
            global.params.doDocComments = 1;
            global.params.docname = xstrdup(arg);
            break;

        case OPT_fdoc_inc_:
            global.params.ddocfiles->push(xstrdup(arg));
            break;

        case OPT_fdump_source:
            global.params.dump_source = value;
            break;

        case OPT_fd_inline_asm:
            gen.useInlineAsm = value;
            break;

        case OPT_fd_verbose:
            global.params.verbose = value;
            break;

        case OPT_fd_version_1:
            global.params.Dversion = 1;
            break;

        case OPT_fd_vtls:
            global.params.vtls = value;
            break;

        case OPT_femit_templates:
            gen.emitTemplates = value ? TEauto : TEnone;
            break;

        case OPT_femit_templates_:
            if (! arg || ! *arg)
                gen.emitTemplates = value ? TEauto : TEnone;
            else if (! strcmp(arg, "normal"))
                gen.emitTemplates = TEnormal;
            else if (! strcmp(arg, "all"))
                gen.emitTemplates = TEall;
            else if (! strcmp(arg, "private"))
                gen.emitTemplates = TEprivate;
            else if (! strcmp(arg, "none"))
                gen.emitTemplates = TEnone;
            else if (! strcmp(arg, "auto"))
                gen.emitTemplates = TEauto;
            else
                error("bad argument for -femit-templates");
            break;

        case OPT_fignore_unknown_pragmas:
            global.params.ignoreUnsupportedPragmas = value;
            break;

        case OPT_fin:
            global.params.useIn = value;
            break;

        case OPT_fintfc:
            global.params.doHdrGeneration = value;
            break;

        case OPT_fintfc_dir_:
            global.params.doHdrGeneration = 1;
            global.params.hdrdir = xstrdup(arg);
            break;

        case OPT_fintfc_file_:
            global.params.doHdrGeneration = 1;
            global.params.hdrname = xstrdup(arg);
            break;

        case OPT_finvariants:
            global.params.useInvariants = value;
            break;

        case OPT_fmake_deps_:
            global.params.makeDeps = new OutBuffer;
            global.params.makeDepsStyle = 1;
            global.params.makeDepsFile = xstrdup(arg);
            if (!global.params.makeDepsFile[0])
                error("bad argument for -fmake-deps");
            break;

        case OPT_fmake_mdeps_:
            global.params.makeDeps = new OutBuffer;
            global.params.makeDepsStyle = 2;
            global.params.makeDepsFile = xstrdup(arg);
            if (!global.params.makeDepsFile[0])
                error("bad argument for -fmake-deps");
            break;

        case OPT_fonly_:
            fonly_arg = xstrdup(arg);
            break;

        case OPT_fout:
            global.params.useOut = value;
            break;
#if V2
        case OPT_fproperty:
            global.params.enforcePropertySyntax = value;
            break;
#endif
        case OPT_frelease:
            global.params.useInvariants = ! value;
            global.params.useIn = ! value;
            global.params.useOut = ! value;
            global.params.useAssert = ! value;
#if V2
            // release mode doesn't turn off bounds checking for safe functions.
            global.params.useArrayBounds = ! value ? 2 : 1;
            flag_bounds_check = ! value;
#else
            flag_bounds_check = global.params.useArrayBounds = ! value;
#endif
            global.params.useSwitchError = ! value;
            break;

        case OPT_funittest:
            global.params.useUnitTests = value;
            break;

        case OPT_fversion_:
            if (ISDIGIT(arg[0]))
            {
                if (! parse_int(arg, & level))
                    goto Lerror_v;
                VersionCondition::setGlobalLevel(level);
            }
            else if (Lexer::isValidIdentifier(CONST_CAST(char*, arg)))
                VersionCondition::addGlobalIdent(xstrdup(arg));
            else
            {
              Lerror_v:
                error("bad argument for -fversion");
            }
            break;

        case OPT_fXf_:
            global.params.doXGeneration = 1;
            global.params.xfilename = xstrdup(arg);
            break;

        case OPT_imultilib:
            multilib_dir = xstrdup(arg);
            break;

        case OPT_iprefix:
            iprefix = xstrdup(arg);
            break;

        case OPT_I:
            global.params.imppath->push(xstrdup(arg)); // %% not sure if we can keep the arg or not
            break;

        case OPT_J:
            global.params.fileImppath->push(xstrdup(arg));
            break;

        case OPT_nostdinc:
            std_inc = false;
            break;

        case OPT_Wall:
            if (value)
                global.params.warnings = 2;
            break;

        case OPT_Werror:
            if (value)
                global.params.warnings = 1;
            break;

        case OPT_Wsign_compare:
            break;

        default:
            break;
    }
    return 1;
}

bool d_post_options(const char ** fn)
{
    // The front end considers the first input file to be the main one.
    if (num_in_fnames)
        *fn = in_fnames[0];

    // Save register names for restoring later.
    memcpy (saved_reg_names, reg_names, sizeof reg_names);

    /* If we are given more than one input file, we must use
       unit-at-a-time mode.  */
    if (num_in_fnames > 1)
        flag_unit_at_a_time = 1;

#if V2
    /* array bounds checking */
    if (global.params.noboundscheck)
        flag_bounds_check = global.params.useArrayBounds = 0;
#endif

    /* Excess precision other than "fast" requires front-end
       support that we don't offer. */
    if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
       flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;

    return false;
}

/* wrapup_global_declaration needs to be called or functions will not
   be emitted. */
Array globalDeclarations;

void
d_add_global_declaration(tree decl)
{
    globalDeclarations.push(decl);
}

static void
d_write_global_declarations()
{
    tree * vec = (tree *) globalDeclarations.data;

    /* Process all file scopes in this compilation, and the external_scope,
       through wrapup_global_declarations and check_global_declarations.  */
    wrapup_global_declarations(vec, globalDeclarations.dim);
    check_global_declarations(vec, globalDeclarations.dim);

    /* We're done parsing; proceed to optimize and emit assembly. */
    cgraph_finalize_compilation_unit();

    /* After cgraph has had a chance to emit everything that's going to
       be emitted, output debug information for globals.  */
    emit_debug_global_declarations(vec, globalDeclarations.dim);
}


/* Gimplification of expression trees.  */
int
d_gimplify_expr (tree *expr_p, gimple_seq *pre_p ATTRIBUTE_UNUSED,
                 gimple_seq *post_p ATTRIBUTE_UNUSED)
{
    enum tree_code code = TREE_CODE (*expr_p);
    switch (code)
    {
        case INIT_EXPR:
        case MODIFY_EXPR:
        {   /* If the back end isn't clever enough to know that the lhs and rhs
               types are the same, add an explicit conversion.  */
            tree op0 = TREE_OPERAND (*expr_p, 0);
            tree op1 = TREE_OPERAND (*expr_p, 1);

            if (!gen.isErrorMark(op0) && !gen.isErrorMark(op1)
                && (AGGREGATE_TYPE_P (TREE_TYPE (op0))
                    || AGGREGATE_TYPE_P (TREE_TYPE (op1)))
                && !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0)))
            {
                TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
                                                    TREE_TYPE (op0), op1);
            }
            return GS_OK;
        }

        default:
            return GS_UNHANDLED;
    }
}

static Module * an_output_module = 0;

Module *
d_gcc_get_output_module()
{
    return an_output_module;
}

static void
nametype(tree type, const char * name)
{
    tree ident = get_identifier(name);
    tree decl = build_decl(UNKNOWN_LOCATION, TYPE_DECL, ident, type);
    TYPE_NAME(type) = decl;
    ObjectFile::rodc(decl, 1);
}

static void
nametype(Type * t)
{
    nametype(t->toCtype(), t->toChars());
}

static void
deps_write(Module * m)
{
    OutBuffer *ob = global.params.makeDeps;
    size_t size, column = 0, colmax = 72;
    FileName * fn;

    // Write out object name.
    fn = m->objfile->name;
    size = fn->len();
    ob->writestring(fn->str);
    column = size;

    ob->writestring(": ");
    column += 2;

    // First dependency is source file for module.
    fn = m->srcfile->name;
    size = fn->len();
    ob->writestring(fn->str);
    column += size;

    // Write out file dependencies.
    for (size_t i = 0; i < m->aimports.dim; i++)
    {
        Module * mi = m->aimports[i];

        // Ignore self references.
        if (mi == m)
            continue;

        if (global.params.makeDepsStyle == 2)
        {
            // Don't emit system modules. This includes core.*, std.*, gcc.* and object.
            ModuleDeclaration * md = mi->md;

            if (md && md->packages)
            {
                if (strcmp((md->packages->tdata()[0])->string, "core") == 0)
                    continue;
                if (strcmp((md->packages->tdata()[0])->string, "std") == 0)
                    continue;
                if (strcmp((md->packages->tdata()[0])->string, "gcc") == 0)
                    continue;
            }
            else if (md && md->id)
            {
                if (strcmp(md->id->string, "object") == 0 && md->packages == NULL)
                    continue;
            }
        }

        // All checks done, write out file path/name.
        fn = mi->srcfile->name;
        size = fn->len();
        column += size;
        if (column > colmax)
        {
            ob->writestring(" \\\n ");
            column = 1 + size;
        }
        else
        {
            ob->writestring(" ");
            column++;
        }
        ob->writestring(fn->str);
    }
    ob->writestring("\n");
}

#if V2
Symbol* rtlsym[N_RTLSYM];
#endif

void
#if D_GCC_VER >= 46
d_parse_file (void)
#else
d_parse_file (int /*set_yydebug*/)
#endif
{
    if (global.params.verbose)
    {
        printf("binary    %s\n", global.params.argv0);
        printf("version   %s\n", global.version);
    }

    if (global.params.verbose && asm_out_file == stdout)
    {   // Really, driver should see the option and turn off -pipe
        error("Cannot use -fd-verbose with -pipe");
        return;
    }

    if (global.params.useUnitTests)
        global.params.useAssert = 1;
#if V1
    global.params.useArrayBounds = flag_bounds_check;
#endif
    if (gen.emitTemplates == TEauto)
    {
        gen.emitTemplates = (supports_one_only()) ? TEall : TEprivate;
    }
    global.params.symdebug = write_symbols != NO_DEBUG;
    //global.params.useInline = flag_inline_functions;
    global.params.obj = ! flag_syntax_only;
    global.params.pic = flag_pic != 0; // Has no effect yet.
    gen.originalOmitFramePointer = flag_omit_frame_pointer;

    // better to use input_location.xxx ?
    (*debug_hooks->start_source_file) (input_line, main_input_filename);

    /*
    printf("input_filename = '%s'\n", input_filename);
    printf("main_input_filename = '%s'\n", main_input_filename);
    */

    for (TY ty = (TY) 0; ty < TMAX; ty = (TY)(ty + 1))
    {
        if (Type::basic[ty] && ty != Terror)
            nametype(Type::basic[ty]);
    }

    an_output_module = NULL;
    Modules modules; // vs. outmodules... = [an_output_module] or modules
    modules.reserve(num_in_fnames);
    AsyncRead * aw = NULL;
    Module * m = NULL;

    // %% FIX
    if ( ! main_input_filename )
    {
        ::error("input file name required; cannot use stdin");
        goto had_errors;
    }

    if (fonly_arg)
    {   /* In this mode, the first file name is supposed to be
           a duplicate of one of the input file. */
        if (strcmp(fonly_arg, main_input_filename))
            ::error("-fonly= argument is different from main input file name");
        if (strcmp(fonly_arg, in_fnames[0]))
            ::error("-fonly= argument is different from first input file name");
    }
    //fprintf (stderr, "***** %d files  main=%s\n", num_in_fnames, input_filename);

    for (size_t i = 0; i < num_in_fnames; i++)
    {
        if (fonly_arg)
        {
            /* %% Do the other modules really need to be processed?
            if (an_output_module)
                break;
             */
        }
        //fprintf(stderr, "fn %d = %s\n", i, in_fnames[i]);
        char * the_fname = xstrdup(in_fnames[i]);
        char * p = FileName::name(the_fname);
        char * e = FileName::ext(p);
        char * name;
        if (e)
        {
            e--;
            gcc_assert(*e == '.');
            name = (char *) xmalloc((e - p) + 1);
            memcpy(name, p, e - p);
            name[e - p] = 0;

            if (name[0] == 0 ||
                    strcmp(name, "..") == 0 ||
                    strcmp(name, ".") == 0)
            {
            Linvalid:
                ::error("invalid file name '%s'", the_fname);
                goto had_errors;
            }
        }
        else
        {
            name = p;
            if (!*name)
                goto Linvalid;
        }

        Identifier * id = Lexer::idPool(name);
        m = new Module(the_fname, id, global.params.doDocComments, global.params.doHdrGeneration);
        if (! strcmp(in_fnames[i], main_input_filename))
            an_output_module = m;
        modules.push(m);
    }

#if V2
    // There is only one of these so far...
    rtlsym[RTLSYM_DHIDDENFUNC] =
        gen.getLibCallDecl(LIBCALL_HIDDEN_FUNC)->toSymbol();
#endif

    // current_module shouldn't have any implications before genobjfile..
    // ... but it does.  We need to know what module in which to insert
    // TemplateInstanceS during the semantic pass.  In order for
    // -femit-templates=private to work, template instances must be emitted
    // in every translation unit.  To do this, the TemplateInstaceS have to
    // have toObjFile called in the module being compiled.
    // TemplateInstance puts itself somwhere during ::semantic, thus it has
    // to know the current module...

    gcc_assert(an_output_module);

    //global.params.verbose = 1;

    // Read files
    aw = AsyncRead::create(modules.dim);
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        aw->addFile(m->srcfile);
    }
    aw->start();
    for (size_t i = 0; i < modules.dim; i++)
    {
        if (aw->read(i))
        {
            error("cannot read file %s", m->srcfile->name->toChars());
            goto had_errors;
        }
    }
    AsyncRead::dispose(aw);

    // Parse files
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (global.params.verbose)
            printf("parse     %s\n", m->toChars());
        if (!Module::rootModule)
            Module::rootModule = m;
        m->importedFrom = m;
        //m->deleteObjFile(); // %% driver does this
        m->parse(global.params.dump_source);
        d_gcc_magic_module(m);
        if (m->isDocFile)
        {
            m->gendocfile();
            // Remove m from list of modules
            modules.remove(i);
            i--;
        }
    }
    if (global.errors)
        goto had_errors;

     if (global.params.doHdrGeneration)
     {
         /* Generate 'header' import files.
          * Since 'header' import files must be independent of command
          * line switches and what else is imported, they are generated
          * before any semantic analysis.
          */
         for (size_t i = 0; i < modules.dim; i++)
         {
             m = modules[i];
             if (fonly_arg && m != an_output_module)
                 continue;
             if (global.params.verbose)
                 printf("import    %s\n", m->toChars());
             m->genhdrfile();
         }
     }
     if (global.errors)
         goto had_errors;

    // load all unconditional imports for better symbol resolving
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (global.params.verbose)
            printf("importall %s\n", m->toChars());
        m->importAll(0);
    }
    if (global.errors)
        goto had_errors;

    // Do semantic analysis
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (global.params.verbose)
            printf("semantic  %s\n", m->toChars());
        m->semantic();
    }
    if (global.errors)
        goto had_errors;

    Module::dprogress = 1;
    Module::runDeferredSemantic();

    // Do pass 2 semantic analysis
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (global.params.verbose)
            printf("semantic2 %s\n", m->toChars());
        m->semantic2();
    }
    if (global.errors)
        goto had_errors;

    // Do pass 3 semantic analysis
    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (global.params.verbose)
            printf("semantic3 %s\n", m->toChars());
        m->semantic3();
    }
    if (global.errors)
        goto had_errors;

    if (global.params.moduleDeps != NULL)
    {
        gcc_assert(global.params.moduleDepsFile != NULL);

        File deps(global.params.moduleDepsFile);
        OutBuffer* ob = global.params.moduleDeps;
        deps.setbuffer((void*)ob->data, ob->offset);
        deps.writev();
    }

    if (global.params.makeDeps != NULL)
    {
        for (size_t i = 0; i < modules.dim; i++)
        {
            m = modules[i];
            deps_write(m);
        }


        OutBuffer* ob = global.params.makeDeps;
        if (global.params.makeDepsFile == NULL)
            printf((char*)ob->data);
        else
        {
            File deps(global.params.makeDepsFile);
            deps.setbuffer((void*)ob->data, ob->offset);
            deps.writev();
        }
    }

    // Do not attempt to generate output files if errors or warnings occurred
    if (global.errors || global.warnings)
        goto had_errors;

    g.ofile = new ObjectFile();
    if (fonly_arg)
        g.ofile->modules.push(an_output_module);
    else
        g.ofile->modules.append(& modules);
    g.irs = & gen; // needed for FuncDeclaration::toObjFile

    // Generate output files
    if (global.params.doXGeneration)
        json_generate(&modules);

    for (size_t i = 0; i < modules.dim; i++)
    {
        m = modules[i];
        if (fonly_arg && m != an_output_module)
            continue;
        if (global.params.verbose)
            printf("code      %s\n", m->toChars());
        if (! flag_syntax_only)
            m->genobjfile(false);
        if (! global.errors && ! errorcount)
        {
            if (global.params.doDocComments)
                m->gendocfile();
        }
    }

    // better to use input_location.xxx ?
    (*debug_hooks->end_source_file) (input_line);
 had_errors:
    // Add DMD error count to GCC error count to to exit with error status
    errorcount += (global.errors + global.warnings);

    g.ofile->finish();
    an_output_module = 0;

    gcc_d_backend_term();
}

void
d_gcc_dump_source(const char * srcname, const char * ext, unsigned char * data, unsigned len)
{
    // Note: There is a dump_base_name variable, but as long as the all-sources hack is in
    // around, the base name has to be determined here.

    /* construct output name */
    char* base = (char*) alloca(strlen(srcname)+1);
    base = strcpy(base, srcname);
    base = basename(base);

    char* name = (char*) alloca(strlen(base)+strlen(ext)+2);
    name = strcpy(name, base);
    if(strlen(ext)>0){
            name = strcat(name, ".");
            name = strcat(name, ext);
    }

    /* output
     * ignores if the output file exists
     * ignores if the output fails
     */
    FILE* output = fopen(name, "w");
    if(output){
        fwrite(data, 1, len, output);
        fclose(output);
    }

    /* cleanup */
    errno=0;
}

bool
d_mark_addressable (tree t)
{
  tree x = t;
  while (1)
    switch (TREE_CODE (x))
      {
      case ADDR_EXPR:
      case COMPONENT_REF:
          /* If D had bit fields, we would need to handle that here */
      case ARRAY_REF:
      case REALPART_EXPR:
      case IMAGPART_EXPR:
        x = TREE_OPERAND (x, 0);
        break;
        /* %% C++ prevents {& this} .... */
        /* %% TARGET_EXPR ... */
      case TRUTH_ANDIF_EXPR:
      case TRUTH_ORIF_EXPR:
      case COMPOUND_EXPR:
        x = TREE_OPERAND (x, 1);
        break;

      case COND_EXPR:
        return d_mark_addressable (TREE_OPERAND (x, 1))
          && d_mark_addressable (TREE_OPERAND (x, 2));

      case CONSTRUCTOR:
        TREE_ADDRESSABLE (x) = 1;
        return true;

      case INDIRECT_REF:
          /* %% this was in Java, not sure for D */
        /* We sometimes add a cast *(TYPE*)&FOO to handle type and mode
           incompatibility problems.  Handle this case by marking FOO.  */
        if (TREE_CODE (TREE_OPERAND (x, 0)) == NOP_EXPR
            && TREE_CODE (TREE_OPERAND (TREE_OPERAND (x, 0), 0)) == ADDR_EXPR)
          {
            x = TREE_OPERAND (TREE_OPERAND (x, 0), 0);
            break;
          }
        if (TREE_CODE (TREE_OPERAND (x, 0)) == ADDR_EXPR)
          {
            x = TREE_OPERAND (x, 0);
            break;
          }
        return true;

      case VAR_DECL:
      case CONST_DECL:
      case PARM_DECL:
      case RESULT_DECL:
      case FUNCTION_DECL:
        TREE_ADDRESSABLE (x) = 1;
        /* drops through */
      default:
        return true;
    }

    return 1;
}


/* Mark EXP as read, not just set, for set but not used -Wunused
   warning purposes.  */

void
d_mark_exp_read (tree exp)
{
    switch (TREE_CODE (exp))
    {
        case VAR_DECL:
        case PARM_DECL:
#if D_GCC_VER >= 46
            DECL_READ_P (exp) = 1;
#endif
            break;

        case ARRAY_REF:
        case COMPONENT_REF:
        case MODIFY_EXPR:
        case REALPART_EXPR:
        case IMAGPART_EXPR:
        case NOP_EXPR:   
        case CONVERT_EXPR:
        case ADDR_EXPR:
            d_mark_exp_read (TREE_OPERAND (exp, 0));
            break;

        case COMPOUND_EXPR:
            d_mark_exp_read (TREE_OPERAND (exp, 1));
            break;

        default:
            break;
    }
}


tree
d_type_for_mode (enum machine_mode mode, int unsignedp)
{
    // taken from c-common.c
  if (mode == TYPE_MODE (integer_type_node))
    return unsignedp ? unsigned_type_node : integer_type_node;

  if (mode == TYPE_MODE (signed_char_type_node))
    return unsignedp ? unsigned_char_type_node : signed_char_type_node;

  if (mode == TYPE_MODE (short_integer_type_node))
    return unsignedp ? short_unsigned_type_node : short_integer_type_node;

  if (mode == TYPE_MODE (long_integer_type_node))
    return unsignedp ? long_unsigned_type_node : long_integer_type_node;

  if (mode == TYPE_MODE (long_long_integer_type_node))
    return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;

  /*%% ?
  if (mode == TYPE_MODE (widest_integer_literal_type_node))
    return unsignedp ? widest_unsigned_literal_type_node
                     : widest_integer_literal_type_node;
  */
  if (mode == QImode)
    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;

  if (mode == HImode)
    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;

  if (mode == SImode)
    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;

  if (mode == DImode)
    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;

#if HOST_BITS_PER_WIDE_INT >= 64
  if (mode == TYPE_MODE (intTI_type_node))
    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
#endif

  if (mode == TYPE_MODE (float_type_node))
    return float_type_node;

  if (mode == TYPE_MODE (double_type_node))
    return double_type_node;

  if (mode == TYPE_MODE (long_double_type_node))
    return long_double_type_node;

  if (mode == TYPE_MODE (build_pointer_type (char_type_node)))
    return build_pointer_type (char_type_node);

  if (mode == TYPE_MODE (build_pointer_type (integer_type_node)))
    return build_pointer_type (integer_type_node);

  if (COMPLEX_MODE_P (mode))
    {
      enum machine_mode inner_mode;
      tree inner_type;

      if (mode == TYPE_MODE (complex_float_type_node))
        return complex_float_type_node;
      if (mode == TYPE_MODE (complex_double_type_node))
        return complex_double_type_node;
      if (mode == TYPE_MODE (complex_long_double_type_node))
        return complex_long_double_type_node;

      if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
        return complex_integer_type_node;

      inner_mode = (machine_mode) GET_MODE_INNER (mode);
      inner_type = d_type_for_mode (inner_mode, unsignedp);
      if (inner_type != NULL_TREE)
        return build_complex_type (inner_type);
    }
  else if (VECTOR_MODE_P (mode))
    {
      enum machine_mode inner_mode = (machine_mode) GET_MODE_INNER (mode);
      tree inner_type = d_type_for_mode (inner_mode, unsignedp);
      if (inner_type != NULL_TREE)
        return build_vector_type_for_mode (inner_type, mode);
    }

  return 0;
}

tree
d_type_for_size (unsigned bits, int unsignedp)
{
  if (bits == TYPE_PRECISION (integer_type_node))
    return unsignedp ? unsigned_type_node : integer_type_node;

  if (bits == TYPE_PRECISION (signed_char_type_node))
    return unsignedp ? unsigned_char_type_node : signed_char_type_node;

  if (bits == TYPE_PRECISION (short_integer_type_node))
    return unsignedp ? short_unsigned_type_node : short_integer_type_node;

  if (bits == TYPE_PRECISION (long_integer_type_node))
    return unsignedp ? long_unsigned_type_node : long_integer_type_node;

  if (bits == TYPE_PRECISION (long_long_integer_type_node))
    return (unsignedp ? long_long_unsigned_type_node
            : long_long_integer_type_node);
  /* %%?
  if (bits == TYPE_PRECISION (widest_integer_literal_type_node))
    return (unsignedp ? widest_unsigned_literal_type_node
            : widest_integer_literal_type_node);
  */
  if (bits <= TYPE_PRECISION (intQI_type_node))
    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;

  if (bits <= TYPE_PRECISION (intHI_type_node))
    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;

  if (bits <= TYPE_PRECISION (intSI_type_node))
    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;

  if (bits <= TYPE_PRECISION (intDI_type_node))
    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;

  return 0;
}

tree
d_unsigned_type (tree type)
{
  tree type1 = TYPE_MAIN_VARIANT (type);
  if (type1 == signed_char_type_node || type1 == char_type_node)
    return unsigned_char_type_node;
  if (type1 == integer_type_node)
    return unsigned_type_node;
  if (type1 == short_integer_type_node)
    return short_unsigned_type_node;
  if (type1 == long_integer_type_node)
    return long_unsigned_type_node;
  if (type1 == long_long_integer_type_node)
    return long_long_unsigned_type_node;
  /* %%?
  if (type1 == widest_integer_literal_type_node)
    return widest_unsigned_literal_type_node;
  */
#if HOST_BITS_PER_WIDE_INT >= 64
  if (type1 == intTI_type_node)
    return unsigned_intTI_type_node;
#endif
  if (type1 == intDI_type_node)
    return unsigned_intDI_type_node;
  if (type1 == intSI_type_node)
    return unsigned_intSI_type_node;
  if (type1 == intHI_type_node)
    return unsigned_intHI_type_node;
  if (type1 == intQI_type_node)
    return unsigned_intQI_type_node;

  return d_signed_or_unsigned_type (1, type);
}

tree
d_signed_type (tree type)
{
  tree type1 = TYPE_MAIN_VARIANT (type);
  if (type1 == unsigned_char_type_node || type1 == char_type_node)
    return signed_char_type_node;
  if (type1 == unsigned_type_node)
    return integer_type_node;
  if (type1 == short_unsigned_type_node)
    return short_integer_type_node;
  if (type1 == long_unsigned_type_node)
    return long_integer_type_node;
  if (type1 == long_long_unsigned_type_node)
    return long_long_integer_type_node;
  /*
  if (type1 == widest_unsigned_literal_type_node)
    return widest_integer_literal_type_node;
  */
#if HOST_BITS_PER_WIDE_INT >= 64
  if (type1 == unsigned_intTI_type_node)
    return intTI_type_node;
#endif
  if (type1 == unsigned_intDI_type_node)
    return intDI_type_node;
  if (type1 == unsigned_intSI_type_node)
    return intSI_type_node;
  if (type1 == unsigned_intHI_type_node)
    return intHI_type_node;
  if (type1 == unsigned_intQI_type_node)
    return intQI_type_node;

  return d_signed_or_unsigned_type (0, type);
}

tree
d_signed_or_unsigned_type (int unsignedp, tree type)
{
  if (! INTEGRAL_TYPE_P (type)
      || TYPE_UNSIGNED (type) == (unsigned) unsignedp)
    return type;

  if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
    return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
    return unsignedp ? unsigned_type_node : integer_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node))
    return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node))
    return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node))
    return (unsignedp ? long_long_unsigned_type_node
            : long_long_integer_type_node);
  /* %%?
  if (TYPE_PRECISION (type) == TYPE_PRECISION (widest_integer_literal_type_node))
    return (unsignedp ? widest_unsigned_literal_type_node
            : widest_integer_literal_type_node);
  */
#if HOST_BITS_PER_WIDE_INT >= 64
  if (TYPE_PRECISION (type) == TYPE_PRECISION (intTI_type_node))
    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
#endif
  if (TYPE_PRECISION (type) == TYPE_PRECISION (intDI_type_node))
    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (intSI_type_node))
    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (intHI_type_node))
    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
  if (TYPE_PRECISION (type) == TYPE_PRECISION (intQI_type_node))
    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;

  return type;
}

/* Type promotion for variable arguments.  */
tree
d_type_promotes_to (tree type)
{
  /* Almost the same as c_type_promotes_to.  This is needed varargs to work on
     certain targets. */
  if (TYPE_MAIN_VARIANT (type) == float_type_node)
    return double_type_node;

  // not quite the same as... if (c_promoting_integer_type_p (type))
  if (INTEGRAL_TYPE_P (type) &&
      (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) )
    {
      /* Preserve unsignedness if not really getting any wider.  */
      if (TYPE_UNSIGNED (type)
          && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
        return unsigned_type_node;
      return integer_type_node;
    }

  return type;
}


struct binding_level * current_binding_level;
struct binding_level * global_binding_level;


static binding_level *
alloc_binding_level()
{
    unsigned sz = sizeof (struct binding_level);
#if D_GCC_VER >= 46
    return (struct binding_level *) ggc_alloc_cleared_atomic (sz);
#else
    return (struct binding_level *) ggc_alloc_cleared (sz);
#endif
}

/* The D front-end does not use the 'binding level' system for a symbol table,
   It is only needed to get debugging information for local variables and
   otherwise support the backend. */

void
pushlevel (int /*arg*/)
{
    binding_level * new_level = alloc_binding_level();
    new_level->level_chain = current_binding_level;
    current_binding_level = new_level;
}

tree
poplevel (int keep, int reverse, int routinebody)
{
    binding_level * level = current_binding_level;
    tree block, decls;

    current_binding_level = level->level_chain;
    decls = level->names;
    if (reverse)
        decls = nreverse(decls);

    if (level->this_block)
        block = level->this_block;
    else if (keep || routinebody)
        block = make_node(BLOCK);
    else
        block = NULL_TREE;

    if (block)
    {
        BLOCK_VARS(block) = routinebody ? NULL_TREE : decls;
        BLOCK_SUBBLOCKS(block) = level->blocks;
        // %% need this for when insert_block is called by backend... or make
        // insert_block do it's work elsewere
        // BLOCK_SUBBLOCKS( block ) = level->blocks;
        // %% pascal does: in each subblock, record that this is the superiod..
    }
    /* In each subblock, record that this is its superior. */
    for (tree t = level->blocks; t; t = TREE_CHAIN (t))
        BLOCK_SUPERCONTEXT (t) = block;
    /* Dispose of the block that we just made inside some higher level. */
    if (routinebody)
        DECL_INITIAL (current_function_decl) = block;
    else if (block)
    {
        // Original logic was: If this block was created by this poplevel
        // call and not and earlier set_block, insert it into the parent's
        // list of blocks.  Blocks created with set_block have to be
        // inserted with insert_block.
        //
        // For D, currently always using set_block/insert_block
        if (!level->this_block)
            current_binding_level->blocks = chainon (current_binding_level->blocks, block);
    }
    /* If we did not make a block for the level just exited, any blocks made for inner
       levels (since they cannot be recorded as subblocks in that level) must be
       carried forward so they will later become subblocks of something else. */
    else if (level->blocks)
        current_binding_level->blocks = chainon (current_binding_level->blocks, level->blocks);

    if (block)
    {
        TREE_USED (block) = 1;
        tree vars = copy_list (BLOCK_VARS (block));

        /* Warnings for unused variables.  */
        for (tree t = nreverse(vars); t != NULL_TREE; t = TREE_CHAIN (t))
        {
            gcc_assert(TREE_CODE (t) == VAR_DECL);
            if ((!TREE_USED (t) /*|| !D_DECL_READ(t)*/) //%% TODO
                && !TREE_NO_WARNING (t)
                && DECL_NAME (t)
                && !DECL_ARTIFICIAL (t))
            {
                if (!TREE_USED (t))
                    warning (OPT_Wunused_variable, "unused variable %q+D", t);
                else if (DECL_CONTEXT (t) == current_function_decl)
                {
#if D_GCC_VER >= 46
                    warning_at (DECL_SOURCE_LOCATION (t),
                                OPT_Wunused_but_set_variable, "variable %qD set but not used", t);
#else
                    warning_at (DECL_SOURCE_LOCATION (t),
                                OPT_Wunused_variable, "variable %qD set but not used", t);
#endif
                }
            }
        }
    }
    return block;
}

int
global_bindings_p (void)
{
    // This is called by the backend before parsing.  Need to make this do
    // something or lang_hooks.clear_binding_stack (lhd_clear_binding_stack)
    // loops forever.
    return current_binding_level == global_binding_level || ! global_binding_level;
}

void
init_global_binding_level()
{
    current_binding_level = global_binding_level = alloc_binding_level();
}


void
insert_block (tree block)
{
    TREE_USED (block) = 1;
    current_binding_level->blocks = chainon (current_binding_level->blocks, block);
}

void
set_block (tree block)
{
    current_binding_level->this_block = block;
}

tree
pushdecl (tree decl)
{
    // %% Pascal: if not a local external routine decl doesn't consitite nesting

    // %% probably  should be cur_irs->getDeclContext()
    // %% should only be for variables OR, should also use TRANSLATION_UNIT for toplevel..
    if (DECL_CONTEXT(decl) == NULL_TREE)
        DECL_CONTEXT(decl) = current_function_decl; // could be NULL_TREE (top level) .. hmm. // hm.m.

    /* Put decls on list in reverse order. We will reverse them later if necessary. */
    TREE_CHAIN (decl) = current_binding_level->names;
    current_binding_level->names = decl;
    if (!TREE_CHAIN (decl))
        current_binding_level->names_end = decl;
    return decl;
}

/* pushdecl_top_level is only for building with Apple GCC. */
extern "C" tree
pushdecl_top_level (tree x)
{
  tree t;
  struct binding_level *b = current_binding_level;

  current_binding_level = global_binding_level;
  t = pushdecl (x);
  current_binding_level = b;
  return t;
}


void
set_decl_binding_chain(tree decl_chain)
{
    gcc_assert(current_binding_level);
    current_binding_level->names = decl_chain;
}


// Supports dbx and stabs
tree
getdecls ()
{
    if (current_binding_level)
        return current_binding_level->names;
    else
        return NULL_TREE;
}


static int
d_types_compatible_p (tree t1, tree t2)
{
    /* Is compatible if types are equivalent */
    if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
        return 1;

    /* Is compatible if we are dealing with C <-> D va_list nodes */
    if ((t1 == d_va_list_type_node && t2 == va_list_type_node)
        || (t2 == d_va_list_type_node && t1 == va_list_type_node))
        return 1;

    /* Is compatible if aggregates are same type or share the same
       attributes. The frontend should have already ensured that types
       aren't wildly different anyway... */
    if (AGGREGATE_TYPE_P (t1) && AGGREGATE_TYPE_P (t2)
        && TREE_CODE (t1) == TREE_CODE (t2))
    {
        if (TREE_CODE (t1) == ARRAY_TYPE)
            return (TREE_TYPE (t1) == TREE_TYPE (t2));

        return (TYPE_ATTRIBUTES (t1) == TYPE_ATTRIBUTES (t2));
    }
    /* else */
    return 0;
}

static void
d_finish_incomplete_decl (tree decl)
{
    if (TREE_CODE (decl) == VAR_DECL)
    {   /* D allows zero-length declarations.  Such a declaration ends up with
           DECL_SIZE(t) == NULL_TREE which is what the backend function
           assembler_variable checks.  This could change in later versions...

           Maybe all of these variables should be aliased to one symbol... */
        if (DECL_SIZE (decl) == 0)
        {
            DECL_SIZE (decl) = bitsize_zero_node;
            DECL_SIZE_UNIT (decl) = size_zero_node;
        }
    }
}

#if V2

/* DMD 2 makes a parameter delclaration's type 'const(T)' if the
   parameter is a simple STCin or STCconst.  The TypeFunction's
   Argument's type stays unqualified, however.

   This mismatch causes a problem with optimization and inlining.  For
   RECORD_TYPE arguments, failure will occur in (setup_one_parameter
   -> fold_convert).  d_types_compatible_p hacks lead to failures in
   the sra pass.

   Fortunately, the middle end provides a simple workaround by using
   this hook.
*/

tree
d_convert_parm_for_inlining  (tree parm, tree value, tree fndecl, int argnum)
{
    if (!value)
        return value;

    if (TYPE_ARG_TYPES(TREE_TYPE(fndecl))
            && (TYPE_MAIN_VARIANT(TREE_TYPE(parm))
                == TYPE_MAIN_VARIANT(TREE_TYPE(value))))
        return value;

    if (TREE_TYPE(parm) != TREE_TYPE(value))
        return build1(NOP_EXPR, TREE_TYPE(parm), value);

    return value;
}
#endif


struct lang_type *
build_d_type_lang_specific(Type * t)
{
    struct lang_type * l;
    unsigned sz = sizeof(struct lang_type);
#if D_GCC_VER >= 46
    l = (struct lang_type *) ggc_alloc_cleared_atomic(sz);
#else
    l = (struct lang_type *) ggc_alloc_cleared(sz);
#endif
    l->d_type = t;
    l->c_type = t->ctype;
    return l;
}

struct lang_decl *
build_d_decl_lang_specific(Declaration * d)
{
    struct lang_decl * l;
    unsigned sz = sizeof(struct lang_decl);
#if D_GCC_VER >= 46
    l = (struct lang_decl *) ggc_alloc_cleared_atomic(sz);
#else
    l = (struct lang_decl *) ggc_alloc_cleared(sz);
#endif
    l->d_decl = d;
    return l;
}


// This preserves tree we create from the garbage collector.
tree d_keep_list = NULL_TREE;

void
d_keep(tree t)
{
    d_keep_list = tree_cons(NULL_TREE, t, d_keep_list);
}

// List of trees that we want to send to the garbage collector.
tree d_free_list = NULL_TREE;

void
d_free(tree t)
{
    TREE_CHAIN(t) = d_free_list;
    d_free_list = t;
}

tree d_eh_personality_decl;

/* Return the GDC personality function decl.  */
static tree
d_eh_personality (void)
{
    if (!d_eh_personality_decl)
    {
#if D_GCC_VER >= 46
        d_eh_personality_decl
            = build_personality_function ("gdc");
#else
        d_eh_personality_decl
            = build_personality_function (USING_SJLJ_EXCEPTIONS
                                          ? "__gdc_personality_sj0"
                                          : "__gdc_personality_v0");
#endif
    }
    return d_eh_personality_decl;
}

static tree
d_build_eh_type_type(tree type)
{
    if (TREE_CODE(type) == ADDR_EXPR)
        return type;    // %% why???

    TypeClass * d_type = (TypeClass *) gen.getDType(type);
    gcc_assert(d_type);
    d_type = (TypeClass *) d_type->toBasetype();
    gcc_assert(d_type->ty == Tclass);
    return gen.addressOf(d_type->sym->toSymbol()->Stree);
}

void
d_init_exceptions(void)
{
    using_eh_for_cleanups ();
}

struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;