Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cc1.cc

    r49d3128 rbbb1b35  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Oct 20 08:14:33 2019
    13 // Update Count     : 385
     12// Last Modified On : Fri Aug 23 15:06:27 2019
     13// Update Count     : 371
    1414//
    1515
     
    3333
    3434
    35 static string compiler_path( CFA_BACKEND_CC );                  // C compiler path/name
     35static string installlibdir( CFA_LIBDIR );                              // fixed location of cc1 and cfa-cpp commands when installed
     36static string compiler_path( CFA_BACKEND_CC );                  // path/name of C compiler
    3637static bool CFA_flag = false;                                                   // -CFA flag
    3738static bool save_temps = false;                                                 // -save-temps flag
    3839static string o_file;
    39 static string bprefix;
    4040
    4141
     
    5858
    5959
    60 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
     60static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
    6161
    6262static void checkEnv1( const char * args[], int & nargs ) { // stage 1
     
    7070
    7171                if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) {
    72                         string val( arg.substr( arg.find_first_of( "=" ) + 1 ) );
     72                        string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) );
    7373                        if ( prefix( val, "-compiler=" ) ) {
    7474                                compiler_path = val.substr( 10 );
     
    8989
    9090                if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) {
    91                         string val( arg.substr( arg.find_first_of( "=" ) + 1 ) );
     91                        string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) );
    9292                        if ( prefix( val, "-compiler=" ) ) {
    9393                                compiler_path = val.substr( 10 );
     
    9898                        } else if ( prefix( val, "-o=" ) ) {            // output file for -CFA
    9999                                o_file = val.substr( 3 );
    100                         } else if ( prefix( val, "-B=" ) ) {            // location of cfa-cpp
    101                                 bprefix = val.substr( 3 );
    102                         } else {                                                                        // normal flag for cfa-cpp
    103                                 args[nargs++] = ( *new string( arg.substr( arg.find_first_of( "=" ) + 1 ) ) ).c_str();
     100                        } else {
     101                                args[nargs++] = ( *new string( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ) ).c_str();
    104102                        } // if
    105103                } // if
     
    108106
    109107
    110 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa";
     108static char tmpname[] = P_tmpdir "/CFAXXXXXX.i";
    111109static int tmpfilefd = -1;
    112110static bool startrm = false;
     
    293291
    294292                execvp( args[0], (char * const *)args );                // should not return
    295                 perror( "CC1 Translator error: stage 1 cpp, execvp" );
    296                 cerr << " invoked " << args[0] << endl;
     293                perror( "CC1 Translator error: stage 1, execvp" );
    297294                exit( EXIT_FAILURE );
    298295        } // if
     
    335332        #endif // __DEBUG_H__
    336333
    337         enum {
    338                 Color_Auto   = 0,
    339                 Color_Always = 1,
    340                 Color_Never  = 2,
    341         } color_arg = Color_Auto;
    342 
    343         const char * color_names[3] = { "--colors=auto", "--colors=always", "--colors=never" };
    344 
    345334        // process all the arguments
    346335
     
    349338                if ( prefix( arg, "-" ) ) {
    350339                        // strip inappropriate flags
    351 
    352                         if ( prefix( arg, "-fdiagnostics-color=" ) ) {
    353                                 string choice = arg.substr(20);
    354                                      if(choice == "always") color_arg = Color_Always;
    355                                 else if(choice == "never" ) color_arg = Color_Never;
    356                                 else if(choice == "auto"  ) color_arg = Color_Auto;
    357                         } else if ( arg == "-fno-diagnostics-color" ) {
    358                                 color_arg = Color_Auto;
    359                         }
    360340
    361341                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
     
    431411                        } // if
    432412                } else {
    433                         tmpfilefd = mkstemps( tmpname, 4 );
     413                        tmpfilefd = mkstemps( tmpname, 2 );
    434414                        if ( tmpfilefd == -1 ) {
    435415                                perror( "CC1 Translator error: stage 2, mkstemp" );
     
    447427
    448428        if ( fork() == 0 ) {                                                            // child runs CFA
    449                 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();
     429                cargs[0] = ( *new string( installlibdir + "cfa-cpp" ) ).c_str();
     430
    450431                cargs[ncargs++] = cpp_in;
    451432
     
    457438                        cargs[ncargs++] = cfa_cpp_out.c_str();
    458439                } // if
    459 
    460                 cargs[ncargs++] = color_names[color_arg];
    461 
    462                 cargs[ncargs] = nullptr;                                                // terminate argument list
     440                cargs[ncargs] = nullptr;                                                        // terminate argument list
    463441
    464442                #ifdef __DEBUG_H__
     
    470448
    471449                execvp( cargs[0], (char * const *)cargs );              // should not return
    472                 perror( "CC1 Translator error: stage 2 cfa-cpp, execvp" );
    473                 cerr << " invoked " << cargs[0] << endl;
     450                perror( "CC1 Translator error: stage 2, execvp" );
    474451                exit( EXIT_FAILURE );
    475452        } // if
     
    507484                args[0] = compiler_path.c_str();
    508485                args[nargs++] = "-S";                                                   // only compile and put assembler output in specified file
    509                 args[nargs++] = "-x";
    510                 args[nargs++] = "cpp-output";
    511 
     486                if ( save_temps ) {                                                             // make gcc accept .ifa suffix
     487                        args[nargs++] = "-x";
     488                        args[nargs++] = "cpp-output";
     489                } // if
    512490                args[nargs++] = cfa_cpp_out.c_str();
    513491                args[nargs] = nullptr;                                                  // terminate argument list
     
    522500
    523501                execvp( args[0], (char * const *)args );                // should not return
    524                 perror( "CC1 Translator error: stage 2 cc1, execvp" );
    525                 cerr << " invoked " << args[0] << endl;
     502                perror( "CC1 Translator error: stage 2, execvp" );
    526503                exit( EXIT_FAILURE );                                                   // tell gcc not to go any further
    527504        } // if
    528505
    529506        wait( &code );                                                                          // wait for child to finish
     507
     508        if ( WIFSIGNALED(code) ) {                                                      // child failed ?
     509                rmtmpfile();                                                                    // remove tmpname
     510                cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl;
     511                exit( EXIT_FAILURE );
     512        } // if
     513
     514        #ifdef __DEBUG_H__
     515        cerr << "return code from gcc cc1:" << WEXITSTATUS(code) << endl;
     516        #endif // __DEBUG_H__
     517
    530518        rmtmpfile();                                                                            // remove tmpname
    531 
    532         if ( WIFSIGNALED(code) ) {                                                      // child failed ?
    533                 cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl;
    534                 exit( EXIT_FAILURE );
    535         } // if
    536 
    537         #ifdef __DEBUG_H__
    538         cerr << "return code from gcc cc1:" << WEXITSTATUS(code) << endl;
    539         #endif // __DEBUG_H__
    540 
    541519        exit( WEXITSTATUS( code ) );                                            // stop regardless of success or failure
    542520} // Stage2
Note: See TracChangeset for help on using the changeset viewer.