Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r14347ac r4f5a8a2  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Feb 10 08:28:09 2019
    13 // Update Count     : 281
     12// Last Modified On : Sat Aug 10 08:44:15 2019
     13// Update Count     : 311
    1414//
    1515
     
    2020#include <string>                                                                               // STL version
    2121#include <string.h>                                                                             // strcmp
     22#include <algorithm>                                                                    // find
    2223
    2324#include <sys/types.h>
     
    2627#include "Common/SemanticError.h"
    2728#include "config.h"                                                                             // configure info
     29
    2830
    2931using std::cerr;
     
    4042} // prefix
    4143
    42 enum { NumSuffixes = 2 };
    43 const string suffixes[NumSuffixes] = { "cfa", "hfa", };
    44 
    45 bool suffix( string arg, const char * args[], int & nargs ) {
     44bool suffix( string arg ) {
     45        enum { NumSuffixes = 3 };
     46        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
    4647        //std::cerr << arg << std::endl;
    4748        size_t dot = arg.find_last_of( "." );
    4849        //std::cerr << dot << " " << (dot != string::npos ? arg.substr( dot + 1 ) : "fred" ) << std::endl;
    4950        if ( dot == string::npos ) return false;
    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;
     51        const string * end = suffixes + NumSuffixes;
     52        return std::find( suffixes, end, arg.substr( dot + 1 ) ) != end;
    6153} // suffix
    6254
    6355
    64 void shuffle( const char *args[], int S, int E, int N ) {
     56void shuffle( const char * args[], int S, int E, int N ) {
    6557        // S & E index 1 passed the end so adjust with -1
    6658        #ifdef __DEBUG_H__
     
    7567} // shuffle
    7668
    77 static inline bool dirExists(const string & path) {
     69static inline bool dirExists( const string & path ) {
    7870    struct stat info;
    7971    if(stat( path.c_str(), &info ) != 0)
     
    8577} //dirExists
    8678
    87 static inline string dir(const string & path) {
    88         return path.substr(0, path.find_last_of('/'));
    89 }
    90 
    9179
    9280#define str(s) #s
    9381
    94 int main( int argc, char *argv[] ) {
     82int main( int argc, char * argv[] ) {
    9583        string Version( CFA_VERSION_LONG );                                     // current version number from CONFIG
    9684        string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
     
    10896        string compiler_name;                                                           // name of C compiler
    10997
     98        bool x_flag = false;                                                            // -x flag
    11099        bool nonoptarg = false;                                                         // indicates non-option argument specified
    111100        bool link = true;                                                                       // linking as well as compiling
    112101        bool verbose = false;                                                           // -v flag
    113         bool quiet = false;                                                             // -quiet flag
    114         bool debug = true;                                                              // -debug flag
    115         bool nolib = false;                                                             // -nolib flag
    116         bool help = false;                                                              // -help flag
     102        bool quiet = false;                                                                     // -quiet flag
     103        bool debug = true;                                                                      // -debug flag
     104        bool nolib = false;                                                                     // -nolib flag
     105        bool help = false;                                                                      // -help flag
    117106        bool CFA_flag = false;                                                          // -CFA flag
    118107        bool cpp_flag = false;                                                          // -E or -M flag, preprocessor only
     
    120109        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
    121110        bool debugging __attribute(( unused )) = false;         // -g flag
    122         bool m32 = false;                                    // -m32 flag
    123         bool m64 = false;                                    // -m64 flag
     111        bool m32 = false;                                                                       // -m32 flag
     112        bool m64 = false;                                                                       // -m64 flag
    124113        bool intree = false;
    125         bool disttree = false;
    126114
    127115        const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     
    140128
    141129        // process command-line arguments
    142 
    143         args[nargs] = "-x";                                                                     // turn off language
    144         nargs += 1;
    145         args[nargs] = "c";
    146         nargs += 1;
    147130
    148131        for ( int i = 1; i < argc; i += 1 ) {
     
    188171                        } else if ( arg == "-in-tree" ) {
    189172                                intree = true;
    190                         } else if ( arg == "-dist-tree" ) {
    191                                 disttree = true;
    192173                        } else if ( arg == "-compiler" ) {
    193174                                // use the user specified compiler
     
    210191                                args[nargs] = argv[i];                                  // pass the argument along
    211192                                nargs += 1;
     193                        } else if ( prefix( arg, "-x" ) ) {                     // file suffix ?
     194                                string lang;
     195                                args[nargs] = argv[i];                                  // pass the argument along
     196                                nargs += 1;
     197                                if ( arg.length() == 2 ) {                              // separate argument ?
     198                                        i += 1;
     199                                        if ( i == argc ) continue;                      // next argument available ?
     200                                        lang = argv[i];
     201                                        args[nargs] = argv[i];                          // pass the argument along
     202                                        nargs += 1;
     203                                } else {
     204                                        lang = arg.substr( 2 );
     205                                } // if
     206                                x_flag = lang != "none";
    212207                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    213208                                std_flag = true;                                                // -std=XX provided
     
    295290                        } // if
    296291                } else {
    297                         bool cfa = suffix( arg, args, nargs );          // check suffix
     292                        bool cfa = suffix( arg );                                       // check suffix
     293                        if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
     294                                args[nargs] = "-x";
     295                                nargs += 1;
     296                                args[nargs] = "c";
     297                                nargs += 1;
     298                        } // if
    298299                        args[nargs] = argv[i];                                          // concatenate file
    299300                        nargs += 1;
    300                         if ( cfa ) {
     301                        if ( ! x_flag && cfa ) {                                        // no explicit suffix and cfa suffix ?
    301302                                args[nargs] = "-x";
    302303                                nargs += 1;
     
    379380        string libdir = libbase + arch + "-" + config;
    380381
    381         if (!disttree) {
    382                 if ( ! nolib && ! dirExists( libdir ) ) {
    383                         cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
    384                         cerr << "Was looking for " << libdir << endl;
    385                         for(int i = 1; i < argc; i++) {
    386                                 cerr << argv[i] << " ";
    387                         }
    388                         cerr << endl;
    389                         libdir = libbase + arch + "-" + "nolib";
    390                 } // if
    391 
    392                 if ( ! dirExists( libdir ) ) {
    393                         cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
    394                         cerr << "Was looking for " << libdir << endl;
    395                         exit( EXIT_FAILURE );
    396                 } // if
    397         } // if
    398 
    399         if(disttree) {
    400                 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str();
    401         } else if(intree) {
    402                 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str();
    403         } else {
    404                 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str();
    405         }
     382        if ( ! nolib && ! dirExists( libdir ) ) {
     383                cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     384                cerr << "Was looking for " << libdir << endl;
     385                libdir = libbase + arch + "-" + "nolib";
     386        } // if
     387
     388        if ( ! dirExists( libdir ) ) {
     389                cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
     390                cerr << "Was looking for " << libdir << endl;
     391                exit( EXIT_FAILURE );
     392        } // if
     393
     394        args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + (intree ? "/prelude" : "")) ).c_str();
    406395        nargs += 1;
    407396
     
    492481
    493482        if ( Bprefix.length() == 0 ) {
    494                 if(disttree) {
    495                         Bprefix = dir(argv[0]);
    496                 } else if(intree) {
    497                         Bprefix = srcdriverdir;
    498                 } else {
    499                         Bprefix = installlibdir;
    500                 }
    501 
     483                Bprefix = ! intree ? installlibdir : srcdriverdir;
    502484                if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/';
    503485                args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
     
    557539        if ( ! quiet ) {
    558540                cerr << "CFA " << "Version " << Version << heading << endl;
     541
    559542                if ( help ) {
    560543                        cerr <<
Note: See TracChangeset for help on using the changeset viewer.