Changes in driver/cfa.cc [14347ac:4f5a8a2]
- File:
-
- 1 edited
-
driver/cfa.cc (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
r14347ac r4f5a8a2 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S un Feb 10 08:28:09201913 // Update Count : 28112 // Last Modified On : Sat Aug 10 08:44:15 2019 13 // Update Count : 311 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> … … 26 27 #include "Common/SemanticError.h" 27 28 #include "config.h" // configure info 29 28 30 29 31 using std::cerr; … … 40 42 } // prefix 41 43 42 enum { NumSuffixes = 2 }; 43 const string suffixes[NumSuffixes] = { "cfa", "hfa", }; 44 45 bool suffix( string arg, const char * args[], int & nargs ) { 44 bool suffix( string arg ) { 45 enum { NumSuffixes = 3 }; 46 static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" }; 46 47 //std::cerr << arg << std::endl; 47 48 size_t dot = arg.find_last_of( "." ); 48 49 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl; 49 50 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 60 return false; 51 const string * end = suffixes + NumSuffixes; 52 return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end; 61 53 } // suffix 62 54 63 55 64 void shuffle( const char * args[], int S, int E, int N ) {56 void shuffle( const char * args[], int S, int E, int N ) { 65 57 // S & E index 1 passed the end so adjust with -1 66 58 #ifdef __DEBUG_H__ … … 75 67 } // shuffle 76 68 77 static inline bool dirExists( const string & path) {69 static inline bool dirExists( const string & path ) { 78 70 struct stat info; 79 71 if(stat( path.c_str(), &info ) != 0) … … 85 77 } //dirExists 86 78 87 static inline string dir(const string & path) {88 return path.substr(0, path.find_last_of('/'));89 }90 91 79 92 80 #define str(s) #s 93 81 94 int main( int argc, char * argv[] ) {82 int main( int argc, char * argv[] ) { 95 83 string Version( CFA_VERSION_LONG ); // current version number from CONFIG 96 84 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); … … 108 96 string compiler_name; // name of C compiler 109 97 98 bool x_flag = false; // -x flag 110 99 bool nonoptarg = false; // indicates non-option argument specified 111 100 bool link = true; // linking as well as compiling 112 101 bool verbose = false; // -v flag 113 bool quiet = false; // -quiet flag114 bool debug = true; // -debug flag115 bool nolib = false; // -nolib flag116 bool help = false; // -help flag102 bool quiet = false; // -quiet flag 103 bool debug = true; // -debug flag 104 bool nolib = false; // -nolib flag 105 bool help = false; // -help flag 117 106 bool CFA_flag = false; // -CFA flag 118 107 bool cpp_flag = false; // -E or -M flag, preprocessor only … … 120 109 bool noincstd_flag = false; // -no-include-stdhdr= flag 121 110 bool debugging __attribute(( unused )) = false; // -g flag 122 bool m32 = false; // -m32 flag123 bool m64 = false; // -m64 flag111 bool m32 = false; // -m32 flag 112 bool m64 = false; // -m64 flag 124 113 bool intree = false; 125 bool disttree = false;126 114 127 115 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 140 128 141 129 // process command-line arguments 142 143 args[nargs] = "-x"; // turn off language144 nargs += 1;145 args[nargs] = "c";146 nargs += 1;147 130 148 131 for ( int i = 1; i < argc; i += 1 ) { … … 188 171 } else if ( arg == "-in-tree" ) { 189 172 intree = true; 190 } else if ( arg == "-dist-tree" ) {191 disttree = true;192 173 } else if ( arg == "-compiler" ) { 193 174 // use the user specified compiler … … 210 191 args[nargs] = argv[i]; // pass the argument along 211 192 nargs += 1; 193 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 194 string lang; 195 args[nargs] = argv[i]; // pass the argument along 196 nargs += 1; 197 if ( arg.length() == 2 ) { // separate argument ? 198 i += 1; 199 if ( i == argc ) continue; // next argument available ? 200 lang = argv[i]; 201 args[nargs] = argv[i]; // pass the argument along 202 nargs += 1; 203 } else { 204 lang = arg.substr( 2 ); 205 } // if 206 x_flag = lang != "none"; 212 207 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 213 208 std_flag = true; // -std=XX provided … … 295 290 } // if 296 291 } else { 297 bool cfa = suffix( arg, args, nargs ); // check suffix 292 bool cfa = suffix( arg ); // check suffix 293 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 294 args[nargs] = "-x"; 295 nargs += 1; 296 args[nargs] = "c"; 297 nargs += 1; 298 } // if 298 299 args[nargs] = argv[i]; // concatenate file 299 300 nargs += 1; 300 if ( cfa ) {301 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ? 301 302 args[nargs] = "-x"; 302 303 nargs += 1; … … 379 380 string libdir = libbase + arch + "-" + config; 380 381 381 if (!disttree) { 382 if ( ! nolib && ! dirExists( libdir ) ) { 383 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; 384 cerr << "Was looking for " << libdir << endl; 385 for(int i = 1; i < argc; i++) { 386 cerr << argv[i] << " "; 387 } 388 cerr << endl; 389 libdir = libbase + arch + "-" + "nolib"; 390 } // if 391 392 if ( ! dirExists( libdir ) ) { 393 cerr << argv[0] << " internal error, cannot find prelude directory." << endl; 394 cerr << "Was looking for " << libdir << endl; 395 exit( EXIT_FAILURE ); 396 } // if 397 } // if 398 399 if(disttree) { 400 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str(); 401 } else if(intree) { 402 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str(); 403 } else { 404 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str(); 405 } 382 if ( ! nolib && ! dirExists( libdir ) ) { 383 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; 384 cerr << "Was looking for " << libdir << endl; 385 libdir = libbase + arch + "-" + "nolib"; 386 } // if 387 388 if ( ! dirExists( libdir ) ) { 389 cerr << argv[0] << " internal error, cannot find prelude directory." << endl; 390 cerr << "Was looking for " << libdir << endl; 391 exit( EXIT_FAILURE ); 392 } // if 393 394 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str(); 406 395 nargs += 1; 407 396 … … 492 481 493 482 if ( Bprefix.length() == 0 ) { 494 if(disttree) { 495 Bprefix = dir(argv[0]); 496 } else if(intree) { 497 Bprefix = srcdriverdir; 498 } else { 499 Bprefix = installlibdir; 500 } 501 483 Bprefix = ! intree ? installlibdir : srcdriverdir; 502 484 if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/'; 503 485 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); … … 557 539 if ( ! quiet ) { 558 540 cerr << "CFA " << "Version " << Version << heading << endl; 541 559 542 if ( help ) { 560 543 cerr <<
Note:
See TracChangeset
for help on using the changeset viewer.