Changeset 937e51d for src/main.cc


Ignore:
Timestamp:
Jun 26, 2015, 4:00:26 PM (10 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
0df292b, e0ff3e6
Parents:
eb50842 (diff), 1869adf (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:

Merge pointer to pointer to qualified fix into master

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    reb50842 r937e51d  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu May 21 21:15:54 2015
    13 // Update Count     : 9
     12// Last Modified On : Mon Jun 22 17:02:11 2015
     13// Update Count     : 73
    1414//
    1515
     
    5151using namespace std;
    5252
     53#define OPTPRINT(x) \
     54        if ( errorp ) std::cerr << x << std::endl;
     55
     56void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
     57
    5358bool
    5459        astp = false,
     60        bresolvep = false,
    5561        exprp = false,
    5662        expraltp = false,
    5763        grammarp = false,
    5864        libcfap = false,
     65        nopreludep = false,
     66        protop = false,
     67        parsep = false,
    5968        resolvep = false,                                                                       // used in AlternativeFinder
    6069        symtabp = false,
    61         parsep = false,
    6270        validp = false,
    63         preludep = true,
    64         protop = false,
    65         codegenp = false,
    66         errorp = false;
    67 
    68 enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Prototypes, Resolver, Symbol, Parse, };
     71        errorp = false,
     72        codegenp = false;
     73
     74enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, };
    6975
    7076static struct option long_opts[] = {
    7177        { "ast", no_argument, 0, Ast },
     78        { "before-resolver", no_argument, 0, Bresolver },
    7279        { "expr", no_argument, 0, Expr },
    7380        { "expralt", no_argument, 0, ExprAlt },
     
    7582        { "libcfa", no_argument, 0, LibCFA },
    7683        { "nopreamble", no_argument, 0, Nopreamble },
     84        { "parse", no_argument, 0, Parse },
    7785        { "prototypes", no_argument, 0, Prototypes },
    7886        { "resolver", no_argument, 0, Resolver },
    7987        { "symbol", no_argument, 0, Symbol },
    80         { "parse", no_argument, 0, Parse },
     88        { "validate", no_argument, 0, Validate },
    8189        { 0, 0, 0, 0 }
    8290};
     
    9199       
    92100        int c;
    93         while ( (c = getopt_long( argc, argv, "aefglnpqrsxyzD:", long_opts, &long_index )) != -1 ) {
     101        while ( (c = getopt_long( argc, argv, "abefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) {
    94102                switch ( c ) {
    95103                  case Ast:
     
    97105                        astp = true;
    98106                        break;
     107                  case Bresolver:
     108                  case 'b':                                                                             // print before resolver steps
     109                        bresolvep = true;
     110                        break;
    99111                  case Expr:
    100112                  case 'e':                                                                             // dump AST after expression analysis
     
    115127                  case Nopreamble:
    116128                  case 'n':                                                                             // do not read preamble
    117                         preludep = false;
     129                        nopreludep = true;
    118130                        break;
    119131                  case Prototypes:
     
    133145                        symtabp = true;
    134146                        break;
    135                   case 'x':                                                                             // dump AST after decl validation pass
     147                  case 'v':                                                                             // dump AST after decl validation pass
    136148                        validp = true;
    137149                        break;
     
    153165
    154166        try {
     167                // choose to read the program from a file or stdin
    155168                if ( optind < argc ) {
    156169                        input = fopen( argv[ optind ], "r" );
     
    169182       
    170183                Parser::get_parser().set_debug( grammarp );
    171        
    172                 if ( preludep ) {                                                               // include gcc builtins
    173                         FILE *builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );
     184
     185                // read in the builtins and the prelude
     186                if ( ! nopreludep ) {                                                   // include gcc builtins
     187                        FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );
    174188                        if ( builtins == NULL ) {
    175                                 std::cout << "Error: can't open builtins" << std::endl;
     189                                std::cerr << "Error: can't open builtins" << std::endl;
    176190                                exit( 1 );
    177191                        } // if
    178          
    179                         Parser::get_parser().set_linkage( LinkageSpec::Compiler );
    180                         Parser::get_parser().parse( builtins );
    181        
    182                         if ( Parser::get_parser().get_parseStatus() != 0 ) {
    183                                 return Parser::get_parser().get_parseStatus();
     192
     193                        parse( builtins, LinkageSpec::Compiler );
     194
     195                        if ( ! libcfap ) {
     196                                // read the prelude in, if we're not generating the cfa library
     197                                FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" );
     198                                if ( prelude == NULL ) {
     199                                        std::cerr << "Error: can't open prelude" << std::endl;
     200                                        exit( 1 );
     201                                } // if
     202                   
     203                    parse( prelude, LinkageSpec::Intrinsic );
    184204                        } // if
    185                         fclose( builtins );
    186 
    187                         FILE *prelude;
    188                         if ( libcfap ) {                                                        // include cfa prelude
    189                                 prelude = input;
    190                         } else {
    191                                 prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" );
    192                         } // if
    193                         if ( prelude == NULL ) {
    194                                 std::cout << "Error: can't open prelude" << std::endl;
    195                                 exit( 1 );
    196                         } // if
    197          
    198                         Parser::get_parser().set_linkage( LinkageSpec::Intrinsic );
    199                         Parser::get_parser().parse( prelude );
    200        
    201                         if ( Parser::get_parser().get_parseStatus() != 0 ) {
    202                                 return Parser::get_parser().get_parseStatus();
    203                         } // if
    204                         fclose( prelude );
    205                 } // if
    206        
     205                } // if
     206
    207207                if ( libcfap ) {
    208                         std::list< Declaration* > translationUnit;
    209                         buildList( Parser::get_parser().get_parseTree(), translationUnit );
    210                         Parser::get_parser().freeTree();
    211                         SymTab::validate( translationUnit, false );
    212                         CodeGen::fixNames( translationUnit );
    213                         LibCfa::makeLibCfa( translationUnit );
    214                         ResolvExpr::resolve( translationUnit );
    215                         GenPoly::convertLvalue( translationUnit );
    216                         GenPoly::box( translationUnit );
    217                         CodeGen::generate( translationUnit, *output, true );
    218                         if ( output != &std::cout ) {
    219                                 delete output;
    220                         } // if
    221                         return 0;
    222                 } // if
    223        
    224                 Parser::get_parser().set_linkage( LinkageSpec::Cforall );
    225  
    226                 Parser::get_parser().parse( input );
    227                 if ( grammarp || Parser::get_parser().get_parseStatus() != 0 ) {
    228                         return Parser::get_parser().get_parseStatus();
    229                 } // if
    230                 fclose( input );
     208                        parse( input, LinkageSpec::Intrinsic );
     209                } else {
     210                        parse( input, LinkageSpec::Cforall, grammarp );
     211                }
    231212 
    232213                if ( parsep ) {
     
    244225                } // if
    245226
     227                // add the assignment statement after the
     228                // initialization of a type parameter
     229                OPTPRINT( "tweak" )
     230                InitTweak::tweak( translationUnit );
     231                OPTPRINT( "validate" )
     232                SymTab::validate( translationUnit, symtabp );
     233                if ( symtabp ) {
     234                        return 0;
     235                } // if
     236
    246237                if ( expraltp ) {
    247                         SymTab::validate( translationUnit, false );
    248238                        ResolvExpr::AlternativePrinter printer( std::cout );
    249239                        acceptAll( translationUnit, printer );
     
    251241                } // if
    252242
    253                 if ( symtabp ) {
    254                         SymTab::validate( translationUnit, true );
    255                         return 0;
    256                 } // if
    257 
    258243                if ( validp ) {
    259                         SymTab::validate( translationUnit, false );
    260                         printAll( translationUnit, std::cout );
    261                         return 0;
    262                 } // if
    263 
     244                        printAll( translationUnit, std::cout );
     245                        return 0;
     246                } // if
     247
     248                OPTPRINT( "mutate" )
     249                ControlStruct::mutate( translationUnit );
     250                OPTPRINT( "fixNames" )
     251                CodeGen::fixNames( translationUnit );
     252
     253                if ( libcfap ) {
     254                        protop = true;
     255                        // generate the bodies of cfa library functions
     256                        LibCfa::makeLibCfa( translationUnit );
     257                } // if
     258
     259                if ( bresolvep ) {
     260                        printAll( translationUnit, std::cout );
     261                        return 0;
     262                } // if
     263
     264                OPTPRINT( "resolve" )
     265                ResolvExpr::resolve( translationUnit );
    264266                if ( exprp ) {
    265                         InitTweak::tweak( translationUnit );
    266                         SymTab::validate( translationUnit, false );
    267                         ControlStruct::mutate( translationUnit );
    268                         CodeGen::fixNames( translationUnit );
    269                         ResolvExpr::resolve( translationUnit );
    270                         printAll( translationUnit, std::cout );
    271                         return 0;
    272                 } // if
    273 
     267                        printAll( translationUnit, std::cout );
     268                }
     269
     270                OPTPRINT( "copyParams" );
     271                GenPoly::copyParams( translationUnit );
     272                OPTPRINT( "convertSpecializations" )
     273                GenPoly::convertSpecializations( translationUnit );             
     274                OPTPRINT( "convertLvalue" )
     275                GenPoly::convertLvalue( translationUnit );
     276                OPTPRINT( "box" )
     277                GenPoly::box( translationUnit );
     278
     279    // print the tree right before code generation
    274280                if ( codegenp ) {
    275                         // print the tree right before code generation
    276                         cerr << "tweak" << endl;
    277                         InitTweak::tweak( translationUnit );
    278                         cerr << "validate" << endl;
    279                         SymTab::validate( translationUnit, false );
    280                         cerr << "mutate" << endl;
    281                         ControlStruct::mutate( translationUnit );
    282                         cerr << "fixNames" << endl;
    283                         CodeGen::fixNames( translationUnit );
    284                         cerr << "resolve" << endl;
    285                         ResolvExpr::resolve( translationUnit );
    286                         cerr << "copyParams" << endl;
    287                         GenPoly::copyParams( translationUnit );
    288                         cerr << "convertSpecializations" << endl;
    289                         GenPoly::convertSpecializations( translationUnit );
    290                         cerr << "convertLvalue" << endl;
    291                         GenPoly::convertLvalue( translationUnit );
    292                         cerr << "box" << endl;
    293                         GenPoly::box( translationUnit );
    294                         if ( errorp ) {
    295                                 printAll( translationUnit, std::cout );
    296                         }
    297                         return 0;
    298                 } // if
    299 
    300                 // add the assignment statement after the
    301                 // initialization of a type parameter
    302                 InitTweak::tweak( translationUnit );
    303 
    304                 //std::cerr << "before validate" << std::endl;
    305                 SymTab::validate( translationUnit, false );
    306                 //Try::visit( translationUnit );
    307                 //Tuples::mutate( translationUnit );
    308                 //InitTweak::mutate( translationUnit );
    309                 //std::cerr << "before mutate" << std::endl;
    310                 ControlStruct::mutate( translationUnit );
    311                 //std::cerr << "before fixNames" << std::endl;
    312                 CodeGen::fixNames( translationUnit );
    313                 //std::cerr << "before resolve" << std::endl;
    314                 ResolvExpr::resolve( translationUnit );
    315                 //Tuples::checkFunctions( translationUnit );
    316                 //        std::cerr << "Finished tuple checkfunctions" << std::endl;
    317                 //printAll( translationUnit, std::cerr );
    318                 //std::cerr << "before copyParams" << std::endl;
    319                 GenPoly::copyParams( translationUnit );
    320                 //std::cerr << "before convertSpecializations" << std::endl;
    321                 GenPoly::convertSpecializations( translationUnit );
    322                 //std::cerr << "before convertLvalue" << std::endl;
    323                 GenPoly::convertLvalue( translationUnit );
    324                 //std::cerr << "before box" << std::endl;
    325                 GenPoly::box( translationUnit );
    326                 //Tuples::mutate( translationUnit );
     281                        printAll( translationUnit, std::cout );
     282                        return 0;
     283                } // if
    327284
    328285                CodeGen::generate( translationUnit, *output, protop );
     
    331288                        delete output;
    332289                } // if
    333 
    334290        } catch ( SemanticError &e ) {
    335291                if ( errorp ) {
    336                         printAll( translationUnit, std::cout );
     292                        printAll( translationUnit, std::cerr );
    337293                }
    338                 e.print( cout );
     294                e.print( std::cerr );
    339295                if ( output != &std::cout ) {
    340296                        delete output;
     
    359315} // main
    360316
     317void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) {
     318        Parser::get_parser().set_linkage( linkage );
     319        Parser::get_parser().parse( input );
     320
     321        fclose( input );
     322        if ( shouldExit || Parser::get_parser().get_parseStatus() != 0 ) {
     323                exit( Parser::get_parser().get_parseStatus() );
     324        } // if
     325}
     326
    361327// Local Variables: //
    362328// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.