Changeset 58fe85a for driver/cc1.cc
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- 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. - File:
-
- 1 edited
-
driver/cc1.cc (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
r3c64c668 r58fe85a 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Oct 20 08:14:33 201913 // Update Count : 38512 // Last Modified On : Tue Nov 17 14:27:08 2020 13 // Update Count : 414 14 14 // 15 15 … … 24 24 #include <unistd.h> // execvp, fork, unlink 25 25 #include <sys/wait.h> // wait 26 #include <fcntl.h> 26 #include <fcntl.h> // creat 27 27 28 28 … … 38 38 static string o_file; 39 39 static string bprefix; 40 static string lang; // -x flag 40 41 41 42 … … 58 59 59 60 60 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // " N__=" suffix61 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "__CFA_FLAG__=" suffix 61 62 62 63 static void checkEnv1( const char * args[], int & nargs ) { // stage 1 … … 73 74 if ( prefix( val, "-compiler=" ) ) { 74 75 compiler_path = val.substr( 10 ); 76 } else if ( prefix( val, "-x=" ) ) { 77 lang = val.substr( 3 ); 75 78 } // if 76 79 } // if … … 94 97 } else if ( val == "-CFA" ) { 95 98 CFA_flag = true; 96 } else if ( val == "-save-temps" ) {99 } else if ( val == "-save-temps" || val == "--save-temps" ) { 97 100 save_temps = true; 98 101 } else if ( prefix( val, "-o=" ) ) { // output file for -CFA … … 100 103 } else if ( prefix( val, "-B=" ) ) { // location of cfa-cpp 101 104 bprefix = val.substr( 3 ); 105 } else if ( prefix( val, "-x=" ) ) { // ignore 102 106 } else { // normal flag for cfa-cpp 103 107 args[nargs++] = ( *new string( arg.substr( arg.find_first_of( "=" ) + 1 ) ) ).c_str(); … … 107 111 } // checkEnv2 108 112 109 110 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa"; 113 #define CFA_SUFFIX ".ifa" 114 115 static char tmpname[] = P_tmpdir "/CFAXXXXXX" CFA_SUFFIX; 111 116 static int tmpfilefd = -1; 112 117 static bool startrm = false; … … 166 171 if ( arg == "-quiet" ) { 167 172 } else if ( arg == "-imultilib" || arg == "-imultiarch" ) { 168 i += 1; // and theargument173 i += 1; // and argument 169 174 } else if ( prefix( arg, "-A" ) ) { 170 175 } else if ( prefix( arg, "-D__GNU" ) ) { … … 173 178 //******** 174 179 } else if ( arg == "-D" && prefix( argv[i + 1], "__GNU" ) ) { 175 i += 1; // and theargument180 i += 1; // and argument 176 181 177 182 // strip flags controlling cpp step … … 180 185 cpp_flag = true; 181 186 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) { 182 i += 1; // and theargument187 i += 1; // and argument 183 188 cpp_flag = true; 184 189 … … 190 195 cpp_out = argv[i]; 191 196 } else { 192 args[nargs++] = argv[i]; // pass theflag along197 args[nargs++] = argv[i]; // pass flag along 193 198 // CPP flags with an argument 194 199 if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" || … … 196 201 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) { 197 202 i += 1; 198 args[nargs++] = argv[i]; // pass theargument along203 args[nargs++] = argv[i]; // pass argument along 199 204 #ifdef __DEBUG_H__ 200 205 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 201 206 #endif // __DEBUG_H__ 202 207 } 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. 203 210 args[nargs++] = "-MF"; // insert before file 204 211 i += 1; 205 args[nargs++] = argv[i]; // pass theargument along212 args[nargs++] = argv[i]; // pass argument along 206 213 #ifdef __DEBUG_H__ 207 214 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; … … 247 254 248 255 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 250 262 args[nargs++] = cpp_in; 251 263 if ( o_flag ) { // location for output … … 270 282 // Run the C preprocessor and save the output in the given file. 271 283 272 if ( fork() == 0 ) { // child process ?284 if ( fork() == 0 ) { // child process ? 273 285 // -o xxx.ii cannot be used to write the output file from cpp because no output file is created if cpp detects 274 286 // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error, … … 280 292 281 293 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 283 300 args[nargs++] = cpp_in; // input to cpp 284 301 args[nargs] = nullptr; // terminate argument list … … 305 322 306 323 if ( WIFSIGNALED(code) ) { // child failed ? 324 rmtmpfile(); // remove tmpname 307 325 cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl; 308 326 exit( EXIT_FAILURE ); 309 327 } // if 310 328 311 exit( WEXITSTATUS( code) );// bad cpp result stops top-level gcc329 exit( WEXITSTATUS( code ) ); // bad cpp result stops top-level gcc 312 330 } // Stage1 313 331 … … 357 375 } else if ( arg == "-fno-diagnostics-color" ) { 358 376 color_arg = Color_Auto; 359 } 377 } // if 360 378 361 379 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" ) ) { 364 382 365 383 // strip inappropriate flags with an argument … … 374 392 375 393 } else { 376 args[nargs++] = argv[i]; // pass theflag along394 args[nargs++] = argv[i]; // pass flag along 377 395 if ( arg == "-o" ) { 378 396 i += 1; 379 397 cpp_out = argv[i]; 380 args[nargs++] = argv[i]; // pass theargument along398 args[nargs++] = argv[i]; // pass argument along 381 399 #ifdef __DEBUG_H__ 382 400 cerr << "arg:\"" << argv[i] << "\"" << endl; … … 425 443 } // if 426 444 427 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";445 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + CFA_SUFFIX; 428 446 if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) { 429 447 perror( "CC1 Translator error: stage 2, creat" ); … … 446 464 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 447 465 448 if ( fork() == 0 ) { // child runs CFA 466 if ( fork() == 0 ) { // child runs CFA preprocessor 449 467 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str(); 450 468 cargs[ncargs++] = cpp_in; … … 504 522 #endif // __DEBUG_H__ 505 523 506 if ( fork() == 0 ) { // child runs CFA524 if ( fork() == 0 ) { // child runs gcc 507 525 args[0] = compiler_path.c_str(); 508 526 args[nargs++] = "-S"; // only compile and put assembler output in specified file
Note:
See TracChangeset
for help on using the changeset viewer.