Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cc1.cc

    rbf71cfd rbec4d24  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 19 10:46:11 2018
    13 // Update Count     : 111
     12// Last Modified On : Mon Sep  3 16:57:05 2018
     13// Update Count     : 125
    1414//
    1515
     
    3232string compiler_name( CFA_BACKEND_CC );                                 // path/name of C compiler
    3333
    34 string D__GCC_X__( "-D__GCC_X__=" );
    3534string D__GCC_BPREFIX__( "-D__GCC_BPREFIX__=" );
    3635string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" );
     
    4746const string suffixes[NumSuffixes] = { "cfa", "hfa", };
    4847
    49 bool suffix( string arg ) {
     48void suffix( string arg, const char * args[], int & nargs ) {
    5049        //std::cerr << arg << std::endl;
    5150        size_t dot = arg.find_last_of( "." );
    5251        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
    53         if ( dot == string::npos ) return false;
     52        if ( dot == string::npos ) return;
    5453        string sx = arg.substr( dot + 1 );
    5554        for ( int i = 0; i < NumSuffixes; i += 1 ) {
    56                 if ( sx == suffixes[i] ) return true;
    57         } // for
    58         return false;
     55                if ( sx == suffixes[i] ) {
     56                        args[nargs] = "-x";
     57                        nargs += 1;
     58                        args[nargs] = "c";
     59                        nargs += 1;
     60                        return;
     61                } // if
     62        } // for
    5963} // suffix
    6064
    6165
    62 void checkEnv( const char *args[], int &nargs ) {
     66void checkEnv( const char * args[], int & nargs ) {
    6367        char *value;
    6468
    65         value = getenv( "__COMPILER__" );
     69        value = getenv( "__CFA_COMPILER__" );
    6670        if ( value != NULL ) {
    6771                compiler_name = value;
     
    110114void Stage1( const int argc, const char * const argv[] ) {
    111115        int code;
    112         int i;
    113116
    114117        string arg;
     
    133136        cerr << "Stage1" << endl;
    134137        #endif // __DEBUG_H__
     138        checkEnv( args, nargs );                                                        // arguments passed via environment variables
     139        #ifdef __DEBUG_H__
     140        for ( int i = 1; i < argc; i += 1 ) {
     141                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
     142        } // for
     143        #endif // __DEBUG_H__
    135144
    136145        // process all the arguments
    137146
    138         checkEnv( args, nargs );                                                        // arguments passed via environment variables
    139 
    140         for ( i = 1; i < argc; i += 1 ) {
    141                 #ifdef __DEBUG_H__
    142                 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    143                 #endif // __DEBUG_H__
     147        for ( int i = 1; i < argc; i += 1 ) {
    144148                arg = argv[i];
    145                 #ifdef __DEBUG_H__
    146                 cerr << "arg:\"" << arg << "\"" << endl;
    147                 #endif // __DEBUG_H__
    148149                if ( prefix( arg, "-" ) ) {
    149150                        // strip g++ flags that are inappropriate or cause duplicates in subsequent passes
     
    179180                                ncargs += 1;
    180181                                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
    192182                        } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) {
    193183                                bprefix = arg.substr( D__GCC_BPREFIX__.size() );
     
    245235        #ifdef __DEBUG_H__
    246236        cerr << "args:";
    247         for ( i = 1; i < nargs; i += 1 ) {
     237        for ( int i = 1; i < nargs; i += 1 ) {
    248238                cerr << " " << args[i];
    249239        } // for
     
    263253
    264254                args[0] = compiler_name.c_str();
     255                suffix( cpp_in, args, nargs );                                  // check suffix
    265256                args[nargs] = cpp_in;
    266257                nargs += 1;
     
    275266                #ifdef __DEBUG_H__
    276267                cerr << "nargs: " << nargs << endl;
    277                 for ( i = 0; args[i] != NULL; i += 1 ) {
     268                for ( int i = 0; args[i] != NULL; i += 1 ) {
    278269                        cerr << args[i] << " ";
    279270                } // for
     
    310301
    311302                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
     303                suffix( cpp_in, args, nargs );                                  // check suffix
    318304                args[nargs] = cpp_in;                                                   // input to cpp
    319305                nargs += 1;
     
    322308                #ifdef __DEBUG_H__
    323309                cerr << "cpp nargs: " << nargs << endl;
    324                 for ( i = 0; args[i] != NULL; i += 1 ) {
     310                for ( int i = 0; args[i] != NULL; i += 1 ) {
    325311                        cerr << args[i] << " ";
    326312                } // for
     
    354340
    355341        if ( fork() == 0 ) {                                                            // child runs CFA
    356                 cargs[0] = ( *new string( bprefix + "/cfa-cpp" ) ).c_str();
     342                cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();
    357343
    358344                // Source file-name used to generate routine names containing global initializations for TU.
     
    375361                #ifdef __DEBUG_H__
    376362                cerr << "cfa-cpp ncargs: " << o_name << " " << CFA_flag << " " << ncargs << endl;
    377                 for ( i = 0; cargs[i] != NULL; i += 1 ) {
     363                for ( int i = 0; cargs[i] != NULL; i += 1 ) {
    378364                        cerr << cargs[i] << " ";
    379365                } // for
     
    405391
    406392void Stage2( const int argc, const char * const * argv ) {
    407         int i;
    408 
    409393        string arg;
    410394
     
    417401        cerr << "Stage2" << endl;
    418402        #endif // __DEBUG_H__
     403        checkEnv( args, nargs );                                                        // arguments passed via environment variables
     404        #ifdef __DEBUG_H__
     405        for ( int i = 1; i < argc; i += 1 ) {
     406                cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
     407        } // for
     408        #endif // __DEBUG_H__
    419409
    420410        // process all the arguments
    421411
    422         checkEnv( args, nargs );                                                        // arguments passed via environment variables
    423 
    424         for ( i = 1; i < argc; i += 1 ) {
    425                 #ifdef __DEBUG_H__
    426                 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    427                 #endif // __DEBUG_H__
     412        for ( int i = 1; i < argc; i += 1 ) {
    428413                arg = argv[i];
    429                 #ifdef __DEBUG_H__
    430                 cerr << "arg:\"" << arg << "\"" << endl;
    431                 #endif // __DEBUG_H__
    432414                if ( prefix( arg, "-" ) ) {
    433415                        // strip inappropriate flags
     
    474456        #ifdef __DEBUG_H__
    475457        cerr << "args:";
    476         for ( i = 1; i < nargs; i += 1 ) {
     458        for ( int i = 1; i < nargs; i += 1 ) {
    477459                cerr << " " << args[i];
    478460        } // for
     
    490472        #ifdef __DEBUG_H__
    491473        cerr << "stage2 nargs: " << nargs << endl;
    492         for ( i = 0; args[i] != NULL; i += 1 ) {
     474        for ( int i = 0; args[i] != NULL; i += 1 ) {
    493475                cerr << args[i] << " ";
    494476        } // for
     
    504486int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) {
    505487        #ifdef __DEBUG_H__
    506         for ( int i = 0; env[i] != NULL; i += 1 ) {
     488        for ( int int i = 0; env[i] != NULL; i += 1 ) {
    507489                cerr << env[i] << endl;
    508490        } // for
Note: See TracChangeset for help on using the changeset viewer.