Changes in driver/cfa.cc [0bf5340:1ee048fd]
- File:
-
- 1 edited
-
driver/cfa.cc (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
r0bf5340 r1ee048fd 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 9 17:57:40201913 // Update Count : 41712 // Last Modified On : Sat Aug 10 08:44:15 2019 13 // Update Count : 311 14 14 // 15 15 … … 28 28 #include "config.h" // configure info 29 29 30 30 31 using std::cerr; 31 32 using std::endl; … … 33 34 using std::to_string; 34 35 36 35 37 //#define __DEBUG_H__ 36 38 37 39 38 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "N__=" suffix 39 40 void Putenv( char * argv[], string arg ) { 41 static int flags = 0; // environment variables must have unique names 42 43 if ( putenv( (char *)( *new string( string( __CFA_FLAGPREFIX__ + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) { 44 cerr << argv[0] << " error, cannot set environment variable." << endl; 45 exit( EXIT_FAILURE ); 46 } // if 47 } // Putenv 48 49 50 bool prefix( const string & arg, const string & pre ) { // check if string has prefix 40 bool prefix( const string & arg, const string & pre ) { 51 41 return arg.substr( 0, pre.size() ) == pre; 52 42 } // prefix 53 43 54 bool suffix( const string & arg ) { // check if string has suffix 55 enum { NumSuffixes = 3 }; 56 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 57 58 size_t dot = arg.find_last_of( "." ); 59 if ( dot == string::npos ) return false; 60 const string * end = suffixes + NumSuffixes; 61 return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end; 44 inline bool ends_with(const string & str, const string & sfix) { 45 if (sfix.size() > str.size()) return false; 46 return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend()); 47 } 48 49 bool suffix( const string & arg ) { 50 static const string suffixes[] = { ".cfa", ".hfa", ".cfa.ii" }; 51 for(const auto sfix : suffixes) { 52 if(arg.size() <= sfix.size()) continue; 53 size_t pos = arg.find_last_of(sfix); 54 size_t exp = (arg.size() - 1); 55 if(pos == exp) return true; 56 } 57 return false; 62 58 } // suffix 63 59 64 60 65 static inline bool dirExists( const string & path ) { // check if directory exists 61 void shuffle( const char * args[], int S, int E, int N ) { 62 // S & E index 1 passed the end so adjust with -1 63 #ifdef __DEBUG_H__ 64 cerr << "shuffle:" << S << " " << E << " " << N << endl; 65 #endif // __DEBUG_H__ 66 for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { 67 #ifdef __DEBUG_H__ 68 cerr << "\t" << j << " " << j-N << endl; 69 #endif // __DEBUG_H__ 70 args[j] = args[j-N]; 71 } // for 72 } // shuffle 73 74 static inline bool dirExists( const string & path ) { 66 75 struct stat info; 67 if ( stat( path.c_str(), &info ) != 0 ) return false; 68 return (info.st_mode & S_IFDIR) != 0; 69 } // dirExists 70 71 72 #define xstr(s) str(s) 76 if(stat( path.c_str(), &info ) != 0) 77 return false; 78 else if(info.st_mode & S_IFDIR) 79 return true; 80 else 81 return false; 82 } //dirExists 83 84 static inline string dir(const string & path) { 85 return path.substr(0, path.find_last_of('/')); 86 } 87 88 73 89 #define str(s) #s 74 90 75 91 int main( int argc, char * argv[] ) { 76 92 string Version( CFA_VERSION_LONG ); // current version number from CONFIG 77 string Major( xstr( CFA_VERSION_MAJOR ) ), Minor( xstr( CFA_VERSION_MINOR ) ), Patch( xstr( CFA_VERSION_PATCH ) );93 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); 78 94 79 95 string installincdir( CFA_INCDIR ); // fixed location of include files … … 83 99 string heading; // banner printed at start of cfa compilation 84 100 string arg; // current command-line argument during command-line parsing 85 string bprefix; // path where gcc looks for compilersteps101 string Bprefix; // path where gcc looks for compiler command steps 86 102 string langstd; // language standard 87 103 … … 90 106 91 107 bool x_flag = false; // -x flag 92 bool nonoptarg = false; // no non-option arguments specified, i.e., no file names93 bool link = true; // link stage occurring108 bool nonoptarg = false; // indicates non-option argument specified 109 bool link = true; // linking as well as compiling 94 110 bool verbose = false; // -v flag 95 111 bool quiet = false; // -quiet flag … … 104 120 bool m32 = false; // -m32 flag 105 121 bool m64 = false; // -m64 flag 106 bool intree = false; // build in tree 107 int o_file = 0; // -o filename position 122 bool intree = false; 123 bool compiling_libs = false; 124 bool disttree = false; 108 125 109 126 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 129 146 130 147 if ( arg == "-Xlinker" || arg == "-o" ) { 131 args[nargs++] = argv[i]; // pass argument along 148 args[nargs] = argv[i]; // pass the argument along 149 nargs += 1; 132 150 i += 1; 133 151 if ( i == argc ) continue; // next argument available ? 134 args[nargs ++] = argv[i]; // passargument along135 if ( arg == "-o" ) o_file = i; // remember file152 args[nargs] = argv[i]; // pass the argument along 153 nargs += 1; 136 154 } else if ( arg == "-XCFA" ) { // CFA pass through 137 155 i += 1; 138 Putenv( argv, argv[i] ); 156 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str(); 157 nargs += 1; 139 158 140 159 // CFA specific arguments … … 143 162 CFA_flag = true; // strip the -CFA flag 144 163 link = false; 145 args[nargs++] = "-fsyntax-only"; // stop after stage 2 164 args[nargs] = "-E"; // replace the argument with -E 165 nargs += 1; 146 166 } else if ( arg == "-debug" ) { 147 167 debug = true; // strip the debug flag 148 168 } else if ( arg == "-nodebug" ) { 149 debug = false; // strip the nodebug flag169 debug = false; // strip the debug flag 150 170 } else if ( arg == "-nolib" ) { 151 171 nolib = true; // strip the nodebug flag … … 162 182 } else if ( arg == "-in-tree" ) { 163 183 intree = true; 184 } else if ( arg == "-dist-tree" ) { 185 disttree = true; 186 } else if ( arg == "-cfalib") { 187 compiling_libs = true; 164 188 } else if ( arg == "-compiler" ) { 165 189 // use the user specified compiler … … 167 191 if ( i == argc ) continue; // next argument available ? 168 192 compiler_path = argv[i]; 169 Putenv( argv, arg + "=" + argv[i] ); 193 if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) { 194 cerr << argv[0] << " error, cannot set environment variable." << endl; 195 exit( EXIT_FAILURE ); 196 } // if 170 197 171 198 // C specific arguments … … 173 200 } else if ( arg == "-v" ) { 174 201 verbose = true; // verbosity required 175 args[nargs++] = argv[i]; // pass argument along 202 args[nargs] = argv[i]; // pass the argument along 203 nargs += 1; 176 204 } else if ( arg == "-g" ) { 177 205 debugging = true; // symbolic debugging required 178 args[nargs++] = argv[i]; // pass argument along 179 } else if ( arg == "-save-temps" ) { 180 args[nargs++] = argv[i]; // pass argument along 181 Putenv( argv, arg ); // save cfa-cpp output 206 args[nargs] = argv[i]; // pass the argument along 207 nargs += 1; 182 208 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 183 209 string lang; 184 args[nargs++] = argv[i]; // pass argument along 210 args[nargs] = argv[i]; // pass the argument along 211 nargs += 1; 185 212 if ( arg.length() == 2 ) { // separate argument ? 186 213 i += 1; 187 214 if ( i == argc ) continue; // next argument available ? 188 215 lang = argv[i]; 189 args[nargs++] = argv[i]; // pass argument along 216 args[nargs] = argv[i]; // pass the argument along 217 nargs += 1; 190 218 } else { 191 219 lang = arg.substr( 2 ); … … 194 222 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 195 223 std_flag = true; // -std=XX provided 196 args[nargs++] = argv[i]; // pass argument along 224 args[nargs] = argv[i]; // pass the argument along 225 nargs += 1; 197 226 } else if ( arg == "-w" ) { 198 args[nargs++] = argv[i]; // pass argument along 199 Putenv( argv, arg ); 227 args[nargs] = argv[i]; // pass the argument along 228 nargs += 1; 229 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 230 nargs += 1; 200 231 } else if ( prefix( arg, "-W" ) ) { // check before next tests 201 232 if ( arg == "-Werror" || arg == "-Wall" ) { 202 args[nargs++] = argv[i]; // pass argument along 203 Putenv( argv, argv[i] ); 233 args[nargs] = argv[i]; // pass the argument along 234 nargs += 1; 235 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 236 nargs += 1; 204 237 } else { 205 238 unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; 206 args[nargs] = argv[i]; // conditionally pass argument along207 const char * warning = argv[i] + adv; // extract warning239 args[nargs] = argv[i]; // conditionally pass the argument along 240 const char * warning = argv[i] + adv; // extract warning 208 241 if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp 209 Putenv( argv, arg);242 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); 210 243 } // if 211 244 nargs += 1; 212 245 } // if 213 246 } else if ( prefix( arg, "-B" ) ) { 214 bprefix = arg.substr(2); // strip the -B flag 247 Bprefix = arg.substr(2); // strip the -B flag 248 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 249 nargs += 1; 250 } else if ( prefix( arg, "-b" ) ) { 251 if ( arg.length() == 2 ) { // separate argument ? 252 i += 1; 253 if ( i == argc ) continue; // next argument available ? 254 arg += argv[i]; // concatenate argument 255 } // if 256 // later versions of gcc require the -b option to appear at the start of the command line 257 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 258 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 259 if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) { 260 cerr << argv[0] << " error, cannot set environment variable." << endl; 261 exit( EXIT_FAILURE ); 262 } // if 263 sargs += 1; 264 nargs += 1; 265 } else if ( prefix( arg, "-V" ) ) { 266 if ( arg.length() == 2 ) { // separate argument ? 267 i += 1; 268 if ( i == argc ) continue; // next argument available ? 269 arg += argv[i]; // concatenate argument 270 } // if 271 // later versions of gcc require the -V option to appear at the start of the command line 272 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 273 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along 274 if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) { 275 cerr << argv[0] << " error, cannot set environment variable." << endl; 276 exit( EXIT_FAILURE ); 277 } // if 278 sargs += 1; 279 nargs += 1; 215 280 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 216 args[nargs++] = argv[i]; // pass argument along 281 args[nargs] = argv[i]; // pass the argument along 282 nargs += 1; 217 283 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 218 284 cpp_flag = true; // cpp only … … 221 287 } else if ( arg[1] == 'l' ) { 222 288 // if the user specifies a library, load it after user code 223 libs[nlibs++] = argv[i]; 289 libs[nlibs] = argv[i]; 290 nlibs += 1; 224 291 } else if ( arg == "-m32" ) { 225 292 m32 = true; 226 293 m64 = false; 227 args[nargs++] = argv[i]; 294 args[nargs] = argv[i]; 295 nargs += 1; 228 296 } else if ( arg == "-m64" ) { 229 297 m64 = true; 230 298 m32 = false; 231 args[nargs++] = argv[i]; 299 args[nargs] = argv[i]; 300 nargs += 1; 232 301 } else { 233 302 // concatenate any other arguments 234 args[nargs++] = argv[i]; 303 args[nargs] = argv[i]; 304 nargs += 1; 235 305 } // if 236 306 } else { 237 307 bool cfa = suffix( arg ); // check suffix 238 308 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 239 args[nargs++] = "-x"; 240 args[nargs++] = "c"; 309 args[nargs] = "-x"; 310 nargs += 1; 311 args[nargs] = "c"; 312 nargs += 1; 241 313 } // if 242 args[nargs++] = argv[i]; // concatenate files 314 args[nargs] = argv[i]; // concatenate file 315 nargs += 1; 243 316 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 244 args[nargs++] = "-x"; 245 args[nargs++] = "none"; 317 args[nargs] = "-x"; 318 nargs += 1; 319 args[nargs] = "none"; 320 nargs += 1; 246 321 } // if 247 322 nonoptarg = true; … … 250 325 251 326 #ifdef __x86_64__ 252 args[nargs++] = "-mcx16"; // allow double-wide CAA 327 args[nargs] = "-mcx16"; // allow double-wide CAA 328 nargs += 1; 253 329 #endif // __x86_64__ 254 330 … … 261 337 #endif // __DEBUG_H__ 262 338 263 // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed.264 339 if ( cpp_flag && CFA_flag ) { 265 340 cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; … … 268 343 269 344 // add the CFA include-library paths, which allow direct access to header files without directory qualification 270 if ( ! intree ) { 271 args[nargs++] = "-I" CFA_INCDIR; 345 if( !intree ) { 346 args[nargs] = "-I" CFA_INCDIR; 347 nargs += 1; 272 348 if ( ! noincstd_flag ) { // do not use during build 273 args[nargs++] = "-I" CFA_INCDIR "stdhdr"; 349 args[nargs] = "-I" CFA_INCDIR "stdhdr"; 350 nargs += 1; 274 351 } // if 275 args[nargs++] = "-I" CFA_INCDIR "concurrency"; 276 args[nargs++] = "-I" CFA_INCDIR "containers"; 352 args[nargs] = "-I" CFA_INCDIR "concurrency"; 353 nargs += 1; 354 args[nargs] = "-I" CFA_INCDIR "containers"; 355 nargs += 1; 277 356 } else { 278 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 357 args[nargs] = "-I" TOP_SRCDIR "libcfa/src"; 358 nargs += 1; 279 359 if ( ! noincstd_flag ) { // do not use during build 280 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 360 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 361 nargs += 1; 281 362 } // if 282 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 283 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 284 } // if 363 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 364 nargs += 1; 365 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 366 nargs += 1; 367 } 285 368 286 369 // add stdbool to get defines for bool/true/false 287 args[nargs++] = "-imacros"; 288 args[nargs++] = "stdbool.h"; 370 args[nargs] = "-imacros"; 371 nargs += 1; 372 args[nargs] = "stdbool.h"; 373 nargs += 1; 289 374 290 375 string libbase; 291 if ( !intree ) {376 if( !intree ) { 292 377 libbase = CFA_LIBDIR; 293 378 } else { 294 379 libbase = TOP_BUILDDIR "libcfa/"; 295 Putenv( argv, "-t" ); 296 } // if 297 298 string arch( m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU) ); 380 } 381 382 if( compiling_libs ) { 383 args[nargs] = "-D__CFA_FLAG__=-t"; 384 nargs += 1; 385 } 386 387 string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU); 299 388 if ( ! m32 && ! m64 ) { 300 389 if ( arch == "x86" ) { 301 args[nargs++] = "-m32"; 390 args[nargs] = "-m32"; 391 nargs += 1; 302 392 } else if ( arch == "x64" ) { 303 args[nargs++] = "-m64"; 393 args[nargs] = "-m64"; 394 nargs += 1; 304 395 } // if 305 396 } // if 306 307 string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) ); 308 if ( ! dirExists( libdir ) ) { 309 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl; 310 exit( EXIT_FAILURE ); 311 } // if 397 const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug"); 398 string libdir = libbase + arch + "-" + config; 399 400 if (!disttree) { 401 if ( ! nolib && ! dirExists( libdir ) ) { 402 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; 403 cerr << "Was looking for " << libdir << endl; 404 for(int i = 1; i < argc; i++) { 405 cerr << argv[i] << " "; 406 } 407 cerr << endl; 408 libdir = libbase + arch + "-" + "nolib"; 409 } // if 410 411 if ( ! dirExists( libdir ) ) { 412 cerr << argv[0] << " internal error, cannot find prelude directory." << endl; 413 cerr << "Was looking for " << libdir << endl; 414 exit( EXIT_FAILURE ); 415 } // if 416 } // if 417 418 if(disttree) { 419 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str(); 420 } else if(intree) { 421 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str(); 422 } else { 423 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str(); 424 } 425 nargs += 1; 312 426 313 427 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries 314 args[nargs++] = libs[i]; 428 args[nargs] = libs[i]; 429 nargs += 1; 315 430 } // for 316 431 317 432 if ( link ) { 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"; 324 325 // include the cfa library in case it is needed 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"; 433 args[nargs] = "-Xlinker"; 434 nargs += 1; 435 args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; 436 nargs += 1; 437 args[nargs] = "-Xlinker"; 438 nargs += 1; 439 args[nargs] = "--undefined=__cfaabi_interpose_startup"; 440 nargs += 1; 441 args[nargs] = "-Xlinker"; 442 nargs += 1; 443 args[nargs] = "--undefined=__cfaabi_appready_startup"; 444 nargs += 1; 445 446 // include the cfa library in case it's needed 447 args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 448 nargs += 1; 449 args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str(); 450 nargs += 1; 451 args[nargs] = "-Wl,--push-state,--as-needed"; 452 nargs += 1; 453 args[nargs] = "-lcfathread"; 454 nargs += 1; 455 args[nargs] = "-Wl,--pop-state"; 456 nargs += 1; 457 args[nargs] = "-lcfa"; 458 nargs += 1; 459 args[nargs] = "-lpthread"; 460 nargs += 1; 461 args[nargs] = "-ldl"; 462 nargs += 1; 463 args[nargs] = "-lrt"; 464 nargs += 1; 465 args[nargs] = "-lm"; 466 nargs += 1; 467 } // if 468 469 // Add exception flags (unconditionally) 470 args[nargs] = "-fexceptions"; 471 nargs += 1; 472 473 // add the correct set of flags based on the type of compile this is 474 475 args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); 476 nargs += 1; 477 args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); 478 nargs += 1; 479 args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); 480 nargs += 1; 481 args[nargs] = "-D__CFA__"; 482 nargs += 1; 483 args[nargs] = "-D__CFORALL__"; 484 nargs += 1; 485 args[nargs] = "-D__cforall"; 486 nargs += 1; 348 487 349 488 if ( cpp_flag ) { 350 args[nargs++] = "-D__CPP__"; 351 } // if 352 489 args[nargs] = "-D__CPP__"; 490 nargs += 1; 491 } // if 492 493 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list 494 nargs += 1; 353 495 if ( CFA_flag ) { 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] ); 496 args[sargs] = "-D__CFA_FLAG__=-N"; 497 args[nargs] = "-D__CFA_PREPROCESS_"; 498 nargs += 1; 359 499 } else { 360 Putenv( argv, "-L" ); 361 } // if 362 363 Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") ); 500 args[sargs] = "-D__CFA_FLAG__=-L"; 501 } // if 502 sargs += 1; 364 503 365 504 if ( debug ) { 366 505 heading += " (debug)"; 367 args[nargs++] = "-D__CFA_DEBUG__"; 506 args[nargs] = "-D__CFA_DEBUG__"; 507 nargs += 1; 368 508 } else { 369 509 heading += " (no debug)"; 370 510 } // if 371 511 372 if ( bprefix.length() == 0 ) { 373 bprefix = ! intree ? installlibdir : srcdriverdir; 374 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 375 Putenv( argv, ( *new string( string("-B=") + bprefix ) ).c_str() ); 376 } // if 377 378 args[nargs++] = "-Xlinker"; // used by backtrace 379 args[nargs++] = "-export-dynamic"; 512 if ( Bprefix.length() == 0 ) { 513 if(disttree) { 514 Bprefix = dir(argv[0]); 515 } else if(intree) { 516 Bprefix = srcdriverdir; 517 } else { 518 Bprefix = installlibdir; 519 } 520 521 if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/'; 522 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 523 nargs += 1; 524 } // if 525 526 args[nargs] = "-Xlinker"; // used by backtrace 527 nargs += 1; 528 args[nargs] = "-export-dynamic"; 529 nargs += 1; 380 530 381 531 // execute the compilation command … … 391 541 392 542 if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name 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 543 args[nargs] = "-no-integrated-cpp"; 544 nargs += 1; 545 args[nargs] = "-Wno-deprecated"; 546 nargs += 1; 547 #ifdef HAVE_CAST_FUNCTION_TYPE 548 args[nargs] = "-Wno-cast-function-type"; 549 nargs += 1; 550 #endif // HAVE_CAST_FUNCTION_TYPE 398 551 if ( ! std_flag ) { // default c11, if none specified 399 args[nargs++] = "-std=gnu11"; 552 args[nargs] = "-std=gnu11"; 553 nargs += 1; 400 554 } // if 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(); 555 args[nargs] = "-fgnu89-inline"; 556 nargs += 1; 557 args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes 558 nargs += 1; 559 args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str(); 560 nargs += 1; 404 561 } else { 405 562 cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl; … … 407 564 } // if 408 565 409 args[nargs] = nullptr; // terminate566 args[nargs] = NULL; // terminate with NULL 410 567 411 568 #ifdef __DEBUG_H__ 412 569 cerr << "nargs: " << nargs << endl; 413 570 cerr << "args:" << endl; 414 for ( int i = 0; args[i] != nullptr; i += 1 ) {415 cerr << " \"" << args[i] << "\" " << endl;571 for ( int i = 0; args[i] != NULL; i += 1 ) { 572 cerr << " \"" << args[i] << "\" "; 416 573 } // for 574 cerr << endl; 417 575 #endif // __DEBUG_H__ 418 576 419 577 if ( ! quiet ) { 420 578 cerr << "CFA " << "Version " << Version << heading << endl; 421 422 579 if ( help ) { 423 580 cerr << … … 434 591 if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc 435 592 436 for ( int i = 0; args[i] != nullptr; i += 1 ) {593 for ( int i = 0; args[i] != NULL; i += 1 ) { 437 594 cerr << args[i] << " "; 438 595 } // for … … 448 605 449 606 execvp( args[0], (char *const *)args ); // should not return 450 perror( "CFA Translator error: execvp" );607 perror( "CFA Translator error: cfa level, execvp" ); 451 608 exit( EXIT_FAILURE ); 452 609 } // main
Note:
See TracChangeset
for help on using the changeset viewer.