Changeset 13d33a75 for driver/cfa.cc
- Timestamp:
- Aug 18, 2020, 4:31:19 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8e9d567
- Parents:
- ef9988b (diff), f2384c9a (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
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
ref9988b r13d33a75 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at May 30 18:28:23202013 // Update Count : 4 3312 // Last Modified On : Sun Aug 16 23:05:59 2020 13 // Update Count : 447 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 ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through 188 if(arg.size() == 5) { 183 184 // CFA specific arguments 185 186 } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through 187 if ( arg.size() == 5 ) { 189 188 i += 1; 190 if ( i == argc ) continue; 189 if ( i == argc ) continue; // next argument available ? 191 190 Putenv( argv, argv[i] ); 192 193 // CFA specific arguments 194 } 195 else if(arg[5] == ',') { 191 } else if ( arg[5] == ',' ) { // CFA specific arguments 196 192 Putenv( argv, argv[i] + 6 ); 197 198 // CFA specific arguments 199 } 200 else { 193 } else { // CFA specific arguments 201 194 args[nargs++] = argv[i]; 202 } 203 195 } // if 204 196 } else if ( arg == "-CFA" ) { 205 197 CFA_flag = true; // strip the -CFA flag … … 210 202 } else if ( arg == "-nodebug" ) { 211 203 debug = false; // strip the nodebug flag 212 } else if ( arg == "-nolib" ) {213 nolib = true; // strip the nodebug flag214 204 } else if ( arg == "-quiet" ) { 215 205 quiet = true; // strip the quiet flag 216 206 } else if ( arg == "-noquiet" ) { 217 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 218 212 } else if ( arg == "-help" ) { 219 213 help = true; // strip the help flag 220 214 } else if ( arg == "-nohelp" ) { 221 215 help = false; // strip the nohelp flag 222 } else if ( arg == "-no-include-stdhdr" ) {223 noincstd_flag = true; // strip the no-include-stdhdr flag224 216 } else if ( arg == "-cfalib") { 225 217 compiling_libs = true; … … 235 227 } else if ( arg == "-v" ) { 236 228 verbose = true; // verbosity required 237 args[nargs++] = argv[i]; // pass argumentalong229 args[nargs++] = argv[i]; // pass flag along 238 230 } else if ( arg == "-g" ) { 239 231 debugging = true; // symbolic debugging required 240 args[nargs++] = argv[i]; // pass argumentalong232 args[nargs++] = argv[i]; // pass flag along 241 233 } else if ( arg == "-save-temps" ) { 242 args[nargs++] = argv[i]; // pass argumentalong234 args[nargs++] = argv[i]; // pass flag along 243 235 Putenv( argv, arg ); // save cfa-cpp output 244 236 } else if ( prefix( arg, "-x" ) ) { // file suffix ? 245 237 string lang; 246 args[nargs++] = argv[i]; // pass argumentalong238 args[nargs++] = argv[i]; // pass flag along 247 239 if ( arg.length() == 2 ) { // separate argument ? 248 240 i += 1; … … 261 253 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 262 254 std_flag = true; // -std=XX provided 263 args[nargs++] = argv[i]; // pass argumentalong255 args[nargs++] = argv[i]; // pass flag along 264 256 } else if ( arg == "-w" ) { 265 args[nargs++] = argv[i]; // pass argumentalong257 args[nargs++] = argv[i]; // pass flag along 266 258 Putenv( argv, arg ); 267 259 } else if ( prefix( arg, "-W" ) ) { // check before next tests 268 260 if ( arg == "-Werror" || arg == "-Wall" ) { 269 args[nargs++] = argv[i]; // pass argumentalong261 args[nargs++] = argv[i]; // pass flag along 270 262 Putenv( argv, argv[i] ); 271 263 } else { … … 281 273 bprefix = arg.substr(2); // strip the -B flag 282 274 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { 283 args[nargs++] = argv[i]; // pass argumentalong275 args[nargs++] = argv[i]; // pass flag along 284 276 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { 285 277 cpp_flag = true; // cpp only 286 278 } // if 287 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 288 286 } else if ( arg[1] == 'l' ) { 289 287 // if the user specifies a library, load it after user code … … 337 335 string libbase; 338 336 switch(path) { 339 case Installed:337 case Installed: 340 338 args[nargs++] = "-I" CFA_INCDIR; 341 339 // do not use during build … … 347 345 libbase = CFA_LIBDIR; 348 346 break; 349 case BuildTree:350 case Distributed:347 case BuildTree: 348 case Distributed: 351 349 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src"; 352 350 // do not use during build … … 382 380 string libdir = libbase + arch + "-" + config; 383 381 384 if ( path != Distributed) {382 if ( path != Distributed ) { 385 383 if ( ! nolib && ! dirExists( libdir ) ) { 386 384 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl; … … 402 400 string preludedir; 403 401 switch(path) { 404 case Installed : preludedir = libdir; break;405 case BuildTree : preludedir = libdir + "/prelude"; break;406 case Distributed : preludedir = dir(argv[0]); break;407 } 402 case Installed : preludedir = libdir; break; 403 case BuildTree : preludedir = libdir + "/prelude"; break; 404 case Distributed : preludedir = dir(argv[0]); break; 405 } // switch 408 406 409 407 Putenv( argv, "--prelude-dir=" + preludedir ); … … 477 475 if ( bprefix.length() == 0 ) { 478 476 switch(path) { 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 } // if477 case Installed : bprefix = installlibdir; break; 478 case BuildTree : bprefix = srcdriverdir ; break; 479 case Distributed : bprefix = dir(argv[0]) ; break; 480 } // switch 481 } // if 482 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/'; 483 Putenv( argv, string("-B=") + bprefix ); 486 484 487 485 args[nargs++] = "-Xlinker"; // used by backtrace … … 505 503 args[nargs++] = "-Wno-cast-function-type"; 506 504 #endif // HAVE_CAST_FUNCTION_TYPE 507 if ( ! std_flag ) { // default c11, if none specified508 args[nargs++] = "-std=gnu11"; 505 if ( ! std_flag && ! x_flag ) { 506 args[nargs++] = "-std=gnu11"; // default c11, if none specified 509 507 } // if 510 508 args[nargs++] = "-fgnu89-inline"; … … 556 554 // execute the command and return the result 557 555 558 execvp( args[0], (char * const *)args );// should not return556 execvp( args[0], (char * const *)args ); // should not return 559 557 perror( "CFA Translator error: execvp" ); 560 558 exit( EXIT_FAILURE );
Note: See TracChangeset
for help on using the changeset viewer.