Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    raced69a r4f5a8a2  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Sep 10 17:00:15 2019
    13 // Update Count     : 420
     12// Last Modified On : Sat Aug 10 08:44:15 2019
     13// Update Count     : 311
    1414//
    1515
     
    2828#include "config.h"                                                                             // configure info
    2929
     30
    3031using std::cerr;
    3132using std::endl;
     
    3334using std::to_string;
    3435
     36
    3537//#define __DEBUG_H__
    3638
    3739
    38 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
    39 
    40 void Putenv( char * argv[], string arg ) {
    41         static int flags = 0;                                                           // environment variables must have unique names
    42 
    43         if ( putenv( (char *)( *new string( string( __CFA_FLAGPREFIX__ + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) {
    44                 cerr << argv[0] << " error, cannot set environment variable." << endl;
    45                 exit( EXIT_FAILURE );
    46         } // if
    47 } // Putenv
    48 
    49 
    50 bool prefix( const string & arg, const string & pre ) { // check if string has prefix
     40bool prefix( string arg, string pre ) {
    5141        return arg.substr( 0, pre.size() ) == pre;
    5242} // prefix
    5343
    54 bool suffix( const string & arg ) {                                             // check if string has suffix
     44bool suffix( string arg ) {
    5545        enum { NumSuffixes = 3 };
    5646        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
    57 
     47        //std::cerr << arg << std::endl;
    5848        size_t dot = arg.find_last_of( "." );
     49        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
    5950        if ( dot == string::npos ) return false;
    6051        const string * end = suffixes + NumSuffixes;
     
    6354
    6455
    65 static inline bool dirExists( const string & path ) {   // check if directory exists
     56void shuffle( const char * args[], int S, int E, int N ) {
     57        // S & E index 1 passed the end so adjust with -1
     58        #ifdef __DEBUG_H__
     59        cerr << "shuffle:" << S << " " << E << " " << N << endl;
     60        #endif // __DEBUG_H__
     61        for ( int j = E-1 + N; j > S-1 + N; j -=1 ) {
     62                #ifdef __DEBUG_H__
     63                cerr << "\t" << j << " " << j-N << endl;
     64                #endif // __DEBUG_H__
     65                args[j] = args[j-N];
     66        } // for
     67} // shuffle
     68
     69static inline bool dirExists( const string & path ) {
    6670    struct stat info;
    67     if ( stat( path.c_str(), &info ) != 0 ) return false;
    68         return (info.st_mode & S_IFDIR) != 0;
    69 } // dirExists
    70 
    71 
    72 #define xstr(s) str(s)
     71    if(stat( path.c_str(), &info ) != 0)
     72        return false;
     73    else if(info.st_mode & S_IFDIR)
     74        return true;
     75    else
     76        return false;
     77} //dirExists
     78
     79
    7380#define str(s) #s
    7481
    7582int main( int argc, char * argv[] ) {
    7683        string Version( CFA_VERSION_LONG );                                     // current version number from CONFIG
    77         string Major( xstr( CFA_VERSION_MAJOR ) ), Minor( xstr( CFA_VERSION_MINOR ) ), Patch( xstr( CFA_VERSION_PATCH ) );
     84        string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
    7885
    7986        string installincdir( CFA_INCDIR );                                     // fixed location of include files
     
    8390        string heading;                                                                         // banner printed at start of cfa compilation
    8491        string arg;                                                                                     // current command-line argument during command-line parsing
    85         string bprefix;                                                                         // path where gcc looks for compiler steps
     92        string Bprefix;                                                                         // path where gcc looks for compiler command steps
    8693        string langstd;                                                                         // language standard
    8794
     
    9097
    9198        bool x_flag = false;                                                            // -x flag
    92         bool nonoptarg = false;                                                         // no non-option arguments specified, i.e., no file names
    93         bool link = true;                                                                       // link stage occurring
     99        bool nonoptarg = false;                                                         // indicates non-option argument specified
     100        bool link = true;                                                                       // linking as well as compiling
    94101        bool verbose = false;                                                           // -v flag
    95102        bool quiet = false;                                                                     // -quiet flag
     
    104111        bool m32 = false;                                                                       // -m32 flag
    105112        bool m64 = false;                                                                       // -m64 flag
    106         bool intree = false;                                                            // build in tree
    107         int o_file = 0;                                                                         // -o filename position
     113        bool intree = false;
    108114
    109115        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    129135
    130136                        if ( arg == "-Xlinker" || arg == "-o" ) {
    131                                 args[nargs++] = argv[i];                                // pass argument along
     137                                args[nargs] = argv[i];                                  // pass the argument along
     138                                nargs += 1;
    132139                                i += 1;
    133140                                if ( i == argc ) continue;                              // next argument available ?
    134                                 args[nargs++] = argv[i];                                // pass argument along
    135                                 if ( arg == "-o" ) o_file = i;                  // remember file
     141                                args[nargs] = argv[i];                                  // pass the argument along
     142                                nargs += 1;
    136143                        } else if ( arg == "-XCFA" ) {                          // CFA pass through
    137144                                i += 1;
    138                                 Putenv( argv, argv[i] );
     145                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str();
     146                                nargs += 1;
    139147
    140148                                // CFA specific arguments
     
    143151                                CFA_flag = true;                                                // strip the -CFA flag
    144152                                link = false;
    145                                 args[nargs++] = "-fsyntax-only";                // stop after stage 2
     153                                args[nargs] = "-E";                                             // replace the argument with -E
     154                                nargs += 1;
    146155                        } else if ( arg == "-debug" ) {
    147156                                debug = true;                                                   // strip the debug flag
    148157                        } else if ( arg == "-nodebug" ) {
    149                                 debug = false;                                                  // strip the nodebug flag
     158                                debug = false;                                                  // strip the debug flag
    150159                        } else if ( arg == "-nolib" ) {
    151160                                nolib = true;                                                   // strip the nodebug flag
     
    167176                                if ( i == argc ) continue;                              // next argument available ?
    168177                                compiler_path = argv[i];
    169                                 Putenv( argv, arg + "=" + argv[i] );
     178                                if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) {
     179                                        cerr << argv[0] << " error, cannot set environment variable." << endl;
     180                                        exit( EXIT_FAILURE );
     181                                } // if
    170182
    171183                                // C specific arguments
     
    173185                        } else if ( arg == "-v" ) {
    174186                                verbose = true;                                                 // verbosity required
    175                                 args[nargs++] = argv[i];                                // pass argument along
     187                                args[nargs] = argv[i];                                  // pass the argument along
     188                                nargs += 1;
    176189                        } else if ( arg == "-g" ) {
    177190                                debugging = true;                                               // symbolic debugging required
    178                                 args[nargs++] = argv[i];                                // pass argument along
    179                         } else if ( arg == "-save-temps" ) {
    180                                 args[nargs++] = argv[i];                                // pass argument along
    181                                 Putenv( argv, arg );                                    // save cfa-cpp output
     191                                args[nargs] = argv[i];                                  // pass the argument along
     192                                nargs += 1;
    182193                        } else if ( prefix( arg, "-x" ) ) {                     // file suffix ?
    183194                                string lang;
    184                                 args[nargs++] = argv[i];                                // pass argument along
     195                                args[nargs] = argv[i];                                  // pass the argument along
     196                                nargs += 1;
    185197                                if ( arg.length() == 2 ) {                              // separate argument ?
    186198                                        i += 1;
    187199                                        if ( i == argc ) continue;                      // next argument available ?
    188200                                        lang = argv[i];
    189                                         args[nargs++] = argv[i];                        // pass argument along
     201                                        args[nargs] = argv[i];                          // pass the argument along
     202                                        nargs += 1;
    190203                                } else {
    191204                                        lang = arg.substr( 2 );
     
    194207                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    195208                                std_flag = true;                                                // -std=XX provided
    196                                 args[nargs++] = argv[i];                                // pass argument along
     209                                args[nargs] = argv[i];                                  // pass the argument along
     210                                nargs += 1;
    197211                        } else if ( arg == "-w" ) {
    198                                 args[nargs++] = argv[i];                                // pass argument along
    199                                 Putenv( argv, arg );
     212                                args[nargs] = argv[i];                                  // pass the argument along
     213                                nargs += 1;
     214                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
     215                                nargs += 1;
    200216                        } else if ( prefix( arg, "-W" ) ) {                     // check before next tests
    201217                                if ( arg == "-Werror" || arg == "-Wall" ) {
    202                                         args[nargs++] = argv[i];                        // pass argument along
    203                                         Putenv( argv, argv[i] );
     218                                        args[nargs] = argv[i];                          // pass the argument along
     219                                        nargs += 1;
     220                                        args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
     221                                        nargs += 1;
    204222                                } else {
    205223                                        unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2;
    206                                         args[nargs] = argv[i];                          // conditionally pass argument along
    207                                         const char * warning = argv[i] + adv; // extract warning
     224                                        args[nargs] = argv[i];                          // conditionally pass the argument along
     225                                        const char * warning = argv[i] + adv;    // extract warning
    208226                                        if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp
    209                                                 Putenv( argv, arg );
     227                                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str();
    210228                                        } // if
    211229                                        nargs += 1;
    212230                                } // if
    213231                        } else if ( prefix( arg, "-B" ) ) {
    214                                 bprefix = arg.substr(2);                                // strip the -B flag
     232                                Bprefix = arg.substr(2);                                // strip the -B flag
     233                                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     234                                nargs += 1;
     235                        } else if ( prefix( arg, "-b" ) ) {
     236                                if ( arg.length() == 2 ) {                              // separate argument ?
     237                                        i += 1;
     238                                        if ( i == argc ) continue;                      // next argument available ?
     239                                        arg += argv[i];                                         // concatenate argument
     240                                } // if
     241                                // later versions of gcc require the -b option to appear at the start of the command line
     242                                shuffle( args, sargs, nargs, 1 );               // make room at front of argument list
     243                                args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along
     244                                if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) {
     245                                        cerr << argv[0] << " error, cannot set environment variable." << endl;
     246                                        exit( EXIT_FAILURE );
     247                                } // if
     248                                sargs += 1;
     249                                nargs += 1;
     250                        } else if ( prefix( arg, "-V" ) ) {
     251                                if ( arg.length() == 2 ) {                              // separate argument ?
     252                                        i += 1;
     253                                        if ( i == argc ) continue;                      // next argument available ?
     254                                        arg += argv[i];                                         // concatenate argument
     255                                } // if
     256                                // later versions of gcc require the -V option to appear at the start of the command line
     257                                shuffle( args, sargs, nargs, 1 );               // make room at front of argument list
     258                                args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along
     259                                if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) {
     260                                        cerr << argv[0] << " error, cannot set environment variable." << endl;
     261                                        exit( EXIT_FAILURE );
     262                                } // if
     263                                sargs += 1;
     264                                nargs += 1;
    215265                        } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) {
    216                                 args[nargs++] = argv[i];                                // pass argument along
     266                                args[nargs] = argv[i];                                  // pass the argument along
     267                                nargs += 1;
    217268                                if ( arg == "-E" || arg == "-M" || arg == "-MM" ) {
    218269                                        cpp_flag = true;                                        // cpp only
     
    221272                        } else if ( arg[1] == 'l' ) {
    222273                                // if the user specifies a library, load it after user code
    223                                 libs[nlibs++] = argv[i];
     274                                libs[nlibs] = argv[i];
     275                                nlibs += 1;
    224276                        } else if ( arg == "-m32" ) {
    225277                                m32 = true;
    226278                                m64 = false;
    227                                 args[nargs++] = argv[i];
     279                                args[nargs] = argv[i];
     280                                nargs += 1;
    228281                        } else if ( arg == "-m64" ) {
    229282                                m64 = true;
    230283                                m32 = false;
    231                                 args[nargs++] = argv[i];
     284                                args[nargs] = argv[i];
     285                                nargs += 1;
    232286                        } else {
    233287                                // concatenate any other arguments
    234                                 args[nargs++] = argv[i];
     288                                args[nargs] = argv[i];
     289                                nargs += 1;
    235290                        } // if
    236291                } else {
    237292                        bool cfa = suffix( arg );                                       // check suffix
    238293                        if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    239                                 args[nargs++] = "-x";
    240                                 args[nargs++] = "c";
     294                                args[nargs] = "-x";
     295                                nargs += 1;
     296                                args[nargs] = "c";
     297                                nargs += 1;
    241298                        } // if
    242                         args[nargs++] = argv[i];                                        // concatenate files
     299                        args[nargs] = argv[i];                                          // concatenate file
     300                        nargs += 1;
    243301                        if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    244                                 args[nargs++] = "-x";
    245                                 args[nargs++] = "none";
     302                                args[nargs] = "-x";
     303                                nargs += 1;
     304                                args[nargs] = "none";
     305                                nargs += 1;
    246306                        } // if
    247307                        nonoptarg = true;
     
    250310
    251311        #ifdef __x86_64__
    252         args[nargs++] = "-mcx16";                                                       // allow double-wide CAA
     312        args[nargs] = "-mcx16";                                                         // allow double-wide CAA
     313        nargs += 1;
    253314        #endif // __x86_64__
    254315
     
    261322        #endif // __DEBUG_H__
    262323
    263         // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed.
    264324        if ( cpp_flag && CFA_flag ) {
    265                 CFA_flag = false;
    266                 cerr << argv[0] << " warning, both -E and -CFA flags specified, using -E and ignoring -CFA." << endl;
     325                cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl;
     326                exit( EXIT_FAILURE );
    267327        } // if
    268328
    269329        // add the CFA include-library paths, which allow direct access to header files without directory qualification
    270         if ( ! intree ) {
    271                 args[nargs++] = "-I" CFA_INCDIR;
     330        if( !intree ) {
     331                args[nargs] = "-I" CFA_INCDIR;
     332                nargs += 1;
    272333                if ( ! noincstd_flag ) {                                                // do not use during build
    273                         args[nargs++] = "-I" CFA_INCDIR "stdhdr";
     334                        args[nargs] = "-I" CFA_INCDIR "stdhdr";
     335                        nargs += 1;
    274336                } // if
    275                 args[nargs++] = "-I" CFA_INCDIR "concurrency";
    276                 args[nargs++] = "-I" CFA_INCDIR "containers";
     337                args[nargs] = "-I" CFA_INCDIR "concurrency";
     338                nargs += 1;
     339                args[nargs] = "-I" CFA_INCDIR "containers";
     340                nargs += 1;
    277341        } else {
    278                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
     342                args[nargs] = "-I" TOP_SRCDIR "libcfa/src";
     343                nargs += 1;
    279344                if ( ! noincstd_flag ) {                                                // do not use during build
    280                         args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
     345                        args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
     346                        nargs += 1;
    281347                } // if
    282                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
    283                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
    284         } // if
     348                args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
     349                nargs += 1;
     350                args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
     351                nargs += 1;
     352        }
    285353
    286354        // add stdbool to get defines for bool/true/false
    287         args[nargs++] = "-imacros";
    288         args[nargs++] = "stdbool.h";
     355        args[nargs] = "-imacros";
     356        nargs += 1;
     357        args[nargs] = "stdbool.h";
     358        nargs += 1;
    289359
    290360        string libbase;
    291         if ( ! intree ) {
     361        if( !intree ) {
    292362                libbase = CFA_LIBDIR;
    293363        } else {
    294364                libbase = TOP_BUILDDIR "libcfa/";
    295                 Putenv( argv, "-t" );
    296         } // if
    297 
    298         string arch( m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU) );
     365                args[nargs] = "-D__CFA_FLAG__=-t";
     366                nargs += 1;
     367        }
     368
     369        string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);
    299370        if ( ! m32 && ! m64 ) {
    300371                if ( arch == "x86" ) {
    301                         args[nargs++] = "-m32";
     372                        args[nargs] = "-m32";
     373                        nargs += 1;
    302374                } else if ( arch == "x64" ) {
    303                         args[nargs++] = "-m64";
     375                        args[nargs] = "-m64";
     376                        nargs += 1;
    304377                }  // if
    305378        } // if
    306 
    307         string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) );
     379        const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug");
     380        string libdir = libbase + arch + "-" + config;
     381
     382        if ( ! nolib && ! 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        } // if
     387
    308388        if ( ! dirExists( libdir ) ) {
    309                 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl;
     389                cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
     390                cerr << "Was looking for " << libdir << endl;
    310391                exit( EXIT_FAILURE );
    311392        } // if
    312393
     394        args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();
     395        nargs += 1;
     396
    313397        for ( int i = 0; i < nlibs; i += 1 ) {                          // copy non-user libraries after all user libraries
    314                 args[nargs++] = libs[i];
     398                args[nargs] = libs[i];
     399                nargs += 1;
    315400        } // for
    316401
    317402        if ( link ) {
    318                 args[nargs++] = "-Xlinker";
    319                 args[nargs++] = "--undefined=__cfaabi_dbg_bits_write";
    320                 args[nargs++] = "-Xlinker";
    321                 args[nargs++] = "--undefined=__cfaabi_interpose_startup";
    322                 args[nargs++] = "-Xlinker";
    323                 args[nargs++] = "--undefined=__cfaabi_appready_startup";
    324 
    325                 // include the cfa library in case it is needed
    326                 args[nargs++] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
    327                 args[nargs++] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
    328                 args[nargs++] = "-Wl,--push-state,--as-needed";
    329                 args[nargs++] = "-lcfathread";
    330                 args[nargs++] = "-Wl,--pop-state";
    331                 args[nargs++] = "-lcfa";
    332                 args[nargs++] = "-lpthread";
    333                 args[nargs++] = "-ldl";
    334                 args[nargs++] = "-lrt";
    335                 args[nargs++] = "-lm";
    336         } // if
    337 
    338         args[nargs++] = "-fexceptions";                                         // add exception flags (unconditionally)
    339 
    340         // add flags based on the type of compile
    341 
    342         args[nargs++] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str();
    343         args[nargs++] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str();
    344         args[nargs++] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str();
    345         args[nargs++] = "-D__CFA__";
    346         args[nargs++] = "-D__CFORALL__";
    347         args[nargs++] = "-D__cforall";
     403                args[nargs] = "-Xlinker";
     404                nargs += 1;
     405                args[nargs] = "--undefined=__cfaabi_dbg_bits_write";
     406                nargs += 1;
     407                args[nargs] = "-Xlinker";
     408                nargs += 1;
     409                args[nargs] = "--undefined=__cfaabi_interpose_startup";
     410                nargs += 1;
     411                args[nargs] = "-Xlinker";
     412                nargs += 1;
     413                args[nargs] = "--undefined=__cfaabi_appready_startup";
     414                nargs += 1;
     415
     416                // include the cfa library in case it's needed
     417                args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
     418                nargs += 1;
     419                args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
     420                nargs += 1;
     421                args[nargs] = "-Wl,--push-state,--as-needed";
     422                nargs += 1;
     423                args[nargs] = "-lcfathread";
     424                nargs += 1;
     425                args[nargs] = "-Wl,--pop-state";
     426                nargs += 1;
     427                args[nargs] = "-lcfa";
     428                nargs += 1;
     429                args[nargs] = "-lpthread";
     430                nargs += 1;
     431                args[nargs] = "-ldl";
     432                nargs += 1;
     433                args[nargs] = "-lrt";
     434                nargs += 1;
     435                args[nargs] = "-lm";
     436                nargs += 1;
     437        } // if
     438
     439        // Add exception flags (unconditionally)
     440        args[nargs] = "-fexceptions";
     441        nargs += 1;
     442
     443        // add the correct set of flags based on the type of compile this is
     444
     445        args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str();
     446        nargs += 1;
     447        args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str();
     448        nargs += 1;
     449        args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str();
     450        nargs += 1;
     451        args[nargs] = "-D__CFA__";
     452        nargs += 1;
     453        args[nargs] = "-D__CFORALL__";
     454        nargs += 1;
     455        args[nargs] = "-D__cforall";
     456        nargs += 1;
    348457
    349458        if ( cpp_flag ) {
    350                 args[nargs++] = "-D__CPP__";
    351         } // if
    352 
     459                args[nargs] = "-D__CPP__";
     460                nargs += 1;
     461        } // if
     462
     463        shuffle( args, sargs, nargs, 1 );                                       // make room at front of argument list
     464        nargs += 1;
    353465        if ( CFA_flag ) {
    354                 Putenv( argv, "-N" );
    355                 Putenv( argv, "-CFA" );
    356                 // -CFA implies cc1 stage 2, but gcc does not pass the -o file to this stage because it believe the file is for
    357                 // the linker. Hence, the -o file is explicit passed to cc1 stage 2 and used as cfa-cpp's output file.
    358                 if ( o_file ) Putenv( argv, string( "-o=" ) + argv[o_file] );
     466                args[sargs] = "-D__CFA_FLAG__=-N";
     467                args[nargs] = "-D__CFA_PREPROCESS_";
     468                nargs += 1;
    359469        } else {
    360                 Putenv( argv, "-L" );
    361         } // if
    362 
    363         Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") );
     470                args[sargs] = "-D__CFA_FLAG__=-L";
     471        } // if
     472        sargs += 1;
    364473
    365474        if ( debug ) {
    366475                heading += " (debug)";
    367                 args[nargs++] = "-D__CFA_DEBUG__";
     476                args[nargs] = "-D__CFA_DEBUG__";
     477                nargs += 1;
    368478        } else {
    369479                heading += " (no debug)";
    370480        } // if
    371481
    372         if ( bprefix.length() == 0 ) {
    373                 bprefix = ! intree ? installlibdir : srcdriverdir;
    374                 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
    375                 Putenv( argv, ( *new string( string("-B=") + bprefix ) ).c_str() );
    376         } // if
    377 
    378         args[nargs++] = "-Xlinker";                                                     // used by backtrace
    379         args[nargs++] = "-export-dynamic";
     482        if ( Bprefix.length() == 0 ) {
     483                Bprefix = ! intree ? installlibdir : srcdriverdir;
     484                if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/';
     485                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     486                nargs += 1;
     487        } // if
     488
     489        args[nargs] = "-Xlinker";                                                       // used by backtrace
     490        nargs += 1;
     491        args[nargs] = "-export-dynamic";
     492        nargs += 1;
    380493
    381494        // execute the compilation command
     
    391504
    392505        if ( prefix( compiler_name, "gcc" ) ) {                         // allow suffix on gcc name
    393                 args[nargs++] = "-no-integrated-cpp";
    394                 args[nargs++] = "-Wno-deprecated";
    395                 #ifdef HAVE_CAST_FUNCTION_TYPE
    396                 args[nargs++] = "-Wno-cast-function-type";
    397                 #endif // HAVE_CAST_FUNCTION_TYPE
     506                args[nargs] = "-no-integrated-cpp";
     507                nargs += 1;
     508                args[nargs] = "-Wno-deprecated";
     509                nargs += 1;
     510#ifdef HAVE_CAST_FUNCTION_TYPE
     511                args[nargs] = "-Wno-cast-function-type";
     512                nargs += 1;
     513#endif // HAVE_CAST_FUNCTION_TYPE
    398514                if ( ! std_flag ) {                                                             // default c11, if none specified
    399                         args[nargs++] = "-std=gnu11";
     515                        args[nargs] = "-std=gnu11";
     516                        nargs += 1;
    400517                } // if
    401                 args[nargs++] = "-fgnu89-inline";
    402                 args[nargs++] = "-D__int8_t_defined";                   // prevent gcc type-size attributes
    403                 args[nargs++] = ( *new string( string("-B") + bprefix ) ).c_str();
     518                args[nargs] = "-fgnu89-inline";
     519                nargs += 1;
     520                args[nargs] = "-D__int8_t_defined";                             // prevent gcc type-size attributes
     521                nargs += 1;
     522                args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str();
     523                nargs += 1;
    404524        } else {
    405525                cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl;
     
    407527        } // if
    408528
    409         args[nargs] = nullptr;                                                          // terminate
     529        args[nargs] = NULL;                                                                     // terminate with NULL
    410530
    411531        #ifdef __DEBUG_H__
    412532        cerr << "nargs: " << nargs << endl;
    413533        cerr << "args:" << endl;
    414         for ( int i = 0; args[i] != nullptr; i += 1 ) {
     534        for ( int i = 0; args[i] != NULL; i += 1 ) {
    415535                cerr << " \"" << args[i] << "\"" << endl;
    416536        } // for
     
    434554                if ( argc == 2 ) exit( EXIT_SUCCESS );                  // if only the -v flag is specified, do not invoke gcc
    435555
    436                 for ( int i = 0; args[i] != nullptr; i += 1 ) {
     556                for ( int i = 0; args[i] != NULL; i += 1 ) {
    437557                        cerr << args[i] << " ";
    438558                } // for
     
    448568
    449569        execvp( args[0], (char *const *)args );                         // should not return
    450         perror( "CFA Translator error: execvp" );
     570        perror( "CFA Translator error: cfa level, execvp" );
    451571        exit( EXIT_FAILURE );
    452572} // main
Note: See TracChangeset for help on using the changeset viewer.