Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    re0bd0f9 r0e464f6  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 22 13:06:18 2019
    13 // Update Count     : 605
     12// Last Modified On : Wed Jun  5 20:35:13 2019
     13// Update Count     : 601
    1414//
    1515
     
    5959#include "ResolvExpr/Resolver.h"            // for resolve
    6060#include "SymTab/Validate.h"                // for validate
    61 #include "SynTree/TopLvalue.h"              // for assertTopLvalue, clearInn...
    6261#include "SynTree/Declaration.h"            // for Declaration
    6362#include "SynTree/Visitor.h"                // for acceptAll
    6463#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    6564#include "Virtual/ExpandCasts.h"            // for expandCasts
    66 
    6765
    6866using namespace std;
     
    9896static std::string PreludeDirector = "";
    9997
    100 static void parse_cmdline( int argc, char *argv[] );
     98static void parse_cmdline( int argc, char *argv[], const char *& filename );
    10199static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
    102100static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
     
    171169        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    172170        ostream * output = & cout;
     171        const char * filename = nullptr;
    173172        list< Declaration * > translationUnit;
    174173
     
    182181        // } // for
    183182
    184         parse_cmdline( argc, argv );                                            // process command-line arguments
     183        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    185184        CodeGen::FixMain::setReplaceMain( !nomainp );
    186185
     
    189188                if ( optind < argc ) {                                                  // any commands after the flags ? => input file name
    190189                        input = fopen( argv[ optind ], "r" );
    191                         assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
     190                        assertf( input, "cannot open %s\n", argv[ optind ] );
     191                        // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)
     192                        if ( filename == nullptr ) filename = argv[ optind ];
     193                        // prelude filename comes in differently
     194                        if ( libcfap ) filename = "prelude.cfa";
    192195                        optind += 1;
    193196                } else {                                                                                // no input file name
    194197                        input = stdin;
     198                        // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
     199                        // a fake name along
     200                        if ( filename == nullptr ) filename = "stdin";
    195201                } // if
    196202
     
    251257                Stats::Time::StopBlock();
    252258
    253                 //std::cerr << "Post-Parse Check" << std::endl;
    254                 clearInnerLvalue( translationUnit );
    255                 assertTopLvalue( translationUnit );
    256 
    257259                // add the assignment statement after the initialization of a type parameter
    258260                PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
     
    273275                } // if
    274276
    275                 assertTopLvalue( translationUnit );
    276277                PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
    277                 assertTopLvalue( translationUnit );
    278278                PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
    279                 assertTopLvalue( translationUnit );
    280279                PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
    281                 assertTopLvalue( translationUnit );
    282280                PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
    283                 assertTopLvalue( translationUnit );
    284281                if ( libcfap ) {
    285282                        // generate the bodies of cfa library functions
     
    305302                } // if
    306303
    307                 assertTopLvalue( translationUnit );
    308 
    309304                PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    310305                if ( exprp ) {
     
    313308                } // if
    314309
    315                 clearInnerLvalue( translationUnit );
    316                 assertTopLvalue( translationUnit );
    317 
    318310                // fix ObjectDecl - replaces ConstructorInit nodes
    319311                PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    320                 clearInnerLvalue( translationUnit );
    321                 assertTopLvalue( translationUnit );
    322312                if ( ctorinitp ) {
    323313                        dump ( translationUnit );
     
    326316
    327317                PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
    328                 assertTopLvalue( translationUnit );
    329318
    330319                PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
    331                 assertTopLvalue( translationUnit );
    332320
    333321                PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
    334                 clearInnerLvalue( translationUnit );
    335                 assertTopLvalue( translationUnit );
    336322
    337323                PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    338                 clearInnerLvalue( translationUnit );
    339                 assertTopLvalue( translationUnit );
    340324
    341325                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
    342                 assertTopLvalue( translationUnit );
    343326
    344327                if ( tuplep ) {
     
    348331
    349332                PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
    350                 assertTopLvalue( translationUnit );
    351333
    352334                PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
     
    355337                        return EXIT_SUCCESS;
    356338                } // if
    357                 clearInnerLvalue( translationUnit );
    358                 assertTopLvalue( translationUnit );
    359339                PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) );
    360                 clearInnerLvalue( translationUnit );
    361                 assertTopLvalue( translationUnit );
     340
    362341
    363342                if ( bboxp ) {
     
    366345                } // if
    367346                PASS( "Box", GenPoly::box( translationUnit ) );
    368                 clearInnerLvalue( translationUnit );
    369                 assertTopLvalue( translationUnit );
    370347
    371348                if ( bcodegenp ) {
     
    379356
    380357                CodeTools::fillLocations( translationUnit );
    381                 assertTopLvalue( translationUnit );
    382358                PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) );
    383359
     
    430406
    431407
    432 static const char optstring[] = ":hlLmNnpP:S:twW:D:";
     408static const char optstring[] = ":hlLmNnpP:S:twW:D:F:";
    433409
    434410enum { PreludeDir = 128 };
     
    448424        { "", no_argument, nullptr, 0 },                                        // -W
    449425        { "", no_argument, nullptr, 0 },                                        // -D
     426        { "", no_argument, nullptr, 0 },                                        // -F
    450427        { nullptr, 0, nullptr, 0 }
    451428}; // long_opts
     
    466443        "",                                                                                                     // -W
    467444        "",                                                                                                     // -D
     445        "",                                                                                                     // -F
    468446}; // description
    469447
     
    500478
    501479static void usage( char *argv[] ) {
    502     cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
     480    cout << "Usage: " << argv[0] << " options are:" << endl;
    503481        int i = 0, j = 1;                                                                       // j skips starting colon
    504482        for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
     
    526504} // usage
    527505
    528 static void parse_cmdline( int argc, char * argv[] ) {
     506static void parse_cmdline( int argc, char * argv[], const char *& filename ) {
    529507        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    530508
     
    597575                  case 'D':                                                                             // ignore -Dxxx, forwarded by cpp, hidden
    598576                        break;
     577                  case 'F':                                                                             // source file-name without suffix, hidden
     578                        filename = optarg;
     579                        break;
    599580                  case '?':                                                                             // unknown option
    600581                        if ( optopt ) {                                                         // short option ?
Note: See TracChangeset for help on using the changeset viewer.