- Timestamp:
- Aug 25, 2019, 8:48:51 AM (6 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:
- 2aab69b, 5a43ab8
- Parents:
- f9bf142 (diff), bbb1b35 (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. - Location:
- driver
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/Makefile.in
rf9bf142 r330d933 218 218 CYGPATH_W = @CYGPATH_W@ 219 219 DEFS = @DEFS@ 220 DEMANGLER = @DEMANGLER@ 220 221 DEPDIR = @DEPDIR@ 221 222 DLLTOOL = @DLLTOOL@ … … 243 244 LIBCFA_TARGET_DIRS = @LIBCFA_TARGET_DIRS@ 244 245 LIBCFA_TARGET_MAKEFILES = @LIBCFA_TARGET_MAKEFILES@ 246 LIBDEMANGLE = @LIBDEMANGLE@ 245 247 LIBOBJS = @LIBOBJS@ 246 248 LIBS = @LIBS@ -
driver/cc1.cc
rf9bf142 r330d933 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 3 16:57:05 201813 // Update Count : 12512 // Last Modified On : Fri Aug 23 15:06:27 2019 13 // Update Count : 371 14 14 // 15 15 … … 19 19 #include <string> 20 20 using std::string; 21 #include <algorithm> // find 21 22 #include <cstdio> // stderr, stdout, perror, fprintf 22 23 #include <cstdlib> // getenv, exit, mkstemp 23 24 #include <unistd.h> // execvp, fork, unlink 24 25 #include <sys/wait.h> // wait 26 #include <fcntl.h> 27 25 28 26 29 #include "config.h" // configure info … … 30 33 31 34 32 string compiler_name( CFA_BACKEND_CC ); // path/name of C compiler 33 34 string D__GCC_BPREFIX__( "-D__GCC_BPREFIX__=" ); 35 string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" ); 36 37 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 38 int tmpfilefd = -1; 39 40 41 bool prefix( string arg, string pre ) { 35 static string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands when installed 36 static string compiler_path( CFA_BACKEND_CC ); // path/name of C compiler 37 static bool CFA_flag = false; // -CFA flag 38 static bool save_temps = false; // -save-temps flag 39 static string o_file; 40 41 42 static bool prefix( const string & arg, const string & pre ) { 42 43 return arg.substr( 0, pre.size() ) == pre; 43 44 } // prefix 44 45 45 enum { NumSuffixes = 2 }; 46 const string suffixes[NumSuffixes] = { "cfa", "hfa", }; 47 48 void suffix( string arg, const char * args[], int & nargs ) { 49 //std::cerr << arg << std::endl; 46 static void suffix( const string & arg, const char * args[], int & nargs ) { 47 enum { NumSuffixes = 3 }; 48 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 49 50 50 size_t dot = arg.find_last_of( "." ); 51 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;52 51 if ( dot == string::npos ) return; 53 string sx = arg.substr( dot + 1 ); 54 for ( int i = 0; i < NumSuffixes; i += 1 ) { 55 if ( sx == suffixes[i] ) { 56 args[nargs] = "-x"; 57 nargs += 1; 58 args[nargs] = "c"; 59 nargs += 1; 60 return; 61 } // if 62 } // for 52 const string * end = suffixes + NumSuffixes; 53 if ( std::find( suffixes, end, arg.substr( dot + 1 ) ) != end ) { 54 args[nargs++] = "-x"; 55 args[nargs++] = "c"; 56 } // if 63 57 } // suffix 64 58 65 59 66 void checkEnv( const char * args[], int & nargs ) { 67 char *value; 68 69 value = getenv( "__CFA_COMPILER__" ); 70 if ( value != NULL ) { 71 compiler_name = value; 72 #ifdef __DEBUG_H__ 73 cerr << "env arg:\"" << compiler_name << "\"" << endl; 74 #endif // __DEBUG_H__ 75 } // if 76 77 value = getenv( "__GCC_MACHINE__" ); 78 if ( value != NULL ) { 79 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 80 #ifdef __DEBUG_H__ 81 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 82 #endif // __DEBUG_H__ 83 nargs += 1; 84 } // if 85 86 value = getenv( "__GCC_VERSION__" ); 87 if ( value != NULL ) { 88 args[nargs] = ( *new string( value ) ).c_str(); // pass the argument along 89 #ifdef __DEBUG_H__ 90 cerr << "env arg:\"" << args[nargs] << "\"" << endl; 91 #endif // __DEBUG_H__ 92 nargs += 1; 93 } // if 94 } // checkEnv 95 96 97 void rmtmpfile() { 60 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); 61 62 static void checkEnv1( const char * args[], int & nargs ) { // stage 1 63 extern char ** environ; 64 65 for ( int i = 0; environ[i]; i += 1 ) { 66 string arg( environ[i] ); 67 #ifdef __DEBUG_H__ 68 cerr << "env arg:\"" << arg << "\"" << endl; 69 #endif // __DEBUG_H__ 70 71 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 72 string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ); 73 if ( prefix( val, "-compiler=" ) ) { 74 compiler_path = val.substr( 10 ); 75 } // if 76 } // if 77 } // for 78 } // checkEnv1 79 80 81 static void checkEnv2( const char * args[], int & nargs ) { // stage 2 82 extern char ** environ; 83 84 for ( int i = 0; environ[i]; i += 1 ) { 85 string arg( environ[i] ); 86 #ifdef __DEBUG_H__ 87 cerr << "env arg:\"" << arg << "\"" << endl; 88 #endif // __DEBUG_H__ 89 90 if ( prefix( arg, __CFA_FLAGPREFIX__ ) ) { 91 string val( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ); 92 if ( prefix( val, "-compiler=" ) ) { 93 compiler_path = val.substr( 10 ); 94 } else if ( val == "-CFA" ) { 95 CFA_flag = true; 96 } else if ( val == "-save-temps" ) { 97 save_temps = true; 98 } else if ( prefix( val, "-o=" ) ) { // output file for -CFA 99 o_file = val.substr( 3 ); 100 } else { 101 args[nargs++] = ( *new string( arg.substr( __CFA_FLAGPREFIX__.size() + 4 ) ) ).c_str(); 102 } // if 103 } // if 104 } // for 105 } // checkEnv2 106 107 108 static char tmpname[] = P_tmpdir "/CFAXXXXXX.i"; 109 static int tmpfilefd = -1; 110 static bool startrm = false; 111 112 static void rmtmpfile() { 113 if ( tmpfilefd == -1 ) return; // RACE, file created ? 114 115 startrm = true; // RACE with C-c C-c 98 116 if ( unlink( tmpname ) == -1 ) { // remove tmpname 99 perror ( "C FA Translator error: cpp failed" );100 exit( EXIT_FAILURE ); 101 } // if 102 tmpfilefd = -1; // mark closed117 perror ( "CC1 Translator error: failed, unlink" ); 118 exit( EXIT_FAILURE ); 119 } // if 120 tmpfilefd = -1; // mark removed 103 121 } // rmtmpfile 104 122 105 123 106 void sigTermHandler( __attribute__((unused)) int signal ) { 124 static void sigTermHandler( int ) { // C-c C-c 125 if ( startrm ) return; // return and let rmtmpfile finish, and then program finishes 126 107 127 if ( tmpfilefd != -1 ) { // RACE, file created ? 108 rmtmpfile(); // remove 109 exit( EXIT_FAILURE ); // terminate110 } // if128 rmtmpfile(); // remove tmpname 129 } // if 130 exit( EXIT_FAILURE ); // terminate 111 131 } // sigTermHandler 112 132 113 133 114 void Stage1( const int argc, const char * const argv[] ) {134 static void Stage1( const int argc, const char * const argv[] ) { 115 135 int code; 116 117 136 string arg; 118 string bprefix; 119 120 const char *cpp_in = NULL; 121 const char *cpp_out = NULL; 122 123 bool CFA_flag = false; 137 138 const char * cpp_in = nullptr; 139 const char * cpp_out = nullptr; 140 124 141 bool cpp_flag = false; 125 const char *o_name = NULL;126 127 const char * args[argc + 100]; // leave space for 100 additional cpp command line values142 bool o_flag = false; 143 144 const char * args[argc + 100]; // leave space for 100 additional cpp command line values 128 145 int nargs = 1; // number of arguments in args list; 0 => command name 129 const char *cargs[20]; // leave space for 20 additional cfa-cpp command line values130 int ncargs = 1; // 0 => command name131 132 signal( SIGINT, sigTermHandler );133 signal( SIGTERM, sigTermHandler );134 146 135 147 #ifdef __DEBUG_H__ 136 148 cerr << "Stage1" << endl; 137 149 #endif // __DEBUG_H__ 138 checkEnv ( args, nargs ); // arguments passed via environment variables150 checkEnv1( args, nargs ); // arguments passed via environment variables 139 151 #ifdef __DEBUG_H__ 140 152 for ( int i = 1; i < argc; i += 1 ) { … … 168 180 i += 1; // and the argument 169 181 cpp_flag = true; 170 } else if ( arg == "-D__CFA_PREPROCESS__" ) { 171 CFA_flag = true; 172 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CFA_PREPROCESS__" ) { 173 i += 1; // and the argument 174 CFA_flag = true; 175 } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) { 176 cargs[ncargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str(); 177 ncargs += 1; 178 } else if ( arg == "-D" && prefix( argv[i + 1], D__CFA_FLAGPREFIX__.substr(2) ) ) { 179 cargs[ncargs] = ( *new string( string( argv[i + 1] ).substr( D__CFA_FLAGPREFIX__.size() - 2 ) ) ).c_str(); 180 ncargs += 1; 181 i += 1; // and the argument 182 } else if ( prefix( arg, D__GCC_BPREFIX__ ) ) { 183 bprefix = arg.substr( D__GCC_BPREFIX__.size() ); 184 } else if ( arg == "-D" && prefix( argv[i + 1], D__GCC_BPREFIX__.substr(2) ) ) { 185 bprefix = string( argv[i + 1] ).substr( D__GCC_BPREFIX__.size() - 2 ); 186 i += 1; // and the argument 187 188 // all other flags 182 183 // all other flags 189 184 190 185 } else if ( arg == "-o" ) { 191 186 i += 1; 192 o_name = argv[i]; 187 o_flag = true; 188 cpp_out = argv[i]; 193 189 } else { 194 args[nargs] = argv[i]; // pass the flag along 195 nargs += 1; 190 args[nargs++] = argv[i]; // pass the flag along 196 191 // CPP flags with an argument 197 192 if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" || … … 199 194 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) { 200 195 i += 1; 201 args[nargs] = argv[i]; // pass the argument along 202 nargs += 1; 196 args[nargs++] = argv[i]; // pass the argument along 203 197 #ifdef __DEBUG_H__ 204 198 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 205 199 #endif // __DEBUG_H__ 206 200 } else if ( arg == "-MD" || arg == "-MMD" ) { 207 args[nargs] = "-MF"; // insert before file 208 nargs += 1; 201 args[nargs++] = "-MF"; // insert before file 209 202 i += 1; 210 args[nargs] = argv[i]; // pass the argument along 211 nargs += 1; 203 args[nargs++] = argv[i]; // pass the argument along 212 204 #ifdef __DEBUG_H__ 213 205 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; … … 216 208 } // if 217 209 } else { // obtain input and possibly output files 218 if ( cpp_in == NULL) {210 if ( cpp_in == nullptr ) { 219 211 cpp_in = argv[i]; 220 212 #ifdef __DEBUG_H__ 221 213 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 222 214 #endif // __DEBUG_H__ 223 } else if ( cpp_out == NULL) {215 } else if ( cpp_out == nullptr ) { 224 216 cpp_out = argv[i]; 225 217 #ifdef __DEBUG_H__ … … 238 230 cerr << " " << args[i]; 239 231 } // for 240 if ( cpp_in != NULL) cerr << " " << cpp_in;241 if ( cpp_out != NULL) cerr << " " << cpp_out;232 if ( cpp_in != nullptr ) cerr << " " << cpp_in; 233 if ( cpp_out != nullptr ) cerr << " " << cpp_out; 242 234 cerr << endl; 243 235 #endif // __DEBUG_H__ 244 236 245 if ( cpp_in == NULL) {237 if ( cpp_in == nullptr ) { 246 238 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl; 247 239 exit( EXIT_FAILURE ); … … 252 244 // output or -o. The call to cfa has a -E so it does not have to be added to the argument list. 253 245 254 args[0] = compiler_ name.c_str();246 args[0] = compiler_path.c_str(); 255 247 suffix( cpp_in, args, nargs ); // check suffix 256 args[nargs] = cpp_in; 257 nargs += 1; 258 if ( o_name != NULL ) { // location for output 259 args[nargs] = "-o"; 260 nargs += 1; 261 args[nargs] = o_name; 262 nargs += 1; 263 } // if 264 args[nargs] = NULL; // terminate argument list 248 args[nargs++] = cpp_in; 249 if ( o_flag ) { // location for output 250 args[nargs++] = "-o"; 251 } // if 252 args[nargs++] = cpp_out; 253 args[nargs] = nullptr; // terminate argument list 265 254 266 255 #ifdef __DEBUG_H__ 267 256 cerr << "nargs: " << nargs << endl; 268 for ( int i = 0; args[i] != NULL; i += 1 ) {257 for ( int i = 0; args[i] != nullptr; i += 1 ) { 269 258 cerr << args[i] << " "; 270 259 } // for … … 272 261 #endif // __DEBUG_H__ 273 262 274 execvp( args[0], (char *const *)args ); // should not return 275 perror( "CFA Translator error: cpp level, execvp" ); 276 exit( EXIT_FAILURE ); 277 } // if 278 279 // Create a temporary file to store output of the C preprocessor. 280 281 tmpfilefd = mkstemp( tmpname ); 282 if ( tmpfilefd == -1 ) { 283 perror( "CFA Translator error: cpp level, mkstemp" ); 284 exit( EXIT_FAILURE ); 285 } // if 286 287 #ifdef __DEBUG_H__ 288 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 289 #endif // __DEBUG_H__ 290 291 // Run the C preprocessor and save the output in tmpfile. 263 execvp( args[0], (char * const *)args ); // should not return 264 perror( "CC1 Translator error: stage 1, execvp" ); 265 exit( EXIT_FAILURE ); 266 } // if 267 268 // Run the C preprocessor and save the output in the given file. 292 269 293 270 if ( fork() == 0 ) { // child process ? … … 295 272 // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error, 296 273 // when cpp writes to stdout. Hence, stdout is redirected into the temporary file. 297 if ( freopen( tmpname, "w", stdout ) == NULL ) { // redirect stdout to tmpname298 perror( "C FA Translator error: cpp level, freopen" );274 if ( freopen( cpp_out, "w", stdout ) == nullptr ) { // redirect stdout to output file 275 perror( "CC1 Translator error: stage 1, freopen" ); 299 276 exit( EXIT_FAILURE ); 300 277 } // if 301 278 302 args[0] = compiler_ name.c_str();279 args[0] = compiler_path.c_str(); 303 280 suffix( cpp_in, args, nargs ); // check suffix 304 args[nargs] = cpp_in; // input to cpp 305 nargs += 1; 306 args[nargs] = NULL; // terminate argument list 281 args[nargs++] = cpp_in; // input to cpp 282 args[nargs] = nullptr; // terminate argument list 307 283 308 284 #ifdef __DEBUG_H__ 309 285 cerr << "cpp nargs: " << nargs << endl; 310 for ( int i = 0; args[i] != NULL; i += 1 ) {286 for ( int i = 0; args[i] != nullptr; i += 1 ) { 311 287 cerr << args[i] << " "; 312 288 } // for … … 314 290 #endif // __DEBUG_H__ 315 291 316 execvp( args[0], (char * const *)args );// should not return317 perror( "C FA Translator error: cpp level, execvp" );292 execvp( args[0], (char * const *)args ); // should not return 293 perror( "CC1 Translator error: stage 1, execvp" ); 318 294 exit( EXIT_FAILURE ); 319 295 } // if … … 325 301 #endif // __DEBUG_H__ 326 302 327 if ( WIFSIGNALED(code) != 0 ) { // child failed ?328 rmtmpfile(); // remove tmpname329 cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl;330 exit( EXIT_FAILURE );331 } // if332 333 if ( WEXITSTATUS(code) != 0 ) { // child error ?334 rmtmpfile(); // remove tmpname335 exit( WEXITSTATUS( code ) ); // do not continue336 } // if337 338 // If -CFA flag specified, run the cfa-cpp preprocessor on the temporary file, and output is written to standard339 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.340 341 if ( fork() == 0 ) { // child runs CFA342 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();343 344 // Source file-name used to generate routine names containing global initializations for TU.345 cargs[ncargs] = ( *new string( "-F" ) ).c_str();346 ncargs += 1;347 cargs[ncargs] = ( *new string( string( cpp_in ) ) ).c_str();348 ncargs += 1;349 350 cargs[ncargs] = tmpname;351 ncargs += 1;352 if ( o_name != NULL ) {353 cargs[ncargs] = o_name;354 ncargs += 1;355 } else if ( ! CFA_flag ) { // run cfa-cpp ?356 cargs[ncargs] = cpp_out;357 ncargs += 1;358 } // if359 cargs[ncargs] = NULL; // terminate argument list360 361 #ifdef __DEBUG_H__362 cerr << "cfa-cpp ncargs: " << (o_name ? o_name : "No -o") << " " << CFA_flag << " " << ncargs << endl;363 for ( int i = 0; cargs[i] != NULL; i += 1 ) {364 cerr << cargs[i] << " ";365 } // for366 cerr << endl;367 #endif // __DEBUG_H__368 369 execvp( cargs[0], (char * const *)cargs ); // should not return370 perror( "CFA Translator error: cpp level, execvp" );371 exit( EXIT_FAILURE );372 } // if373 374 wait( &code ); // wait for child to finish375 376 #ifdef __DEBUG_H__377 cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl;378 #endif // __DEBUG_H__379 380 // Must unlink here because file must exist across execvp.381 rmtmpfile(); // remove tmpname382 383 303 if ( WIFSIGNALED(code) ) { // child failed ? 384 cerr << "C FA Translator error: cfa-cpp failed with signal" << WTERMSIG(code) << endl;385 exit( EXIT_FAILURE ); 386 } // if 387 388 exit( WEXITSTATUS(code) ); 304 cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl; 305 exit( EXIT_FAILURE ); 306 } // if 307 308 exit( WEXITSTATUS(code) ); // bad cpp result stops top-level gcc 389 309 } // Stage1 390 310 391 311 392 void Stage2( const int argc, const char * const * argv ) { 312 static void Stage2( const int argc, const char * const * argv ) { 313 int code; 393 314 string arg; 394 315 395 const char *cpp_in = NULL; 396 397 const char *args[argc + 100]; // leave space for 100 additional cfa command line values 316 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 398 320 int nargs = 1; // number of arguments in args list; 0 => command name 321 const char * cargs[20]; // leave space for 20 additional cfa-cpp command line values 322 int ncargs = 1; // 0 => command name 399 323 400 324 #ifdef __DEBUG_H__ 401 325 cerr << "Stage2" << endl; 402 326 #endif // __DEBUG_H__ 403 checkEnv ( args, nargs ); // arguments passed via environment variables327 checkEnv2( cargs, ncargs ); // arguments passed via environment variables 404 328 #ifdef __DEBUG_H__ 405 329 for ( int i = 1; i < argc; i += 1 ) { … … 430 354 431 355 } else { 432 args[nargs] = argv[i]; // pass the flag along 433 nargs += 1; 356 args[nargs++] = argv[i]; // pass the flag along 434 357 if ( arg == "-o" ) { 435 358 i += 1; 436 args[nargs] = argv[i]; // pass the argument along437 nargs += 1;359 cpp_out = argv[i]; 360 args[nargs++] = argv[i]; // pass the argument along 438 361 #ifdef __DEBUG_H__ 439 362 cerr << "arg:\"" << argv[i] << "\"" << endl; … … 442 365 } // if 443 366 } else { // obtain input and possibly output files 444 if ( cpp_in == NULL) {367 if ( cpp_in == nullptr ) { 445 368 cpp_in = argv[i]; 446 369 #ifdef __DEBUG_H__ 447 370 cerr << "cpp_in:\"" << cpp_in << "\"" << endl; 448 371 #endif // __DEBUG_H__ 372 } else if ( cpp_out == nullptr ) { 373 cpp_out = argv[i]; 374 #ifdef __DEBUG_H__ 375 cerr << "cpp_out:\"" << cpp_out << "\""<< endl; 376 #endif // __DEBUG_H__ 449 377 } else { 450 cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;378 cerr << "Usage: " << argv[0] << " more than two files specified" << endl; 451 379 exit( EXIT_FAILURE ); 452 380 } // if 453 381 } // if 454 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 392 393 // Create a temporary file, if needed, to store output of the cfa-cpp preprocessor. Cannot be created in forked 394 // process because variables tmpname and tmpfilefd are cloned. 395 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; 422 #endif // __DEBUG_H__ 423 } // if 424 425 // If -CFA flag specified, run the cfa-cpp preprocessor on the temporary file, and output is written to standard 426 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 427 428 if ( fork() == 0 ) { // child runs CFA 429 cargs[0] = ( *new string( installlibdir + "cfa-cpp" ) ).c_str(); 430 431 cargs[ncargs++] = cpp_in; 432 433 if ( CFA_flag ) { // run cfa-cpp ? 434 if ( o_file.size() != 0 ) { // location for output 435 cargs[ncargs++] = ( *new string( o_file.c_str() ) ).c_str(); 436 } // if 437 } else { 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 ) { 444 cerr << cargs[i] << " "; 445 } // for 446 cerr << endl; 447 #endif // __DEBUG_H__ 448 449 execvp( cargs[0], (char * const *)cargs ); // should not return 450 perror( "CC1 Translator error: stage 2, execvp" ); 451 exit( EXIT_FAILURE ); 452 } // if 453 454 wait( &code ); // wait for child to finish 455 456 if ( WIFSIGNALED(code) ) { // child failed ? 457 rmtmpfile(); // remove tmpname 458 cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl; 459 exit( EXIT_FAILURE ); 460 } // if 461 462 if ( CFA_flag ) { // no tmpfile created 463 exit( WEXITSTATUS( code ) ); // stop regardless of success or failure 464 } // if 465 466 #ifdef __DEBUG_H__ 467 cerr << "return code from cfa-cpp:" << WEXITSTATUS(code) << endl; 468 #endif // __DEBUG_H__ 469 470 if ( WEXITSTATUS(code) ) { // child error ? 471 rmtmpfile(); // remove tmpname 472 exit( WEXITSTATUS( code ) ); // do not continue 473 } // if 455 474 456 475 #ifdef __DEBUG_H__ … … 459 478 cerr << " " << args[i]; 460 479 } // for 461 cerr << endl; 462 if ( cpp_in != NULL ) cerr << " " << cpp_in; 463 #endif // __DEBUG_H__ 464 465 args[0] = compiler_name.c_str(); 466 args[nargs] = "-S"; // only compile and put assembler output in specified file 467 nargs += 1; 468 args[nargs] = cpp_in; 469 nargs += 1; 470 args[nargs] = NULL; // terminate argument list 471 472 #ifdef __DEBUG_H__ 473 cerr << "stage2 nargs: " << nargs << endl; 474 for ( int i = 0; args[i] != NULL; i += 1 ) { 475 cerr << args[i] << " "; 476 } // for 477 cerr << endl; 478 #endif // __DEBUG_H__ 479 480 execvp( args[0], (char * const *)args ); // should not return 481 perror( "CFA Translator error: cpp level, execvp" ); 482 exit( EXIT_FAILURE ); // tell gcc not to go any further 480 cerr << " " << cpp_in << endl; 481 #endif // __DEBUG_H__ 482 483 if ( fork() == 0 ) { // child runs CFA 484 args[0] = compiler_path.c_str(); 485 args[nargs++] = "-S"; // only compile and put assembler output in specified file 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 492 493 #ifdef __DEBUG_H__ 494 cerr << "stage2 nargs: " << nargs << endl; 495 for ( int i = 0; args[i] != nullptr; i += 1 ) { 496 cerr << args[i] << " "; 497 } // for 498 cerr << endl; 499 #endif // __DEBUG_H__ 500 501 execvp( args[0], (char * const *)args ); // should not return 502 perror( "CC1 Translator error: stage 2, execvp" ); 503 exit( EXIT_FAILURE ); // tell gcc not to go any further 504 } // if 505 506 wait( &code ); // wait for child to finish 507 508 if ( WIFSIGNALED(code) ) { // child failed ? 509 rmtmpfile(); // remove tmpname 510 cerr << "CC1 Translator error: stage 2, child failed " << WTERMSIG(code) << endl; 511 exit( EXIT_FAILURE ); 512 } // if 513 514 #ifdef __DEBUG_H__ 515 cerr << "return code from gcc cc1:" << WEXITSTATUS(code) << endl; 516 #endif // __DEBUG_H__ 517 518 rmtmpfile(); // remove tmpname 519 exit( WEXITSTATUS( code ) ); // stop regardless of success or failure 483 520 } // Stage2 484 521 485 522 523 // This program is called twice because of the -no-integrated-cpp. The calls are differentiated by the first 524 // command-line argument. The first call replaces the traditional cpp pass to preprocess the C program. The second call 525 // is to the compiler, which is broken into two steps: preprocess again with cfa-cpp and then call gcc to compile the 526 // doubly preprocessed program. 527 486 528 int main( const int argc, const char * const argv[], __attribute__((unused)) const char * const env[] ) { 487 529 #ifdef __DEBUG_H__ 488 for ( int i = 0; env[i] != NULL; i += 1 ) {530 for ( int i = 0; env[i] != nullptr; i += 1 ) { 489 531 cerr << env[i] << endl; 490 532 } // for 491 533 #endif // __DEBUG_H__ 492 534 493 string arg = argv[1]; 535 signal( SIGINT, sigTermHandler ); 536 signal( SIGTERM, sigTermHandler ); 537 538 string arg( argv[1] ); 494 539 495 540 // Currently, stage 1 starts with flag -E and stage 2 with flag -fpreprocessed. -
driver/cfa.cc
rf9bf142 r330d933 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 10 08:28:09201913 // Update Count : 28112 // Last Modified On : Fri Aug 23 16:27:07 2019 13 // Update Count : 411 14 14 // 15 15 … … 20 20 #include <string> // STL version 21 21 #include <string.h> // strcmp 22 #include <algorithm> // find 22 23 23 24 #include <sys/types.h> … … 32 33 using std::to_string; 33 34 34 35 35 //#define __DEBUG_H__ 36 36 37 37 38 bool prefix( string arg, string pre ) { 38 void Putenv( char * argv[], string arg ) { 39 static int flags = 0; // environment variables must have unique names 40 41 if ( putenv( (char *)( *new string( string( "__CFA_FLAG" + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) { 42 cerr << argv[0] << " error, cannot set environment variable." << endl; 43 exit( EXIT_FAILURE ); 44 } // if 45 } // Putenv 46 47 48 bool prefix( const string & arg, const string & pre ) { // check if string has prefix 39 49 return arg.substr( 0, pre.size() ) == pre; 40 50 } // prefix 41 51 42 enum { NumSuffixes = 2 }; 43 const string suffixes[NumSuffixes] = { "cfa", "hfa", }; 44 45 bool suffix( string arg, const char * args[], int & nargs ) { 46 //std::cerr << arg << std::endl; 52 bool suffix( const string & arg ) { // check if string has suffix 53 enum { NumSuffixes = 3 }; 54 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 55 47 56 size_t dot = arg.find_last_of( "." ); 48 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;49 57 if ( dot == string::npos ) return false; 50 string sx = arg.substr( dot + 1 ); 51 for ( int i = 0; i < NumSuffixes; i += 1 ) { 52 if ( sx == suffixes[i] ) { 53 args[nargs] = "-x"; 54 nargs += 1; 55 args[nargs] = "c"; 56 nargs += 1; 57 return true; 58 } // if 59 } // for 58 const string * end = suffixes + NumSuffixes; 59 return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end; 60 } // suffix 61 62 63 static inline bool dirExists( const string & path ) { // check if directory exists 64 struct stat info; 65 if ( stat( path.c_str(), &info ) != 0 ) return false; 66 if ( info.st_mode & S_IFDIR ) return true; 60 67 return false; 61 } // suffix 62 63 64 void shuffle( const char *args[], int S, int E, int N ) { 65 // S & E index 1 passed the end so adjust with -1 66 #ifdef __DEBUG_H__ 67 cerr << "shuffle:" << S << " " << E << " " << N << endl; 68 #endif // __DEBUG_H__ 69 for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { 70 #ifdef __DEBUG_H__ 71 cerr << "\t" << j << " " << j-N << endl; 72 #endif // __DEBUG_H__ 73 args[j] = args[j-N]; 74 } // for 75 } // shuffle 76 77 static inline bool dirExists(const string & path) { 78 struct stat info; 79 if(stat( path.c_str(), &info ) != 0) 80 return false; 81 else if(info.st_mode & S_IFDIR) 82 return true; 83 else 84 return false; 85 } //dirExists 86 87 68 } // dirExists 69 70 71 #define xstr(s) str(s) 88 72 #define str(s) #s 89 73 90 int main( int argc, char * argv[] ) {74 int main( int argc, char * argv[] ) { 91 75 string Version( CFA_VERSION_LONG ); // current version number from CONFIG 92 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch(str( CFA_VERSION_PATCH ) );76 string Major( xstr( CFA_VERSION_MAJOR ) ), Minor( xstr( CFA_VERSION_MINOR ) ), Patch( xstr( CFA_VERSION_PATCH ) ); 93 77 94 78 string installincdir( CFA_INCDIR ); // fixed location of include files … … 104 88 string compiler_name; // name of C compiler 105 89 106 bool nonoptarg = false; // indicates non-option argument specified 107 bool link = true; // linking as well as compiling 90 bool x_flag = false; // -x flag 91 bool nonoptarg = false; // no non-option arguments specified, i.e., no file names 92 bool link = true; // link stage occurring 108 93 bool verbose = false; // -v flag 109 bool quiet = false; // -quiet flag110 bool debug = true; // -debug flag111 bool nolib = false; // -nolib flag112 bool help = false; // -help flag94 bool quiet = false; // -quiet flag 95 bool debug = true; // -debug flag 96 bool nolib = false; // -nolib flag 97 bool help = false; // -help flag 113 98 bool CFA_flag = false; // -CFA flag 114 99 bool cpp_flag = false; // -E or -M flag, preprocessor only … … 116 101 bool noincstd_flag = false; // -no-include-stdhdr= flag 117 102 bool debugging __attribute(( unused )) = false; // -g flag 118 bool m32 = false; // -m32 flag 119 bool m64 = false; // -m64 flag 120 bool intree = false; 103 bool m32 = false; // -m32 flag 104 bool m64 = false; // -m64 flag 105 bool intree = false; // build in tree 106 int o_file = 0; // -o filename position 121 107 122 108 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 142 128 143 129 if ( arg == "-Xlinker" || arg == "-o" ) { 144 args[nargs] = argv[i]; // pass the argument along 145 nargs += 1; 130 args[nargs++] = argv[i]; // pass argument along 146 131 i += 1; 147 132 if ( i == argc ) continue; // next argument available ? 148 args[nargs ] = argv[i]; // pass theargument along149 nargs += 1;133 args[nargs++] = argv[i]; // pass argument along 134 if ( arg == "-o" ) o_file = i; // remember file 150 135 } else if ( arg == "-XCFA" ) { // CFA pass through 151 136 i += 1; 152 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str(); 153 nargs += 1; 137 Putenv( argv, argv[i] ); 154 138 155 139 // CFA specific arguments … … 158 142 CFA_flag = true; // strip the -CFA flag 159 143 link = false; 160 args[nargs] = "-E"; // replace the argument with -E 161 nargs += 1; 144 args[nargs++] = "-fsyntax-only"; // stop after stage 2 162 145 } else if ( arg == "-debug" ) { 163 146 debug = true; // strip the debug flag 164 147 } else if ( arg == "-nodebug" ) { 165 debug = false; // strip the debug flag148 debug = false; // strip the nodebug flag 166 149 } else if ( arg == "-nolib" ) { 167 150 nolib = true; // strip the nodebug flag … … 183 166 if ( i == argc ) continue; // next argument available ? 184 167 compiler_path = argv[i]; 185 if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) { 186 cerr << argv[0] << " error, cannot set environment variable." << endl; 187 exit( EXIT_FAILURE ); 188 } // if 168 Putenv( argv, arg + "=" + argv[i] ); 189 169 190 170 // C specific arguments … … 192 172 } else if ( arg == "-v" ) { 193 173 verbose = true; // verbosity required 194 args[nargs] = argv[i]; // pass the argument along 195 nargs += 1; 174 args[nargs++] = argv[i]; // pass argument along 196 175 } else if ( arg == "-g" ) { 197 176 debugging = true; // symbolic debugging required 198 args[nargs] = argv[i]; // pass the argument along 199 nargs += 1; 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 181 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 182 string lang; 183 args[nargs++] = argv[i]; // pass argument along 184 if ( arg.length() == 2 ) { // separate argument ? 185 i += 1; 186 if ( i == argc ) continue; // next argument available ? 187 lang = argv[i]; 188 args[nargs++] = argv[i]; // pass argument along 189 } else { 190 lang = arg.substr( 2 ); 191 } // if 192 x_flag = lang != "none"; 200 193 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 201 194 std_flag = true; // -std=XX provided 202 args[nargs] = argv[i]; // pass the argument along 203 nargs += 1; 195 args[nargs++] = argv[i]; // pass argument along 204 196 } else if ( arg == "-w" ) { 205 args[nargs] = argv[i]; // pass the argument along 206 nargs += 1; 207 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 208 nargs += 1; 197 args[nargs++] = argv[i]; // pass argument along 198 Putenv( argv, arg ); 209 199 } else if ( prefix( arg, "-W" ) ) { // check before next tests 210 200 if ( arg == "-Werror" || arg == "-Wall" ) { 211 args[nargs] = argv[i]; // pass the argument along 212 nargs += 1; 213 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 214 nargs += 1; 201 args[nargs++] = argv[i]; // pass argument along 202 Putenv( argv, argv[i] ); 215 203 } else { 216 204 unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; 217 args[nargs] = argv[i]; // conditionally pass theargument along218 const char * warning = argv[i] + adv; 205 args[nargs] = argv[i]; // conditionally pass argument along 206 const char * warning = argv[i] + adv; // extract warning 219 207 if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp 220 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str();208 Putenv( argv, arg ); 221 209 } // if 222 210 nargs += 1; … … 224 212 } else if ( prefix( arg, "-B" ) ) { 225 213 Bprefix = arg.substr(2); // strip the -B flag 226 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 227 nargs += 1; 228 } else if ( prefix( arg, "-b" ) ) { 229 if ( arg.length() == 2 ) { // separate argument ? 230 i += 1; 231 if ( i == argc ) continue; // next argument available ? 232 arg += argv[i]; // concatenate argument 233 } // if 234 // later versions of gcc require the -b option to appear at the start of the command line 235 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 236 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 237 if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) { 238 cerr << argv[0] << " error, cannot set environment variable." << endl; 239 exit( EXIT_FAILURE ); 240 } // if 241 sargs += 1; 242 nargs += 1; 243 } else if ( prefix( arg, "-V" ) ) { 244 if ( arg.length() == 2 ) { // separate argument ? 245 i += 1; 246 if ( i == argc ) continue; // next argument available ? 247 arg += argv[i]; // concatenate argument 248 } // if 249 // later versions of gcc require the -V option to appear at the start of the command line 250 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 251 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 252 if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) { 253 cerr << argv[0] << " error, cannot set environment variable." << endl; 254 exit( EXIT_FAILURE ); 255 } // if 256 sargs += 1; 257 nargs += 1; 214 args[nargs++] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 258 215 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 259 args[nargs] = argv[i]; // pass the argument along 260 nargs += 1; 216 args[nargs++] = argv[i]; // pass argument along 261 217 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 262 218 cpp_flag = true; // cpp only … … 265 221 } else if ( arg[1] == 'l' ) { 266 222 // if the user specifies a library, load it after user code 267 libs[nlibs] = argv[i]; 268 nlibs += 1; 223 libs[nlibs++] = argv[i]; 269 224 } else if ( arg == "-m32" ) { 270 225 m32 = true; 271 226 m64 = false; 272 args[nargs] = argv[i]; 273 nargs += 1; 227 args[nargs++] = argv[i]; 274 228 } else if ( arg == "-m64" ) { 275 229 m64 = true; 276 230 m32 = false; 277 args[nargs] = argv[i]; 278 nargs += 1; 231 args[nargs++] = argv[i]; 279 232 } else { 280 233 // concatenate any other arguments 281 args[nargs] = argv[i]; 282 nargs += 1; 234 args[nargs++] = argv[i]; 283 235 } // if 284 236 } else { 285 bool cfa = suffix( arg, args, nargs ); // check suffix 286 args[nargs] = argv[i]; // concatenate file 287 nargs += 1; 288 if ( cfa ) { 289 args[nargs] = "-x"; 290 nargs += 1; 291 args[nargs] = "none"; 292 nargs += 1; 237 bool cfa = suffix( arg ); // check suffix 238 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 239 args[nargs++] = "-x"; 240 args[nargs++] = "c"; 241 } // if 242 args[nargs++] = argv[i]; // concatenate files 243 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 244 args[nargs++] = "-x"; 245 args[nargs++] = "none"; 293 246 } // if 294 247 nonoptarg = true; … … 296 249 } // for 297 250 298 args[nargs] = "-x"; // turn off language299 nargs += 1;300 args[nargs] = "none";301 nargs += 1;302 303 251 #ifdef __x86_64__ 304 args[nargs] = "-mcx16"; // allow double-wide CAA 305 nargs += 1; 252 args[nargs++] = "-mcx16"; // allow double-wide CAA 306 253 #endif // __x86_64__ 307 254 … … 314 261 #endif // __DEBUG_H__ 315 262 263 // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed. 316 264 if ( cpp_flag && CFA_flag ) { 317 265 cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; … … 320 268 321 269 // add the CFA include-library paths, which allow direct access to header files without directory qualification 322 if( !intree ) { 323 args[nargs] = "-I" CFA_INCDIR; 324 nargs += 1; 270 if ( ! intree ) { 271 args[nargs++] = "-I" CFA_INCDIR; 325 272 if ( ! noincstd_flag ) { // do not use during build 326 args[nargs] = "-I" CFA_INCDIR "stdhdr"; 327 nargs += 1; 273 args[nargs++] = "-I" CFA_INCDIR "stdhdr"; 328 274 } // if 329 args[nargs] = "-I" CFA_INCDIR "concurrency"; 330 nargs += 1; 331 args[nargs] = "-I" CFA_INCDIR "containers"; 332 nargs += 1; 333 } else { 334 args[nargs] = "-I" TOP_SRCDIR "libcfa/src"; 335 nargs += 1; 275 args[nargs++] = "-I" CFA_INCDIR "concurrency"; 276 args[nargs++] = "-I" CFA_INCDIR "containers"; 277 } else { 278 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 336 279 if ( ! noincstd_flag ) { // do not use during build 337 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 338 nargs += 1; 280 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 339 281 } // if 340 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 341 nargs += 1; 342 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 343 nargs += 1; 344 } 282 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 283 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 284 } // if 345 285 346 286 // add stdbool to get defines for bool/true/false 347 args[nargs] = "-imacros"; 348 nargs += 1; 349 args[nargs] = "stdbool.h"; 350 nargs += 1; 287 args[nargs++] = "-imacros"; 288 args[nargs++] = "stdbool.h"; 351 289 352 290 string libbase; 353 if ( !intree ) {291 if ( ! intree ) { 354 292 libbase = CFA_LIBDIR; 355 293 } else { 356 294 libbase = TOP_BUILDDIR "libcfa/"; 357 args[nargs] = "-D__CFA_FLAG__=-t"; 358 nargs += 1; 359 } 360 361 string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU); 295 Putenv( argv, "-t" ); 296 } // if 297 298 string arch( m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU) ); 362 299 if ( ! m32 && ! m64 ) { 363 300 if ( arch == "x86" ) { 364 args[nargs] = "-m32"; 365 nargs += 1; 301 args[nargs++] = "-m32"; 366 302 } else if ( arch == "x64" ) { 367 args[nargs] = "-m64"; 368 nargs += 1; 303 args[nargs++] = "-m64"; 369 304 } // if 370 305 } // if 371 const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug"); 372 string libdir = libbase + arch + "-" + config; 373 374 if ( ! nolib && ! dirExists( libdir ) ) { 375 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; 376 cerr << "Was looking for " << libdir << endl; 377 libdir = libbase + arch + "-" + "nolib"; 378 } // if 379 306 307 string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) ); 380 308 if ( ! dirExists( libdir ) ) { 381 cerr << argv[0] << " internal error, cannot find prelude directory." << endl; 382 cerr << "Was looking for " << libdir << endl; 309 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl; 383 310 exit( EXIT_FAILURE ); 384 311 } // if 385 312 386 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();387 nargs += 1;388 389 313 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries 390 args[nargs] = libs[i]; 391 nargs += 1; 314 args[nargs++] = libs[i]; 392 315 } // for 393 316 394 317 if ( link ) { 395 args[nargs] = "-Xlinker"; 396 nargs += 1; 397 args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; 398 nargs += 1; 399 args[nargs] = "-Xlinker"; 400 nargs += 1; 401 args[nargs] = "--undefined=__cfaabi_interpose_startup"; 402 nargs += 1; 403 args[nargs] = "-Xlinker"; 404 nargs += 1; 405 args[nargs] = "--undefined=__cfaabi_appready_startup"; 406 nargs += 1; 318 args[nargs++] = "-Xlinker"; 319 args[nargs++] = "--undefined=__cfaabi_dbg_bits_write"; 320 args[nargs++] = "-Xlinker"; 321 args[nargs++] = "--undefined=__cfaabi_interpose_startup"; 322 args[nargs++] = "-Xlinker"; 323 args[nargs++] = "--undefined=__cfaabi_appready_startup"; 407 324 408 325 // include the cfa library in case it's needed 409 args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 410 nargs += 1; 411 args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 412 nargs += 1; 413 args[nargs] = "-Wl,--push-state,--as-needed"; 414 nargs += 1; 415 args[nargs] = "-lcfathread"; 416 nargs += 1; 417 args[nargs] = "-Wl,--pop-state"; 418 nargs += 1; 419 args[nargs] = "-lcfa"; 420 nargs += 1; 421 args[nargs] = "-lpthread"; 422 nargs += 1; 423 args[nargs] = "-ldl"; 424 nargs += 1; 425 args[nargs] = "-lrt"; 426 nargs += 1; 427 args[nargs] = "-lm"; 428 nargs += 1; 429 } // if 430 431 // Add exception flags (unconditionally) 432 args[nargs] = "-fexceptions"; 433 nargs += 1; 434 435 // add the correct set of flags based on the type of compile this is 436 437 args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); 438 nargs += 1; 439 args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); 440 nargs += 1; 441 args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); 442 nargs += 1; 443 args[nargs] = "-D__CFA__"; 444 nargs += 1; 445 args[nargs] = "-D__CFORALL__"; 446 nargs += 1; 447 args[nargs] = "-D__cforall"; 448 nargs += 1; 326 args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 327 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 328 args[nargs++] = "-Wl,--push-state,--as-needed"; 329 args[nargs++] = "-lcfathread"; 330 args[nargs++] = "-Wl,--pop-state"; 331 args[nargs++] = "-lcfa"; 332 args[nargs++] = "-lpthread"; 333 args[nargs++] = "-ldl"; 334 args[nargs++] = "-lrt"; 335 args[nargs++] = "-lm"; 336 } // if 337 338 args[nargs++] = "-fexceptions"; // add exception flags (unconditionally) 339 340 // add flags based on the type of compile 341 342 args[nargs++] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); 343 args[nargs++] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); 344 args[nargs++] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); 345 args[nargs++] = "-D__CFA__"; 346 args[nargs++] = "-D__CFORALL__"; 347 args[nargs++] = "-D__cforall"; 449 348 450 349 if ( cpp_flag ) { 451 args[nargs] = "-D__CPP__"; 452 nargs += 1; 453 } // if 454 455 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 456 nargs += 1; 350 args[nargs++] = "-D__CPP__"; 351 } // if 352 457 353 if ( CFA_flag ) { 458 args[sargs] = "-D__CFA_FLAG__=-N"; 459 args[nargs] = "-D__CFA_PREPROCESS_"; 460 nargs += 1; 461 } else { 462 args[sargs] = "-D__CFA_FLAG__=-L"; 463 } // if 464 sargs += 1; 354 Putenv( argv, "-N" ); 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. 358 if ( o_file ) Putenv( argv, string( "-o=" ) + argv[o_file] ); 359 } else { 360 Putenv( argv, "-L" ); 361 } // if 362 363 Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") ); 465 364 466 365 if ( debug ) { 467 366 heading += " (debug)"; 468 args[nargs] = "-D__CFA_DEBUG__"; 469 nargs += 1; 367 args[nargs++] = "-D__CFA_DEBUG__"; 470 368 } else { 471 369 heading += " (no debug)"; … … 475 373 Bprefix = ! intree ? installlibdir : srcdriverdir; 476 374 if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/'; 477 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 478 nargs += 1; 479 } // if 480 481 args[nargs] = "-Xlinker"; // used by backtrace 482 nargs += 1; 483 args[nargs] = "-export-dynamic"; 484 nargs += 1; 375 args[nargs++] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 376 } // if 377 378 args[nargs++] = "-Xlinker"; // used by backtrace 379 args[nargs++] = "-export-dynamic"; 485 380 486 381 // execute the compilation command … … 496 391 497 392 if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name 498 args[nargs] = "-no-integrated-cpp"; 499 nargs += 1; 500 args[nargs] = "-Wno-deprecated"; 501 nargs += 1; 502 #ifdef HAVE_CAST_FUNCTION_TYPE 503 args[nargs] = "-Wno-cast-function-type"; 504 nargs += 1; 505 #endif // HAVE_CAST_FUNCTION_TYPE 393 args[nargs++] = "-no-integrated-cpp"; 394 args[nargs++] = "-Wno-deprecated"; 395 #ifdef HAVE_CAST_FUNCTION_TYPE 396 args[nargs++] = "-Wno-cast-function-type"; 397 #endif // HAVE_CAST_FUNCTION_TYPE 506 398 if ( ! std_flag ) { // default c11, if none specified 507 args[nargs] = "-std=gnu11"; 508 nargs += 1; 399 args[nargs++] = "-std=gnu11"; 509 400 } // if 510 args[nargs] = "-fgnu89-inline"; 511 nargs += 1; 512 args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes 513 nargs += 1; 514 args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str(); 515 nargs += 1; 401 args[nargs++] = "-fgnu89-inline"; 402 args[nargs++] = "-D__int8_t_defined"; // prevent gcc type-size attributes 403 args[nargs++] = ( *new string( string("-B") + Bprefix ) ).c_str(); 516 404 } else { 517 405 cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl; … … 519 407 } // if 520 408 521 args[nargs] = NULL; // terminate with NULL409 args[nargs] = nullptr; // terminate 522 410 523 411 #ifdef __DEBUG_H__ 524 412 cerr << "nargs: " << nargs << endl; 525 413 cerr << "args:" << endl; 526 for ( int i = 0; args[i] != NULL; i += 1 ) {414 for ( int i = 0; args[i] != nullptr; i += 1 ) { 527 415 cerr << " \"" << args[i] << "\"" << endl; 528 416 } // for … … 546 434 if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc 547 435 548 for ( int i = 0; args[i] != NULL; i += 1 ) {436 for ( int i = 0; args[i] != nullptr; i += 1 ) { 549 437 cerr << args[i] << " "; 550 438 } // for … … 560 448 561 449 execvp( args[0], (char *const *)args ); // should not return 562 perror( "CFA Translator error: cfa level,execvp" );450 perror( "CFA Translator error: execvp" ); 563 451 exit( EXIT_FAILURE ); 564 452 } // main
Note:
See TracChangeset
for help on using the changeset viewer.