Changeset 90152a4 for driver/cc1.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/cc1.cc

    rf9feab8 r90152a4  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 18 08:14:21 2017
    13 // Update Count     : 81
     12// Last Modified On : Thu Jul 19 10:46:11 2018
     13// Update Count     : 111
    1414//
    1515
     
    3232string compiler_name( CFA_BACKEND_CC );                                 // path/name of C compiler
    3333
     34string D__GCC_X__( "-D__GCC_X__=" );
    3435string D__GCC_BPREFIX__( "-D__GCC_BPREFIX__=" );
    3536string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" );
     
    4344} // prefix
    4445
     46enum { NumSuffixes = 2 };
     47const string suffixes[NumSuffixes] = { "cfa", "hfa", };
     48
     49bool suffix( string arg ) {
     50        //std::cerr << arg << std::endl;
     51        size_t dot = arg.find_last_of( "." );
     52        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
     53        if ( dot == string::npos ) return false;
     54        string sx = arg.substr( dot + 1 );
     55        for ( int i = 0; i < NumSuffixes; i += 1 ) {
     56                if ( sx == suffixes[i] ) return true;
     57        } // for
     58        return false;
     59} // suffix
     60
    4561
    4662void checkEnv( const char *args[], int &nargs ) {
     
    5066        if ( value != NULL ) {
    5167                compiler_name = value;
    52 #ifdef __DEBUG_H__
     68                #ifdef __DEBUG_H__
    5369                cerr << "env arg:\"" << compiler_name << "\"" << endl;
    54 #endif // __DEBUG_H__
     70                #endif // __DEBUG_H__
    5571        } // if
    5672
     
    5874        if ( value != NULL ) {
    5975                args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along
    60 #ifdef __DEBUG_H__
     76                #ifdef __DEBUG_H__
    6177                cerr << "env arg:\"" << args[nargs] << "\"" << endl;
    62 #endif // __DEBUG_H__
     78                #endif // __DEBUG_H__
    6379                nargs += 1;
    6480        } // if
     
    6783        if ( value != NULL ) {
    6884                args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along
    69 #ifdef __DEBUG_H__
     85                #ifdef __DEBUG_H__
    7086                cerr << "env arg:\"" << args[nargs] << "\"" << endl;
    71 #endif // __DEBUG_H__
     87                #endif // __DEBUG_H__
    7288                nargs += 1;
    7389        } // if
     
    114130        signal( SIGTERM, sigTermHandler );
    115131
    116 #ifdef __DEBUG_H__
     132        #ifdef __DEBUG_H__
    117133        cerr << "Stage1" << endl;
    118 #endif // __DEBUG_H__
     134        #endif // __DEBUG_H__
    119135
    120136        // process all the arguments
     
    123139
    124140        for ( i = 1; i < argc; i += 1 ) {
    125 #ifdef __DEBUG_H__
     141                #ifdef __DEBUG_H__
    126142                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    127 #endif // __DEBUG_H__
     143                #endif // __DEBUG_H__
    128144                arg = argv[i];
    129 #ifdef __DEBUG_H__
     145                #ifdef __DEBUG_H__
    130146                cerr << "arg:\"" << arg << "\"" << endl;
    131 #endif // __DEBUG_H__
     147                #endif // __DEBUG_H__
    132148                if ( prefix( arg, "-" ) ) {
    133149                        // strip g++ flags that are inappropriate or cause duplicates in subsequent passes
     
    163179                                ncargs += 1;
    164180                                i += 1;                                                                 // and the argument
     181                        // } else if ( prefix( arg, D__GCC_X__ ) ) {
     182                        //      args[nargs] = "-x";
     183                        //      nargs += 1;
     184                        //      args[nargs] = ( *new string( arg.substr( D__GCC_X__.size() ) ) ).c_str(); // pass the flag along
     185                        //      nargs += 1;
     186                        // } else if ( arg == "-D" && prefix( argv[i + 1], D__GCC_X__.substr(2) ) ) {
     187                        //      args[nargs] = "-x";
     188                        //      nargs += 1;
     189                        //      args[nargs] = ( *new string( string( argv[i + 1] ).substr( D__GCC_X__.size() - 2 ) ) ).c_str(); // pass the flag along
     190                        //      nargs += 1;
     191                        //      i += 1;                                                                 // and the argument
    165192                        } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) {
    166193                                bprefix = arg.substr( D__GCC_BPREFIX__.size() );
     
    184211                                        args[nargs] = argv[i];                          // pass the argument along
    185212                                        nargs += 1;
    186 #ifdef __DEBUG_H__
     213                                        #ifdef __DEBUG_H__
    187214                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    188 #endif // __DEBUG_H__
     215                                        #endif // __DEBUG_H__
    189216                                } else if ( arg == "-MD" || arg == "-MMD" ) {
    190217                                        args[nargs] = "-MF";                            // insert before file
     
    193220                                        args[nargs] = argv[i];                          // pass the argument along
    194221                                        nargs += 1;
    195 #ifdef __DEBUG_H__
     222                                        #ifdef __DEBUG_H__
    196223                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    197 #endif // __DEBUG_H__
     224                                        #endif // __DEBUG_H__
    198225                                } // if
    199226                        } // if
     
    201228                        if ( cpp_in == NULL ) {
    202229                                cpp_in = argv[i];
    203 #ifdef __DEBUG_H__
     230                                #ifdef __DEBUG_H__
    204231                                cerr << "cpp_in:\"" << cpp_in << "\"" << endl;
    205 #endif // __DEBUG_H__
     232                                #endif // __DEBUG_H__
    206233                        } else if ( cpp_out == NULL ) {
    207234                                cpp_out = argv[i];
    208 #ifdef __DEBUG_H__
     235                                #ifdef __DEBUG_H__
    209236                                cerr << "cpp_out:\"" << cpp_out << "\""<< endl;
    210 #endif // __DEBUG_H__
     237                                #endif // __DEBUG_H__
    211238                        } else {
    212239                                cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
     
    216243        } // for
    217244
    218 #ifdef __DEBUG_H__
     245        #ifdef __DEBUG_H__
    219246        cerr << "args:";
    220247        for ( i = 1; i < nargs; i += 1 ) {
     
    224251        if ( cpp_out != NULL ) cerr << " " << cpp_out;
    225252        cerr << endl;
    226 #endif // __DEBUG_H__
     253        #endif // __DEBUG_H__
    227254
    228255        if ( cpp_in == NULL ) {
     
    246273                args[nargs] = NULL;                                                             // terminate argument list
    247274
    248 #ifdef __DEBUG_H__
     275                #ifdef __DEBUG_H__
    249276                cerr << "nargs: " << nargs << endl;
    250277                for ( i = 0; args[i] != NULL; i += 1 ) {
     
    252279                } // for
    253280                cerr << endl;
    254 #endif // __DEBUG_H__
     281                #endif // __DEBUG_H__
    255282
    256283                execvp( args[0], (char *const *)args );                 // should not return
     
    267294        } // if
    268295
    269 #ifdef __DEBUG_H__
     296        #ifdef __DEBUG_H__
    270297        cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl;
    271 #endif // __DEBUG_H__
     298        #endif // __DEBUG_H__
    272299
    273300        // Run the C preprocessor and save the output in tmpfile.
     
    283310
    284311                args[0] = compiler_name.c_str();
     312                if ( suffix( cpp_in ) ) {
     313                        args[nargs] = "-x";
     314                        nargs += 1;
     315                        args[nargs] = "c";
     316                        nargs += 1;
     317                } // if
    285318                args[nargs] = cpp_in;                                                   // input to cpp
    286319                nargs += 1;
    287320                args[nargs] = NULL;                                                             // terminate argument list
    288321
    289 #ifdef __DEBUG_H__
     322                #ifdef __DEBUG_H__
    290323                cerr << "cpp nargs: " << nargs << endl;
    291324                for ( i = 0; args[i] != NULL; i += 1 ) {
     
    293326                } // for
    294327                cerr << endl;
    295 #endif // __DEBUG_H__
     328                #endif // __DEBUG_H__
    296329
    297330                execvp( args[0], (char *const *)args );                 // should not return
     
    302335        wait( &code );                                                                          // wait for child to finish
    303336
    304 #ifdef __DEBUG_H__
     337        #ifdef __DEBUG_H__
    305338        cerr << "return code from cpp:" << WEXITSTATUS(code) << endl;
    306 #endif // __DEBUG_H__
     339        #endif // __DEBUG_H__
    307340
    308341        if ( WIFSIGNALED(code) != 0 ) {                                         // child failed ?
     
    340373                cargs[ncargs] = NULL;                                                   // terminate argument list
    341374
    342 #ifdef __DEBUG_H__
     375                #ifdef __DEBUG_H__
    343376                cerr << "cfa-cpp ncargs: " << o_name << " " << CFA_flag << " " << ncargs << endl;
    344377                for ( i = 0; cargs[i] != NULL; i += 1 ) {
     
    346379                } // for
    347380                cerr << endl;
    348 #endif // __DEBUG_H__
     381                #endif // __DEBUG_H__
    349382
    350383                execvp( cargs[0], (char * const *)cargs );              // should not return
     
    355388        wait( &code );                                                                          // wait for child to finish
    356389
    357 #ifdef __DEBUG_H__
     390        #ifdef __DEBUG_H__
    358391        cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl;
    359 #endif // __DEBUG_H__
     392        #endif // __DEBUG_H__
    360393
    361394        // Must unlink here because file must exist across execvp.
     
    381414        int nargs = 1;                                                                          // number of arguments in args list; 0 => command name
    382415
    383 #ifdef __DEBUG_H__
     416        #ifdef __DEBUG_H__
    384417        cerr << "Stage2" << endl;
    385 #endif // __DEBUG_H__
     418        #endif // __DEBUG_H__
    386419
    387420        // process all the arguments
     
    390423
    391424        for ( i = 1; i < argc; i += 1 ) {
    392 #ifdef __DEBUG_H__
     425                #ifdef __DEBUG_H__
    393426                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    394 #endif // __DEBUG_H__
     427                #endif // __DEBUG_H__
    395428                arg = argv[i];
    396 #ifdef __DEBUG_H__
     429                #ifdef __DEBUG_H__
    397430                cerr << "arg:\"" << arg << "\"" << endl;
    398 #endif // __DEBUG_H__
     431                #endif // __DEBUG_H__
    399432                if ( prefix( arg, "-" ) ) {
    400433                        // strip inappropriate flags
    401434
    402435                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
    403                                  // Currently CFA does not suppose precompiled .h files.
    404                                  prefix( arg, "--output-pch" ) ) {
     436                                // Currently CFA does not suppose precompiled .h files.
     437                                prefix( arg, "--output-pch" ) ) {
    405438
    406439                                // strip inappropriate flags with an argument
     
    408441                        } else if ( arg == "-auxbase" || arg == "-auxbase-strip" || arg == "-dumpbase" ) {
    409442                                i += 1;
    410 #ifdef __DEBUG_H__
     443                                #ifdef __DEBUG_H__
    411444                                cerr << "arg:\"" << argv[i] << "\"" << endl;
    412 #endif // __DEBUG_H__
     445                                #endif // __DEBUG_H__
    413446
    414447                                // all other flags
     
    421454                                        args[nargs] = argv[i];                          // pass the argument along
    422455                                        nargs += 1;
    423 #ifdef __DEBUG_H__
     456                                        #ifdef __DEBUG_H__
    424457                                        cerr << "arg:\"" << argv[i] << "\"" << endl;
    425 #endif // __DEBUG_H__
     458                                        #endif // __DEBUG_H__
    426459                                } // if
    427460                        } // if
     
    429462                        if ( cpp_in == NULL ) {
    430463                                cpp_in = argv[i];
    431 #ifdef __DEBUG_H__
     464                                #ifdef __DEBUG_H__
    432465                                cerr << "cpp_in:\"" << cpp_in << "\"" << endl;
    433 #endif // __DEBUG_H__
     466                                #endif // __DEBUG_H__
    434467                        } else {
    435468                                cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
     
    439472        } // for
    440473
    441 #ifdef __DEBUG_H__
     474        #ifdef __DEBUG_H__
    442475        cerr << "args:";
    443476        for ( i = 1; i < nargs; i += 1 ) {
     
    446479        cerr << endl;
    447480        if ( cpp_in != NULL ) cerr << " " << cpp_in;
    448 #endif // __DEBUG_H__
     481        #endif // __DEBUG_H__
    449482
    450483        args[0] = compiler_name.c_str();
     
    455488        args[nargs] = NULL;                                                                     // terminate argument list
    456489
    457 #ifdef __DEBUG_H__
     490        #ifdef __DEBUG_H__
    458491        cerr << "stage2 nargs: " << nargs << endl;
    459492        for ( i = 0; args[i] != NULL; i += 1 ) {
     
    461494        } // for
    462495        cerr << endl;
    463 #endif // __DEBUG_H__
     496        #endif // __DEBUG_H__
    464497
    465498        execvp( args[0], (char * const *)args );                        // should not return
     
    470503
    471504int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) {
    472 #ifdef __DEBUG_H__
     505        #ifdef __DEBUG_H__
    473506        for ( int i = 0; env[i] != NULL; i += 1 ) {
    474507                cerr << env[i] << endl;
    475508        } // for
    476 #endif // __DEBUG_H__
     509        #endif // __DEBUG_H__
    477510
    478511        string arg = argv[1];
Note: See TracChangeset for help on using the changeset viewer.