Changeset 90152a4 for driver/cfa.cc
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (8 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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 moved
-
driver/cfa.cc (moved) (moved from src/driver/cfa.cc ) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/cfa.cc
rf9feab8 r90152a4 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Oct 31 11:40:44 201713 // Update Count : 16012 // Last Modified On : Fri Aug 10 18:17:58 2018 13 // Update Count : 259 14 14 // 15 15 … … 19 19 #include <unistd.h> // execvp 20 20 #include <string> // STL version 21 21 #include <string.h> // strcmp 22 23 #include <sys/types.h> 24 #include <sys/stat.h> 25 26 #include "Common/SemanticError.h" 22 27 #include "config.h" // configure info 23 28 … … 35 40 } // prefix 36 41 42 enum { NumSuffixes = 2 }; 43 const string suffixes[NumSuffixes] = { "cfa", "hfa", }; 44 45 bool suffix( string arg ) { 46 //std::cerr << arg << std::endl; 47 size_t dot = arg.find_last_of( "." ); 48 //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl; 49 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] ) return true; 53 } // for 54 return false; 55 } // suffix 56 37 57 38 58 void shuffle( const char *args[], int S, int E, int N ) { 39 59 // S & E index 1 passed the end so adjust with -1 40 #ifdef __DEBUG_H__60 #ifdef __DEBUG_H__ 41 61 cerr << "shuffle:" << S << " " << E << " " << N << endl; 42 #endif // __DEBUG_H__62 #endif // __DEBUG_H__ 43 63 for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { 44 #ifdef __DEBUG_H__64 #ifdef __DEBUG_H__ 45 65 cerr << "\t" << j << " " << j-N << endl; 46 #endif // __DEBUG_H__66 #endif // __DEBUG_H__ 47 67 args[j] = args[j-N]; 48 68 } // for 49 69 } // shuffle 50 70 71 static inline bool dirExists(const string & path) { 72 struct stat info; 73 if(stat( path.c_str(), &info ) != 0) 74 return false; 75 else if(info.st_mode & S_IFDIR) 76 return true; 77 else 78 return false; 79 } //dirExists 80 51 81 52 82 #define str(s) #s … … 56 86 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); 57 87 58 string installincdir( CFA_INCDIR ); // fixed location of include files 59 string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands 88 string installincdir( CFA_INCDIR ); // fixed location of include files 89 string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands when installed 90 string srcdriverdir ( TOP_BUILDDIR "driver"); // fixed location of cc1 and cfa-cpp commands when in tree 60 91 61 92 string heading; // banner printed at start of cfa compilation … … 77 108 bool std_flag = false; // -std= flag 78 109 bool noincstd_flag = false; // -no-include-stdhdr= flag 110 bool xflag = false; // user supplied -x flag 79 111 bool debugging __attribute(( unused )) = false; // -g flag 112 bool m32 = false; // -m32 flag 113 bool m64 = false; // -m64 flag 114 bool intree = false; 80 115 81 116 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags … … 86 121 int nlibs = 0; 87 122 88 #ifdef __DEBUG_H__123 #ifdef __DEBUG_H__ 89 124 cerr << "CFA:" << endl; 90 #endif // __DEBUG_H__125 #endif // __DEBUG_H__ 91 126 92 127 // process command-line arguments 93 128 94 129 for ( int i = 1; i < argc; i += 1 ) { 95 #ifdef __DEBUG_H__130 #ifdef __DEBUG_H__ 96 131 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; 97 #endif // __DEBUG_H__132 #endif // __DEBUG_H__ 98 133 arg = argv[i]; // convert to string value 99 #ifdef __DEBUG_H__134 #ifdef __DEBUG_H__ 100 135 cerr << "arg:\"" << arg << "\"" << endl; 101 #endif // __DEBUG_H__136 #endif // __DEBUG_H__ 102 137 if ( prefix( arg, "-" ) ) { 103 138 // pass through arguments … … 136 171 } else if ( arg == "-no-include-stdhdr" ) { 137 172 noincstd_flag = true; // strip the no-include-stdhdr flag 173 } else if ( arg == "-in-tree" ) { 174 intree = true; 138 175 } else if ( arg == "-compiler" ) { 139 176 // use the user specified compiler … … 156 193 args[nargs] = argv[i]; // pass the argument along 157 194 nargs += 1; 158 } else if ( prefix( arg, "-std=" ) ) {195 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { 159 196 std_flag = true; // -std=XX provided 160 197 args[nargs] = argv[i]; // pass the argument along 161 198 nargs += 1; 199 } else if ( arg == "-x" ) { 200 xflag = true; 201 args[nargs] = argv[i]; // pass the argument along 202 nargs += 1; 203 i += 1; // advance to argument 204 args[nargs] = argv[i]; // pass the argument along 205 nargs += 1; 206 // args[nargs] = ( *new string( string("-D__GCC_X__=") + argv[i] ) ).c_str(); // add the argument for -x 207 // nargs += 1; 208 } else if ( prefix( arg, "-x" ) ) { 209 xflag = true; 210 args[nargs] = argv[i]; // pass the argument along 211 nargs += 1; 212 // args[nargs] = ( *new string( string("-D__GCC_X__=") + arg.substr(2) ) ).c_str(); // add the argument for -x 213 // nargs += 1; 214 } else if ( arg == "-w" ) { 215 args[nargs] = argv[i]; // pass the argument along 216 nargs += 1; 217 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 218 nargs += 1; 219 } else if ( prefix( arg, "-W" ) ) { // check before next tests 220 if ( arg == "-Werror" || arg == "-Wall" ) { 221 args[nargs] = argv[i]; // pass the argument along 222 nargs += 1; 223 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp 224 nargs += 1; 225 } else { 226 unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; 227 args[nargs] = argv[i]; // conditionally pass the argument along 228 const char * warning = argv[i] + adv; // extract warning 229 if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp 230 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); 231 } // if 232 nargs += 1; 233 } // if 162 234 } else if ( prefix( arg, "-B" ) ) { 163 235 Bprefix = arg.substr(2); // strip the -B flag … … 205 277 libs[nlibs] = argv[i]; 206 278 nlibs += 1; 279 } else if ( arg == "-m32" ) { 280 m32 = true; 281 m64 = false; 282 args[nargs] = argv[i]; 283 nargs += 1; 284 } else if ( arg == "-m64" ) { 285 m64 = true; 286 m32 = false; 287 args[nargs] = argv[i]; 288 nargs += 1; 207 289 } else { 208 290 // concatenate any other arguments … … 211 293 } // if 212 294 } else { 295 bool opt = false; 296 if ( ! xflag && suffix( arg ) ) { 297 args[nargs] = "-x"; 298 nargs += 1; 299 args[nargs] = "c"; 300 nargs += 1; 301 // args[nargs] = ( *new string( string("-D__GCC_X__=c") ) ).c_str(); // add the argument for -x 302 // nargs += 1; 303 opt = true; 304 } // if 213 305 // concatenate other arguments 214 306 args[nargs] = argv[i]; 215 307 nargs += 1; 308 if ( opt ) { 309 args[nargs] = "-x"; 310 nargs += 1; 311 args[nargs] = "none"; 312 nargs += 1; 313 // args[nargs] = ( *new string( string("-D__GCC_X__=none") ) ).c_str(); // add the argument for -x 314 // nargs += 1; 315 } // if 216 316 nonoptarg = true; 317 xflag = false; 217 318 } // if 218 319 } // for 219 320 220 #ifdef __DEBUG_H__ 321 #ifdef __x86_64__ 322 args[nargs] = "-mcx16"; // allow double-wide CAA 323 nargs += 1; 324 #endif // __x86_64__ 325 326 #ifdef __DEBUG_H__ 221 327 cerr << "args:"; 222 328 for ( int i = 1; i < nargs; i += 1 ) { … … 224 330 } // for 225 331 cerr << endl; 226 #endif // __DEBUG_H__332 #endif // __DEBUG_H__ 227 333 228 334 if ( cpp_flag && CFA_flag ) { … … 232 338 233 339 // add the CFA include-library paths, which allow direct access to header files without directory qualification 234 args[nargs] = "-I" CFA_INCDIR; 235 nargs += 1; 236 if ( ! noincstd_flag ) { // do not use during build 237 args[nargs] = "-I" CFA_INCDIR "/stdhdr"; 238 nargs += 1; 239 } // if 240 args[nargs] = "-I" CFA_INCDIR "/concurrency"; 241 nargs += 1; 242 args[nargs] = "-I" CFA_INCDIR "/containers"; 243 nargs += 1; 244 245 #ifdef HAVE_LIBCFA 340 if( !intree ) { 341 args[nargs] = "-I" CFA_INCDIR; 342 nargs += 1; 343 if ( ! noincstd_flag ) { // do not use during build 344 args[nargs] = "-I" CFA_INCDIR "/stdhdr"; 345 nargs += 1; 346 } // if 347 args[nargs] = "-I" CFA_INCDIR "/concurrency"; 348 nargs += 1; 349 args[nargs] = "-I" CFA_INCDIR "/containers"; 350 nargs += 1; 351 } else { 352 args[nargs] = "-I" TOP_SRCDIR "libcfa/src"; 353 nargs += 1; 354 if ( ! noincstd_flag ) { // do not use during build 355 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr"; 356 nargs += 1; 357 } // if 358 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency"; 359 nargs += 1; 360 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers"; 361 nargs += 1; 362 } 363 364 // add stdbool to get defines for bool/true/false 365 args[nargs] = "-imacros"; 366 nargs += 1; 367 args[nargs] = "stdbool.h"; 368 nargs += 1; 369 370 string libbase; 371 if( !intree ) { 372 libbase = CFA_LIBDIR; 373 } else { 374 libbase = TOP_BUILDDIR "libcfa/"; 375 args[nargs] = "-D__CFA_FLAG__=-t"; 376 nargs += 1; 377 } 378 379 const char * const arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU); 380 const char * config = debug ? "debug": "nodebug"; 381 string libdir = libbase + arch + "-" + config; 382 if( !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 } 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 } 393 394 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str(); 395 nargs += 1; 396 246 397 if ( link ) { 247 #if ! defined(HAVE_LIBCFA_RELEASE) 248 if( !debug ) { 249 cerr << "error: Option -nodebug is not available, libcfa was not installed." << endl; 250 exit( EXIT_FAILURE ); 251 } 252 #endif 253 #if ! defined(HAVE_LIBCFA_DEBUG) 254 if( debug ) { 255 cerr << "error: Option -debug is not available, libcfa-d was not installed." << endl; 256 exit( EXIT_FAILURE ); 257 } 258 #endif 398 args[nargs] = "-Xlinker"; 399 nargs += 1; 400 args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; 401 nargs += 1; 402 args[nargs] = "-Xlinker"; 403 nargs += 1; 404 args[nargs] = "--undefined=__cfaabi_interpose_startup"; 405 nargs += 1; 406 args[nargs] = "-Xlinker"; 407 nargs += 1; 408 args[nargs] = "--undefined=__cfaabi_appready_startup"; 409 nargs += 1; 410 args[nargs] = "-Xlinker"; 411 nargs += 1; 412 args[nargs] = "--undefined=__cfaabi_dbg_record"; 413 nargs += 1; 259 414 260 415 // include the cfa library in case it's needed 261 args[nargs] = "-L" CFA_LIBDIR; 262 nargs += 1; 263 if( debug ) { 264 args[nargs] = "-lcfa-d"; 265 } else { 266 args[nargs] = "-lcfa"; 267 } 416 args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src" : "")) ).c_str(); 417 nargs += 1; 418 args[nargs] = "-lcfa"; 268 419 nargs += 1; 269 420 args[nargs] = "-lpthread"; … … 273 424 args[nargs] = "-lrt"; 274 425 nargs += 1; 275 args[nargs] = "-Xlinker"; 276 nargs += 1; 277 args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; 278 nargs += 1; 279 280 } // if 281 #endif //HAVE_LIBCFA 426 } // if 282 427 283 428 // Add exception flags (unconditionally) … … 325 470 326 471 if ( Bprefix.length() == 0 ) { 327 Bprefix = installlibdir;472 Bprefix = !intree ? installlibdir : srcdriverdir; 328 473 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); 329 474 nargs += 1; 330 475 } // if 476 477 args[nargs] = "-Xlinker"; // used by backtrace 478 nargs += 1; 479 args[nargs] = "-export-dynamic"; 480 nargs += 1; 331 481 332 482 // execute the compilation command … … 346 496 args[nargs] = "-Wno-deprecated"; 347 497 nargs += 1; 348 if ( ! std_flag ) { // default c 99, if none specified349 args[nargs] = "-std=gnu 99";498 if ( ! std_flag ) { // default c11, if none specified 499 args[nargs] = "-std=gnu11"; 350 500 nargs += 1; 351 501 } // if … … 370 520 args[nargs] = NULL; // terminate with NULL 371 521 372 #ifdef __DEBUG_H__522 #ifdef __DEBUG_H__ 373 523 cerr << "nargs: " << nargs << endl; 374 524 cerr << "args:" << endl; … … 376 526 cerr << " \"" << args[i] << "\"" << endl; 377 527 } // for 378 #endif // __DEBUG_H__528 #endif // __DEBUG_H__ 379 529 380 530 if ( ! quiet ) {
Note:
See TracChangeset
for help on using the changeset viewer.