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