Changeset f80e0218 for src/main.cc


Ignore:
Timestamp:
Jun 30, 2016, 4:32:56 PM (10 years ago)
Author:
Thierry Delisle <tdelisle@…>
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, with_gc
Children:
ea29e73
Parents:
1b5c81ed (diff), 84d4d6f (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 branch 'master' into gc_noraii

Conflicts:

Jenkinsfile
src/SymTab/Validate.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r1b5c81ed rf80e0218  
    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
     
    4040#include "MakeLibCfa.h"
    4141#include "InitTweak/Mutate.h"
    42 #include "InitTweak/RemoveInit.h"
     42#include "InitTweak/GenInit.h"
     43#include "InitTweak/FixInit.h"
     44#include "InitTweak/FixGlobalInit.h"
    4345//#include "Explain/GenProlog.h"
    4446//#include "Try/Visit.h"
     
    5557
    5658static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
    57 static void dump( std::list< Declaration * > & translationUnit );
     59static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout );
    5860
    5961bool
    6062        astp = false,
    6163        bresolvep = false,
     64        bboxp = false,
     65        ctorinitp = false,
    6266        exprp = false,
    6367        expraltp = false,
     
    7478        codegenp = false;
    7579
    76 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, };
    7781
    7882static struct option long_opts[] = {
    7983        { "ast", no_argument, 0, Ast },
     84        { "before-box", no_argument, 0, Bbox },
    8085        { "before-resolver", no_argument, 0, Bresolver },
     86        { "ctorinitfix", no_argument, 0, CtorInitFix },
    8187        { "expr", no_argument, 0, Expr },
    8288        { "expralt", no_argument, 0, ExprAlt },
     
    97103        std::ostream *output = &std::cout;
    98104        int long_index;
    99         std::list< Declaration* > translationUnit;
     105        std::list< Declaration * > translationUnit;
     106        const char *filename = NULL;
    100107
    101108        opterr = 0;                                                                                     // prevent getopt from printing error messages
    102        
     109
    103110        int c;
    104         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 ) {
    105112                switch ( c ) {
    106113                  case Ast:
     
    112119                        bresolvep = true;
    113120                        break;
     121                  case 'B':                                                                             // print before resolver steps
     122                        bboxp = true;
     123                        break;
     124                  case CtorInitFix:
     125                  case 'c':
     126                        ctorinitp = true;
     127                        break;
    114128                  case Expr:
    115129                  case 'e':                                                                             // dump AST after expression analysis
     
    163177                  case 'D':                                                                             // ignore -Dxxx
    164178                        break;
     179                  case 'F':                                                                             // source file-name without suffix
     180                        filename = optarg;
     181                        break;
    165182                  case '?':
    166183                        cout << "Unknown option: '" << (char)optopt << "'" << endl;
    167                         exit(1);
     184                        exit( EXIT_FAILURE );
    168185                  default:
    169186                        abort();
     
    176193                        input = fopen( argv[ optind ], "r" );
    177194                        if ( ! input ) {
    178                                 std::cout << "Error: can't open " << argv[optind] << std::endl;
    179                                 exit( 1 );
     195                                std::cout << "Error: can't open " << argv[ optind ] << std::endl;
     196                                exit( EXIT_FAILURE );
    180197                        } // 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";
    181202                        optind += 1;
    182203                } else {
    183204                        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";
    184208                } // if
    185209
     
    187211                        output = new ofstream( argv[ optind ] );
    188212                } // if
    189        
     213
    190214                Parser::get_parser().set_debug( grammarp );
    191215
     
    196220                        if ( builtins == NULL ) {
    197221                                std::cerr << "Error: can't open builtins.cf" << std::endl;
    198                                 exit( 1 );
     222                                exit( EXIT_FAILURE );
    199223                        } // if
    200224
     
    206230                                if ( prelude == NULL ) {
    207231                                        std::cerr << "Error: can't open prelude.cf" << std::endl;
    208                                         exit( 1 );
     232                                        exit( EXIT_FAILURE );
    209233                                } // if
    210                    
     234
    211235                                parse( prelude, LinkageSpec::Intrinsic );
    212236                        } // if
    213237                } // if
    214238
    215                 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );     
    216  
     239                parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );
     240
    217241                if ( parsep ) {
    218242                        Parser::get_parser().get_parseTree()->printList( std::cout );
     
    249273                OPTPRINT( "mutate" )
    250274                ControlStruct::mutate( translationUnit );
    251                 OPTPRINT( "fixNames" ) 
     275                OPTPRINT( "fixNames" )
    252276                CodeGen::fixNames( translationUnit );
    253                 OPTPRINT( "tweak" )
    254                 InitTweak::tweak( translationUnit );
     277                OPTPRINT( "fixGlobalInit" );
     278                InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep );
     279                OPTPRINT( "tweakInit" )
     280                InitTweak::genInit( translationUnit );
    255281
    256282                if ( libcfap ) {
     
    268294                if ( exprp ) {
    269295                        dump( translationUnit );
     296                        return 0;
     297                }
     298
     299                OPTPRINT( "fixInit" )
     300                // fix ObjectDecl - replaces ConstructorInit nodes
     301                InitTweak::fix( translationUnit );
     302                if ( ctorinitp ) {
     303                        dump ( translationUnit );
     304                        return 0;
    270305                }
    271306
     
    276311                OPTPRINT( "convertLvalue" )
    277312                GenPoly::convertLvalue( translationUnit );
     313
     314                if ( bboxp ) {
     315                        dump( translationUnit );
     316                        return 0;
     317                }
    278318                OPTPRINT( "box" )
    279319                GenPoly::box( translationUnit );
    280                
     320
    281321                // print tree right before code generation
    282322                if ( codegenp ) {
     
    292332        } catch ( SemanticError &e ) {
    293333                if ( errorp ) {
    294                         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;
    295337                }
    296338                e.print( std::cerr );
     
    314356        } // try
    315357
     358        deleteAll( translationUnit );
    316359        return 0;
    317360} // main
     
    331374}
    332375
    333 static void dump( std::list< Declaration * > & translationUnit ) {
     376static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {
    334377        std::list< Declaration * > decls;
    335378        if ( noprotop ) {
    336                 filter( translationUnit.begin(), translationUnit.end(), 
     379                filter( translationUnit.begin(), translationUnit.end(),
    337380                                std::back_inserter( decls ), notPrelude );
    338381        } else {
     
    340383        }
    341384
    342         printAll( decls, std::cout );
     385        printAll( decls, out );
    343386        deleteAll( translationUnit );
    344387}
Note: See TracChangeset for help on using the changeset viewer.