Changeset 90152a4 for driver/cfa.cc


Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into cleanup-dtors

File:
1 moved

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    rf9feab8 r90152a4  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct 31 11:40:44 2017
    13 // Update Count     : 160
     12// Last Modified On : Fri Aug 10 18:17:58 2018
     13// Update Count     : 259
    1414//
    1515
     
    1919#include <unistd.h>                                                                             // execvp
    2020#include <string>                                                                               // STL version
    21 
     21#include <string.h>                                                                             // strcmp
     22
     23#include <sys/types.h>
     24#include <sys/stat.h>
     25
     26#include "Common/SemanticError.h"
    2227#include "config.h"                                                                             // configure info
    2328
     
    3540} // prefix
    3641
     42enum { NumSuffixes = 2 };
     43const string suffixes[NumSuffixes] = { "cfa", "hfa", };
     44
     45bool suffix( string arg ) {
     46        //std::cerr << arg << std::endl;
     47        size_t dot = arg.find_last_of( "." );
     48        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
     49        if ( dot == string::npos ) return false;
     50        string sx = arg.substr( dot + 1 );
     51        for ( int i = 0; i < NumSuffixes; i += 1 ) {
     52                if ( sx == suffixes[i] ) return true;
     53        } // for
     54        return false;
     55} // suffix
     56
    3757
    3858void shuffle( const char *args[], int S, int E, int N ) {
    3959        // S & E index 1 passed the end so adjust with -1
    40 #ifdef __DEBUG_H__
     60        #ifdef __DEBUG_H__
    4161        cerr << "shuffle:" << S << " " << E << " " << N << endl;
    42 #endif // __DEBUG_H__
     62        #endif // __DEBUG_H__
    4363        for ( int j = E-1 + N; j > S-1 + N; j -=1 ) {
    44 #ifdef __DEBUG_H__
     64                #ifdef __DEBUG_H__
    4565                cerr << "\t" << j << " " << j-N << endl;
    46 #endif // __DEBUG_H__
     66                #endif // __DEBUG_H__
    4767                args[j] = args[j-N];
    4868        } // for
    4969} // shuffle
    5070
     71static inline bool dirExists(const string & path) {
     72    struct stat info;
     73    if(stat( path.c_str(), &info ) != 0)
     74        return false;
     75    else if(info.st_mode & S_IFDIR)
     76        return true;
     77    else
     78        return false;
     79} //dirExists
     80
    5181
    5282#define str(s) #s
     
    5686        string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
    5787
    58         string installincdir( CFA_INCDIR );                                     // fixed location of include files
    59         string installlibdir( CFA_LIBDIR );                                     // fixed location of cc1 and cfa-cpp commands
     88        string installincdir( CFA_INCDIR );                         // fixed location of include files
     89        string installlibdir( CFA_LIBDIR );                         // fixed location of cc1 and cfa-cpp commands when installed
     90        string srcdriverdir ( TOP_BUILDDIR "driver");                // fixed location of cc1 and cfa-cpp commands when in tree
    6091
    6192        string heading;                                                                         // banner printed at start of cfa compilation
     
    77108        bool std_flag = false;                                                          // -std= flag
    78109        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
     110        bool xflag = false;                                                                     // user supplied -x flag
    79111        bool debugging __attribute(( unused )) = false;         // -g flag
     112        bool m32 = false;                                    // -m32 flag
     113        bool m64 = false;                                    // -m64 flag
     114        bool intree = false;
    80115
    81116        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    86121        int nlibs = 0;
    87122
    88 #ifdef __DEBUG_H__
     123        #ifdef __DEBUG_H__
    89124        cerr << "CFA:" << endl;
    90 #endif // __DEBUG_H__
     125        #endif // __DEBUG_H__
    91126
    92127        // process command-line arguments
    93128
    94129        for ( int i = 1; i < argc; i += 1 ) {
    95 #ifdef __DEBUG_H__
     130                #ifdef __DEBUG_H__
    96131                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    97 #endif // __DEBUG_H__
     132                #endif // __DEBUG_H__
    98133                arg = argv[i];                                                                  // convert to string value
    99 #ifdef __DEBUG_H__
     134                #ifdef __DEBUG_H__
    100135                cerr << "arg:\"" << arg << "\"" << endl;
    101 #endif // __DEBUG_H__
     136                #endif // __DEBUG_H__
    102137                if ( prefix( arg, "-" ) ) {
    103138                        // pass through arguments
     
    136171                        } else if ( arg == "-no-include-stdhdr" ) {
    137172                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
     173                        } else if ( arg == "-in-tree" ) {
     174                                intree = true;
    138175                        } else if ( arg == "-compiler" ) {
    139176                                // use the user specified compiler
     
    156193                                args[nargs] = argv[i];                                  // pass the argument along
    157194                                nargs += 1;
    158                         } else if ( prefix( arg, "-std=" ) ) {
     195                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    159196                                std_flag = true;                                                // -std=XX provided
    160197                                args[nargs] = argv[i];                                  // pass the argument along
    161198                                nargs += 1;
     199                        } else if ( arg == "-x" ) {
     200                                xflag = true;
     201                                args[nargs] = argv[i];                                  // pass the argument along
     202                                nargs += 1;
     203                                i += 1;                                                                 // advance to argument
     204                                args[nargs] = argv[i];                                  // pass the argument along
     205                                nargs += 1;
     206                                // args[nargs] = ( *new string( string("-D__GCC_X__=") + argv[i] ) ).c_str(); // add the argument for -x
     207                                // nargs += 1;
     208                        } else if ( prefix( arg, "-x" ) ) {
     209                                xflag = true;
     210                                args[nargs] = argv[i];                                  // pass the argument along
     211                                nargs += 1;
     212                                // args[nargs] = ( *new string( string("-D__GCC_X__=") + arg.substr(2) ) ).c_str(); // add the argument for -x
     213                                // nargs += 1;
     214                        } else if ( arg == "-w" ) {
     215                                args[nargs] = argv[i];                                  // pass the argument along
     216                                nargs += 1;
     217                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
     218                                nargs += 1;
     219                        } else if ( prefix( arg, "-W" ) ) {                     // check before next tests
     220                                if ( arg == "-Werror" || arg == "-Wall" ) {
     221                                        args[nargs] = argv[i];                          // pass the argument along
     222                                        nargs += 1;
     223                                        args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
     224                                        nargs += 1;
     225                                } else {
     226                                        unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2;
     227                                        args[nargs] = argv[i];                          // conditionally pass the argument along
     228                                        const char * warning = argv[i] + adv;     // extract warning
     229                                        if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp
     230                                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str();
     231                                        } // if
     232                                        nargs += 1;
     233                                } // if
    162234                        } else if ( prefix( arg, "-B" ) ) {
    163235                                Bprefix = arg.substr(2);                                // strip the -B flag
     
    205277                                libs[nlibs] = argv[i];
    206278                                nlibs += 1;
     279                        } else if ( arg == "-m32" ) {
     280                                m32 = true;
     281                                m64 = false;
     282                                args[nargs] = argv[i];
     283                                nargs += 1;
     284                        } else if ( arg == "-m64" ) {
     285                                m64 = true;
     286                                m32 = false;
     287                                args[nargs] = argv[i];
     288                                nargs += 1;
    207289                        } else {
    208290                                // concatenate any other arguments
     
    211293                        } // if
    212294                } else {
     295                        bool opt = false;
     296                        if ( ! xflag && suffix( arg ) ) {
     297                                args[nargs] = "-x";
     298                                nargs += 1;
     299                                args[nargs] = "c";
     300                                nargs += 1;
     301                                // args[nargs] = ( *new string( string("-D__GCC_X__=c") ) ).c_str(); // add the argument for -x
     302                                // nargs += 1;
     303                                opt = true;
     304                        } // if
    213305                        // concatenate other arguments
    214306                        args[nargs] = argv[i];
    215307                        nargs += 1;
     308                        if ( opt ) {
     309                                args[nargs] = "-x";
     310                                nargs += 1;
     311                                args[nargs] = "none";
     312                                nargs += 1;
     313                                // args[nargs] = ( *new string( string("-D__GCC_X__=none") ) ).c_str(); // add the argument for -x
     314                                // nargs += 1;
     315                        } // if
    216316                        nonoptarg = true;
     317                        xflag = false;
    217318                } // if
    218319        } // for
    219320
    220 #ifdef __DEBUG_H__
     321        #ifdef __x86_64__
     322        args[nargs] = "-mcx16";                                                         // allow double-wide CAA
     323        nargs += 1;
     324        #endif // __x86_64__
     325
     326        #ifdef __DEBUG_H__
    221327        cerr << "args:";
    222328        for ( int i = 1; i < nargs; i += 1 ) {
     
    224330        } // for
    225331        cerr << endl;
    226 #endif // __DEBUG_H__
     332        #endif // __DEBUG_H__
    227333
    228334        if ( cpp_flag && CFA_flag ) {
     
    232338
    233339        // add the CFA include-library paths, which allow direct access to header files without directory qualification
    234         args[nargs] = "-I" CFA_INCDIR;
    235         nargs += 1;
    236         if ( ! noincstd_flag ) {                                                        // do not use during build
    237                 args[nargs] = "-I" CFA_INCDIR "/stdhdr";
    238                 nargs += 1;
    239         } // if
    240         args[nargs] = "-I" CFA_INCDIR "/concurrency";
    241         nargs += 1;
    242         args[nargs] = "-I" CFA_INCDIR "/containers";
    243         nargs += 1;
    244 
    245 #ifdef HAVE_LIBCFA
     340        if( !intree ) {
     341                args[nargs] = "-I" CFA_INCDIR;
     342                nargs += 1;
     343                if ( ! noincstd_flag ) {                                                        // do not use during build
     344                        args[nargs] = "-I" CFA_INCDIR "/stdhdr";
     345                        nargs += 1;
     346                } // if
     347                args[nargs] = "-I" CFA_INCDIR "/concurrency";
     348                nargs += 1;
     349                args[nargs] = "-I" CFA_INCDIR "/containers";
     350                nargs += 1;
     351        } else {
     352                args[nargs] = "-I" TOP_SRCDIR "libcfa/src";
     353                nargs += 1;
     354                if ( ! noincstd_flag ) {                                                        // do not use during build
     355                        args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
     356                        nargs += 1;
     357                } // if
     358                args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
     359                nargs += 1;
     360                args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
     361                nargs += 1;
     362        }
     363
     364        // add stdbool to get defines for bool/true/false
     365        args[nargs] = "-imacros";
     366        nargs += 1;
     367        args[nargs] = "stdbool.h";
     368        nargs += 1;
     369
     370        string libbase;
     371        if( !intree ) {
     372                libbase = CFA_LIBDIR;
     373        } else {
     374                libbase = TOP_BUILDDIR "libcfa/";
     375                args[nargs] = "-D__CFA_FLAG__=-t";
     376                nargs += 1;
     377        }
     378
     379        const char * const arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);
     380        const char * config = debug ? "debug": "nodebug";
     381        string libdir = libbase + arch + "-" + config;
     382        if( !dirExists(libdir) ) {
     383                cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     384                cerr << "Was looking for " << libdir << endl;
     385                libdir = libbase + arch + "-" + "nolib";
     386        }
     387
     388        if( !dirExists(libdir) ) {
     389                cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
     390                cerr << "Was looking for " << libdir << endl;
     391                exit( EXIT_FAILURE );
     392        }
     393
     394        args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();
     395        nargs += 1;
     396
    246397        if ( link ) {
    247                 #if ! defined(HAVE_LIBCFA_RELEASE)
    248                         if( !debug ) {
    249                                 cerr << "error: Option -nodebug is not available, libcfa was not installed." << endl;
    250                                 exit( EXIT_FAILURE );
    251                                 }
    252                 #endif
    253                 #if ! defined(HAVE_LIBCFA_DEBUG)
    254                         if( debug ) {
    255                                 cerr << "error: Option -debug is not available, libcfa-d was not installed." << endl;
    256                                 exit( EXIT_FAILURE );
    257                                 }
    258                 #endif
     398                args[nargs] = "-Xlinker";
     399                nargs += 1;
     400                args[nargs] = "--undefined=__cfaabi_dbg_bits_write";
     401                nargs += 1;
     402                args[nargs] = "-Xlinker";
     403                nargs += 1;
     404                args[nargs] = "--undefined=__cfaabi_interpose_startup";
     405                nargs += 1;
     406                args[nargs] = "-Xlinker";
     407                nargs += 1;
     408                args[nargs] = "--undefined=__cfaabi_appready_startup";
     409                nargs += 1;
     410                args[nargs] = "-Xlinker";
     411                nargs += 1;
     412                args[nargs] = "--undefined=__cfaabi_dbg_record";
     413                nargs += 1;
    259414
    260415                // include the cfa library in case it's needed
    261                 args[nargs] = "-L" CFA_LIBDIR;
    262                 nargs += 1;
    263                 if( debug ) {
    264                         args[nargs] = "-lcfa-d";
    265                 } else {
    266                         args[nargs] = "-lcfa";
    267                 }
     416                args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src" : "")) ).c_str();
     417                nargs += 1;
     418                args[nargs] = "-lcfa";
    268419                nargs += 1;
    269420                args[nargs] = "-lpthread";
     
    273424                args[nargs] = "-lrt";
    274425                nargs += 1;
    275                 args[nargs] = "-Xlinker";
    276                 nargs += 1;
    277                 args[nargs] = "--undefined=__cfaabi_dbg_bits_write";
    278                 nargs += 1;
    279 
    280         } // if
    281 #endif //HAVE_LIBCFA
     426        } // if
    282427
    283428        // Add exception flags (unconditionally)
     
    325470
    326471        if ( Bprefix.length() == 0 ) {
    327                 Bprefix = installlibdir;
     472                Bprefix = !intree ? installlibdir : srcdriverdir;
    328473                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
    329474                nargs += 1;
    330475        } // if
     476
     477        args[nargs] = "-Xlinker";                                                       // used by backtrace
     478        nargs += 1;
     479        args[nargs] = "-export-dynamic";
     480        nargs += 1;
    331481
    332482        // execute the compilation command
     
    346496                args[nargs] = "-Wno-deprecated";
    347497                nargs += 1;
    348                 if ( ! std_flag ) {                                                             // default c99, if none specified
    349                         args[nargs] = "-std=gnu99";
     498                if ( ! std_flag ) {                                                             // default c11, if none specified
     499                        args[nargs] = "-std=gnu11";
    350500                        nargs += 1;
    351501                } // if
     
    370520        args[nargs] = NULL;                                                                     // terminate with NULL
    371521
    372 #ifdef __DEBUG_H__
     522        #ifdef __DEBUG_H__
    373523        cerr << "nargs: " << nargs << endl;
    374524        cerr << "args:" << endl;
     
    376526                cerr << " \"" << args[i] << "\"" << endl;
    377527        } // for
    378 #endif // __DEBUG_H__
     528        #endif // __DEBUG_H__
    379529
    380530        if ( ! quiet ) {
Note: See TracChangeset for help on using the changeset viewer.