Changeset bdd516a for driver/cc1.cc


Ignore:
Timestamp:
Apr 28, 2015, 4:21:36 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
42e2ad7
Parents:
ad17ba6a
Message:

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cc1.cc

    rad17ba6a rbdd516a  
    88// Created On       : Fri Aug 26 14:23:51 2005
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Sat Jan 10 14:16:06 2015
    11 // Update Count     : 15
     10// Last Modified On : Mon Apr 27 23:11:52 2015
     11// Update Count     : 39
    1212//
    1313
     
    3434string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" );
    3535
     36char tmpname[] = P_tmpdir "/CFAXXXXXX";
     37int tmpfilefd = -1;
     38
    3639
    3740bool prefix( string arg, string pre ) {
     
    6972    } // if
    7073} // checkEnv
     74
     75
     76void rmtmpfile() {
     77    if ( unlink( tmpname ) == -1 ) {                    // remove tmpname
     78        perror ( "CFA Translator error: cpp failed" );
     79        exit( EXIT_FAILURE );
     80    } // if
     81    tmpfilefd = -1;                                     // mark closed
     82} // rmtmpfile
     83
     84
     85void sigTermHandler( int signal ) {
     86    if ( tmpfilefd != -1 ) {                            // RACE, file created ?
     87        rmtmpfile();                                    // remove
     88        exit( EXIT_FAILURE );                           // terminate
     89    } // if
     90} // sigTermHandler
    7191
    7292
     
    89109    const char *uargs[20];                              // leave space for 20 additional cfa-cpp command line values
    90110    int nuargs = 1;                                     // 0 => command name
     111
     112    signal( SIGINT,  sigTermHandler );
     113    signal( SIGTERM, sigTermHandler );
    91114
    92115    // process all the arguments
     
    116139                i += 1;                                 // and the argument
    117140
    118             // strip cfa flags controlling cpp step
    119 
     141            // strip flags controlling cpp step
     142
     143            } else if ( arg == "-D__CPP__" ) {
     144                cpp_flag = true;
     145            } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {
     146                i += 1;                                 // and the argument
     147                cpp_flag = true;
    120148            } else if ( arg == "-D__CFA__" ) {
    121149                CFA_flag = true;
     
    123151                i += 1;                                 // and the argument
    124152                CFA_flag = true;
    125             } else if ( arg == "-D__CPP__" ) {
    126                 cpp_flag = true;
    127             } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {
    128                 i += 1;                                 // and the argument
    129                 cpp_flag = true;
    130153            } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) {
    131154                uargs[nuargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str();
     
    233256    // Create a temporary file to store output of the C preprocessor.
    234257
    235     char tmpname[] = P_tmpdir "/CFAXXXXXX";
    236     int tmpfile = mkstemp( tmpname );
    237     if ( tmpfile == -1 ) {
     258    tmpfilefd = mkstemp( tmpname );
     259    if ( tmpfilefd == -1 ) {
    238260        perror( "CFA Translator error: cpp level, mkstemp" );
    239261        exit( EXIT_FAILURE );
     
    241263
    242264#ifdef __DEBUG_H__
    243     cerr << "tmpname:" << tmpname << " tmpfile:" << tmpfile << endl;
     265    cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl;
    244266#endif // __DEBUG_H__
    245267
     
    280302
    281303    if ( WIFSIGNALED(code) != 0 ) {                     // child failed ?
    282         unlink( tmpname );                              // remove tmpname
     304        rmtmpfile();                                    // remove tmpname
    283305        cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl;
    284306        exit( EXIT_FAILURE );
     
    286308
    287309    if ( WEXITSTATUS(code) != 0 ) {                     // child error ?
    288         unlink( tmpname );                              // remove tmpname
     310        rmtmpfile();                                    // remove tmpname
    289311        exit( WEXITSTATUS( code ) );                    // do not continue
    290312    } // if
     
    293315    // output.  Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.
    294316
    295     if ( CFA_flag || fork() == 0 ) {                    // conditional fork ?
     317    if ( fork() == 0 ) {                                // child runs CFA
    296318        uargs[0] = ( *new string( bprefix + "/cfa-cpp" ) ).c_str();
    297319
     
    330352
    331353    // Must unlink here because file must exist across execvp.
    332     if ( unlink( tmpname ) == -1 ) {
    333         perror( "CFA Translator error: cpp level, unlink" );
    334         exit( EXIT_FAILURE );
    335     } // if
     354    rmtmpfile();                                        // remove tmpname
    336355
    337356    if ( WIFSIGNALED(code) ) {                          // child failed ?
Note: See TracChangeset for help on using the changeset viewer.