Changeset 58fe85a for driver/cfa.cc
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
driver/cfa.cc (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
r3c64c668 r58fe85a 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 31 16:48:03202013 // Update Count : 4 2112 // Last Modified On : Tue Nov 17 14:27:28 2020 13 // Update Count : 440 14 14 // 15 15 16 16 #include <iostream> 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 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 25 24 #include <sys/types.h> 26 25 #include <sys/stat.h> … … 34 33 using std::to_string; 35 34 36 // #define __DEBUG_H__ 37 38 // "N__=" suffix 39 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); 40 41 void Putenv( char * argv[], string arg ) { 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 ) { 42 43 // environment variables must have unique names 43 44 static int flags = 0; … … 49 50 } // Putenv 50 51 51 // check if string has prefix 52 bool prefix( const string & arg, const string & pre ) { 52 static bool prefix( const string & arg, const string & pre ) { // check if string has prefix 53 53 return arg.substr( 0, pre.size() ) == pre; 54 54 } // prefix 55 55 56 inline bool ends_with(const string & str, const string & sfix) {56 static 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 bool suffix( const string & arg ) {62 static 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 73 72 static inline bool dirExists( const string & path ) { // check if directory exists 74 73 struct stat info; … … 79 78 static inline string dir(const string & path) { 80 79 return path.substr(0, path.find_last_of('/')); 81 } 80 } // dir 82 81 83 82 // Different path modes … … 118 117 } 119 118 120 121 #define xstr(s) str(s)122 #define str(s) #s123 119 124 120 int main( int argc, char * argv[] ) { … … 158 154 PathMode path = FromProc(); 159 155 160 const char * args[argc + 100]; // cfa command line values, plus some space for additional flags156 const char * args[argc + 100]; // cfa command line values, plus some space for additional flags 161 157 int sargs = 1; // starting location for arguments in args list 162 158 int nargs = sargs; // number of arguments in args list; 0 => command name 163 159 164 const char * libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags160 const char * libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags 165 161 int nlibs = 0; 166 162 … … 180 176 181 177 if ( arg == "-Xlinker" || arg == "-o" ) { 182 args[nargs++] = argv[i]; // pass argumentalong178 args[nargs++] = argv[i]; // pass flag along 183 179 i += 1; 184 180 if ( i == argc ) continue; // next argument available ? 185 181 args[nargs++] = argv[i]; // pass argument along 186 182 if ( arg == "-o" ) o_file = i; // remember file 187 } else if ( arg == "-XCFA" ) { // CFA pass through188 i += 1;189 if ( i == argc ) continue; // next argument available ?190 Putenv( argv, argv[i] );191 183 192 184 // CFA specific arguments 193 185 186 } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through 187 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 arguments 192 Putenv( argv, argv[i] + 6 ); 193 } else { // CFA specific arguments 194 args[nargs++] = argv[i]; 195 } // if 194 196 } else if ( arg == "-CFA" ) { 195 197 CFA_flag = true; // strip the -CFA flag … … 200 202 } else if ( arg == "-nodebug" ) { 201 203 debug = false; // strip the nodebug flag 202 } else if ( arg == "-nolib" ) {203 nolib = true; // strip the nodebug flag204 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 flag 210 } else if ( arg == "-nolib" ) { 211 nolib = true; // strip the nolib flag 208 212 } else if ( arg == "-help" ) { 209 213 help = true; // strip the help flag 210 214 } else if ( arg == "-nohelp" ) { 211 215 help = false; // strip the nohelp flag 212 } else if ( arg == "-no-include-stdhdr" ) {213 noincstd_flag = true; // strip the no-include-stdhdr flag214 216 } else if ( arg == "-cfalib") { 215 217 compiling_libs = true; … … 225 227 } else if ( arg == "-v" ) { 226 228 verbose = true; // verbosity required 227 args[nargs++] = argv[i]; // pass argumentalong229 args[nargs++] = argv[i]; // pass flag along 228 230 } else if ( arg == "-g" ) { 229 231 debugging = true; // symbolic debugging required 230 args[nargs++] = argv[i]; // pass argumentalong231 } else if ( arg == "-save-temps" ) {232 args[nargs++] = argv[i]; // pass argumentalong232 args[nargs++] = argv[i]; // pass flag along 233 } else if ( arg == "-save-temps" || arg == "--save-temps" ) { 234 args[nargs++] = argv[i]; // pass flag along 233 235 Putenv( argv, arg ); // save cfa-cpp output 234 236 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 235 237 string lang; 236 args[nargs++] = argv[i]; // pass argumentalong238 args[nargs++] = argv[i]; // pass flag along 237 239 if ( arg.length() == 2 ) { // separate argument ? 238 240 i += 1; … … 243 245 lang = arg.substr( 2 ); 244 246 } // if 245 x_flag = lang != "none"; 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 246 253 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 247 254 std_flag = true; // -std=XX provided 248 args[nargs++] = argv[i]; // pass argumentalong255 args[nargs++] = argv[i]; // pass flag along 249 256 } else if ( arg == "-w" ) { 250 args[nargs++] = argv[i]; // pass argumentalong257 args[nargs++] = argv[i]; // pass flag along 251 258 Putenv( argv, arg ); 252 259 } else if ( prefix( arg, "-W" ) ) { // check before next tests 253 260 if ( arg == "-Werror" || arg == "-Wall" ) { 254 args[nargs++] = argv[i]; // pass argumentalong261 args[nargs++] = argv[i]; // pass flag along 255 262 Putenv( argv, argv[i] ); 256 263 } else { … … 266 273 bprefix = arg.substr(2); // strip the -B flag 267 274 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 268 args[nargs++] = argv[i]; // pass argumentalong275 args[nargs++] = argv[i]; // pass flag along 269 276 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 270 277 cpp_flag = true; // cpp only 271 278 } // if 272 279 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 along 284 i += 1; 285 args[nargs++] = argv[i]; // pass argument along 273 286 } else if ( arg[1] == 'l' ) { 274 287 // if the user specifies a library, load it after user code … … 302 315 303 316 #ifdef __x86_64__ 304 args[nargs++] = "-mcx16"; // allow double-wide CA A317 args[nargs++] = "-mcx16"; // allow double-wide CAS 305 318 #endif // __x86_64__ 306 319 … … 322 335 string libbase; 323 336 switch(path) { 324 case Installed:337 case Installed: 325 338 args[nargs++] = "-I" CFA_INCDIR; 326 339 // do not use during build … … 332 345 libbase = CFA_LIBDIR; 333 346 break; 334 case BuildTree:335 case Distributed:347 case BuildTree: 348 case Distributed: 336 349 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 337 350 // do not use during build … … 367 380 string libdir = libbase + arch + "-" + config; 368 381 369 if ( path != Distributed) {382 if ( path != Distributed ) { 370 383 if ( ! nolib && ! dirExists( libdir ) ) { 371 384 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; … … 385 398 } // if 386 399 400 string preludedir; 387 401 switch(path) { 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 } 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(); 392 410 393 411 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries … … 415 433 args[nargs++] = "-Wl,--pop-state"; 416 434 args[nargs++] = "-pthread"; 435 #if defined( __x86_64__ ) || defined( __ARM_ARCH ) 436 args[nargs++] = "-latomic"; // allow double-wide CAS 437 #endif // __x86_64__ 417 438 args[nargs++] = "-ldl"; 418 args[nargs++] = "-lrt";419 439 args[nargs++] = "-lm"; 420 440 } // if … … 454 474 if ( bprefix.length() == 0 ) { 455 475 switch(path) { 456 case Installed : bprefix = installlibdir; break;457 case BuildTree : bprefix = srcdriverdir ; break;458 case Distributed : bprefix = dir(argv[0]) ; break;459 } 460 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';461 Putenv( argv, string("-B=") + bprefix );462 } // if476 case Installed : bprefix = installlibdir; break; 477 case BuildTree : bprefix = srcdriverdir ; break; 478 case Distributed : bprefix = dir(argv[0]) ; break; 479 } // switch 480 } // if 481 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 482 Putenv( argv, string("-B=") + bprefix ); 463 483 464 484 args[nargs++] = "-Xlinker"; // used by backtrace … … 482 502 args[nargs++] = "-Wno-cast-function-type"; 483 503 #endif // HAVE_CAST_FUNCTION_TYPE 484 if ( ! std_flag ) { // default c11, if none specified485 args[nargs++] = "-std=gnu11"; 504 if ( ! std_flag && ! x_flag ) { 505 args[nargs++] = "-std=gnu11"; // default c11, if none specified 486 506 } // if 487 507 args[nargs++] = "-fgnu89-inline"; … … 533 553 // execute the command and return the result 534 554 535 execvp( args[0], (char * const *)args );// should not return555 execvp( args[0], (char * const *)args ); // should not return 536 556 perror( "CFA Translator error: execvp" ); 537 557 exit( EXIT_FAILURE );
Note:
See TracChangeset
for help on using the changeset viewer.