source: driver/cfa.cc @ c2051e10

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since c2051e10 was c2051e10, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Merge branch 'master' into distcc

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