Changes in driver/cfa.cc [406970b1:9b34766]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
r406970b1 r9b34766 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Sep 2 17:59:20202013 // Update Count : 43 812 // Last Modified On : Tue Aug 18 16:40:22 2020 13 // Update Count : 435 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 * 160 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 * 164 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 183 184 // CFA specific arguments 185 186 } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through 187 if ( arg.size() == 5 ) { 187 } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through 188 if(arg.size() == 5) { 188 189 i += 1; 189 if ( i == argc ) continue; // next argument available ?190 if ( i == argc ) continue; // next argument available ? 190 191 Putenv( argv, argv[i] ); 191 } else if ( arg[5] == ',' ) { // CFA specific arguments 192 193 // CFA specific arguments 194 } 195 else if(arg[5] == ',') { 192 196 Putenv( argv, argv[i] + 6 ); 193 } else { // CFA specific arguments 197 198 // CFA specific arguments 199 } 200 else { 194 201 args[nargs++] = argv[i]; 195 } // if 202 } 203 196 204 } else if ( arg == "-CFA" ) { 197 205 CFA_flag = true; // strip the -CFA flag … … 202 210 } else if ( arg == "-nodebug" ) { 203 211 debug = false; // strip the nodebug flag 212 } else if ( arg == "-nolib" ) { 213 nolib = true; // strip the nodebug flag 204 214 } else if ( arg == "-quiet" ) { 205 215 quiet = true; // strip the quiet flag 206 216 } else if ( arg == "-noquiet" ) { 207 217 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 218 } else if ( arg == "-help" ) { 213 219 help = true; // strip the help flag 214 220 } else if ( arg == "-nohelp" ) { 215 221 help = false; // strip the nohelp flag 222 } else if ( arg == "-no-include-stdhdr" ) { 223 noincstd_flag = true; // strip the no-include-stdhdr flag 216 224 } else if ( arg == "-cfalib") { 217 225 compiling_libs = true; … … 227 235 } else if ( arg == "-v" ) { 228 236 verbose = true; // verbosity required 229 args[nargs++] = argv[i]; // pass flagalong237 args[nargs++] = argv[i]; // pass argument along 230 238 } else if ( arg == "-g" ) { 231 239 debugging = true; // symbolic debugging required 232 args[nargs++] = argv[i]; // pass flagalong240 args[nargs++] = argv[i]; // pass argument along 233 241 } else if ( arg == "-save-temps" ) { 234 args[nargs++] = argv[i]; // pass flagalong242 args[nargs++] = argv[i]; // pass argument along 235 243 Putenv( argv, arg ); // save cfa-cpp output 236 244 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 237 245 string lang; 238 args[nargs++] = argv[i]; // pass flagalong246 args[nargs++] = argv[i]; // pass argument along 239 247 if ( arg.length() == 2 ) { // separate argument ? 240 248 i += 1; … … 253 261 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 254 262 std_flag = true; // -std=XX provided 255 args[nargs++] = argv[i]; // pass flagalong263 args[nargs++] = argv[i]; // pass argument along 256 264 } else if ( arg == "-w" ) { 257 args[nargs++] = argv[i]; // pass flagalong265 args[nargs++] = argv[i]; // pass argument along 258 266 Putenv( argv, arg ); 259 267 } else if ( prefix( arg, "-W" ) ) { // check before next tests 260 268 if ( arg == "-Werror" || arg == "-Wall" ) { 261 args[nargs++] = argv[i]; // pass flagalong269 args[nargs++] = argv[i]; // pass argument along 262 270 Putenv( argv, argv[i] ); 263 271 } else { … … 273 281 bprefix = arg.substr(2); // strip the -B flag 274 282 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 275 args[nargs++] = argv[i]; // pass flagalong283 args[nargs++] = argv[i]; // pass argument along 276 284 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 277 285 cpp_flag = true; // cpp only 278 286 } // if 279 287 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 288 } else if ( arg[1] == 'l' ) { 287 289 // if the user specifies a library, load it after user code … … 335 337 string libbase; 336 338 switch(path) { 337 339 case Installed: 338 340 args[nargs++] = "-I" CFA_INCDIR; 339 341 // do not use during build … … 345 347 libbase = CFA_LIBDIR; 346 348 break; 347 348 349 case BuildTree: 350 case Distributed: 349 351 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 350 352 // do not use during build … … 380 382 string libdir = libbase + arch + "-" + config; 381 383 382 if ( path != Distributed) {384 if (path != Distributed) { 383 385 if ( ! nolib && ! dirExists( libdir ) ) { 384 386 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; … … 400 402 string preludedir; 401 403 switch(path) { 402 403 404 405 } // switch404 case Installed : preludedir = libdir; break; 405 case BuildTree : preludedir = libdir + "/prelude"; break; 406 case Distributed : preludedir = dir(argv[0]); break; 407 } 406 408 407 409 Putenv( argv, "--prelude-dir=" + preludedir ); … … 437 439 #endif // __x86_64__ 438 440 args[nargs++] = "-ldl"; 441 args[nargs++] = "-lrt"; 439 442 args[nargs++] = "-lm"; 440 443 } // if … … 474 477 if ( bprefix.length() == 0 ) { 475 478 switch(path) { 476 477 478 479 } // switch480 } // if481 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';482 Putenv( argv, string("-B=") + bprefix );479 case Installed : bprefix = installlibdir; break; 480 case BuildTree : bprefix = srcdriverdir ; break; 481 case Distributed : bprefix = dir(argv[0]) ; break; 482 } 483 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 484 Putenv( argv, string("-B=") + bprefix ); 485 } // if 483 486 484 487 args[nargs++] = "-Xlinker"; // used by backtrace … … 502 505 args[nargs++] = "-Wno-cast-function-type"; 503 506 #endif // HAVE_CAST_FUNCTION_TYPE 504 if ( ! std_flag && ! x_flag ) {505 args[nargs++] = "-std=gnu11"; // default c11, if none specified507 if ( ! std_flag ) { // default c11, if none specified 508 args[nargs++] = "-std=gnu11"; 506 509 } // if 507 510 args[nargs++] = "-fgnu89-inline"; … … 553 556 // execute the command and return the result 554 557 555 execvp( args[0], (char * const *)args );// should not return558 execvp( args[0], (char *const *)args ); // should not return 556 559 perror( "CFA Translator error: execvp" ); 557 560 exit( EXIT_FAILURE );
Note: See TracChangeset
for help on using the changeset viewer.