Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r6cf27a07 re497c1d  
    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 : Tue Jul  5 15:23:11 2016
    13 // Update Count     : 209
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 28 13:05:02 2015
     13// Update Count     : 165
    1414//
    1515
     
    4040#include "MakeLibCfa.h"
    4141#include "InitTweak/Mutate.h"
    42 #include "InitTweak/GenInit.h"
    43 #include "InitTweak/FixInit.h"
     42#include "InitTweak/RemoveInit.h"
    4443//#include "Explain/GenProlog.h"
    4544//#include "Try/Visit.h"
    4645
    47 #include "Common/SemanticError.h"
    48 #include "Common/UnimplementedError.h"
     46#include "SemanticError.h"
     47#include "UnimplementedError.h"
    4948
    5049#include "../config.h"
     
    5655
    5756static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false );
    58 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout );
     57static void dump( std::list< Declaration * > & translationUnit );
    5958
    6059bool
    6160        astp = false,
    6261        bresolvep = false,
    63         bboxp = false,
    64         ctorinitp = false,
    6562        exprp = false,
    6663        expraltp = false,
     
    7269        resolvep = false,                                                                       // used in AlternativeFinder
    7370        symtabp = false,
    74         treep = false,
    7571        validp = false,
    7672        errorp = false,
    7773        codegenp = false;
    7874
    79 enum { Ast, Bbox, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };
     75enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, };
    8076
    8177static struct option long_opts[] = {
    8278        { "ast", no_argument, 0, Ast },
    83         { "before-box", no_argument, 0, Bbox },
    8479        { "before-resolver", no_argument, 0, Bresolver },
    85         { "ctorinitfix", no_argument, 0, CtorInitFix },
    8680        { "expr", no_argument, 0, Expr },
    8781        { "expralt", no_argument, 0, ExprAlt },
     
    9387        { "resolver", no_argument, 0, Resolver },
    9488        { "symbol", no_argument, 0, Symbol },
    95         { "tree", no_argument, 0, Tree },
    9689        { "validate", no_argument, 0, Validate },
    9790        { 0, 0, 0, 0 }
     
    10295        std::ostream *output = &std::cout;
    10396        int long_index;
    104         std::list< Declaration * > translationUnit;
    105         const char *filename = NULL;
     97        std::list< Declaration* > translationUnit;
    10698
    10799        opterr = 0;                                                                                     // prevent getopt from printing error messages
    108 
     100       
    109101        int c;
    110         while ( (c = getopt_long( argc, argv, "abBcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) {
     102        while ( (c = getopt_long( argc, argv, "abefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) {
    111103                switch ( c ) {
    112104                  case Ast:
     
    118110                        bresolvep = true;
    119111                        break;
    120                   case 'B':                                                                             // print before resolver steps
    121                         bboxp = true;
    122                         break;
    123                   case CtorInitFix:
    124                   case 'c':
    125                         ctorinitp = true;
    126                         break;
    127112                  case Expr:
    128113                  case 'e':                                                                             // dump AST after expression analysis
     
    161146                        symtabp = true;
    162147                        break;
    163                   case Tree:
    164                   case 't':                                                                             // build in tree
    165                         treep = true;
    166                         break;
    167148                  case 'v':                                                                             // dump AST after decl validation pass
    168149                        validp = true;
     
    176157                  case 'D':                                                                             // ignore -Dxxx
    177158                        break;
    178                   case 'F':                                                                             // source file-name without suffix
    179                         filename = optarg;
    180                         break;
    181159                  case '?':
    182160                        cout << "Unknown option: '" << (char)optopt << "'" << endl;
    183                         exit( EXIT_FAILURE );
     161                        exit(1);
    184162                  default:
    185163                        abort();
     
    192170                        input = fopen( argv[ optind ], "r" );
    193171                        if ( ! input ) {
    194                                 std::cout << "Error: can't open " << argv[ optind ] << std::endl;
    195                                 exit( EXIT_FAILURE );
     172                                std::cout << "Error: can't open " << argv[optind] << std::endl;
     173                                exit( 1 );
    196174                        } // if
    197                         // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)
    198                         if ( filename == NULL ) filename = argv[ optind ];
    199                         // prelude filename comes in differently
    200                         if ( libcfap ) filename = "prelude.cf";
    201175                        optind += 1;
    202176                } else {
    203177                        input = stdin;
    204                         // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
    205                         // a fake name along
    206                         if ( filename == NULL ) filename = "stdin";
    207178                } // if
    208179
     
    210181                        output = new ofstream( argv[ optind ] );
    211182                } // if
    212 
     183       
    213184                Parser::get_parser().set_debug( grammarp );
    214185
    215                 // read in the builtins, extras, and the prelude
     186                // read in the builtins and the prelude
    216187                if ( ! nopreludep ) {                                                   // include gcc builtins
    217                         // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
    218                         FILE * builtins = fopen( libcfap | treep ? "builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
     188                        FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );
    219189                        if ( builtins == NULL ) {
    220                                 std::cerr << "Error: can't open builtins.cf" << std::endl;
    221                                 exit( EXIT_FAILURE );
     190                                std::cerr << "Error: can't open builtins" << std::endl;
     191                                exit( 1 );
    222192                        } // if
     193
    223194                        parse( builtins, LinkageSpec::Compiler );
    224195
    225                         // read the extra prelude in, if not generating the cfa library
    226                         FILE * extras = fopen( libcfap | treep ? "extras.cf" : CFA_LIBDIR "/extras.cf", "r" );
    227                         if ( extras == NULL ) {
    228                                 std::cerr << "Error: can't open extras.cf" << std::endl;
    229                                 exit( EXIT_FAILURE );
     196                        if ( ! libcfap ) {
     197                                // read the prelude in, if we're not generating the cfa library
     198                                FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" );
     199                                if ( prelude == NULL ) {
     200                                        std::cerr << "Error: can't open prelude" << std::endl;
     201                                        exit( 1 );
     202                                } // if
     203                   
     204                    parse( prelude, LinkageSpec::Intrinsic );
    230205                        } // if
    231                         parse( extras, LinkageSpec::C );
    232 
    233                         if ( ! libcfap ) {
    234                                 // read the prelude in, if not generating the cfa library
    235                                 FILE * prelude = fopen( treep ? "prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" );
    236                                 if ( prelude == NULL ) {
    237                                         std::cerr << "Error: can't open prelude.cf" << std::endl;
    238                                         exit( EXIT_FAILURE );
    239                                 } // if
    240 
    241                                 parse( prelude, LinkageSpec::Intrinsic );
    242                         } // if
    243                 } // if
    244 
    245                 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp );
    246 
     206                } // if
     207
     208                if ( libcfap ) {
     209                        parse( input, LinkageSpec::Intrinsic );
     210                } else {
     211                        parse( input, LinkageSpec::Cforall, grammarp );
     212                }
     213 
    247214                if ( parsep ) {
    248215                        Parser::get_parser().get_parseTree()->printList( std::cout );
     
    259226                } // if
    260227
    261                 // add the assignment statement after the initialization of a type parameter
     228                // add the assignment statement after the
     229                // initialization of a type parameter
    262230                OPTPRINT( "validate" )
    263231                SymTab::validate( translationUnit, symtabp );
     
    279247                OPTPRINT( "mutate" )
    280248                ControlStruct::mutate( translationUnit );
    281                 OPTPRINT( "fixNames" )
     249                OPTPRINT( "fixNames" ) 
    282250                CodeGen::fixNames( translationUnit );
    283                 OPTPRINT( "tweakInit" )
    284                 InitTweak::genInit( translationUnit );
     251                OPTPRINT( "tweak" )
     252                InitTweak::tweak( translationUnit );
    285253
    286254                if ( libcfap ) {
     
    298266                if ( exprp ) {
    299267                        dump( translationUnit );
    300                         return 0;
    301                 }
    302 
    303                 // fix ObjectDecl - replaces ConstructorInit nodes
    304                 OPTPRINT( "fixInit" )
    305                 InitTweak::fix( translationUnit, filename, libcfap || treep );
    306                 if ( ctorinitp ) {
    307                         dump ( translationUnit );
    308                         return 0;
    309268                }
    310269
     
    312271                GenPoly::copyParams( translationUnit );
    313272                OPTPRINT( "convertSpecializations" )
    314                 GenPoly::convertSpecializations( translationUnit );
     273                GenPoly::convertSpecializations( translationUnit );             
    315274                OPTPRINT( "convertLvalue" )
    316275                GenPoly::convertLvalue( translationUnit );
    317 
    318                 if ( bboxp ) {
    319                         dump( translationUnit );
    320                         return 0;
    321                 }
    322276                OPTPRINT( "box" )
    323277                GenPoly::box( translationUnit );
     
    336290        } catch ( SemanticError &e ) {
    337291                if ( errorp ) {
    338                         std::cerr << "---AST at error:---" << std::endl;
    339                         dump( translationUnit, std::cerr );
    340                         std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl;
     292                        dump( translationUnit );
    341293                }
    342294                e.print( std::cerr );
     
    360312        } // try
    361313
    362         deleteAll( translationUnit );
    363314        return 0;
    364315} // main
     
    378329}
    379330
    380 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {
     331static void dump( std::list< Declaration * > & translationUnit ) {
    381332        std::list< Declaration * > decls;
    382333        if ( noprotop ) {
    383                 filter( translationUnit.begin(), translationUnit.end(),
     334                filter( translationUnit.begin(), translationUnit.end(), 
    384335                                std::back_inserter( decls ), notPrelude );
    385336        } else {
     
    387338        }
    388339
    389         printAll( decls, out );
    390         deleteAll( translationUnit );
     340        printAll( decls, std::cout );
    391341}
    392342
Note: See TracChangeset for help on using the changeset viewer.