Changeset 58fe85a for driver/cc1.cc


Ignore:
Timestamp:
Jan 7, 2021, 3:27:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
2b4daf2, 64aeca0
Parents:
3c64c668 (diff), eef8dfb (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 park_unpark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cc1.cc

    r3c64c668 r58fe85a  
    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 : Tue Nov 17 14:27:08 2020
     13// Update Count     : 414
    1414//
    1515
     
    2424#include <unistd.h>                                                                             // execvp, fork, unlink
    2525#include <sys/wait.h>                                                                   // wait
    26 #include <fcntl.h>
     26#include <fcntl.h>                                                                              // creat
    2727
    2828
     
    3838static string o_file;
    3939static string bprefix;
     40static string lang;                                                                             // -x flag
    4041
    4142
     
    5859
    5960
    60 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
     61static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
    6162
    6263static void checkEnv1( const char * args[], int & nargs ) { // stage 1
     
    7374                        if ( prefix( val, "-compiler=" ) ) {
    7475                                compiler_path = val.substr( 10 );
     76                        } else if ( prefix( val, "-x=" ) ) {
     77                                lang = val.substr( 3 );
    7578                        } // if
    7679                } // if
     
    9497                        } else if ( val == "-CFA" ) {
    9598                                CFA_flag = true;
    96                         } else if ( val == "-save-temps" ) {
     99                        } else if ( val == "-save-temps" || val == "--save-temps" ) {
    97100                                save_temps = true;
    98101                        } else if ( prefix( val, "-o=" ) ) {            // output file for -CFA
     
    100103                        } else if ( prefix( val, "-B=" ) ) {            // location of cfa-cpp
    101104                                bprefix = val.substr( 3 );
     105                        } else if ( prefix( val, "-x=" ) ) {            // ignore
    102106                        } else {                                                                        // normal flag for cfa-cpp
    103107                                args[nargs++] = ( *new string( arg.substr( arg.find_first_of( "=" ) + 1 ) ) ).c_str();
     
    107111} // checkEnv2
    108112
    109 
    110 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa";
     113#define CFA_SUFFIX ".ifa"
     114
     115static char tmpname[] = P_tmpdir "/CFAXXXXXX" CFA_SUFFIX;
    111116static int tmpfilefd = -1;
    112117static bool startrm = false;
     
    166171                        if ( arg == "-quiet" ) {
    167172                        } else if ( arg == "-imultilib" || arg == "-imultiarch" ) {
    168                                 i += 1;                                                                 // and the argument
     173                                i += 1;                                                                 // and argument
    169174                        } else if ( prefix( arg, "-A" ) ) {
    170175                        } else if ( prefix( arg, "-D__GNU" ) ) {
     
    173178                                //********
    174179                        } else if ( arg == "-D" && prefix( argv[i + 1], "__GNU" ) ) {
    175                                 i += 1;                                                                 // and the argument
     180                                i += 1;                                                                 // and argument
    176181
    177182                                // strip flags controlling cpp step
     
    180185                                cpp_flag = true;
    181186                        } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {
    182                                 i += 1;                                                                 // and the argument
     187                                i += 1;                                                                 // and argument
    183188                                cpp_flag = true;
    184189
     
    190195                                cpp_out = argv[i];
    191196                        } else {
    192                                 args[nargs++] = argv[i];                                // pass the flag along
     197                                args[nargs++] = argv[i];                                // pass flag along
    193198                                // CPP flags with an argument
    194199                                if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||
     
    196201                                         arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {
    197202                                        i += 1;
    198                                         args[nargs++] = argv[i];                        // pass the argument along
     203                                        args[nargs++] = argv[i];                        // pass argument along
    199204                                        #ifdef __DEBUG_H__
    200205                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    201206                                        #endif // __DEBUG_H__
    202207                                } else if ( arg == "-MD" || arg == "-MMD" ) {
     208                                        // gcc frontend generates the dependency file-name after the -MD/-MMD flag, but it is necessary to
     209                                        // prefix that file name with -MF.
    203210                                        args[nargs++] = "-MF";                          // insert before file
    204211                                        i += 1;
    205                                         args[nargs++] = argv[i];                        // pass the argument along
     212                                        args[nargs++] = argv[i];                        // pass argument along
    206213                                        #ifdef __DEBUG_H__
    207214                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
     
    247254
    248255                args[0] = compiler_path.c_str();
    249                 suffix( cpp_in, args, nargs );                                  // check suffix
     256                if ( lang.size() == 0 ) {
     257                        suffix( cpp_in, args, nargs );                          // check suffix
     258                } else {
     259                        args[nargs++] = "-x";
     260                        args[nargs++] = ( *new string( lang.c_str() ) ).c_str();
     261                } // if
    250262                args[nargs++] = cpp_in;
    251263                if ( o_flag ) {                                                                 // location for output
     
    270282        // Run the C preprocessor and save the output in the given file.
    271283
    272         if ( fork() == 0 ) {                                                             // child process ?
     284        if ( fork() == 0 ) {                                                            // child process ?
    273285                // -o xxx.ii cannot be used to write the output file from cpp because no output file is created if cpp detects
    274286                // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error,
     
    280292
    281293                args[0] = compiler_path.c_str();
    282                 suffix( cpp_in, args, nargs );                                  // check suffix
     294                if ( lang.size() == 0 ) {
     295                        suffix( cpp_in, args, nargs );                          // check suffix
     296                } else {
     297                        args[nargs++] = "-x";
     298                        args[nargs++] = ( *new string( lang.c_str() ) ).c_str();
     299                } // if
    283300                args[nargs++] = cpp_in;                                                 // input to cpp
    284301                args[nargs] = nullptr;                                                  // terminate argument list
     
    305322
    306323        if ( WIFSIGNALED(code) ) {                                                      // child failed ?
     324                rmtmpfile();                                                                    // remove tmpname
    307325                cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl;
    308326                exit( EXIT_FAILURE );
    309327        } // if
    310328
    311         exit( WEXITSTATUS(code) );                                                      // bad cpp result stops top-level gcc
     329        exit( WEXITSTATUS( code ) );                                            // bad cpp result stops top-level gcc
    312330} // Stage1
    313331
     
    357375                        } else if ( arg == "-fno-diagnostics-color" ) {
    358376                                color_arg = Color_Auto;
    359                         }
     377                        } // if
    360378
    361379                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
    362                                 // Currently CFA does not suppose precompiled .h files.
    363                                 prefix( arg, "--output-pch" ) ) {
     380                                 // Currently CFA does not suppose precompiled .h files.
     381                                 prefix( arg, "--output-pch" ) ) {
    364382
    365383                                // strip inappropriate flags with an argument
     
    374392
    375393                        } else {
    376                                 args[nargs++] = argv[i];                                // pass the flag along
     394                                args[nargs++] = argv[i];                                // pass flag along
    377395                                if ( arg == "-o" ) {
    378396                                        i += 1;
    379397                                        cpp_out = argv[i];
    380                                         args[nargs++] = argv[i];                        // pass the argument along
     398                                        args[nargs++] = argv[i];                        // pass argument along
    381399                                        #ifdef __DEBUG_H__
    382400                                        cerr << "arg:\"" << argv[i] << "\"" << endl;
     
    425443                        } // if
    426444
    427                         cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";
     445                        cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + CFA_SUFFIX;
    428446                        if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) {
    429447                                perror( "CC1 Translator error: stage 2, creat" );
     
    446464        // output.  Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.
    447465
    448         if ( fork() == 0 ) {                                                            // child runs CFA
     466        if ( fork() == 0 ) {                                                            // child runs CFA preprocessor
    449467                cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();
    450468                cargs[ncargs++] = cpp_in;
     
    504522        #endif // __DEBUG_H__
    505523
    506         if ( fork() == 0 ) {                                                            // child runs CFA
     524        if ( fork() == 0 ) {                                                            // child runs gcc
    507525                args[0] = compiler_path.c_str();
    508526                args[nargs++] = "-S";                                                   // only compile and put assembler output in specified file
Note: See TracChangeset for help on using the changeset viewer.