Changes in src/driver/cc1.cc [dffaeac:e3215c5]
- File:
-
- 1 edited
-
src/driver/cc1.cc (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/driver/cc1.cc
rdffaeac re3215c5 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 13 17:40:10201813 // Update Count : 11012 // Last Modified On : Sat May 12 16:11:53 2018 13 // Update Count : 94 14 14 // 15 15 … … 44 44 } // prefix 45 45 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 } // for58 return false;59 } // suffix60 61 46 62 47 void checkEnv( const char *args[], int &nargs ) { … … 66 51 if ( value != NULL ) { 67 52 compiler_name = value; 68 #ifdef __DEBUG_H__53 #ifdef __DEBUG_H__ 69 54 cerr << "env arg:\"" << compiler_name << "\"" << endl; 70 #endif // __DEBUG_H__55 #endif // __DEBUG_H__ 71 56 } // if 72 57 … … 74 59 if ( value != NULL ) { 75 60 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 76 #ifdef __DEBUG_H__61 #ifdef __DEBUG_H__ 77 62 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 78 #endif // __DEBUG_H__63 #endif // __DEBUG_H__ 79 64 nargs += 1; 80 65 } // if … … 83 68 if ( value != NULL ) { 84 69 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 85 #ifdef __DEBUG_H__70 #ifdef __DEBUG_H__ 86 71 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 87 #endif // __DEBUG_H__72 #endif // __DEBUG_H__ 88 73 nargs += 1; 89 74 } // if … … 130 115 signal( SIGTERM, sigTermHandler ); 131 116 132 #ifdef __DEBUG_H__117 #ifdef __DEBUG_H__ 133 118 cerr << "Stage1" << endl; 134 #endif // __DEBUG_H__119 #endif // __DEBUG_H__ 135 120 136 121 // process all the arguments … … 139 124 140 125 for ( i = 1; i < argc; i += 1 ) { 141 #ifdef __DEBUG_H__126 #ifdef __DEBUG_H__ 142 127 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 143 #endif // __DEBUG_H__128 #endif // __DEBUG_H__ 144 129 arg = argv[i]; 145 #ifdef __DEBUG_H__130 #ifdef __DEBUG_H__ 146 131 cerr << "arg:\"" << arg << "\"" << endl; 147 #endif // __DEBUG_H__132 #endif // __DEBUG_H__ 148 133 if ( prefix( arg, "-" ) ) { 149 134 // strip g++ flags that are inappropriate or cause duplicates in subsequent passes … … 179 164 ncargs += 1; 180 165 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 along185 //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 along190 //nargs += 1;191 //i += 1; // and the argument166 } 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 192 177 } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) { 193 178 bprefix = arg.substr( D__GCC_BPREFIX__.size() ); … … 211 196 args[nargs] = argv[i]; // pass the argument along 212 197 nargs += 1; 213 #ifdef __DEBUG_H__198 #ifdef __DEBUG_H__ 214 199 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 215 #endif // __DEBUG_H__200 #endif // __DEBUG_H__ 216 201 } else if ( arg == "-MD" || arg == "-MMD" ) { 217 202 args[nargs] = "-MF"; // insert before file … … 220 205 args[nargs] = argv[i]; // pass the argument along 221 206 nargs += 1; 222 #ifdef __DEBUG_H__207 #ifdef __DEBUG_H__ 223 208 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 224 #endif // __DEBUG_H__209 #endif // __DEBUG_H__ 225 210 } // if 226 211 } // if … … 228 213 if ( cpp_in == NULL ) { 229 214 cpp_in = argv[i]; 230 #ifdef __DEBUG_H__215 #ifdef __DEBUG_H__ 231 216 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 232 #endif // __DEBUG_H__217 #endif // __DEBUG_H__ 233 218 } else if ( cpp_out == NULL ) { 234 219 cpp_out = argv[i]; 235 #ifdef __DEBUG_H__220 #ifdef __DEBUG_H__ 236 221 cerr << "cpp_out:\"" << cpp_out << "\""<< endl; 237 #endif // __DEBUG_H__222 #endif // __DEBUG_H__ 238 223 } else { 239 224 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; … … 243 228 } // for 244 229 245 #ifdef __DEBUG_H__230 #ifdef __DEBUG_H__ 246 231 cerr << "args:"; 247 232 for ( i = 1; i < nargs; i += 1 ) { … … 251 236 if ( cpp_out != NULL ) cerr << " " << cpp_out; 252 237 cerr << endl; 253 #endif // __DEBUG_H__238 #endif // __DEBUG_H__ 254 239 255 240 if ( cpp_in == NULL ) { … … 273 258 args[nargs] = NULL; // terminate argument list 274 259 275 #ifdef __DEBUG_H__260 #ifdef __DEBUG_H__ 276 261 cerr << "nargs: " << nargs << endl; 277 262 for ( i = 0; args[i] != NULL; i += 1 ) { … … 279 264 } // for 280 265 cerr << endl; 281 #endif // __DEBUG_H__266 #endif // __DEBUG_H__ 282 267 283 268 execvp( args[0], (char *const *)args ); // should not return … … 294 279 } // if 295 280 296 #ifdef __DEBUG_H__281 #ifdef __DEBUG_H__ 297 282 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 298 #endif // __DEBUG_H__283 #endif // __DEBUG_H__ 299 284 300 285 // Run the C preprocessor and save the output in tmpfile. … … 310 295 311 296 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 } // if318 297 args[nargs] = cpp_in; // input to cpp 319 298 nargs += 1; 320 299 args[nargs] = NULL; // terminate argument list 321 300 322 #ifdef __DEBUG_H__301 #ifdef __DEBUG_H__ 323 302 cerr << "cpp nargs: " << nargs << endl; 324 303 for ( i = 0; args[i] != NULL; i += 1 ) { … … 326 305 } // for 327 306 cerr << endl; 328 #endif // __DEBUG_H__307 #endif // __DEBUG_H__ 329 308 330 309 execvp( args[0], (char *const *)args ); // should not return … … 335 314 wait( &code ); // wait for child to finish 336 315 337 #ifdef __DEBUG_H__316 #ifdef __DEBUG_H__ 338 317 cerr << "return code from cpp:" << WEXITSTATUS(code) << endl; 339 #endif // __DEBUG_H__318 #endif // __DEBUG_H__ 340 319 341 320 if ( WIFSIGNALED(code) != 0 ) { // child failed ? … … 373 352 cargs[ncargs] = NULL; // terminate argument list 374 353 375 #ifdef __DEBUG_H__354 #ifdef __DEBUG_H__ 376 355 cerr << "cfa-cpp ncargs: " << o_name << " " << CFA_flag << " " << ncargs << endl; 377 356 for ( i = 0; cargs[i] != NULL; i += 1 ) { … … 379 358 } // for 380 359 cerr << endl; 381 #endif // __DEBUG_H__360 #endif // __DEBUG_H__ 382 361 383 362 execvp( cargs[0], (char * const *)cargs ); // should not return … … 388 367 wait( &code ); // wait for child to finish 389 368 390 #ifdef __DEBUG_H__369 #ifdef __DEBUG_H__ 391 370 cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl; 392 #endif // __DEBUG_H__371 #endif // __DEBUG_H__ 393 372 394 373 // Must unlink here because file must exist across execvp. … … 414 393 int nargs = 1; // number of arguments in args list; 0 => command name 415 394 416 #ifdef __DEBUG_H__395 #ifdef __DEBUG_H__ 417 396 cerr << "Stage2" << endl; 418 #endif // __DEBUG_H__397 #endif // __DEBUG_H__ 419 398 420 399 // process all the arguments … … 423 402 424 403 for ( i = 1; i < argc; i += 1 ) { 425 #ifdef __DEBUG_H__404 #ifdef __DEBUG_H__ 426 405 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 427 #endif // __DEBUG_H__406 #endif // __DEBUG_H__ 428 407 arg = argv[i]; 429 #ifdef __DEBUG_H__408 #ifdef __DEBUG_H__ 430 409 cerr << "arg:\"" << arg << "\"" << endl; 431 #endif // __DEBUG_H__410 #endif // __DEBUG_H__ 432 411 if ( prefix( arg, "-" ) ) { 433 412 // strip inappropriate flags 434 413 435 414 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" ) ) { 438 417 439 418 // strip inappropriate flags with an argument … … 441 420 } else if ( arg == "-auxbase" || arg == "-auxbase-strip" || arg == "-dumpbase" ) { 442 421 i += 1; 443 #ifdef __DEBUG_H__422 #ifdef __DEBUG_H__ 444 423 cerr << "arg:\"" << argv[i] << "\"" << endl; 445 #endif // __DEBUG_H__424 #endif // __DEBUG_H__ 446 425 447 426 // all other flags … … 454 433 args[nargs] = argv[i]; // pass the argument along 455 434 nargs += 1; 456 #ifdef __DEBUG_H__435 #ifdef __DEBUG_H__ 457 436 cerr << "arg:\"" << argv[i] << "\"" << endl; 458 #endif // __DEBUG_H__437 #endif // __DEBUG_H__ 459 438 } // if 460 439 } // if … … 462 441 if ( cpp_in == NULL ) { 463 442 cpp_in = argv[i]; 464 #ifdef __DEBUG_H__443 #ifdef __DEBUG_H__ 465 444 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 466 #endif // __DEBUG_H__445 #endif // __DEBUG_H__ 467 446 } else { 468 447 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; … … 472 451 } // for 473 452 474 #ifdef __DEBUG_H__453 #ifdef __DEBUG_H__ 475 454 cerr << "args:"; 476 455 for ( i = 1; i < nargs; i += 1 ) { … … 479 458 cerr << endl; 480 459 if ( cpp_in != NULL ) cerr << " " << cpp_in; 481 #endif // __DEBUG_H__460 #endif // __DEBUG_H__ 482 461 483 462 args[0] = compiler_name.c_str(); … … 488 467 args[nargs] = NULL; // terminate argument list 489 468 490 #ifdef __DEBUG_H__469 #ifdef __DEBUG_H__ 491 470 cerr << "stage2 nargs: " << nargs << endl; 492 471 for ( i = 0; args[i] != NULL; i += 1 ) { … … 494 473 } // for 495 474 cerr << endl; 496 #endif // __DEBUG_H__475 #endif // __DEBUG_H__ 497 476 498 477 execvp( args[0], (char * const *)args ); // should not return … … 503 482 504 483 int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) { 505 #ifdef __DEBUG_H__484 #ifdef __DEBUG_H__ 506 485 for ( int i = 0; env[i] != NULL; i += 1 ) { 507 486 cerr << env[i] << endl; 508 487 } // for 509 #endif // __DEBUG_H__488 #endif // __DEBUG_H__ 510 489 511 490 string arg = argv[1];
Note:
See TracChangeset
for help on using the changeset viewer.