Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rd3b7937 rdd51906  
    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 : Wed Jan 27 22:20:20 2016
    13 // Update Count     : 199
     12// Last Modified On : Sun Jun  5 15:57:30 2016
     13// Update Count     : 205
    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"
     
    4140#include "MakeLibCfa.h"
    4241#include "InitTweak/Mutate.h"
    43 #include "InitTweak/RemoveInit.h"
     42#include "InitTweak/GenInit.h"
     43#include "InitTweak/FixInit.h"
     44#include "InitTweak/FixGlobalInit.h"
    4445//#include "Explain/GenProlog.h"
    4546//#include "Try/Visit.h"
     
    5657
    5758static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
    58 static void dump( std::list< Declaration * > & translationUnit );
     59static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout );
    5960
    6061bool
    6162        astp = false,
    6263        bresolvep = false,
     64        bboxp = false,
     65        ctorinitp = false,
    6366        exprp = false,
    6467        expraltp = false,
     
    7578        codegenp = false;
    7679
    77 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
     80enum { Ast, Bbox, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
    7881
    7982static struct option long_opts[] = {
    8083        { "ast", no_argument, 0, Ast },
     84        { "before-box", no_argument, 0, Bbox },
    8185        { "before-resolver", no_argument, 0, Bresolver },
     86        { "ctorinitfix", no_argument, 0, CtorInitFix },
    8287        { "expr", no_argument, 0, Expr },
    8388        { "expralt", no_argument, 0, ExprAlt },
     
    98103        std::ostream *output = &std::cout;
    99104        int long_index;
    100         std::list< Declaration* > translationUnit;
     105        std::list< Declaration * > translationUnit;
     106        const char *filename = NULL;
    101107
    102108        opterr = 0;                                                                                     // prevent getopt from printing error messages
    103        
     109
    104110        int c;
    105         while ( (c = getopt_long( argc, argv, "abefglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {
     111        while ( (c = getopt_long( argc, argv, "abBcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) {
    106112                switch ( c ) {
    107113                  case Ast:
     
    113119                        bresolvep = true;
    114120                        break;
     121                  case 'B':                                                                             // print before resolver steps
     122                        bboxp = true;
     123                        break;
     124                  case CtorInitFix:
     125                  case 'c':
     126                        ctorinitp = true;
     127                        break;
    115128                  case Expr:
    116129                  case 'e':                                                                             // dump AST after expression analysis
     
    164177                  case 'D':                                                                             // ignore -Dxxx
    165178                        break;
     179                  case 'F':                                                                             // source file-name without suffix
     180                        filename = optarg;
     181                        break;
    166182                  case '?':
    167183                        cout << "Unknown option: '" << (char)optopt << "'" << endl;
    168                         exit(1);
     184                        exit( EXIT_FAILURE );
    169185                  default:
    170186                        abort();
     
    177193                        input = fopen( argv[ optind ], "r" );
    178194                        if ( ! input ) {
    179                                 std::cout << "Error: can't open " << argv[optind] << std::endl;
    180                                 exit( 1 );
     195                                std::cout << "Error: can't open " << argv[ optind ] << std::endl;
     196                                exit( EXIT_FAILURE );
    181197                        } // 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";
    182202                        optind += 1;
    183203                } else {
    184204                        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";
    185208                } // if
    186209
     
    188211                        output = new ofstream( argv[ optind ] );
    189212                } // if
    190        
     213
    191214                Parser::get_parser().set_debug( grammarp );
    192215
     
    197220                        if ( builtins == NULL ) {
    198221                                std::cerr << "Error: can't open builtins.cf" << std::endl;
    199                                 exit( 1 );
     222                                exit( EXIT_FAILURE );
    200223                        } // if
    201224
     
    207230                                if ( prelude == NULL ) {
    208231                                        std::cerr << "Error: can't open prelude.cf" << std::endl;
    209                                         exit( 1 );
     232                                        exit( EXIT_FAILURE );
    210233                                } // if
    211                    
     234
    212235                                parse( prelude, LinkageSpec::Intrinsic );
    213236                        } // if
    214237                } // if
    215238
    216                 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );     
    217  
     239                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );
     240
    218241                if ( parsep ) {
    219242                        Parser::get_parser().get_parseTree()->printList( std::cout );
     
    250273                OPTPRINT( "mutate" )
    251274                ControlStruct::mutate( translationUnit );
    252                 OPTPRINT( "fixNames" ) 
     275                OPTPRINT( "fixNames" )
    253276                CodeGen::fixNames( translationUnit );
    254                 OPTPRINT( "tweak" )
    255                 InitTweak::tweak( translationUnit );
     277                OPTPRINT( "fixGlobalInit" );
     278                InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep );
     279                OPTPRINT( "tweakInit" )
     280                InitTweak::genInit( translationUnit );
    256281
    257282                if ( libcfap ) {
     
    269294                if ( exprp ) {
    270295                        dump( translationUnit );
     296                        return 0;
    271297                }
    272298
    273                 OPTPRINT( "instantiateGeneric" )
    274                 GenPoly::instantiateGeneric( translationUnit );
     299                OPTPRINT( "fixInit" )
     300                // fix ObjectDecl - replaces ConstructorInit nodes
     301                InitTweak::fix( translationUnit );
     302                if ( ctorinitp ) {
     303                        dump ( translationUnit );
     304                        return 0;
     305                }
     306
    275307                OPTPRINT( "copyParams" );
    276308                GenPoly::copyParams( translationUnit );
     
    279311                OPTPRINT( "convertLvalue" )
    280312                GenPoly::convertLvalue( translationUnit );
     313
     314                if ( bboxp ) {
     315                        dump( translationUnit );
     316                        return 0;
     317                }
    281318                OPTPRINT( "box" )
    282319                GenPoly::box( translationUnit );
     
    295332        } catch ( SemanticError &e ) {
    296333                if ( errorp ) {
    297                         dump( translationUnit );
     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;
    298337                }
    299338                e.print( std::cerr );
     
    317356        } // try
    318357
     358        deleteAll( translationUnit );
    319359        return 0;
    320360} // main
     
    334374}
    335375
    336 static void dump( std::list< Declaration * > & translationUnit ) {
     376static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {
    337377        std::list< Declaration * > decls;
    338378        if ( noprotop ) {
    339                 filter( translationUnit.begin(), translationUnit.end(), 
     379                filter( translationUnit.begin(), translationUnit.end(),
    340380                                std::back_inserter( decls ), notPrelude );
    341381        } else {
     
    343383        }
    344384
    345         printAll( decls, std::cout );
     385        printAll( decls, out );
    346386        deleteAll( translationUnit );
    347387}
Note: See TracChangeset for help on using the changeset viewer.