Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r0e464f6 re0bd0f9  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  5 20:35:13 2019
    13 // Update Count     : 601
     12// Last Modified On : Thu Aug 22 13:06:18 2019
     13// Update Count     : 605
    1414//
    1515
     
    5959#include "ResolvExpr/Resolver.h"            // for resolve
    6060#include "SymTab/Validate.h"                // for validate
     61#include "SynTree/TopLvalue.h"              // for assertTopLvalue, clearInn...
    6162#include "SynTree/Declaration.h"            // for Declaration
    6263#include "SynTree/Visitor.h"                // for acceptAll
    6364#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    6465#include "Virtual/ExpandCasts.h"            // for expandCasts
     66
    6567
    6668using namespace std;
     
    9698static std::string PreludeDirector = "";
    9799
    98 static void parse_cmdline( int argc, char *argv[], const char *& filename );
     100static void parse_cmdline( int argc, char *argv[] );
    99101static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
    100102static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
     
    169171        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    170172        ostream * output = & cout;
    171         const char * filename = nullptr;
    172173        list< Declaration * > translationUnit;
    173174
     
    181182        // } // for
    182183
    183         parse_cmdline( argc, argv, filename );                          // process command-line arguments
     184        parse_cmdline( argc, argv );                                            // process command-line arguments
    184185        CodeGen::FixMain::setReplaceMain( !nomainp );
    185186
     
    188189                if ( optind < argc ) {                                                  // any commands after the flags ? => input file name
    189190                        input = fopen( argv[ optind ], "r" );
    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";
     191                        assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
    195192                        optind += 1;
    196193                } else {                                                                                // no input file name
    197194                        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";
    201195                } // if
    202196
     
    257251                Stats::Time::StopBlock();
    258252
     253                //std::cerr << "Post-Parse Check" << std::endl;
     254                clearInnerLvalue( translationUnit );
     255                assertTopLvalue( translationUnit );
     256
    259257                // add the assignment statement after the initialization of a type parameter
    260258                PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
     
    275273                } // if
    276274
     275                assertTopLvalue( translationUnit );
    277276                PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
     277                assertTopLvalue( translationUnit );
    278278                PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
     279                assertTopLvalue( translationUnit );
    279280                PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
     281                assertTopLvalue( translationUnit );
    280282                PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
     283                assertTopLvalue( translationUnit );
    281284                if ( libcfap ) {
    282285                        // generate the bodies of cfa library functions
     
    302305                } // if
    303306
     307                assertTopLvalue( translationUnit );
     308
    304309                PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    305310                if ( exprp ) {
     
    308313                } // if
    309314
     315                clearInnerLvalue( translationUnit );
     316                assertTopLvalue( translationUnit );
     317
    310318                // fix ObjectDecl - replaces ConstructorInit nodes
    311319                PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
     320                clearInnerLvalue( translationUnit );
     321                assertTopLvalue( translationUnit );
    312322                if ( ctorinitp ) {
    313323                        dump ( translationUnit );
     
    316326
    317327                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 );
    318329
    319330                PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
     331                assertTopLvalue( translationUnit );
    320332
    321333                PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
     334                clearInnerLvalue( translationUnit );
     335                assertTopLvalue( translationUnit );
    322336
    323337                PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     338                clearInnerLvalue( translationUnit );
     339                assertTopLvalue( translationUnit );
    324340
    325341                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     342                assertTopLvalue( translationUnit );
    326343
    327344                if ( tuplep ) {
     
    331348
    332349                PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     350                assertTopLvalue( translationUnit );
    333351
    334352                PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
     
    337355                        return EXIT_SUCCESS;
    338356                } // if
     357                clearInnerLvalue( translationUnit );
     358                assertTopLvalue( translationUnit );
    339359                PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) );
    340 
     360                clearInnerLvalue( translationUnit );
     361                assertTopLvalue( translationUnit );
    341362
    342363                if ( bboxp ) {
     
    345366                } // if
    346367                PASS( "Box", GenPoly::box( translationUnit ) );
     368                clearInnerLvalue( translationUnit );
     369                assertTopLvalue( translationUnit );
    347370
    348371                if ( bcodegenp ) {
     
    356379
    357380                CodeTools::fillLocations( translationUnit );
     381                assertTopLvalue( translationUnit );
    358382                PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) );
    359383
     
    406430
    407431
    408 static const char optstring[] = ":hlLmNnpP:S:twW:D:F:";
     432static const char optstring[] = ":hlLmNnpP:S:twW:D:";
    409433
    410434enum { PreludeDir = 128 };
     
    424448        { "", no_argument, nullptr, 0 },                                        // -W
    425449        { "", no_argument, nullptr, 0 },                                        // -D
    426         { "", no_argument, nullptr, 0 },                                        // -F
    427450        { nullptr, 0, nullptr, 0 }
    428451}; // long_opts
     
    443466        "",                                                                                                     // -W
    444467        "",                                                                                                     // -D
    445         "",                                                                                                     // -F
    446468}; // description
    447469
     
    478500
    479501static void usage( char *argv[] ) {
    480     cout << "Usage: " << argv[0] << " options are:" << endl;
     502    cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
    481503        int i = 0, j = 1;                                                                       // j skips starting colon
    482504        for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
     
    504526} // usage
    505527
    506 static void parse_cmdline( int argc, char * argv[], const char *& filename ) {
     528static void parse_cmdline( int argc, char * argv[] ) {
    507529        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    508530
     
    575597                  case 'D':                                                                             // ignore -Dxxx, forwarded by cpp, hidden
    576598                        break;
    577                   case 'F':                                                                             // source file-name without suffix, hidden
    578                         filename = optarg;
    579                         break;
    580599                  case '?':                                                                             // unknown option
    581600                        if ( optopt ) {                                                         // short option ?
Note: See TracChangeset for help on using the changeset viewer.