Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/driver/cc1.cc

    rdffaeac re3215c5  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 13 17:40:10 2018
    13 // Update Count     : 110
     12// Last Modified On : Sat May 12 16:11:53 2018
     13// Update Count     : 94
    1414//
    1515
     
    4444} // prefix
    4545
    46 enum { NumSuffixes = 2 };
    47 const string suffixes[NumSuffixes] = { "cfa", "hfa", };
    48 
    49 bool 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 
    6146
    6247void checkEnv( const char *args[], int &nargs ) {
     
    6651        if ( value != NULL ) {
    6752                compiler_name = value;
    68                 #ifdef __DEBUG_H__
     53#ifdef __DEBUG_H__
    6954                cerr << "env arg:\"" << compiler_name << "\"" << endl;
    70                 #endif // __DEBUG_H__
     55#endif // __DEBUG_H__
    7156        } // if
    7257
     
    7459        if ( value != NULL ) {
    7560                args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along
    76                 #ifdef __DEBUG_H__
     61#ifdef __DEBUG_H__
    7762                cerr << "env arg:\"" << args[nargs] << "\"" << endl;
    78                 #endif // __DEBUG_H__
     63#endif // __DEBUG_H__
    7964                nargs += 1;
    8065        } // if
     
    8368        if ( value != NULL ) {
    8469                args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along
    85                 #ifdef __DEBUG_H__
     70#ifdef __DEBUG_H__
    8671                cerr << "env arg:\"" << args[nargs] << "\"" << endl;
    87                 #endif // __DEBUG_H__
     72#endif // __DEBUG_H__
    8873                nargs += 1;
    8974        } // if
     
    130115        signal( SIGTERM, sigTermHandler );
    131116
    132         #ifdef __DEBUG_H__
     117#ifdef __DEBUG_H__
    133118        cerr << "Stage1" << endl;
    134         #endif // __DEBUG_H__
     119#endif // __DEBUG_H__
    135120
    136121        // process all the arguments
     
    139124
    140125        for ( i = 1; i < argc; i += 1 ) {
    141                 #ifdef __DEBUG_H__
     126#ifdef __DEBUG_H__
    142127                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    143                 #endif // __DEBUG_H__
     128#endif // __DEBUG_H__
    144129                arg = argv[i];
    145                 #ifdef __DEBUG_H__
     130#ifdef __DEBUG_H__
    146131                cerr << "arg:\"" << arg << "\"" << endl;
    147                 #endif // __DEBUG_H__
     132#endif // __DEBUG_H__
    148133                if ( prefix( arg, "-" ) ) {
    149134                        // strip g++ flags that are inappropriate or cause duplicates in subsequent passes
     
    179164                                ncargs += 1;
    180165                                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
     166                        } else if ( prefix( arg, D__GCC_X__ ) ) {
     167                                args[nargs] = "-x";
     168                                nargs += 1;
     169                                args[nargs] = ( *new string( arg.substr( D__GCC_X__.size() ) ) ).c_str(); // pass the flag along
     170                                nargs += 1;
     171                        } else if ( arg == "-D" && prefix( argv[i + 1], D__GCC_X__.substr(2) ) ) {
     172                                args[nargs] = "-x";
     173                                nargs += 1;
     174                                args[nargs] = ( *new string( string( argv[i + 1] ).substr( D__GCC_X__.size() - 2 ) ) ).c_str(); // pass the flag along
     175                                nargs += 1;
     176                                i += 1;                                                                 // and the argument
    192177                        } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) {
    193178                                bprefix = arg.substr( D__GCC_BPREFIX__.size() );
     
    211196                                        args[nargs] = argv[i];                          // pass the argument along
    212197                                        nargs += 1;
    213                                         #ifdef __DEBUG_H__
     198#ifdef __DEBUG_H__
    214199                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    215                                         #endif // __DEBUG_H__
     200#endif // __DEBUG_H__
    216201                                } else if ( arg == "-MD" || arg == "-MMD" ) {
    217202                                        args[nargs] = "-MF";                            // insert before file
     
    220205                                        args[nargs] = argv[i];                          // pass the argument along
    221206                                        nargs += 1;
    222                                         #ifdef __DEBUG_H__
     207#ifdef __DEBUG_H__
    223208                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    224                                         #endif // __DEBUG_H__
     209#endif // __DEBUG_H__
    225210                                } // if
    226211                        } // if
     
    228213                        if ( cpp_in == NULL ) {
    229214                                cpp_in = argv[i];
    230                                 #ifdef __DEBUG_H__
     215#ifdef __DEBUG_H__
    231216                                cerr << "cpp_in:\"" << cpp_in << "\"" << endl;
    232                                 #endif // __DEBUG_H__
     217#endif // __DEBUG_H__
    233218                        } else if ( cpp_out == NULL ) {
    234219                                cpp_out = argv[i];
    235                                 #ifdef __DEBUG_H__
     220#ifdef __DEBUG_H__
    236221                                cerr << "cpp_out:\"" << cpp_out << "\""<< endl;
    237                                 #endif // __DEBUG_H__
     222#endif // __DEBUG_H__
    238223                        } else {
    239224                                cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
     
    243228        } // for
    244229
    245         #ifdef __DEBUG_H__
     230#ifdef __DEBUG_H__
    246231        cerr << "args:";
    247232        for ( i = 1; i < nargs; i += 1 ) {
     
    251236        if ( cpp_out != NULL ) cerr << " " << cpp_out;
    252237        cerr << endl;
    253         #endif // __DEBUG_H__
     238#endif // __DEBUG_H__
    254239
    255240        if ( cpp_in == NULL ) {
     
    273258                args[nargs] = NULL;                                                             // terminate argument list
    274259
    275                 #ifdef __DEBUG_H__
     260#ifdef __DEBUG_H__
    276261                cerr << "nargs: " << nargs << endl;
    277262                for ( i = 0; args[i] != NULL; i += 1 ) {
     
    279264                } // for
    280265                cerr << endl;
    281                 #endif // __DEBUG_H__
     266#endif // __DEBUG_H__
    282267
    283268                execvp( args[0], (char *const *)args );                 // should not return
     
    294279        } // if
    295280
    296         #ifdef __DEBUG_H__
     281#ifdef __DEBUG_H__
    297282        cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl;
    298         #endif // __DEBUG_H__
     283#endif // __DEBUG_H__
    299284
    300285        // Run the C preprocessor and save the output in tmpfile.
     
    310295
    311296                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
    318297                args[nargs] = cpp_in;                                                   // input to cpp
    319298                nargs += 1;
    320299                args[nargs] = NULL;                                                             // terminate argument list
    321300
    322                 #ifdef __DEBUG_H__
     301#ifdef __DEBUG_H__
    323302                cerr << "cpp nargs: " << nargs << endl;
    324303                for ( i = 0; args[i] != NULL; i += 1 ) {
     
    326305                } // for
    327306                cerr << endl;
    328                 #endif // __DEBUG_H__
     307#endif // __DEBUG_H__
    329308
    330309                execvp( args[0], (char *const *)args );                 // should not return
     
    335314        wait( &code );                                                                          // wait for child to finish
    336315
    337         #ifdef __DEBUG_H__
     316#ifdef __DEBUG_H__
    338317        cerr << "return code from cpp:" << WEXITSTATUS(code) << endl;
    339         #endif // __DEBUG_H__
     318#endif // __DEBUG_H__
    340319
    341320        if ( WIFSIGNALED(code) != 0 ) {                                         // child failed ?
     
    373352                cargs[ncargs] = NULL;                                                   // terminate argument list
    374353
    375                 #ifdef __DEBUG_H__
     354#ifdef __DEBUG_H__
    376355                cerr << "cfa-cpp ncargs: " << o_name << " " << CFA_flag << " " << ncargs << endl;
    377356                for ( i = 0; cargs[i] != NULL; i += 1 ) {
     
    379358                } // for
    380359                cerr << endl;
    381                 #endif // __DEBUG_H__
     360#endif // __DEBUG_H__
    382361
    383362                execvp( cargs[0], (char * const *)cargs );              // should not return
     
    388367        wait( &code );                                                                          // wait for child to finish
    389368
    390         #ifdef __DEBUG_H__
     369#ifdef __DEBUG_H__
    391370        cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl;
    392         #endif // __DEBUG_H__
     371#endif // __DEBUG_H__
    393372
    394373        // Must unlink here because file must exist across execvp.
     
    414393        int nargs = 1;                                                                          // number of arguments in args list; 0 => command name
    415394
    416         #ifdef __DEBUG_H__
     395#ifdef __DEBUG_H__
    417396        cerr << "Stage2" << endl;
    418         #endif // __DEBUG_H__
     397#endif // __DEBUG_H__
    419398
    420399        // process all the arguments
     
    423402
    424403        for ( i = 1; i < argc; i += 1 ) {
    425                 #ifdef __DEBUG_H__
     404#ifdef __DEBUG_H__
    426405                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    427                 #endif // __DEBUG_H__
     406#endif // __DEBUG_H__
    428407                arg = argv[i];
    429                 #ifdef __DEBUG_H__
     408#ifdef __DEBUG_H__
    430409                cerr << "arg:\"" << arg << "\"" << endl;
    431                 #endif // __DEBUG_H__
     410#endif // __DEBUG_H__
    432411                if ( prefix( arg, "-" ) ) {
    433412                        // strip inappropriate flags
    434413
    435414                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
    436                                 // Currently CFA does not suppose precompiled .h files.
    437                                 prefix( arg, "--output-pch" ) ) {
     415                                 // Currently CFA does not suppose precompiled .h files.
     416                                 prefix( arg, "--output-pch" ) ) {
    438417
    439418                                // strip inappropriate flags with an argument
     
    441420                        } else if ( arg == "-auxbase" || arg == "-auxbase-strip" || arg == "-dumpbase" ) {
    442421                                i += 1;
    443                                 #ifdef __DEBUG_H__
     422#ifdef __DEBUG_H__
    444423                                cerr << "arg:\"" << argv[i] << "\"" << endl;
    445                                 #endif // __DEBUG_H__
     424#endif // __DEBUG_H__
    446425
    447426                                // all other flags
     
    454433                                        args[nargs] = argv[i];                          // pass the argument along
    455434                                        nargs += 1;
    456                 #ifdef __DEBUG_H__
     435#ifdef __DEBUG_H__
    457436                                        cerr << "arg:\"" << argv[i] << "\"" << endl;
    458                 #endif // __DEBUG_H__
     437#endif // __DEBUG_H__
    459438                                } // if
    460439                        } // if
     
    462441                        if ( cpp_in == NULL ) {
    463442                                cpp_in = argv[i];
    464                                 #ifdef __DEBUG_H__
     443#ifdef __DEBUG_H__
    465444                                cerr << "cpp_in:\"" << cpp_in << "\"" << endl;
    466                                 #endif // __DEBUG_H__
     445#endif // __DEBUG_H__
    467446                        } else {
    468447                                cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
     
    472451        } // for
    473452
    474         #ifdef __DEBUG_H__
     453#ifdef __DEBUG_H__
    475454        cerr << "args:";
    476455        for ( i = 1; i < nargs; i += 1 ) {
     
    479458        cerr << endl;
    480459        if ( cpp_in != NULL ) cerr << " " << cpp_in;
    481         #endif // __DEBUG_H__
     460#endif // __DEBUG_H__
    482461
    483462        args[0] = compiler_name.c_str();
     
    488467        args[nargs] = NULL;                                                                     // terminate argument list
    489468
    490         #ifdef __DEBUG_H__
     469#ifdef __DEBUG_H__
    491470        cerr << "stage2 nargs: " << nargs << endl;
    492471        for ( i = 0; args[i] != NULL; i += 1 ) {
     
    494473        } // for
    495474        cerr << endl;
    496         #endif // __DEBUG_H__
     475#endif // __DEBUG_H__
    497476
    498477        execvp( args[0], (char * const *)args );                        // should not return
     
    503482
    504483int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) {
    505         #ifdef __DEBUG_H__
     484#ifdef __DEBUG_H__
    506485        for ( int i = 0; env[i] != NULL; i += 1 ) {
    507486                cerr << env[i] << endl;
    508487        } // for
    509         #endif // __DEBUG_H__
     488#endif // __DEBUG_H__
    510489
    511490        string arg = argv[1];
Note: See TracChangeset for help on using the changeset viewer.