source: driver/cfa.cc @ 6d44da1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 6d44da1 was 6d44da1, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Merge branch 'master' into shared_library

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