Changeset e67a82d for driver


Ignore:
Timestamp:
Aug 20, 2020, 11:48:15 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d685cb0
Parents:
67ca73e (diff), 013b028 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

fix conflicts

Location:
driver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • driver/cc1.cc

    r67ca73e re67a82d  
    1010// Created On       : Fri Aug 26 14:23:51 2005
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 30 18:09:05 2020
    13 // Update Count     : 404
     12// Last Modified On : Sun Aug 16 21:03:02 2020
     13// Update Count     : 413
    1414//
    1515
     
    2424#include <unistd.h>                                                                             // execvp, fork, unlink
    2525#include <sys/wait.h>                                                                   // wait
    26 #include <fcntl.h>
     26#include <fcntl.h>                                                                              // creat
    2727
    2828
     
    5959
    6060
    61 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "N__=" suffix
     61static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
    6262
    6363static void checkEnv1( const char * args[], int & nargs ) { // stage 1
     
    111111} // checkEnv2
    112112
    113 
    114 static char tmpname[] = P_tmpdir "/CFAXXXXXX.ifa";
     113#define CFA_SUFFIX ".ifa"
     114
     115static char tmpname[] = P_tmpdir "/CFAXXXXXX" CFA_SUFFIX;
    115116static int tmpfilefd = -1;
    116117static bool startrm = false;
     
    170171                        if ( arg == "-quiet" ) {
    171172                        } else if ( arg == "-imultilib" || arg == "-imultiarch" ) {
    172                                 i += 1;                                                                 // and the argument
     173                                i += 1;                                                                 // and argument
    173174                        } else if ( prefix( arg, "-A" ) ) {
    174175                        } else if ( prefix( arg, "-D__GNU" ) ) {
     
    177178                                //********
    178179                        } else if ( arg == "-D" && prefix( argv[i + 1], "__GNU" ) ) {
    179                                 i += 1;                                                                 // and the argument
     180                                i += 1;                                                                 // and argument
    180181
    181182                                // strip flags controlling cpp step
     
    184185                                cpp_flag = true;
    185186                        } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {
    186                                 i += 1;                                                                 // and the argument
     187                                i += 1;                                                                 // and argument
    187188                                cpp_flag = true;
    188189
     
    194195                                cpp_out = argv[i];
    195196                        } else {
    196                                 args[nargs++] = argv[i];                                // pass the flag along
     197                                args[nargs++] = argv[i];                                // pass flag along
    197198                                // CPP flags with an argument
    198199                                if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||
     
    200201                                         arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {
    201202                                        i += 1;
    202                                         args[nargs++] = argv[i];                        // pass the argument along
     203                                        args[nargs++] = argv[i];                        // pass argument along
    203204                                        #ifdef __DEBUG_H__
    204205                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
    205206                                        #endif // __DEBUG_H__
    206207                                } else if ( arg == "-MD" || arg == "-MMD" ) {
     208                                        // gcc frontend generates the dependency file-name after the -MD/-MMD flag, but it is necessary to
     209                                        // prefix that file name with -MF.
    207210                                        args[nargs++] = "-MF";                          // insert before file
    208211                                        i += 1;
    209                                         args[nargs++] = argv[i];                        // pass the argument along
     212                                        args[nargs++] = argv[i];                        // pass argument along
    210213                                        #ifdef __DEBUG_H__
    211214                                        cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
     
    279282        // Run the C preprocessor and save the output in the given file.
    280283
    281         if ( fork() == 0 ) {                                                             // child process ?
     284        if ( fork() == 0 ) {                                                            // child process ?
    282285                // -o xxx.ii cannot be used to write the output file from cpp because no output file is created if cpp detects
    283286                // an error (e.g., cannot find include file). Whereas, output is always generated, even when there is an error,
     
    319322
    320323        if ( WIFSIGNALED(code) ) {                                                      // child failed ?
     324                rmtmpfile();                                                                    // remove tmpname
    321325                cerr << "CC1 Translator error: stage 1, child failed " << WTERMSIG(code) << endl;
    322326                exit( EXIT_FAILURE );
    323327        } // if
    324328
    325         exit( WEXITSTATUS(code) );                                                      // bad cpp result stops top-level gcc
     329        exit( WEXITSTATUS( code ) );                                            // bad cpp result stops top-level gcc
    326330} // Stage1
    327331
     
    371375                        } else if ( arg == "-fno-diagnostics-color" ) {
    372376                                color_arg = Color_Auto;
    373                         }
     377                        } // if
    374378
    375379                        if ( arg == "-quiet" || arg == "-version" || arg == "-fpreprocessed" ||
    376                                 // Currently CFA does not suppose precompiled .h files.
    377                                 prefix( arg, "--output-pch" ) ) {
     380                                 // Currently CFA does not suppose precompiled .h files.
     381                                 prefix( arg, "--output-pch" ) ) {
    378382
    379383                                // strip inappropriate flags with an argument
     
    388392
    389393                        } else {
    390                                 args[nargs++] = argv[i];                                // pass the flag along
     394                                args[nargs++] = argv[i];                                // pass flag along
    391395                                if ( arg == "-o" ) {
    392396                                        i += 1;
    393397                                        cpp_out = argv[i];
    394                                         args[nargs++] = argv[i];                        // pass the argument along
     398                                        args[nargs++] = argv[i];                        // pass argument along
    395399                                        #ifdef __DEBUG_H__
    396400                                        cerr << "arg:\"" << argv[i] << "\"" << endl;
     
    439443                        } // if
    440444
    441                         cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + ".ifa";
     445                        cfa_cpp_out = cfa_cpp_out.substr( 0, dot ) + CFA_SUFFIX;
    442446                        if ( creat( cfa_cpp_out.c_str(), 0666 ) == -1 ) {
    443447                                perror( "CC1 Translator error: stage 2, creat" );
     
    460464        // output.  Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file.
    461465
    462         if ( fork() == 0 ) {                                                            // child runs CFA
     466        if ( fork() == 0 ) {                                                            // child runs CFA preprocessor
    463467                cargs[0] = ( *new string( bprefix + "cfa-cpp" ) ).c_str();
    464468                cargs[ncargs++] = cpp_in;
     
    518522        #endif // __DEBUG_H__
    519523
    520         if ( fork() == 0 ) {                                                            // child runs CFA
     524        if ( fork() == 0 ) {                                                            // child runs gcc
    521525                args[0] = compiler_path.c_str();
    522526                args[nargs++] = "-S";                                                   // only compile and put assembler output in specified file
  • driver/cfa.cc

    r67ca73e re67a82d  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 18 16:40:22 2020
    13 // Update Count     : 435
     12// Last Modified On : Thu Aug 20 23:43:59 2020
     13// Update Count     : 436
    1414//
    1515
    1616#include <iostream>
    17 #include <cstdio>      // perror
    18 #include <cstdlib>     // putenv, exit
    19 #include <climits>     // PATH_MAX
    20 #include <unistd.h>    // execvp
    21 #include <string>      // STL version
    22 #include <string.h>    // strcmp
    23 #include <algorithm>   // find
    24 
     17#include <cstdio>                                                                               // perror
     18#include <cstdlib>                                                                              // putenv, exit
     19#include <climits>                                                                              // PATH_MAX
     20#include <string>                                                                               // STL version
     21#include <algorithm>                                                                    // find
     22
     23#include <unistd.h>                                                                             // execvp
    2524#include <sys/types.h>
    2625#include <sys/stat.h>
     
    3433using std::to_string;
    3534
    36 // #define __DEBUG_H__
    37 
    38 // "N__=" suffix
    39 static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
    40 
    41 void Putenv( char * argv[], string arg ) {
     35//#define __DEBUG_H__
     36
     37#define xstr(s) str(s)
     38#define str(s) #s
     39
     40static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );               // "__CFA_FLAG__=" suffix
     41
     42static void Putenv( char * argv[], string arg ) {
    4243        // environment variables must have unique names
    4344        static int flags = 0;
     
    4950} // Putenv
    5051
    51 // check if string has prefix
    52 bool prefix( const string & arg, const string & pre ) {
     52static bool prefix( const string & arg, const string & pre ) { // check if string has prefix
    5353        return arg.substr( 0, pre.size() ) == pre;
    5454} // prefix
    5555
    56 inline bool ends_with(const string & str, const string & sfix) {
     56static inline bool ends_with(const string & str, const string & sfix) {
    5757        if (sfix.size() > str.size()) return false;
    5858        return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
     
    6060
    6161// check if string has suffix
    62 bool suffix( const string & arg ) {
     62static bool suffix( const string & arg ) {
    6363        enum { NumSuffixes = 3 };
    6464        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     
    7070} // suffix
    7171
    72 
    7372static inline bool dirExists( const string & path ) {   // check if directory exists
    7473    struct stat info;
     
    7978static inline string dir(const string & path) {
    8079        return path.substr(0, path.find_last_of('/'));
    81 }
     80} // dir
    8281
    8382// Different path modes
     
    118117}
    119118
    120 
    121 #define xstr(s) str(s)
    122 #define str(s) #s
    123119
    124120int main( int argc, char * argv[] ) {
     
    158154        PathMode path = FromProc();
    159155
    160         const char *args[argc + 100];                                           // cfa command line values, plus some space for additional flags
     156        const char * args[argc + 100];                                          // cfa command line values, plus some space for additional flags
    161157        int sargs = 1;                                                                          // starting location for arguments in args list
    162158        int nargs = sargs;                                                                      // number of arguments in args list; 0 => command name
    163159
    164         const char *libs[argc + 20];                                            // non-user libraries must come separately, plus some added libraries and flags
     160        const char * libs[argc + 20];                                           // non-user libraries must come separately, plus some added libraries and flags
    165161        int nlibs = 0;
    166162
     
    180176
    181177                        if ( arg == "-Xlinker" || arg == "-o" ) {
    182                                 args[nargs++] = argv[i];                                // pass argument along
     178                                args[nargs++] = argv[i];                                // pass flag along
    183179                                i += 1;
    184180                                if ( i == argc ) continue;                              // next argument available ?
    185181                                args[nargs++] = argv[i];                                // pass argument along
    186182                                if ( arg == "-o" ) o_file = i;                  // remember file
    187                         } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) {                           // CFA pass through
    188                                 if(arg.size() == 5) {
     183
     184                                // CFA specific arguments
     185
     186                        } else if ( strncmp(arg.c_str(), "-XCFA", 5) == 0 ) { // CFA pass through
     187                                if ( arg.size() == 5 ) {
    189188                                        i += 1;
    190                                         if ( i == argc ) continue;                              // next argument available ?
     189                                        if ( i == argc ) continue;                      // next argument available ?
    191190                                        Putenv( argv, argv[i] );
    192 
    193                                         // CFA specific arguments
    194                                 }
    195                                 else if(arg[5] == ',') {
     191                                } else if ( arg[5] == ',' ) {                   // CFA specific arguments
    196192                                        Putenv( argv, argv[i] + 6 );
    197 
    198                                         // CFA specific arguments
    199                                 }
    200                                 else {
     193                                } else {                                                                // CFA specific arguments
    201194                                        args[nargs++] = argv[i];
    202                                 }
    203 
     195                                } // if
    204196                        } else if ( arg == "-CFA" ) {
    205197                                CFA_flag = true;                                                // strip the -CFA flag
     
    210202                        } else if ( arg == "-nodebug" ) {
    211203                                debug = false;                                                  // strip the nodebug flag
    212                         } else if ( arg == "-nolib" ) {
    213                                 nolib = true;                                                   // strip the nodebug flag
    214204                        } else if ( arg == "-quiet" ) {
    215205                                quiet = true;                                                   // strip the quiet flag
    216206                        } else if ( arg == "-noquiet" ) {
    217207                                quiet = false;                                                  // strip the noquiet flag
     208                        } else if ( arg == "-no-include-stdhdr" ) {
     209                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
     210                        } else if ( arg == "-nolib" ) {
     211                                nolib = true;                                                   // strip the nolib flag
    218212                        } else if ( arg == "-help" ) {
    219213                                help = true;                                                    // strip the help flag
    220214                        } else if ( arg == "-nohelp" ) {
    221215                                help = false;                                                   // strip the nohelp flag
    222                         } else if ( arg == "-no-include-stdhdr" ) {
    223                                 noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    224216                        } else if ( arg == "-cfalib") {
    225217                                compiling_libs = true;
     
    235227                        } else if ( arg == "-v" ) {
    236228                                verbose = true;                                                 // verbosity required
    237                                 args[nargs++] = argv[i];                                // pass argument along
     229                                args[nargs++] = argv[i];                                // pass flag along
    238230                        } else if ( arg == "-g" ) {
    239231                                debugging = true;                                               // symbolic debugging required
    240                                 args[nargs++] = argv[i];                                // pass argument along
     232                                args[nargs++] = argv[i];                                // pass flag along
    241233                        } else if ( arg == "-save-temps" ) {
    242                                 args[nargs++] = argv[i];                                // pass argument along
     234                                args[nargs++] = argv[i];                                // pass flag along
    243235                                Putenv( argv, arg );                                    // save cfa-cpp output
    244236                        } else if ( prefix( arg, "-x" ) ) {                     // file suffix ?
    245237                                string lang;
    246                                 args[nargs++] = argv[i];                                // pass argument along
     238                                args[nargs++] = argv[i];                                // pass flag along
    247239                                if ( arg.length() == 2 ) {                              // separate argument ?
    248240                                        i += 1;
     
    261253                        } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
    262254                                std_flag = true;                                                // -std=XX provided
    263                                 args[nargs++] = argv[i];                                // pass argument along
     255                                args[nargs++] = argv[i];                                // pass flag along
    264256                        } else if ( arg == "-w" ) {
    265                                 args[nargs++] = argv[i];                                // pass argument along
     257                                args[nargs++] = argv[i];                                // pass flag along
    266258                                Putenv( argv, arg );
    267259                        } else if ( prefix( arg, "-W" ) ) {                     // check before next tests
    268260                                if ( arg == "-Werror" || arg == "-Wall" ) {
    269                                         args[nargs++] = argv[i];                        // pass argument along
     261                                        args[nargs++] = argv[i];                        // pass flag along
    270262                                        Putenv( argv, argv[i] );
    271263                                } else {
     
    281273                                bprefix = arg.substr(2);                                // strip the -B flag
    282274                        } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) {
    283                                 args[nargs++] = argv[i];                                // pass argument along
     275                                args[nargs++] = argv[i];                                // pass flag along
    284276                                if ( arg == "-E" || arg == "-M" || arg == "-MM" ) {
    285277                                        cpp_flag = true;                                        // cpp only
    286278                                } // if
    287279                                link = false;                           // no linkage required
     280                        } else if ( arg == "-D" || arg == "-U" || arg == "-I" || arg == "-MF" || arg == "-MT" || arg == "-MQ" ||
     281                                                arg == "-include" || arg == "-imacros" || arg == "-idirafter" || arg == "-iprefix" ||
     282                                                arg == "-iwithprefix" || arg == "-iwithprefixbefore" || arg == "-isystem" || arg == "-isysroot" ) {
     283                                args[nargs++] = argv[i];                                // pass flag along
     284                                i += 1;
     285                                args[nargs++] = argv[i];                                // pass argument along
    288286                        } else if ( arg[1] == 'l' ) {
    289287                                // if the user specifies a library, load it after user code
     
    337335        string libbase;
    338336        switch(path) {
    339         case Installed:
     337          case Installed:
    340338                args[nargs++] = "-I" CFA_INCDIR;
    341339                // do not use during build
     
    347345                libbase = CFA_LIBDIR;
    348346                break;
    349         case BuildTree:
    350         case Distributed:
     347          case BuildTree:
     348          case Distributed:
    351349                args[nargs++] = "-I" TOP_SRCDIR "libcfa/src";
    352350                // do not use during build
     
    382380        string libdir = libbase + arch + "-" + config;
    383381
    384         if (path != Distributed) {
     382        if ( path != Distributed ) {
    385383                if ( ! nolib && ! dirExists( libdir ) ) {
    386384                        cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
     
    402400        string preludedir;
    403401        switch(path) {
    404         case Installed   : preludedir = libdir; break;
    405         case BuildTree   : preludedir = libdir + "/prelude"; break;
    406         case Distributed : preludedir = dir(argv[0]); break;
    407         }
     402          case Installed   : preludedir = libdir; break;
     403          case BuildTree   : preludedir = libdir + "/prelude"; break;
     404          case Distributed : preludedir = dir(argv[0]); break;
     405        } // switch
    408406
    409407        Putenv( argv, "--prelude-dir=" + preludedir );
     
    477475        if ( bprefix.length() == 0 ) {
    478476                switch(path) {
    479                 case Installed   : bprefix = installlibdir; break;
    480                 case BuildTree   : bprefix = srcdriverdir ; break;
    481                 case Distributed : bprefix = dir(argv[0]) ; break;
    482                 }
    483                 if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
    484                 Putenv( argv, string("-B=") + bprefix );
    485         } // if
     477                  case Installed   : bprefix = installlibdir; break;
     478                  case BuildTree   : bprefix = srcdriverdir ; break;
     479                  case Distributed : bprefix = dir(argv[0]) ; break;
     480                } // switch
     481        } // if
     482        if ( bprefix[bprefix.length() - 1] != '/' ) bprefix += '/';
     483        Putenv( argv, string("-B=") + bprefix );
    486484
    487485        args[nargs++] = "-Xlinker";                                                     // used by backtrace
     
    505503                args[nargs++] = "-Wno-cast-function-type";
    506504                #endif // HAVE_CAST_FUNCTION_TYPE
    507                 if ( ! std_flag ) {                                                             // default c11, if none specified
    508                         args[nargs++] = "-std=gnu11";
     505                if ( ! std_flag && ! x_flag ) {
     506                        args[nargs++] = "-std=gnu11";                           // default c11, if none specified
    509507                } // if
    510508                args[nargs++] = "-fgnu89-inline";
     
    556554        // execute the command and return the result
    557555
    558         execvp( args[0], (char *const *)args );                         // should not return
     556        execvp( args[0], (char * const *)args );                        // should not return
    559557        perror( "CFA Translator error: execvp" );
    560558        exit( EXIT_FAILURE );
Note: See TracChangeset for help on using the changeset viewer.