Changeset bbb1b35
- Timestamp:
- Aug 23, 2019, 5:39:48 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 330d933
- Parents:
- ef22ad6
- Location:
- driver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
ref22ad6 rbbb1b35 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 22 22:29:52201913 // Update Count : 3 2812 // Last Modified On : Fri Aug 23 15:06:27 2019 13 // Update Count : 371 14 14 // 15 15 … … 24 24 #include <unistd.h> // execvp, fork, unlink 25 25 #include <sys/wait.h> // wait 26 #include <fcntl.h> 27 26 28 27 29 #include "config.h" // configure info … … 34 36 static string compiler_path( CFA_BACKEND_CC ); // path/name of C compiler 35 37 static bool CFA_flag = false; // -CFA flag 38 static bool save_temps = false; // -save-temps flag 36 39 static string o_file; 40 37 41 38 42 static bool prefix( const string & arg, const string & pre ) { … … 44 48 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 45 49 46 //std::cerr << arg << std::endl;47 50 size_t dot = arg.find_last_of( "." ); 48 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;49 51 if ( dot == string::npos ) return; 50 52 const string * end = suffixes + NumSuffixes; … … 62 64 63 65 for ( int i = 0; environ[i]; i += 1 ) { 64 string arg = environ[i];66 string arg( environ[i] ); 65 67 #ifdef __DEBUG_H__ 66 68 cerr << "env arg:\"" << arg << "\"" << endl; … … 68 70 69 71 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 70 string val = arg.substr( __CFA_FLAGPREFIX__.size() + 4);72 string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ); 71 73 if ( prefix( val, "-compiler=" ) ) { 72 74 compiler_path = val.substr( 10 ); … … 81 83 82 84 for ( int i = 0; environ[i]; i += 1 ) { 83 string arg = environ[i];85 string arg( environ[i] ); 84 86 #ifdef __DEBUG_H__ 85 87 cerr << "env arg:\"" << arg << "\"" << endl; … … 87 89 88 90 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 89 string val = arg.substr( __CFA_FLAGPREFIX__.size() + 4);91 string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ); 90 92 if ( prefix( val, "-compiler=" ) ) { 91 93 compiler_path = val.substr( 10 ); 92 } else if ( prefix( val, "-CFA" )) {94 } else if ( val == "-CFA" ) { 93 95 CFA_flag = true; 96 } else if ( val == "-save-temps" ) { 97 save_temps = true; 94 98 } else if ( prefix( val, "-o=" ) ) { // output file for -CFA 95 99 o_file = val.substr( 3 ); … … 107 111 108 112 static void rmtmpfile() { 113 if ( tmpfilefd == -1 ) return; // RACE, file created ? 114 109 115 startrm = true; // RACE with C-c C-c 110 116 if ( unlink( tmpname ) == -1 ) { // remove tmpname … … 130 136 string arg; 131 137 132 const char * cpp_in = NULL;133 const char * cpp_out = NULL;138 const char * cpp_in = nullptr; 139 const char * cpp_out = nullptr; 134 140 135 141 bool cpp_flag = false; 136 142 bool o_flag = false; 137 143 138 const char * args[argc + 100]; // leave space for 100 additional cpp command line values144 const char * args[argc + 100]; // leave space for 100 additional cpp command line values 139 145 int nargs = 1; // number of arguments in args list; 0 => command name 140 146 … … 202 208 } // if 203 209 } else { // obtain input and possibly output files 204 if ( cpp_in == NULL) {210 if ( cpp_in == nullptr ) { 205 211 cpp_in = argv[i]; 206 212 #ifdef __DEBUG_H__ 207 213 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 208 214 #endif // __DEBUG_H__ 209 } else if ( cpp_out == NULL) {215 } else if ( cpp_out == nullptr ) { 210 216 cpp_out = argv[i]; 211 217 #ifdef __DEBUG_H__ … … 224 230 cerr << " " << args[i]; 225 231 } // for 226 if ( cpp_in != NULL) cerr << " " << cpp_in;227 if ( cpp_out != NULL) cerr << " " << cpp_out;232 if ( cpp_in != nullptr ) cerr << " " << cpp_in; 233 if ( cpp_out != nullptr ) cerr << " " << cpp_out; 228 234 cerr << endl; 229 235 #endif // __DEBUG_H__ 230 236 231 if ( cpp_in == NULL) {237 if ( cpp_in == nullptr ) { 232 238 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; 233 239 exit( EXIT_FAILURE ); … … 245 251 } // if 246 252 args[nargs++] = cpp_out; 247 args[nargs] = NULL;// terminate argument list253 args[nargs] = nullptr; // terminate argument list 248 254 249 255 #ifdef __DEBUG_H__ 250 256 cerr << "nargs: " << nargs << endl; 251 for ( int i = 0; args[i] != NULL; i += 1 ) {257 for ( int i = 0; args[i] != nullptr; i += 1 ) { 252 258 cerr << args[i] << " "; 253 259 } // for … … 255 261 #endif // __DEBUG_H__ 256 262 257 execvp( args[0], (char * const *)args );// should not return263 execvp( args[0], (char * const *)args ); // should not return 258 264 perror( "CC1 Translator error: stage 1, execvp" ); 259 265 exit( EXIT_FAILURE ); … … 266 272 // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error, 267 273 // when cpp writes to stdout. Hence, stdout is redirected into the temporary file. 268 if ( freopen( cpp_out, "w", stdout ) == NULL) { // redirect stdout to output file274 if ( freopen( cpp_out, "w", stdout ) == nullptr ) { // redirect stdout to output file 269 275 perror( "CC1 Translator error: stage 1, freopen" ); 270 276 exit( EXIT_FAILURE ); … … 274 280 suffix( cpp_in, args, nargs ); // check suffix 275 281 args[nargs++] = cpp_in; // input to cpp 276 args[nargs] = NULL;// terminate argument list282 args[nargs] = nullptr; // terminate argument list 277 283 278 284 #ifdef __DEBUG_H__ 279 285 cerr << "cpp nargs: " << nargs << endl; 280 for ( int i = 0; args[i] != NULL; i += 1 ) {286 for ( int i = 0; args[i] != nullptr; i += 1 ) { 281 287 cerr << args[i] << " "; 282 288 } // for … … 284 290 #endif // __DEBUG_H__ 285 291 286 execvp( args[0], (char * const *)args );// should not return292 execvp( args[0], (char * const *)args ); // should not return 287 293 perror( "CC1 Translator error: stage 1, execvp" ); 288 294 exit( EXIT_FAILURE ); … … 308 314 string arg; 309 315 310 const char * cpp_in = NULL;311 const char * cpp_out = NULL;312 313 const char * args[argc + 100]; // leave space for 100 additional cfa command line values316 const char * cpp_in = nullptr; 317 const char * cpp_out = nullptr; 318 319 const char * args[argc + 100]; // leave space for 100 additional cfa command line values 314 320 int nargs = 1; // number of arguments in args list; 0 => command name 315 const char * cargs[20]; // leave space for 20 additional cfa-cpp command line values321 const char * cargs[20]; // leave space for 20 additional cfa-cpp command line values 316 322 int ncargs = 1; // 0 => command name 317 323 … … 359 365 } // if 360 366 } else { // obtain input and possibly output files 361 if ( cpp_in == NULL) {367 if ( cpp_in == nullptr ) { 362 368 cpp_in = argv[i]; 363 369 #ifdef __DEBUG_H__ 364 370 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 365 371 #endif // __DEBUG_H__ 366 } else if ( cpp_out == NULL) {372 } else if ( cpp_out == nullptr ) { 367 373 cpp_out = argv[i]; 368 374 #ifdef __DEBUG_H__ … … 370 376 #endif // __DEBUG_H__ 371 377 } else { 372 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;378 cerr << "Usage: " << argv[0] << " more than two files specified" << endl; 373 379 exit( EXIT_FAILURE ); 374 380 } // if 375 381 } // if 376 382 } // for 383 384 if ( cpp_in == nullptr ) { 385 cerr << "Usage: " << argv[0] << " missing input file" << endl; 386 exit( EXIT_FAILURE ); 387 } // if 388 if ( cpp_out == nullptr ) { 389 cerr << "Usage: " << argv[0] << " missing output file" << endl; 390 exit( EXIT_FAILURE ); 391 } // if 377 392 378 393 // Create a temporary file, if needed, to store output of the cfa-cpp preprocessor. Cannot be created in forked 379 394 // process because variables tmpname and tmpfilefd are cloned. 380 395 381 if ( ! CFA_flag ) { // run cfa-cpp ? 382 tmpfilefd = mkstemps( tmpname, 2 ); 383 if ( tmpfilefd == -1 ) { 384 perror( "CC1 Translator error: stage 2, mkstemp" ); 385 exit( EXIT_FAILURE ); 386 } // if 387 388 #ifdef __DEBUG_H__ 389 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 396 string cfa_cpp_out; 397 398 if ( ! CFA_flag ) { // run compiler ? 399 if ( save_temps ) { 400 cfa_cpp_out = cpp_in; 401 size_t dot = cfa_cpp_out.find_last_of( "." ); 402 if ( dot == string::npos ) { 403 cerr << "CC1 Translator error: stage 2, bad file name " << endl; 404 exit( EXIT_FAILURE ); 405 } // if 406 407 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa"; 408 if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) { 409 perror( "CC1 Translator error: stage 2, creat" ); 410 exit( EXIT_FAILURE ); 411 } // if 412 } else { 413 tmpfilefd = mkstemps( tmpname, 2 ); 414 if ( tmpfilefd == -1 ) { 415 perror( "CC1 Translator error: stage 2, mkstemp" ); 416 exit( EXIT_FAILURE ); 417 } // if 418 cfa_cpp_out = tmpname; 419 } // if 420 #ifdef __DEBUG_H__ 421 cerr << "cfa_cpp_out: " << cfa_cpp_out << endl; 390 422 #endif // __DEBUG_H__ 391 423 } // if … … 404 436 } // if 405 437 } else { 406 cargs[ncargs++] = tmpname;407 } // if 408 cargs[ncargs] = NULL; // terminate argument list409 410 #ifdef __DEBUG_H__ 411 for ( int i = 0; cargs[i] != NULL; i += 1 ) {438 cargs[ncargs++] = cfa_cpp_out.c_str(); 439 } // if 440 cargs[ncargs] = nullptr; // terminate argument list 441 442 #ifdef __DEBUG_H__ 443 for ( int i = 0; cargs[i] != nullptr; i += 1 ) { 412 444 cerr << cargs[i] << " "; 413 445 } // for … … 446 478 cerr << " " << args[i]; 447 479 } // for 448 cerr << endl; 449 if ( cpp_in != NULL ) cerr << " " << cpp_in; 480 cerr << " " << cpp_in << endl; 450 481 #endif // __DEBUG_H__ 451 482 … … 453 484 args[0] = compiler_path.c_str(); 454 485 args[nargs++] = "-S"; // only compile and put assembler output in specified file 455 args[nargs++] = tmpname; 456 args[nargs] = NULL; // terminate argument list 486 if ( save_temps ) { // make gcc accept .ifa suffix 487 args[nargs++] = "-x"; 488 args[nargs++] = "cpp-output"; 489 } // if 490 args[nargs++] = cfa_cpp_out.c_str(); 491 args[nargs] = nullptr; // terminate argument list 457 492 458 493 #ifdef __DEBUG_H__ 459 494 cerr << "stage2 nargs: " << nargs << endl; 460 for ( int i = 0; args[i] != NULL; i += 1 ) {495 for ( int i = 0; args[i] != nullptr; i += 1 ) { 461 496 cerr << args[i] << " "; 462 497 } // for … … 493 528 int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) { 494 529 #ifdef __DEBUG_H__ 495 for ( int i = 0; env[i] != NULL; i += 1 ) {530 for ( int i = 0; env[i] != nullptr; i += 1 ) { 496 531 cerr << env[i] << endl; 497 532 } // for … … 501 536 signal( SIGTERM, sigTermHandler ); 502 537 503 string arg = argv[1];538 string arg( argv[1] ); 504 539 505 540 // Currently, stage 1 starts with flag -E and stage 2 with flag -fpreprocessed. -
driver/cfa.cc
ref22ad6 rbbb1b35 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 22 22:29:50201913 // Update Count : 4 0312 // Last Modified On : Fri Aug 23 16:27:07 2019 13 // Update Count : 411 14 14 // 15 15 … … 39 39 static int flags = 0; // environment variables must have unique names 40 40 41 if ( putenv( (char *)( *new string( string( "__CFA_FLAG" + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) != 0) {41 if ( putenv( (char *)( *new string( string( "__CFA_FLAG" + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) { 42 42 cerr << argv[0] << " error, cannot set environment variable." << endl; 43 43 exit( EXIT_FAILURE ); … … 89 89 90 90 bool x_flag = false; // -x flag 91 bool nonoptarg = false; // indicates non-option argument specified92 bool link = true; // link ing as well as compiling91 bool nonoptarg = false; // no non-option arguments specified, i.e., no file names 92 bool link = true; // link stage occurring 93 93 bool verbose = false; // -v flag 94 94 bool quiet = false; // -quiet flag … … 103 103 bool m32 = false; // -m32 flag 104 104 bool m64 = false; // -m64 flag 105 bool intree = false; 105 bool intree = false; // build in tree 106 106 int o_file = 0; // -o filename position 107 107 … … 176 176 debugging = true; // symbolic debugging required 177 177 args[nargs++] = argv[i]; // pass argument along 178 } else if ( arg == "-save-temps" ) { 179 args[nargs++] = argv[i]; // pass argument along 180 Putenv( argv, arg ); // save cfa-cpp output 178 181 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 179 182 string lang; … … 258 261 #endif // __DEBUG_H__ 259 262 260 // if ( cpp_flag && CFA_flag ) { 261 // cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; 262 // exit( EXIT_FAILURE ); 263 // } // if 263 // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed. 264 if ( cpp_flag && CFA_flag ) { 265 cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; 266 exit( EXIT_FAILURE ); 267 } // if 264 268 265 269 // add the CFA include-library paths, which allow direct access to header files without directory qualification … … 292 296 } // if 293 297 294 string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);298 string arch( m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU) ); 295 299 if ( ! m32 && ! m64 ) { 296 300 if ( arch == "x86" ) { … … 301 305 } // if 302 306 303 string libdir = libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug"));307 string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) ); 304 308 if ( ! dirExists( libdir ) ) { 305 309 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl; … … 350 354 Putenv( argv, "-N" ); 351 355 Putenv( argv, "-CFA" ); 356 // -CFA implies cc1 stage 2, but gcc does not pass the -o file to this stage because it believe the file is for 357 // the linker. Hence, the -o file is explicit passed to cc1 stage 2 and used as cfa-cpp's output file. 352 358 if ( o_file ) Putenv( argv, string( "-o=" ) + argv[o_file] ); 353 359 } else { … … 401 407 } // if 402 408 403 args[nargs] = NULL;// terminate409 args[nargs] = nullptr; // terminate 404 410 405 411 #ifdef __DEBUG_H__ 406 412 cerr << "nargs: " << nargs << endl; 407 413 cerr << "args:" << endl; 408 for ( int i = 0; args[i] != NULL; i += 1 ) {414 for ( int i = 0; args[i] != nullptr; i += 1 ) { 409 415 cerr << " \"" << args[i] << "\"" << endl; 410 416 } // for … … 428 434 if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc 429 435 430 for ( int i = 0; args[i] != NULL; i += 1 ) {436 for ( int i = 0; args[i] != nullptr; i += 1 ) { 431 437 cerr << args[i] << " "; 432 438 } // for
Note: See TracChangeset
for help on using the changeset viewer.