Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    rbbb1b35 r2026bb6  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 23 16:27:07 2019
    13 // Update Count     : 411
     12// Last Modified On : Sun Feb 10 08:28:09 2019
     13// Update Count     : 281
    1414//
    1515
     
    2020#include <string>                                                                               // STL version
    2121#include <string.h>                                                                             // strcmp
    22 #include <algorithm>                                                                    // find
    2322
    2423#include <sys/types.h>
     
    3332using std::to_string;
    3433
     34
    3535//#define __DEBUG_H__
    3636
    3737
    38 void Putenv( char * argv[], string arg ) {
    39         static int flags = 0;                                                           // environment variables must have unique names
    40 
    41         if ( putenv( (char *)( *new string( string( "__CFA_FLAG" + to_string( flags++ ) + "__=" ) + arg ) ).c_str() ) ) {
    42                 cerr << argv[0] << " error, cannot set environment variable." << endl;
    43                 exit( EXIT_FAILURE );
    44         } // if
    45 } // Putenv
    46 
    47 
    48 bool prefix( const string & arg, const string & pre ) { // check if string has prefix
     38bool prefix( string arg, string pre ) {
    4939        return arg.substr( 0, pre.size() ) == pre;
    5040} // prefix
    5141
    52 bool suffix( const string & arg ) {                                             // check if string has suffix
    53         enum { NumSuffixes = 3 };
    54         static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
    55 
     42enum { NumSuffixes = 2 };
     43const string suffixes[NumSuffixes] = { "cfa", "hfa", };
     44
     45bool suffix( string arg, const char * args[], int & nargs ) {
     46        //std::cerr << arg << std::endl;
    5647        size_t dot = arg.find_last_of( "." );
     48        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
    5749        if ( dot == string::npos ) return false;
    58         const string * end = suffixes + NumSuffixes;
    59         return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end;
     50        string sx = arg.substr( dot + 1 );
     51        for ( int i = 0; i < NumSuffixes; i += 1 ) {
     52                if ( sx == suffixes[i] ) {
     53                        args[nargs] = "-x";
     54                        nargs += 1;
     55                        args[nargs] = "c";
     56                        nargs += 1;
     57                        return true;
     58                } // if
     59        } // for
     60        return false;
    6061} // suffix
    6162
    6263
    63 static inline bool dirExists( const string & path ) {   // check if directory exists
     64void shuffle( const char *args[], int S, int E, int N ) {
     65        // S & E index 1 passed the end so adjust with -1
     66        #ifdef __DEBUG_H__
     67        cerr << "shuffle:" << S << " " << E << " " << N << endl;
     68        #endif // __DEBUG_H__
     69        for ( int j = E-1 + N; j > S-1 + N; j -=1 ) {
     70                #ifdef __DEBUG_H__
     71                cerr << "\t" << j << " " << j-N << endl;
     72                #endif // __DEBUG_H__
     73                args[j] = args[j-N];
     74        } // for
     75} // shuffle
     76
     77static inline bool dirExists(const string & path) {
    6478    struct stat info;
    65     if ( stat( path.c_str(), &info ) != 0 ) return false;
    66     if ( info.st_mode & S_IFDIR ) return true;
    67         return false;
    68 } // dirExists
    69 
    70 
    71 #define xstr(s) str(s)
     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
     87
    7288#define str(s) #s
    7389
    74 int main( int argc, char * argv[] ) {
     90int main( int argc, char *argv[] ) {
    7591        string Version( CFA_VERSION_LONG );                                     // current version number from CONFIG
    76         string Major( xstr( CFA_VERSION_MAJOR ) ), Minor( xstr( CFA_VERSION_MINOR ) ), Patch( xstr( CFA_VERSION_PATCH ) );
     92        string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
    7793
    7894        string installincdir( CFA_INCDIR );                                     // fixed location of include files
     
    88104        string compiler_name;                                                           // name of C compiler
    89105
    90         bool x_flag = false;                                                            // -x flag
    91         bool nonoptarg = false;                                                         // no non-option arguments specified, i.e., no file names
    92         bool link = true;                                                                       // link stage occurring
     106        bool nonoptarg = false;                                                         // indicates non-option argument specified
     107        bool link = true;                                                                       // linking as well as compiling
    93108        bool verbose = false;                                                           // -v flag
    94         bool quiet = false;                                                                     // -quiet flag
    95         bool debug = true;                                                                      // -debug flag
    96         bool nolib = false;                                                                     // -nolib flag
    97         bool help = false;                                                                      // -help flag
     109        bool quiet = false;                                                             // -quiet flag
     110        bool debug = true;                                                              // -debug flag
     111        bool nolib = false;                                                             // -nolib flag
     112        bool help = false;                                                              // -help flag
    98113        bool CFA_flag = false;                                                          // -CFA flag
    99114        bool cpp_flag = false;                                                          // -E or -M flag, preprocessor only
     
    101116        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
    102117        bool debugging __attribute(( unused )) = false;         // -g flag
    103         bool m32 = false;                                                                       // -m32 flag
    104         bool m64 = false;                                                                       // -m64 flag
    105         bool intree = false;                                                            // build in tree
    106         int o_file = 0;                                                                         // -o filename position
     118        bool m32 = false;                                    // -m32 flag
     119        bool m64 = false;                                    // -m64 flag
     120        bool intree = false;
    107121
    108122        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    128142
    129143                        if ( arg == "-Xlinker" || arg == "-o" ) {
    130                                 args[nargs++] = argv[i];                                // pass argument along
     144                                args[nargs] = argv[i];                                  // pass the argument along
     145                                nargs += 1;
    131146                                i += 1;
    132147                                if ( i == argc ) continue;                              // next argument available ?
    133                                 args[nargs++] = argv[i];                                // pass argument along
    134                                 if ( arg == "-o" ) o_file = i;                  // remember file
     148                                args[nargs] = argv[i];                                  // pass the argument along
     149                                nargs += 1;
    135150                        } else if ( arg == "-XCFA" ) {                          // CFA pass through
    136151                                i += 1;
    137                                 Putenv( argv, argv[i] );
     152                                args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str();
     153                                nargs += 1;
    138154
    139155                                // CFA specific arguments
     
    142158                                CFA_flag = true;                                                // strip the -CFA flag
    143159                                link = false;
    144                                 args[nargs++] = "-fsyntax-only";                // stop after stage 2
     160                                args[nargs] = "-E";                                             // replace the argument with -E
     161                                nargs += 1;
    145162                        } else if ( arg == "-debug" ) {
    146163                                debug = true;                                                   // strip the debug flag
    147164                        } else if ( arg == "-nodebug" ) {
    148                                 debug = false;                                                  // strip the nodebug flag
     165                                debug = false;                                                  // strip the debug flag
    149166                        } else if ( arg == "-nolib" ) {
    150167                                nolib = true;                                                   // strip the nodebug flag
     
    166183                                if ( i == argc ) continue;                              // next argument available ?
    167184                                compiler_path = argv[i];
    168                                 Putenv( argv, arg + "=" + argv[i] );
     185                                if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) {
     186                                        cerr << argv[0] << " error, cannot set environment variable." << endl;
     187                                        exit( EXIT_FAILURE );
     188                                } // if
    169189
    170190                                // C specific arguments
     
    172192                        } else if ( arg == "-v" ) {
    173193                                verbose = true;                                                 // verbosity required
    174                                 args[nargs++] = argv[i];                                // pass argument along
     194                                args[nargs] = argv[i];                                  // pass the argument along
     195                                nargs += 1;
    175196                        } else if ( arg == "-g" ) {
    176197                                debugging = true;                                               // symbolic debugging required
    177                                 args[nargs++] = argv[i];                                // pass argument along
    178                         } else if ( arg == "-save-temps" ) {
    179                                 args[nargs++] = argv[i];                                // pass argument along
    180                                 Putenv( argv, arg );                                    // save cfa-cpp output
    181                         } else if ( prefix( arg, "-x" ) ) {                     // file suffix ?
    182                                 string lang;
    183                                 args[nargs++] = argv[i];                                // pass argument along
     198                                args[nargs] = argv[i];                                  // pass the argument along
     199                                nargs += 1;
     200                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
     201                                std_flag = true;                                                // -std=XX provided
     202                                args[nargs] = argv[i];                                  // pass the argument along
     203                                nargs += 1;
     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
     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
     222                                        nargs += 1;
     223                                } // if
     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" ) ) {
    184229                                if ( arg.length() == 2 ) {                              // separate argument ?
    185230                                        i += 1;
    186231                                        if ( i == argc ) continue;                      // next argument available ?
    187                                         lang = argv[i];
    188                                         args[nargs++] = argv[i];                        // pass argument along
    189                                 } else {
    190                                         lang = arg.substr( 2 );
    191                                 } // if
    192                                 x_flag = lang != "none";
    193                         } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    194                                 std_flag = true;                                                // -std=XX provided
    195                                 args[nargs++] = argv[i];                                // pass argument along
    196                         } else if ( arg == "-w" ) {
    197                                 args[nargs++] = argv[i];                                // pass argument along
    198                                 Putenv( argv, arg );
    199                         } else if ( prefix( arg, "-W" ) ) {                     // check before next tests
    200                                 if ( arg == "-Werror" || arg == "-Wall" ) {
    201                                         args[nargs++] = argv[i];                        // pass argument along
    202                                         Putenv( argv, argv[i] );
    203                                 } else {
    204                                         unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2;
    205                                         args[nargs] = argv[i];                          // conditionally pass argument along
    206                                         const char * warning = argv[i] + adv; // extract warning
    207                                         if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp
    208                                                 Putenv( argv, arg );
    209                                         } // if
    210                                         nargs += 1;
    211                                 } // if
    212                         } else if ( prefix( arg, "-B" ) ) {
    213                                 Bprefix = arg.substr(2);                                // strip the -B flag
    214                                 args[nargs++] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     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;
    215258                        } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) {
    216                                 args[nargs++] = argv[i];                                // pass argument along
     259                                args[nargs] = argv[i];                                  // pass the argument along
     260                                nargs += 1;
    217261                                if ( arg == "-E" || arg == "-M" || arg == "-MM" ) {
    218262                                        cpp_flag = true;                                        // cpp only
     
    221265                        } else if ( arg[1] == 'l' ) {
    222266                                // if the user specifies a library, load it after user code
    223                                 libs[nlibs++] = argv[i];
     267                                libs[nlibs] = argv[i];
     268                                nlibs += 1;
    224269                        } else if ( arg == "-m32" ) {
    225270                                m32 = true;
    226271                                m64 = false;
    227                                 args[nargs++] = argv[i];
     272                                args[nargs] = argv[i];
     273                                nargs += 1;
    228274                        } else if ( arg == "-m64" ) {
    229275                                m64 = true;
    230276                                m32 = false;
    231                                 args[nargs++] = argv[i];
     277                                args[nargs] = argv[i];
     278                                nargs += 1;
    232279                        } else {
    233280                                // concatenate any other arguments
    234                                 args[nargs++] = argv[i];
     281                                args[nargs] = argv[i];
     282                                nargs += 1;
    235283                        } // if
    236284                } else {
    237                         bool cfa = suffix( arg );                                       // check suffix
    238                         if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    239                                 args[nargs++] = "-x";
    240                                 args[nargs++] = "c";
    241                         } // if
    242                         args[nargs++] = argv[i];                                        // concatenate files
    243                         if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    244                                 args[nargs++] = "-x";
    245                                 args[nargs++] = "none";
     285                        bool cfa = suffix( arg, args, nargs );          // check suffix
     286                        args[nargs] = argv[i];                                          // concatenate file
     287                        nargs += 1;
     288                        if ( cfa ) {
     289                                args[nargs] = "-x";
     290                                nargs += 1;
     291                                args[nargs] = "none";
     292                                nargs += 1;
    246293                        } // if
    247294                        nonoptarg = true;
     
    249296        } // for
    250297
     298    args[nargs] = "-x";                                                                 // turn off language
     299    nargs += 1;
     300    args[nargs] = "none";
     301    nargs += 1;
     302
    251303        #ifdef __x86_64__
    252         args[nargs++] = "-mcx16";                                                       // allow double-wide CAA
     304        args[nargs] = "-mcx16";                                                         // allow double-wide CAA
     305        nargs += 1;
    253306        #endif // __x86_64__
    254307
     
    261314        #endif // __DEBUG_H__
    262315
    263         // -E flag stops at cc1 stage 1, so cfa-cpp in cc1 stage 2 is never executed.
    264316        if ( cpp_flag && CFA_flag ) {
    265317                cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl;
     
    268320
    269321        // 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;
     322        if( !intree ) {
     323                args[nargs] = "-I" CFA_INCDIR;
     324                nargs += 1;
    272325                if ( ! noincstd_flag ) {                                                // do not use during build
    273                         args[nargs++] = "-I" CFA_INCDIR "stdhdr";
     326                        args[nargs] = "-I" CFA_INCDIR "stdhdr";
     327                        nargs += 1;
    274328                } // if
    275                 args[nargs++] = "-I" CFA_INCDIR "concurrency";
    276                 args[nargs++] = "-I" CFA_INCDIR "containers";
     329                args[nargs] = "-I" CFA_INCDIR "concurrency";
     330                nargs += 1;
     331                args[nargs] = "-I" CFA_INCDIR "containers";
     332                nargs += 1;
    277333        } else {
    278                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
     334                args[nargs] = "-I" TOP_SRCDIR "libcfa/src";
     335                nargs += 1;
    279336                if ( ! noincstd_flag ) {                                                // do not use during build
    280                         args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
     337                        args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
     338                        nargs += 1;
    281339                } // if
    282                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
    283                 args[nargs++] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
    284         } // 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        }
    285345
    286346        // add stdbool to get defines for bool/true/false
    287         args[nargs++] = "-imacros";
    288         args[nargs++] = "stdbool.h";
     347        args[nargs] = "-imacros";
     348        nargs += 1;
     349        args[nargs] = "stdbool.h";
     350        nargs += 1;
    289351
    290352        string libbase;
    291         if ( ! intree ) {
     353        if( !intree ) {
    292354                libbase = CFA_LIBDIR;
    293355        } else {
    294356                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) );
     357                args[nargs] = "-D__CFA_FLAG__=-t";
     358                nargs += 1;
     359        }
     360
     361        string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);
    299362        if ( ! m32 && ! m64 ) {
    300363                if ( arch == "x86" ) {
    301                         args[nargs++] = "-m32";
     364                        args[nargs] = "-m32";
     365                        nargs += 1;
    302366                } else if ( arch == "x64" ) {
    303                         args[nargs++] = "-m64";
     367                        args[nargs] = "-m64";
     368                        nargs += 1;
    304369                }  // if
    305370        } // if
    306 
    307         string libdir( libbase + arch + "-" + (nolib ? "nolib" : (debug ? "debug": "nodebug")) );
     371        const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug");
     372        string libdir = libbase + arch + "-" + config;
     373
     374        if ( ! nolib && ! dirExists( libdir ) ) {
     375                cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     376                cerr << "Was looking for " << libdir << endl;
     377                libdir = libbase + arch + "-" + "nolib";
     378        } // if
     379
    308380        if ( ! dirExists( libdir ) ) {
    309                 cerr << argv[0] << " internal error, cannot find prelude directory " << libdir << endl;
     381                cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
     382                cerr << "Was looking for " << libdir << endl;
    310383                exit( EXIT_FAILURE );
    311384        } // if
    312385
     386        args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();
     387        nargs += 1;
     388
    313389        for ( int i = 0; i < nlibs; i += 1 ) {                          // copy non-user libraries after all user libraries
    314                 args[nargs++] = libs[i];
     390                args[nargs] = libs[i];
     391                nargs += 1;
    315392        } // for
    316393
    317394        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";
     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;
     403                args[nargs] = "-Xlinker";
     404                nargs += 1;
     405                args[nargs] = "--undefined=__cfaabi_appready_startup";
     406                nargs += 1;
    324407
    325408                // include the cfa library in case it's 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";
     409                args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
     410                nargs += 1;
     411                args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
     412                nargs += 1;
     413                args[nargs] = "-Wl,--push-state,--as-needed";
     414                nargs += 1;
     415                args[nargs] = "-lcfathread";
     416                nargs += 1;
     417                args[nargs] = "-Wl,--pop-state";
     418                nargs += 1;
     419                args[nargs] = "-lcfa";
     420                nargs += 1;
     421                args[nargs] = "-lpthread";
     422                nargs += 1;
     423                args[nargs] = "-ldl";
     424                nargs += 1;
     425                args[nargs] = "-lrt";
     426                nargs += 1;
     427                args[nargs] = "-lm";
     428                nargs += 1;
     429        } // if
     430
     431        // Add exception flags (unconditionally)
     432        args[nargs] = "-fexceptions";
     433        nargs += 1;
     434
     435        // add the correct set of flags based on the type of compile this is
     436
     437        args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str();
     438        nargs += 1;
     439        args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str();
     440        nargs += 1;
     441        args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str();
     442        nargs += 1;
     443        args[nargs] = "-D__CFA__";
     444        nargs += 1;
     445        args[nargs] = "-D__CFORALL__";
     446        nargs += 1;
     447        args[nargs] = "-D__cforall";
     448        nargs += 1;
    348449
    349450        if ( cpp_flag ) {
    350                 args[nargs++] = "-D__CPP__";
    351         } // if
    352 
     451                args[nargs] = "-D__CPP__";
     452                nargs += 1;
     453        } // if
     454
     455        shuffle( args, sargs, nargs, 1 );                                       // make room at front of argument list
     456        nargs += 1;
    353457        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] );
     458                args[sargs] = "-D__CFA_FLAG__=-N";
     459                args[nargs] = "-D__CFA_PREPROCESS_";
     460                nargs += 1;
    359461        } else {
    360                 Putenv( argv, "-L" );
    361         } // if
    362 
    363         Putenv( argv, "--prelude-dir=" + libdir + (intree ? "/prelude" : "") );
     462                args[sargs] = "-D__CFA_FLAG__=-L";
     463        } // if
     464        sargs += 1;
    364465
    365466        if ( debug ) {
    366467                heading += " (debug)";
    367                 args[nargs++] = "-D__CFA_DEBUG__";
     468                args[nargs] = "-D__CFA_DEBUG__";
     469                nargs += 1;
    368470        } else {
    369471                heading += " (no debug)";
     
    373475                Bprefix = ! intree ? installlibdir : srcdriverdir;
    374476                if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/';
    375                 args[nargs++] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
    376         } // if
    377 
    378         args[nargs++] = "-Xlinker";                                                     // used by backtrace
    379         args[nargs++] = "-export-dynamic";
     477                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     478                nargs += 1;
     479        } // if
     480
     481        args[nargs] = "-Xlinker";                                                       // used by backtrace
     482        nargs += 1;
     483        args[nargs] = "-export-dynamic";
     484        nargs += 1;
    380485
    381486        // execute the compilation command
     
    391496
    392497        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
     498                args[nargs] = "-no-integrated-cpp";
     499                nargs += 1;
     500                args[nargs] = "-Wno-deprecated";
     501                nargs += 1;
     502#ifdef HAVE_CAST_FUNCTION_TYPE
     503                args[nargs] = "-Wno-cast-function-type";
     504                nargs += 1;
     505#endif // HAVE_CAST_FUNCTION_TYPE
    398506                if ( ! std_flag ) {                                                             // default c11, if none specified
    399                         args[nargs++] = "-std=gnu11";
     507                        args[nargs] = "-std=gnu11";
     508                        nargs += 1;
    400509                } // 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();
     510                args[nargs] = "-fgnu89-inline";
     511                nargs += 1;
     512                args[nargs] = "-D__int8_t_defined";                             // prevent gcc type-size attributes
     513                nargs += 1;
     514                args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str();
     515                nargs += 1;
    404516        } else {
    405517                cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl;
     
    407519        } // if
    408520
    409         args[nargs] = nullptr;                                                          // terminate
     521        args[nargs] = NULL;                                                                     // terminate with NULL
    410522
    411523        #ifdef __DEBUG_H__
    412524        cerr << "nargs: " << nargs << endl;
    413525        cerr << "args:" << endl;
    414         for ( int i = 0; args[i] != nullptr; i += 1 ) {
     526        for ( int i = 0; args[i] != NULL; i += 1 ) {
    415527                cerr << " \"" << args[i] << "\"" << endl;
    416528        } // for
     
    434546                if ( argc == 2 ) exit( EXIT_SUCCESS );                  // if only the -v flag is specified, do not invoke gcc
    435547
    436                 for ( int i = 0; args[i] != nullptr; i += 1 ) {
     548                for ( int i = 0; args[i] != NULL; i += 1 ) {
    437549                        cerr << args[i] << " ";
    438550                } // for
     
    448560
    449561        execvp( args[0], (char *const *)args );                         // should not return
    450         perror( "CFA Translator error: execvp" );
     562        perror( "CFA Translator error: cfa level, execvp" );
    451563        exit( EXIT_FAILURE );
    452564} // main
Note: See TracChangeset for help on using the changeset viewer.