Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rd3b7937 rf77f12e2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // main.cc -- 
     7// main.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 27 22:20:20 2016
    13 // Update Count     : 199
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Mon Apr 11 17:49:38 2016
     13// Update Count     : 200
    1414//
    1515
     
    2424#include "SynTree/Declaration.h"
    2525#include "SynTree/Visitor.h"
    26 #include "GenPoly/InstantiateGeneric.h"
    2726#include "GenPoly/Lvalue.h"
    2827#include "GenPoly/Specialize.h"
     
    4241#include "InitTweak/Mutate.h"
    4342#include "InitTweak/RemoveInit.h"
     43#include "InitTweak/FixInit.h"
    4444//#include "Explain/GenProlog.h"
    4545//#include "Try/Visit.h"
     
    5656
    5757static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
    58 static void dump( std::list< Declaration * > & translationUnit );
     58static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout );
    5959
    6060bool
    6161        astp = false,
    6262        bresolvep = false,
     63        ctorinitp = false,
    6364        exprp = false,
    6465        expraltp = false,
     
    7576        codegenp = false;
    7677
    77 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
     78enum { Ast, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
    7879
    7980static struct option long_opts[] = {
    8081        { "ast", no_argument, 0, Ast },
    8182        { "before-resolver", no_argument, 0, Bresolver },
     83        { "ctorinitfix", no_argument, 0, CtorInitFix },
    8284        { "expr", no_argument, 0, Expr },
    8385        { "expralt", no_argument, 0, ExprAlt },
     
    101103
    102104        opterr = 0;                                                                                     // prevent getopt from printing error messages
    103        
     105
    104106        int c;
    105         while ( (c = getopt_long( argc, argv, "abefglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {
     107        while ( (c = getopt_long( argc, argv, "abcefFglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {
    106108                switch ( c ) {
    107109                  case Ast:
     
    112114                  case 'b':                                                                             // print before resolver steps
    113115                        bresolvep = true;
     116                        break;
     117                        case CtorInitFix:
     118                        case 'c':
     119                        ctorinitp = true;
    114120                        break;
    115121                  case Expr:
     
    188194                        output = new ofstream( argv[ optind ] );
    189195                } // if
    190        
     196
    191197                Parser::get_parser().set_debug( grammarp );
    192198
     
    209215                                        exit( 1 );
    210216                                } // if
    211                    
     217
    212218                                parse( prelude, LinkageSpec::Intrinsic );
    213219                        } // if
    214220                } // if
    215221
    216                 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );     
    217  
     222                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );
     223
    218224                if ( parsep ) {
    219225                        Parser::get_parser().get_parseTree()->printList( std::cout );
     
    250256                OPTPRINT( "mutate" )
    251257                ControlStruct::mutate( translationUnit );
    252                 OPTPRINT( "fixNames" ) 
     258                OPTPRINT( "fixNames" )
    253259                CodeGen::fixNames( translationUnit );
    254                 OPTPRINT( "tweak" )
     260                OPTPRINT( "tweakInit" )
    255261                InitTweak::tweak( translationUnit );
    256262
     
    269275                if ( exprp ) {
    270276                        dump( translationUnit );
     277                        return 0;
    271278                }
    272279
    273                 OPTPRINT( "instantiateGeneric" )
    274                 GenPoly::instantiateGeneric( translationUnit );
     280                OPTPRINT( "fixInit" )
     281                // fix ObjectDecl - replaces ConstructorInit nodes
     282                InitTweak::fix( translationUnit );
     283                if ( ctorinitp ) {
     284                        dump ( translationUnit );
     285                        return 0;
     286                }
     287
    275288                OPTPRINT( "copyParams" );
    276289                GenPoly::copyParams( translationUnit );
     
    295308        } catch ( SemanticError &e ) {
    296309                if ( errorp ) {
    297                         dump( translationUnit );
     310                        std::cerr << "---AST at error:---" << std::endl;
     311                        dump( translationUnit, std::cerr );
     312                        std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl;
    298313                }
    299314                e.print( std::cerr );
     
    317332        } // try
    318333
     334        deleteAll( translationUnit );
    319335        return 0;
    320336} // main
     
    334350}
    335351
    336 static void dump( std::list< Declaration * > & translationUnit ) {
     352static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {
    337353        std::list< Declaration * > decls;
    338354        if ( noprotop ) {
    339                 filter( translationUnit.begin(), translationUnit.end(), 
     355                filter( translationUnit.begin(), translationUnit.end(),
    340356                                std::back_inserter( decls ), notPrelude );
    341357        } else {
     
    343359        }
    344360
    345         printAll( decls, std::cout );
     361        printAll( decls, out );
    346362        deleteAll( translationUnit );
    347363}
Note: See TracChangeset for help on using the changeset viewer.