[b87a5ed] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[76c7f65e] | 7 | // cfa.cc -- |
---|
[b87a5ed] | 8 | // |
---|
[51b7345] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Tue Aug 20 13:44:49 2002 |
---|
[201aeb9] | 11 | // Last Modified By : Peter A. Buhr |
---|
[dffaeac] | 12 | // Last Modified On : Fri Jul 13 17:40:12 2018 |
---|
| 13 | // Update Count : 258 |
---|
[b87a5ed] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include <iostream> |
---|
[b87a5ed] | 17 | #include <cstdio> // perror |
---|
| 18 | #include <cstdlib> // putenv, exit |
---|
| 19 | #include <unistd.h> // execvp |
---|
| 20 | #include <string> // STL version |
---|
[44bca7f] | 21 | #include <string.h> // strcmp |
---|
[51b7345] | 22 | |
---|
[44bca7f] | 23 | #include "Common/SemanticError.h" |
---|
[b87a5ed] | 24 | #include "config.h" // configure info |
---|
[51b7345] | 25 | |
---|
| 26 | using std::cerr; |
---|
| 27 | using std::endl; |
---|
| 28 | using std::string; |
---|
[47a8d17] | 29 | using std::to_string; |
---|
[51b7345] | 30 | |
---|
| 31 | |
---|
| 32 | //#define __DEBUG_H__ |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | bool prefix( string arg, string pre ) { |
---|
[b87a5ed] | 36 | return arg.substr( 0, pre.size() ) == pre; |
---|
[51b7345] | 37 | } // prefix |
---|
| 38 | |
---|
[dffaeac] | 39 | enum { NumSuffixes = 2 }; |
---|
| 40 | const string suffixes[NumSuffixes] = { "cfa", "hfa", }; |
---|
| 41 | |
---|
| 42 | bool suffix( string arg ) { |
---|
| 43 | //std::cerr << arg << std::endl; |
---|
| 44 | size_t dot = arg.find_last_of( "." ); |
---|
| 45 | //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl; |
---|
| 46 | if ( dot == string::npos ) return false; |
---|
| 47 | string sx = arg.substr( dot + 1 ); |
---|
| 48 | for ( int i = 0; i < NumSuffixes; i += 1 ) { |
---|
| 49 | if ( sx == suffixes[i] ) return true; |
---|
| 50 | } // for |
---|
| 51 | return false; |
---|
| 52 | } // suffix |
---|
| 53 | |
---|
[51b7345] | 54 | |
---|
| 55 | void shuffle( const char *args[], int S, int E, int N ) { |
---|
[b87a5ed] | 56 | // S & E index 1 passed the end so adjust with -1 |
---|
[dffaeac] | 57 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 58 | cerr << "shuffle:" << S << " " << E << " " << N << endl; |
---|
[dffaeac] | 59 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 60 | for ( int j = E-1 + N; j > S-1 + N; j -=1 ) { |
---|
[dffaeac] | 61 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 62 | cerr << "\t" << j << " " << j-N << endl; |
---|
[dffaeac] | 63 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 64 | args[j] = args[j-N]; |
---|
| 65 | } // for |
---|
[51b7345] | 66 | } // shuffle |
---|
| 67 | |
---|
| 68 | |
---|
[4b1afb6] | 69 | #define str(s) #s |
---|
| 70 | |
---|
[51b7345] | 71 | int main( int argc, char *argv[] ) { |
---|
[4b1afb6] | 72 | string Version( CFA_VERSION_LONG ); // current version number from CONFIG |
---|
| 73 | string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) ); |
---|
[51b7345] | 74 | |
---|
[00cc023] | 75 | string installincdir( CFA_INCDIR ); // fixed location of include files |
---|
| 76 | string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands |
---|
[51b7345] | 77 | |
---|
[b87a5ed] | 78 | string heading; // banner printed at start of cfa compilation |
---|
| 79 | string arg; // current command-line argument during command-line parsing |
---|
| 80 | string Bprefix; // path where gcc looks for compiler command steps |
---|
| 81 | string langstd; // language standard |
---|
[51b7345] | 82 | |
---|
[e24f13a] | 83 | string compiler_path( CFA_BACKEND_CC ); // path/name of C compiler |
---|
[b87a5ed] | 84 | string compiler_name; // name of C compiler |
---|
[51b7345] | 85 | |
---|
[b87a5ed] | 86 | bool nonoptarg = false; // indicates non-option argument specified |
---|
| 87 | bool link = true; // linking as well as compiling |
---|
| 88 | bool verbose = false; // -v flag |
---|
| 89 | bool quiet = false; // -quiet flag |
---|
| 90 | bool debug = true; // -debug flag |
---|
| 91 | bool help = false; // -help flag |
---|
| 92 | bool CFA_flag = false; // -CFA flag |
---|
| 93 | bool cpp_flag = false; // -E or -M flag, preprocessor only |
---|
[de62360d] | 94 | bool std_flag = false; // -std= flag |
---|
[d746bc8] | 95 | bool noincstd_flag = false; // -no-include-stdhdr= flag |
---|
[dffaeac] | 96 | bool xflag = false; // user supplied -x flag |
---|
[6e4b913] | 97 | bool debugging __attribute(( unused )) = false; // -g flag |
---|
[51b7345] | 98 | |
---|
[b87a5ed] | 99 | const char *args[argc + 100]; // cfa command line values, plus some space for additional flags |
---|
| 100 | int sargs = 1; // starting location for arguments in args list |
---|
| 101 | int nargs = sargs; // number of arguments in args list; 0 => command name |
---|
[51b7345] | 102 | |
---|
[b87a5ed] | 103 | const char *libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags |
---|
| 104 | int nlibs = 0; |
---|
[51b7345] | 105 | |
---|
[dffaeac] | 106 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 107 | cerr << "CFA:" << endl; |
---|
[dffaeac] | 108 | #endif // __DEBUG_H__ |
---|
[51b7345] | 109 | |
---|
[b87a5ed] | 110 | // process command-line arguments |
---|
[51b7345] | 111 | |
---|
[b87a5ed] | 112 | for ( int i = 1; i < argc; i += 1 ) { |
---|
[dffaeac] | 113 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 114 | cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl; |
---|
[dffaeac] | 115 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 116 | arg = argv[i]; // convert to string value |
---|
[dffaeac] | 117 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 118 | cerr << "arg:\"" << arg << "\"" << endl; |
---|
[dffaeac] | 119 | #endif // __DEBUG_H__ |
---|
[b87a5ed] | 120 | if ( prefix( arg, "-" ) ) { |
---|
| 121 | // pass through arguments |
---|
| 122 | |
---|
| 123 | if ( arg == "-Xlinker" || arg == "-o" ) { |
---|
| 124 | args[nargs] = argv[i]; // pass the argument along |
---|
| 125 | nargs += 1; |
---|
| 126 | i += 1; |
---|
| 127 | if ( i == argc ) continue; // next argument available ? |
---|
| 128 | args[nargs] = argv[i]; // pass the argument along |
---|
| 129 | nargs += 1; |
---|
| 130 | } else if ( arg == "-XCFA" ) { // CFA pass through |
---|
| 131 | i += 1; |
---|
| 132 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str(); |
---|
| 133 | nargs += 1; |
---|
| 134 | |
---|
| 135 | // CFA specific arguments |
---|
| 136 | |
---|
| 137 | } else if ( arg == "-CFA" ) { |
---|
| 138 | CFA_flag = true; // strip the -CFA flag |
---|
| 139 | link = false; |
---|
| 140 | args[nargs] = "-E"; // replace the argument with -E |
---|
| 141 | nargs += 1; |
---|
| 142 | } else if ( arg == "-debug" ) { |
---|
| 143 | debug = true; // strip the debug flag |
---|
| 144 | } else if ( arg == "-nodebug" ) { |
---|
| 145 | debug = false; // strip the nodebug flag |
---|
| 146 | } else if ( arg == "-quiet" ) { |
---|
| 147 | quiet = true; // strip the quiet flag |
---|
| 148 | } else if ( arg == "-noquiet" ) { |
---|
| 149 | quiet = false; // strip the noquiet flag |
---|
| 150 | } else if ( arg == "-help" ) { |
---|
| 151 | help = true; // strip the help flag |
---|
| 152 | } else if ( arg == "-nohelp" ) { |
---|
| 153 | help = false; // strip the nohelp flag |
---|
[d746bc8] | 154 | } else if ( arg == "-no-include-stdhdr" ) { |
---|
| 155 | noincstd_flag = true; // strip the no-include-stdhdr flag |
---|
[b87a5ed] | 156 | } else if ( arg == "-compiler" ) { |
---|
| 157 | // use the user specified compiler |
---|
| 158 | i += 1; |
---|
| 159 | if ( i == argc ) continue; // next argument available ? |
---|
| 160 | compiler_path = argv[i]; |
---|
| 161 | if ( putenv( (char *)( *new string( string( "__U_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) { |
---|
| 162 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 163 | exit( EXIT_FAILURE ); |
---|
| 164 | } // if |
---|
| 165 | |
---|
[de62360d] | 166 | // C specific arguments |
---|
[b87a5ed] | 167 | |
---|
| 168 | } else if ( arg == "-v" ) { |
---|
| 169 | verbose = true; // verbosity required |
---|
| 170 | args[nargs] = argv[i]; // pass the argument along |
---|
| 171 | nargs += 1; |
---|
| 172 | } else if ( arg == "-g" ) { |
---|
| 173 | debugging = true; // symbolic debugging required |
---|
| 174 | args[nargs] = argv[i]; // pass the argument along |
---|
| 175 | nargs += 1; |
---|
[e3215c5] | 176 | } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) { |
---|
[53ba273] | 177 | std_flag = true; // -std=XX provided |
---|
[de62360d] | 178 | args[nargs] = argv[i]; // pass the argument along |
---|
| 179 | nargs += 1; |
---|
[dffaeac] | 180 | } else if ( arg == "-x" ) { |
---|
| 181 | xflag = true; |
---|
[e3215c5] | 182 | args[nargs] = argv[i]; // pass the argument along |
---|
| 183 | nargs += 1; |
---|
| 184 | i += 1; // advance to argument |
---|
| 185 | args[nargs] = argv[i]; // pass the argument along |
---|
| 186 | nargs += 1; |
---|
[dffaeac] | 187 | // args[nargs] = ( *new string( string("-D__GCC_X__=") + argv[i] ) ).c_str(); // add the argument for -x |
---|
| 188 | // nargs += 1; |
---|
| 189 | } else if ( prefix( arg, "-x" ) ) { |
---|
| 190 | xflag = true; |
---|
[e3215c5] | 191 | args[nargs] = argv[i]; // pass the argument along |
---|
| 192 | nargs += 1; |
---|
[dffaeac] | 193 | // args[nargs] = ( *new string( string("-D__GCC_X__=") + arg.substr(2) ) ).c_str(); // add the argument for -x |
---|
| 194 | // nargs += 1; |
---|
[44bca7f] | 195 | } else if ( arg == "-w" ) { |
---|
| 196 | args[nargs] = argv[i]; // pass the argument along |
---|
| 197 | nargs += 1; |
---|
| 198 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp |
---|
| 199 | nargs += 1; |
---|
| 200 | } else if ( prefix( arg, "-W" ) ) { // check before next tests |
---|
| 201 | if ( arg == "-Werror" || arg == "-Wall" ) { |
---|
| 202 | args[nargs] = argv[i]; // pass the argument along |
---|
| 203 | nargs += 1; |
---|
| 204 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp |
---|
| 205 | nargs += 1; |
---|
| 206 | } else { |
---|
| 207 | unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2; |
---|
| 208 | args[nargs] = argv[i]; // conditionally pass the argument along |
---|
[af39199d] | 209 | const char * warning = argv[i] + adv; // extract warning |
---|
| 210 | if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp |
---|
| 211 | args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); |
---|
| 212 | } // if |
---|
[44bca7f] | 213 | nargs += 1; |
---|
| 214 | } // if |
---|
[b87a5ed] | 215 | } else if ( prefix( arg, "-B" ) ) { |
---|
| 216 | Bprefix = arg.substr(2); // strip the -B flag |
---|
| 217 | args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); |
---|
| 218 | nargs += 1; |
---|
| 219 | } else if ( prefix( arg, "-b" ) ) { |
---|
| 220 | if ( arg.length() == 2 ) { // separate argument ? |
---|
| 221 | i += 1; |
---|
| 222 | if ( i == argc ) continue; // next argument available ? |
---|
| 223 | arg += argv[i]; // concatenate argument |
---|
| 224 | } // if |
---|
| 225 | // later versions of gcc require the -b option to appear at the start of the command line |
---|
| 226 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 227 | args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along |
---|
| 228 | if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) { |
---|
| 229 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 230 | exit( EXIT_FAILURE ); |
---|
| 231 | } // if |
---|
| 232 | sargs += 1; |
---|
| 233 | nargs += 1; |
---|
| 234 | } else if ( prefix( arg, "-V" ) ) { |
---|
| 235 | if ( arg.length() == 2 ) { // separate argument ? |
---|
| 236 | i += 1; |
---|
| 237 | if ( i == argc ) continue; // next argument available ? |
---|
| 238 | arg += argv[i]; // concatenate argument |
---|
| 239 | } // if |
---|
| 240 | // later versions of gcc require the -V option to appear at the start of the command line |
---|
| 241 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 242 | args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along |
---|
| 243 | if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) { |
---|
| 244 | cerr << argv[0] << " error, cannot set environment variable." << endl; |
---|
| 245 | exit( EXIT_FAILURE ); |
---|
| 246 | } // if |
---|
| 247 | sargs += 1; |
---|
| 248 | nargs += 1; |
---|
| 249 | } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) { |
---|
| 250 | args[nargs] = argv[i]; // pass the argument along |
---|
| 251 | nargs += 1; |
---|
| 252 | if ( arg == "-E" || arg == "-M" || arg == "-MM" ) { |
---|
| 253 | cpp_flag = true; // cpp only |
---|
| 254 | } // if |
---|
| 255 | link = false; // no linkage required |
---|
| 256 | } else if ( arg[1] == 'l' ) { |
---|
| 257 | // if the user specifies a library, load it after user code |
---|
| 258 | libs[nlibs] = argv[i]; |
---|
| 259 | nlibs += 1; |
---|
| 260 | } else { |
---|
| 261 | // concatenate any other arguments |
---|
| 262 | args[nargs] = argv[i]; |
---|
| 263 | nargs += 1; |
---|
| 264 | } // if |
---|
| 265 | } else { |
---|
[dffaeac] | 266 | bool opt = false; |
---|
| 267 | if ( ! xflag && suffix( arg ) ) { |
---|
| 268 | args[nargs] = "-x"; |
---|
| 269 | nargs += 1; |
---|
| 270 | args[nargs] = "c"; |
---|
| 271 | nargs += 1; |
---|
| 272 | // args[nargs] = ( *new string( string("-D__GCC_X__=c") ) ).c_str(); // add the argument for -x |
---|
| 273 | // nargs += 1; |
---|
| 274 | opt = true; |
---|
| 275 | } // if |
---|
[b87a5ed] | 276 | // concatenate other arguments |
---|
| 277 | args[nargs] = argv[i]; |
---|
| 278 | nargs += 1; |
---|
[dffaeac] | 279 | if ( opt ) { |
---|
| 280 | args[nargs] = "-x"; |
---|
| 281 | nargs += 1; |
---|
| 282 | args[nargs] = "none"; |
---|
| 283 | nargs += 1; |
---|
| 284 | // args[nargs] = ( *new string( string("-D__GCC_X__=none") ) ).c_str(); // add the argument for -x |
---|
| 285 | // nargs += 1; |
---|
| 286 | } // if |
---|
[b87a5ed] | 287 | nonoptarg = true; |
---|
[dffaeac] | 288 | xflag = false; |
---|
[b87a5ed] | 289 | } // if |
---|
| 290 | } // for |
---|
[51b7345] | 291 | |
---|
[dffaeac] | 292 | #ifdef __x86_64__ |
---|
[a83d08b] | 293 | args[nargs] = "-mcx16"; // allow double-wide CAA |
---|
| 294 | nargs += 1; |
---|
[dffaeac] | 295 | #endif // __x86_64__ |
---|
[e3215c5] | 296 | |
---|
[dffaeac] | 297 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 298 | cerr << "args:"; |
---|
| 299 | for ( int i = 1; i < nargs; i += 1 ) { |
---|
| 300 | cerr << " " << args[i]; |
---|
| 301 | } // for |
---|
| 302 | cerr << endl; |
---|
[dffaeac] | 303 | #endif // __DEBUG_H__ |
---|
[51b7345] | 304 | |
---|
[b87a5ed] | 305 | if ( cpp_flag && CFA_flag ) { |
---|
| 306 | cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl; |
---|
| 307 | exit( EXIT_FAILURE ); |
---|
| 308 | } // if |
---|
[51b7345] | 309 | |
---|
[6e4b913] | 310 | // add the CFA include-library paths, which allow direct access to header files without directory qualification |
---|
[b87a5ed] | 311 | args[nargs] = "-I" CFA_INCDIR; |
---|
| 312 | nargs += 1; |
---|
[d746bc8] | 313 | if ( ! noincstd_flag ) { // do not use during build |
---|
| 314 | args[nargs] = "-I" CFA_INCDIR "/stdhdr"; |
---|
| 315 | nargs += 1; |
---|
| 316 | } // if |
---|
[0e76cf4f] | 317 | args[nargs] = "-I" CFA_INCDIR "/concurrency"; |
---|
| 318 | nargs += 1; |
---|
[76c7f65e] | 319 | args[nargs] = "-I" CFA_INCDIR "/containers"; |
---|
| 320 | nargs += 1; |
---|
| 321 | |
---|
[dffaeac] | 322 | #ifdef HAVE_LIBCFA |
---|
[b87a5ed] | 323 | if ( link ) { |
---|
[0edebf8] | 324 | #if ! defined(HAVE_LIBCFA_RELEASE) |
---|
[dffaeac] | 325 | if ( ! debug ) { |
---|
| 326 | cerr << "error: Option -nodebug is unavailable, libcfa was not installed." << endl; |
---|
| 327 | exit( EXIT_FAILURE ); |
---|
| 328 | } // if |
---|
[0edebf8] | 329 | #endif |
---|
| 330 | #if ! defined(HAVE_LIBCFA_DEBUG) |
---|
[dffaeac] | 331 | if ( debug ) { |
---|
| 332 | cerr << "error: Option -debug is unavailable, libcfa-d was not installed." << endl; |
---|
| 333 | exit( EXIT_FAILURE ); |
---|
| 334 | } // if |
---|
[0edebf8] | 335 | #endif |
---|
| 336 | |
---|
[6bfe5cc] | 337 | args[nargs] = "-Xlinker"; |
---|
| 338 | nargs += 1; |
---|
| 339 | args[nargs] = "--undefined=__cfaabi_dbg_bits_write"; |
---|
| 340 | nargs += 1; |
---|
| 341 | args[nargs] = "-Xlinker"; |
---|
| 342 | nargs += 1; |
---|
| 343 | args[nargs] = "--undefined=__cfaabi_interpose_startup"; |
---|
| 344 | nargs += 1; |
---|
[c2ea058] | 345 | args[nargs] = "-Xlinker"; |
---|
| 346 | nargs += 1; |
---|
| 347 | args[nargs] = "--undefined=__cfaabi_appready_startup"; |
---|
| 348 | nargs += 1; |
---|
[6bfe5cc] | 349 | |
---|
[b87a5ed] | 350 | // include the cfa library in case it's needed |
---|
| 351 | args[nargs] = "-L" CFA_LIBDIR; |
---|
[51b7345] | 352 | nargs += 1; |
---|
[e3215c5] | 353 | if ( debug ) { |
---|
[0edebf8] | 354 | args[nargs] = "-lcfa-d"; |
---|
| 355 | } else { |
---|
| 356 | args[nargs] = "-lcfa"; |
---|
[e3215c5] | 357 | } // if |
---|
[51b7345] | 358 | nargs += 1; |
---|
[63f78f0] | 359 | args[nargs] = "-lpthread"; |
---|
| 360 | nargs += 1; |
---|
[9d944b2] | 361 | args[nargs] = "-ldl"; |
---|
| 362 | nargs += 1; |
---|
[c5ac6d5] | 363 | args[nargs] = "-lrt"; |
---|
| 364 | nargs += 1; |
---|
[51b7345] | 365 | } // if |
---|
[dffaeac] | 366 | #endif // HAVE_LIBCFA |
---|
[51b7345] | 367 | |
---|
[e9145a3] | 368 | // Add exception flags (unconditionally) |
---|
| 369 | args[nargs] = "-fexceptions"; |
---|
| 370 | nargs += 1; |
---|
| 371 | |
---|
[b87a5ed] | 372 | // add the correct set of flags based on the type of compile this is |
---|
[8c17ab0] | 373 | |
---|
[ec129c4] | 374 | args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str(); |
---|
[51b7345] | 375 | nargs += 1; |
---|
[b87a5ed] | 376 | args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str(); |
---|
[51b7345] | 377 | nargs += 1; |
---|
[ec129c4] | 378 | args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str(); |
---|
[1db21619] | 379 | nargs += 1; |
---|
[4c82a3c] | 380 | args[nargs] = "-D__CFA__"; |
---|
| 381 | nargs += 1; |
---|
| 382 | args[nargs] = "-D__CFORALL__"; |
---|
[02e5ab6] | 383 | nargs += 1; |
---|
[6acb935] | 384 | args[nargs] = "-D__cforall"; |
---|
| 385 | nargs += 1; |
---|
[51b7345] | 386 | |
---|
[b87a5ed] | 387 | if ( cpp_flag ) { |
---|
| 388 | args[nargs] = "-D__CPP__"; |
---|
| 389 | nargs += 1; |
---|
| 390 | } // if |
---|
[51b7345] | 391 | |
---|
[fa477f7] | 392 | shuffle( args, sargs, nargs, 1 ); // make room at front of argument list |
---|
| 393 | nargs += 1; |
---|
[b87a5ed] | 394 | if ( CFA_flag ) { |
---|
[fa477f7] | 395 | args[sargs] = "-D__CFA_FLAG__=-N"; |
---|
[4c82a3c] | 396 | args[nargs] = "-D__CFA_PREPROCESS_"; |
---|
[b87a5ed] | 397 | nargs += 1; |
---|
[fa477f7] | 398 | } else { |
---|
| 399 | args[sargs] = "-D__CFA_FLAG__=-L"; |
---|
[b87a5ed] | 400 | } // if |
---|
[fa477f7] | 401 | sargs += 1; |
---|
[51b7345] | 402 | |
---|
[b87a5ed] | 403 | if ( debug ) { |
---|
| 404 | heading += " (debug)"; |
---|
| 405 | args[nargs] = "-D__CFA_DEBUG__"; |
---|
| 406 | nargs += 1; |
---|
| 407 | } else { |
---|
| 408 | heading += " (no debug)"; |
---|
| 409 | } // if |
---|
[51b7345] | 410 | |
---|
[b87a5ed] | 411 | if ( Bprefix.length() == 0 ) { |
---|
| 412 | Bprefix = installlibdir; |
---|
| 413 | args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str(); |
---|
| 414 | nargs += 1; |
---|
| 415 | } // if |
---|
[51b7345] | 416 | |
---|
[6bfe5cc] | 417 | args[nargs] = "-Xlinker"; // used by backtrace |
---|
| 418 | nargs += 1; |
---|
| 419 | args[nargs] = "-export-dynamic"; |
---|
| 420 | nargs += 1; |
---|
| 421 | |
---|
[b87a5ed] | 422 | // execute the compilation command |
---|
[51b7345] | 423 | |
---|
[b87a5ed] | 424 | args[0] = compiler_path.c_str(); // set compiler command for exec |
---|
| 425 | // find actual name of the compiler independent of the path to it |
---|
| 426 | int p = compiler_path.find_last_of( '/' ); // scan r -> l for first '/' |
---|
| 427 | if ( p == -1 ) { |
---|
| 428 | compiler_name = compiler_path; |
---|
| 429 | } else { |
---|
| 430 | compiler_name = *new string( compiler_path.substr( p + 1 ) ); |
---|
| 431 | } // if |
---|
[51b7345] | 432 | |
---|
[b87a5ed] | 433 | if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name |
---|
| 434 | args[nargs] = "-no-integrated-cpp"; |
---|
| 435 | nargs += 1; |
---|
[76c7f65e] | 436 | args[nargs] = "-Wno-deprecated"; |
---|
[b87a5ed] | 437 | nargs += 1; |
---|
[157d094] | 438 | if ( ! std_flag ) { // default c11, if none specified |
---|
| 439 | args[nargs] = "-std=gnu11"; |
---|
[de62360d] | 440 | nargs += 1; |
---|
| 441 | } // if |
---|
[76c7f65e] | 442 | args[nargs] = "-fgnu89-inline"; |
---|
[6e991d6] | 443 | nargs += 1; |
---|
[201aeb9] | 444 | args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes |
---|
| 445 | nargs += 1; |
---|
[b87a5ed] | 446 | args[nargs] = ( *new string( string("-B") + Bprefix + "/" ) ).c_str(); |
---|
| 447 | nargs += 1; |
---|
[d3b7937] | 448 | args[nargs] = "-lm"; |
---|
| 449 | nargs += 1; |
---|
[b87a5ed] | 450 | } else { |
---|
[e24f13a] | 451 | cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl; |
---|
[b87a5ed] | 452 | exit( EXIT_FAILURE ); |
---|
| 453 | } // if |
---|
[51b7345] | 454 | |
---|
[b87a5ed] | 455 | for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries |
---|
| 456 | args[nargs] = libs[i]; |
---|
| 457 | nargs += 1; |
---|
| 458 | } // for |
---|
[51b7345] | 459 | |
---|
[b87a5ed] | 460 | args[nargs] = NULL; // terminate with NULL |
---|
[51b7345] | 461 | |
---|
[dffaeac] | 462 | #ifdef __DEBUG_H__ |
---|
[b87a5ed] | 463 | cerr << "nargs: " << nargs << endl; |
---|
| 464 | cerr << "args:" << endl; |
---|
| 465 | for ( int i = 0; args[i] != NULL; i += 1 ) { |
---|
| 466 | cerr << " \"" << args[i] << "\"" << endl; |
---|
| 467 | } // for |
---|
[dffaeac] | 468 | #endif // __DEBUG_H__ |
---|
[51b7345] | 469 | |
---|
[b87a5ed] | 470 | if ( ! quiet ) { |
---|
| 471 | cerr << "CFA " << "Version " << Version << heading << endl; |
---|
| 472 | |
---|
| 473 | if ( help ) { |
---|
| 474 | cerr << |
---|
| 475 | "-debug\t\t\t: use cfa runtime with debug checking" << endl << |
---|
| 476 | "-help\t\t\t: print this help message" << endl << |
---|
| 477 | "-quiet\t\t\t: print no messages from the cfa command" << endl << |
---|
| 478 | "-CFA\t\t\t: run the cpp preprocessor and the cfa-cpp translator" << endl << |
---|
| 479 | "-XCFA -cfa-cpp-flag\t: pass next flag as-is to the cfa-cpp translator" << endl << |
---|
| 480 | "...\t\t\t: any other " << compiler_name << " flags" << endl; |
---|
| 481 | } // if |
---|
[51b7345] | 482 | } // if |
---|
| 483 | |
---|
[b87a5ed] | 484 | if ( verbose ) { |
---|
| 485 | if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc |
---|
[51b7345] | 486 | |
---|
[b87a5ed] | 487 | for ( int i = 0; args[i] != NULL; i += 1 ) { |
---|
| 488 | cerr << args[i] << " "; |
---|
| 489 | } // for |
---|
| 490 | cerr << endl; |
---|
| 491 | } // if |
---|
[51b7345] | 492 | |
---|
[b87a5ed] | 493 | if ( ! nonoptarg ) { |
---|
| 494 | cerr << argv[0] << " error, no input files" << endl; |
---|
| 495 | exit( EXIT_FAILURE ); |
---|
| 496 | } // if |
---|
[51b7345] | 497 | |
---|
[b87a5ed] | 498 | // execute the command and return the result |
---|
[51b7345] | 499 | |
---|
[b87a5ed] | 500 | execvp( args[0], (char *const *)args ); // should not return |
---|
| 501 | perror( "CFA Translator error: cfa level, execvp" ); |
---|
| 502 | exit( EXIT_FAILURE ); |
---|
[51b7345] | 503 | } // main |
---|
| 504 | |
---|
| 505 | // Local Variables: // |
---|
[b87a5ed] | 506 | // tab-width: 4 // |
---|
| 507 | // mode: c++ // |
---|
[51b7345] | 508 | // compile-command: "make install" // |
---|
| 509 | // End: // |
---|