Changes in driver/cfa.cc [b4130f9:c334ecd]
- File:
-
- 1 edited
-
driver/cfa.cc (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
rb4130f9 rc334ecd 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Nov 17 14:27:28202013 // Update Count : 4 4012 // Last Modified On : Fri Jan 31 16:48:03 2020 13 // Update Count : 421 14 14 // 15 15 16 16 #include <iostream> 17 #include <cstdio> // perror 18 #include <cstdlib> // putenv, exit 19 #include <climits> // PATH_MAX 20 #include <string> // STL version 21 #include <algorithm> // find 22 23 #include <unistd.h> // execvp 17 #include <cstdio> // perror 18 #include <cstdlib> // putenv, exit 19 #include <climits> // PATH_MAX 20 #include <unistd.h> // execvp 21 #include <string> // STL version 22 #include <string.h> // strcmp 23 #include <algorithm> // find 24 24 25 #include <sys/types.h> 25 26 #include <sys/stat.h> … … 33 34 using std::to_string; 34 35 35 //#define __DEBUG_H__ 36 37 #define xstr(s) str(s) 38 #define str(s) #s 39 40 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "__CFA_FLAG__=" suffix 41 42 static void Putenv( char * argv[], string arg ) { 36 // #define __DEBUG_H__ 37 38 // "N__=" suffix 39 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); 40 41 void Putenv( char * argv[], string arg ) { 43 42 // environment variables must have unique names 44 43 static int flags = 0; … … 50 49 } // Putenv 51 50 52 static bool prefix( const string & arg, const string & pre ) { // check if string has prefix 51 // check if string has prefix 52 bool prefix( const string & arg, const string & pre ) { 53 53 return arg.substr( 0, pre.size() ) == pre; 54 54 } // prefix 55 55 56 staticinline bool ends_with(const string & str, const string & sfix) {56 inline bool ends_with(const string & str, const string & sfix) { 57 57 if (sfix.size() > str.size()) return false; 58 58 return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend()); … … 60 60 61 61 // check if string has suffix 62 staticbool suffix( const string & arg ) {62 bool suffix( const string & arg ) { 63 63 enum { NumSuffixes = 3 }; 64 64 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; … … 70 70 } // suffix 71 71 72 72 73 static inline bool dirExists( const string & path ) { // check if directory exists 73 74 struct stat info; … … 78 79 static inline string dir(const string & path) { 79 80 return path.substr(0, path.find_last_of('/')); 80 } // dir81 } 81 82 82 83 // Different path modes … … 117 118 } 118 119 120 121 #define xstr(s) str(s) 122 #define str(s) #s 119 123 120 124 int main( int argc, char * argv[] ) { … … 154 158 PathMode path = FromProc(); 155 159 156 const char * args[argc + 100]; // cfa command line values, plus some space for additional flags160 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags 157 161 int sargs = 1; // starting location for arguments in args list 158 162 int nargs = sargs; // number of arguments in args list; 0 => command name 159 163 160 const char * libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags164 const char *libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags 161 165 int nlibs = 0; 162 166 … … 176 180 177 181 if ( arg == "-Xlinker" || arg == "-o" ) { 178 args[nargs++] = argv[i]; // pass flagalong182 args[nargs++] = argv[i]; // pass argument along 179 183 i += 1; 180 184 if ( i == argc ) continue; // next argument available ? 181 185 args[nargs++] = argv[i]; // pass argument along 182 186 if ( arg == "-o" ) o_file = i; // remember file 187 } else if ( arg == "-XCFA" ) { // CFA pass through 188 i += 1; 189 if ( i == argc ) continue; // next argument available ? 190 Putenv( argv, argv[i] ); 183 191 184 192 // CFA specific arguments 185 193 186 } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through187 if ( arg.size() == 5 ) {188 i += 1;189 if ( i == argc ) continue; // next argument available ?190 Putenv( argv, argv[i] );191 } else if ( arg[5] == ',' ) { // CFA specific arguments192 Putenv( argv, argv[i] + 6 );193 } else { // CFA specific arguments194 args[nargs++] = argv[i];195 } // if196 194 } else if ( arg == "-CFA" ) { 197 195 CFA_flag = true; // strip the -CFA flag … … 202 200 } else if ( arg == "-nodebug" ) { 203 201 debug = false; // strip the nodebug flag 202 } else if ( arg == "-nolib" ) { 203 nolib = true; // strip the nodebug flag 204 204 } else if ( arg == "-quiet" ) { 205 205 quiet = true; // strip the quiet flag 206 206 } else if ( arg == "-noquiet" ) { 207 207 quiet = false; // strip the noquiet flag 208 } else if ( arg == "-no-include-stdhdr" ) {209 noincstd_flag = true; // strip the no-include-stdhdr flag210 } else if ( arg == "-nolib" ) {211 nolib = true; // strip the nolib flag212 208 } else if ( arg == "-help" ) { 213 209 help = true; // strip the help flag 214 210 } else if ( arg == "-nohelp" ) { 215 211 help = false; // strip the nohelp flag 212 } else if ( arg == "-no-include-stdhdr" ) { 213 noincstd_flag = true; // strip the no-include-stdhdr flag 216 214 } else if ( arg == "-cfalib") { 217 215 compiling_libs = true; … … 227 225 } else if ( arg == "-v" ) { 228 226 verbose = true; // verbosity required 229 args[nargs++] = argv[i]; // pass flagalong227 args[nargs++] = argv[i]; // pass argument along 230 228 } else if ( arg == "-g" ) { 231 229 debugging = true; // symbolic debugging required 232 args[nargs++] = argv[i]; // pass flagalong233 } else if ( arg == "-save-temps" || arg == "--save-temps") {234 args[nargs++] = argv[i]; // pass flagalong230 args[nargs++] = argv[i]; // pass argument along 231 } else if ( arg == "-save-temps" ) { 232 args[nargs++] = argv[i]; // pass argument along 235 233 Putenv( argv, arg ); // save cfa-cpp output 236 234 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 237 235 string lang; 238 args[nargs++] = argv[i]; // pass flagalong236 args[nargs++] = argv[i]; // pass argument along 239 237 if ( arg.length() == 2 ) { // separate argument ? 240 238 i += 1; … … 245 243 lang = arg.substr( 2 ); 246 244 } // if 247 if ( x_flag ) { 248 cerr << argv[0] << " warning, only one -x flag per compile, ignoring subsequent flag." << endl; 249 } else { 250 x_flag = true; 251 Putenv( argv, string( "-x=" ) + lang ); 252 } // if 245 x_flag = lang != "none"; 253 246 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 254 247 std_flag = true; // -std=XX provided 255 args[nargs++] = argv[i]; // pass flagalong248 args[nargs++] = argv[i]; // pass argument along 256 249 } else if ( arg == "-w" ) { 257 args[nargs++] = argv[i]; // pass flagalong250 args[nargs++] = argv[i]; // pass argument along 258 251 Putenv( argv, arg ); 259 252 } else if ( prefix( arg, "-W" ) ) { // check before next tests 260 253 if ( arg == "-Werror" || arg == "-Wall" ) { 261 args[nargs++] = argv[i]; // pass flagalong254 args[nargs++] = argv[i]; // pass argument along 262 255 Putenv( argv, argv[i] ); 263 256 } else { … … 273 266 bprefix = arg.substr(2); // strip the -B flag 274 267 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 275 args[nargs++] = argv[i]; // pass flagalong268 args[nargs++] = argv[i]; // pass argument along 276 269 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 277 270 cpp_flag = true; // cpp only 278 271 } // if 279 272 link = false; // no linkage required 280 } else if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||281 arg == "-include" || arg == "-imacros" || arg == "-idirafter" || arg == "-iprefix" ||282 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {283 args[nargs++] = argv[i]; // pass flag along284 i += 1;285 args[nargs++] = argv[i]; // pass argument along286 273 } else if ( arg[1] == 'l' ) { 287 274 // if the user specifies a library, load it after user code … … 315 302 316 303 #ifdef __x86_64__ 317 args[nargs++] = "-mcx16"; // allow double-wide CA S304 args[nargs++] = "-mcx16"; // allow double-wide CAA 318 305 #endif // __x86_64__ 319 306 … … 335 322 string libbase; 336 323 switch(path) { 337 case Installed:324 case Installed: 338 325 args[nargs++] = "-I" CFA_INCDIR; 339 326 // do not use during build … … 345 332 libbase = CFA_LIBDIR; 346 333 break; 347 case BuildTree:348 case Distributed:334 case BuildTree: 335 case Distributed: 349 336 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 350 337 // do not use during build … … 380 367 string libdir = libbase + arch + "-" + config; 381 368 382 if ( path != Distributed) {369 if (path != Distributed) { 383 370 if ( ! nolib && ! dirExists( libdir ) ) { 384 371 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; … … 398 385 } // if 399 386 400 string preludedir;401 387 switch(path) { 402 case Installed : preludedir = libdir; break; 403 case BuildTree : preludedir = libdir + "/prelude"; break; 404 case Distributed : preludedir = dir(argv[0]); break; 405 } // switch 406 407 Putenv( argv, "--prelude-dir=" + preludedir ); 408 args[nargs++] = "-include"; 409 args[nargs++] = (*new string(preludedir + "/defines.hfa")).c_str(); 388 case Installed : Putenv( argv, "--prelude-dir=" + libdir ); break; 389 case BuildTree : Putenv( argv, "--prelude-dir=" + libdir + "/prelude" ); break; 390 case Distributed : Putenv( argv, "--prelude-dir=" + dir(argv[0]) ); break; 391 } 410 392 411 393 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries … … 429 411 args[nargs++] = "-lcfathread"; 430 412 args[nargs++] = "-Wl,--pop-state"; 431 args[nargs++] = "-Wl,--push-state,--no-as-needed";432 413 args[nargs++] = "-lcfa"; 433 args[nargs++] = "-Wl,--pop-state";434 414 args[nargs++] = "-pthread"; 435 #if defined( __x86_64__ ) || defined( __ARM_ARCH )436 args[nargs++] = "-latomic"; // allow double-wide CAS437 #endif // __x86_64__438 415 args[nargs++] = "-ldl"; 416 args[nargs++] = "-lrt"; 439 417 args[nargs++] = "-lm"; 440 418 } // if … … 474 452 if ( bprefix.length() == 0 ) { 475 453 switch(path) { 476 case Installed : bprefix = installlibdir; break;477 case BuildTree : bprefix = srcdriverdir ; break;478 case Distributed : bprefix = dir(argv[0]) ; break;479 } // switch480 } // if481 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';482 Putenv( argv, string("-B=") + bprefix );454 case Installed : bprefix = installlibdir; break; 455 case BuildTree : bprefix = srcdriverdir ; break; 456 case Distributed : bprefix = dir(argv[0]) ; break; 457 } 458 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 459 Putenv( argv, string("-B=") + bprefix ); 460 } // if 483 461 484 462 args[nargs++] = "-Xlinker"; // used by backtrace … … 502 480 args[nargs++] = "-Wno-cast-function-type"; 503 481 #endif // HAVE_CAST_FUNCTION_TYPE 504 if ( ! std_flag && ! x_flag ) {505 args[nargs++] = "-std=gnu11"; // default c11, if none specified482 if ( ! std_flag ) { // default c11, if none specified 483 args[nargs++] = "-std=gnu11"; 506 484 } // if 507 485 args[nargs++] = "-fgnu89-inline"; … … 553 531 // execute the command and return the result 554 532 555 execvp( args[0], (char * const *)args );// should not return533 execvp( args[0], (char *const *)args ); // should not return 556 534 perror( "CFA Translator error: execvp" ); 557 535 exit( EXIT_FAILURE );
Note:
See TracChangeset
for help on using the changeset viewer.