Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rdd51906 rd3b7937  
    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
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jun  5 15:57:30 2016
    13 // Update Count     : 205
     12// Last Modified On : Wed Jan 27 22:20:20 2016
     13// Update Count     : 199
    1414//
    1515
     
    2424#include "SynTree/Declaration.h"
    2525#include "SynTree/Visitor.h"
     26#include "GenPoly/InstantiateGeneric.h"
    2627#include "GenPoly/Lvalue.h"
    2728#include "GenPoly/Specialize.h"
     
    4041#include "MakeLibCfa.h"
    4142#include "InitTweak/Mutate.h"
    42 #include "InitTweak/GenInit.h"
    43 #include "InitTweak/FixInit.h"
    44 #include "InitTweak/FixGlobalInit.h"
     43#include "InitTweak/RemoveInit.h"
    4544//#include "Explain/GenProlog.h"
    4645//#include "Try/Visit.h"
     
    5756
    5857static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
    59 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout );
     58static void dump( std::list< Declaration * > & translationUnit );
    6059
    6160bool
    6261        astp = false,
    6362        bresolvep = false,
    64         bboxp = false,
    65         ctorinitp = false,
    6663        exprp = false,
    6764        expraltp = false,
     
    7875        codegenp = false;
    7976
    80 enum { Ast, Bbox, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
     77enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
    8178
    8279static struct option long_opts[] = {
    8380        { "ast", no_argument, 0, Ast },
    84         { "before-box", no_argument, 0, Bbox },
    8581        { "before-resolver", no_argument, 0, Bresolver },
    86         { "ctorinitfix", no_argument, 0, CtorInitFix },
    8782        { "expr", no_argument, 0, Expr },
    8883        { "expralt", no_argument, 0, ExprAlt },
     
    10398        std::ostream *output = &std::cout;
    10499        int long_index;
    105         std::list< Declaration * > translationUnit;
    106         const char *filename = NULL;
     100        std::list< Declaration* > translationUnit;
    107101
    108102        opterr = 0;                                                                                     // prevent getopt from printing error messages
    109 
     103       
    110104        int c;
    111         while ( (c = getopt_long( argc, argv, "abBcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) {
     105        while ( (c = getopt_long( argc, argv, "abefglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {
    112106                switch ( c ) {
    113107                  case Ast:
     
    119113                        bresolvep = true;
    120114                        break;
    121                   case 'B':                                                                             // print before resolver steps
    122                         bboxp = true;
    123                         break;
    124                   case CtorInitFix:
    125                   case 'c':
    126                         ctorinitp = true;
    127                         break;
    128115                  case Expr:
    129116                  case 'e':                                                                             // dump AST after expression analysis
     
    177164                  case 'D':                                                                             // ignore -Dxxx
    178165                        break;
    179                   case 'F':                                                                             // source file-name without suffix
    180                         filename = optarg;
    181                         break;
    182166                  case '?':
    183167                        cout << "Unknown option: '" << (char)optopt << "'" << endl;
    184                         exit( EXIT_FAILURE );
     168                        exit(1);
    185169                  default:
    186170                        abort();
     
    193177                        input = fopen( argv[ optind ], "r" );
    194178                        if ( ! input ) {
    195                                 std::cout << "Error: can't open " << argv[ optind ] << std::endl;
    196                                 exit( EXIT_FAILURE );
     179                                std::cout << "Error: can't open " << argv[optind] << std::endl;
     180                                exit( 1 );
    197181                        } // if
    198                         // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)
    199                         if ( filename == NULL ) filename = argv[ optind ];
    200                         // prelude filename comes in differently
    201                         if ( libcfap ) filename = "prelude.cf";
    202182                        optind += 1;
    203183                } else {
    204184                        input = stdin;
    205                         // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
    206                         // a fake name along
    207                         if ( filename == NULL ) filename = "stdin";
    208185                } // if
    209186
     
    211188                        output = new ofstream( argv[ optind ] );
    212189                } // if
    213 
     190       
    214191                Parser::get_parser().set_debug( grammarp );
    215192
     
    220197                        if ( builtins == NULL ) {
    221198                                std::cerr << "Error: can't open builtins.cf" << std::endl;
    222                                 exit( EXIT_FAILURE );
     199                                exit( 1 );
    223200                        } // if
    224201
     
    230207                                if ( prelude == NULL ) {
    231208                                        std::cerr << "Error: can't open prelude.cf" << std::endl;
    232                                         exit( EXIT_FAILURE );
     209                                        exit( 1 );
    233210                                } // if
    234 
     211                   
    235212                                parse( prelude, LinkageSpec::Intrinsic );
    236213                        } // if
    237214                } // if
    238215
    239                 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );
    240 
     216                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );     
     217 
    241218                if ( parsep ) {
    242219                        Parser::get_parser().get_parseTree()->printList( std::cout );
     
    273250                OPTPRINT( "mutate" )
    274251                ControlStruct::mutate( translationUnit );
    275                 OPTPRINT( "fixNames" )
     252                OPTPRINT( "fixNames" ) 
    276253                CodeGen::fixNames( translationUnit );
    277                 OPTPRINT( "fixGlobalInit" );
    278                 InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep );
    279                 OPTPRINT( "tweakInit" )
    280                 InitTweak::genInit( translationUnit );
     254                OPTPRINT( "tweak" )
     255                InitTweak::tweak( translationUnit );
    281256
    282257                if ( libcfap ) {
     
    294269                if ( exprp ) {
    295270                        dump( translationUnit );
    296                         return 0;
    297271                }
    298272
    299                 OPTPRINT( "fixInit" )
    300                 // fix ObjectDecl - replaces ConstructorInit nodes
    301                 InitTweak::fix( translationUnit );
    302                 if ( ctorinitp ) {
    303                         dump ( translationUnit );
    304                         return 0;
    305                 }
    306 
     273                OPTPRINT( "instantiateGeneric" )
     274                GenPoly::instantiateGeneric( translationUnit );
    307275                OPTPRINT( "copyParams" );
    308276                GenPoly::copyParams( translationUnit );
     
    311279                OPTPRINT( "convertLvalue" )
    312280                GenPoly::convertLvalue( translationUnit );
    313 
    314                 if ( bboxp ) {
    315                         dump( translationUnit );
    316                         return 0;
    317                 }
    318281                OPTPRINT( "box" )
    319282                GenPoly::box( translationUnit );
     
    332295        } catch ( SemanticError &e ) {
    333296                if ( errorp ) {
    334                         std::cerr << "---AST at error:---" << std::endl;
    335                         dump( translationUnit, std::cerr );
    336                         std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl;
     297                        dump( translationUnit );
    337298                }
    338299                e.print( std::cerr );
     
    356317        } // try
    357318
    358         deleteAll( translationUnit );
    359319        return 0;
    360320} // main
     
    374334}
    375335
    376 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {
     336static void dump( std::list< Declaration * > & translationUnit ) {
    377337        std::list< Declaration * > decls;
    378338        if ( noprotop ) {
    379                 filter( translationUnit.begin(), translationUnit.end(),
     339                filter( translationUnit.begin(), translationUnit.end(), 
    380340                                std::back_inserter( decls ), notPrelude );
    381341        } else {
     
    383343        }
    384344
    385         printAll( decls, out );
     345        printAll( decls, std::cout );
    386346        deleteAll( translationUnit );
    387347}
Note: See TracChangeset for help on using the changeset viewer.