- Timestamp:
- Aug 20, 2020, 11:48:15 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d685cb0
- Parents:
- 67ca73e (diff), 013b028 (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. - Location:
- driver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
r67ca73e re67a82d 10 10 // Created On : Fri Aug 26 14:23:51 2005 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at May 30 18:09:05202013 // Update Count : 4 0412 // Last Modified On : Sun Aug 16 21:03:02 2020 13 // Update Count : 413 14 14 // 15 15 … … 24 24 #include <unistd.h> // execvp, fork, unlink 25 25 #include <sys/wait.h> // wait 26 #include <fcntl.h> 26 #include <fcntl.h> // creat 27 27 28 28 … … 59 59 60 60 61 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // " N__=" suffix61 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" ); // "__CFA_FLAG__=" suffix 62 62 63 63 static void checkEnv1( const char * args[], int & nargs ) { // stage 1 … … 111 111 } // checkEnv2 112 112 113 114 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa"; 113 #define CFA_SUFFIX ".ifa" 114 115 static char tmpname[] = P_tmpdir "/CFAXXXXXX" CFA_SUFFIX; 115 116 static int tmpfilefd = -1; 116 117 static bool startrm = false; … … 170 171 if ( arg == "-quiet" ) { 171 172 } else if ( arg == "-imultilib" || arg == "-imultiarch" ) { 172 i += 1; // and theargument173 i += 1; // and argument 173 174 } else if ( prefix( arg, "-A" ) ) { 174 175 } else if ( prefix( arg, "-D__GNU" ) ) { … … 177 178 //******** 178 179 } else if ( arg == "-D" && prefix( argv[i + 1], "__GNU" ) ) { 179 i += 1; // and theargument180 i += 1; // and argument 180 181 181 182 // strip flags controlling cpp step … … 184 185 cpp_flag = true; 185 186 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) { 186 i += 1; // and theargument187 i += 1; // and argument 187 188 cpp_flag = true; 188 189 … … 194 195 cpp_out = argv[i]; 195 196 } else { 196 args[nargs++] = argv[i]; // pass theflag along197 args[nargs++] = argv[i]; // pass flag along 197 198 // CPP flags with an argument 198 199 if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" || … … 200 201 arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) { 201 202 i += 1; 202 args[nargs++] = argv[i]; // pass theargument along203 args[nargs++] = argv[i]; // pass argument along 203 204 #ifdef __DEBUG_H__ 204 205 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 205 206 #endif // __DEBUG_H__ 206 207 } else if ( arg == "-MD" || arg == "-MMD" ) { 208 // gcc frontend generates the dependency file-name after the -MD/-MMD flag, but it is necessary to 209 // prefix that file name with -MF. 207 210 args[nargs++] = "-MF"; // insert before file 208 211 i += 1; 209 args[nargs++] = argv[i]; // pass theargument along212 args[nargs++] = argv[i]; // pass argument along 210 213 #ifdef __DEBUG_H__ 211 214 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; … … 279 282 // Run the C preprocessor and save the output in the given file. 280 283 281 if ( fork() == 0 ) { 284 if ( fork() == 0 ) { // child process ? 282 285 // -o xxx.ii cannot be used to write the output file from cpp because no output file is created if cpp detects 283 286 // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error, … … 319 322 320 323 if ( WIFSIGNALED(code) ) { // child failed ? 324 rmtmpfile(); // remove tmpname 321 325 cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl; 322 326 exit( EXIT_FAILURE ); 323 327 } // if 324 328 325 exit( WEXITSTATUS( code) );// bad cpp result stops top-level gcc329 exit( WEXITSTATUS( code ) ); // bad cpp result stops top-level gcc 326 330 } // Stage1 327 331 … … 371 375 } else if ( arg == "-fno-diagnostics-color" ) { 372 376 color_arg = Color_Auto; 373 } 377 } // if 374 378 375 379 if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" || 376 // Currently CFA does not suppose precompiled .h files.377 prefix( arg, "--output-pch" ) ) {380 // Currently CFA does not suppose precompiled .h files. 381 prefix( arg, "--output-pch" ) ) { 378 382 379 383 // strip inappropriate flags with an argument … … 388 392 389 393 } else { 390 args[nargs++] = argv[i]; // pass theflag along394 args[nargs++] = argv[i]; // pass flag along 391 395 if ( arg == "-o" ) { 392 396 i += 1; 393 397 cpp_out = argv[i]; 394 args[nargs++] = argv[i]; // pass theargument along398 args[nargs++] = argv[i]; // pass argument along 395 399 #ifdef __DEBUG_H__ 396 400 cerr << "arg:\"" << argv[i] << "\"" << endl; … … 439 443 } // if 440 444 441 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";445 cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + CFA_SUFFIX; 442 446 if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) { 443 447 perror( "CC1 Translator error: stage 2, creat" ); … … 460 464 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 461 465 462 if ( fork() == 0 ) { // child runs CFA 466 if ( fork() == 0 ) { // child runs CFA preprocessor 463 467 cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str(); 464 468 cargs[ncargs++] = cpp_in; … … 518 522 #endif // __DEBUG_H__ 519 523 520 if ( fork() == 0 ) { // child runs CFA524 if ( fork() == 0 ) { // child runs gcc 521 525 args[0] = compiler_path.c_str(); 522 526 args[nargs++] = "-S"; // only compile and put assembler output in specified file -
driver/cfa.cc
r67ca73e re67a82d 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Aug 18 16:40:22202013 // Update Count : 43 512 // Last Modified On : Thu Aug 20 23:43:59 2020 13 // Update Count : 436 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.