Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rbd06384 r4990812  
    1 
    21//
    32// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     
    1110// Created On       : Fri May 15 23:12:02 2015
    1211// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Tue Oct 31 12:22:40 2017
    14 // Update Count     : 445
     12// Last Modified On : Mon May  7 14:35:57 2018
     13// Update Count     : 492
    1514//
    1615
     
    3534#include "CodeTools/DeclStats.h"            // for printDeclStats
    3635#include "CodeTools/TrackLoc.h"             // for fillLocations
     36#include "Common/CompilerError.h"           // for CompilerError
     37#include "Common/Heap.h"
    3738#include "Common/PassVisitor.h"
    38 #include "Common/CompilerError.h"           // for CompilerError
    39 #include "Common/GC.h"                                          // for GC
    4039#include "Common/SemanticError.h"           // for SemanticError
    4140#include "Common/UnimplementedError.h"      // for UnimplementedError
     
    5857#include "SymTab/Validate.h"                // for validate
    5958#include "SynTree/Declaration.h"            // for Declaration
    60 #include "SynTree/GcTracer.h"               // for GC << TranslationUnit
    6159#include "SynTree/Visitor.h"                // for acceptAll
    6260#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
     
    6563using namespace std;
    6664
    67 #define OPTPRINT(x) if ( errorp ) cerr << x << endl;
     65#define PASS(name, pass)                   \
     66        if ( errorp ) { cerr << name << endl; } \
     67        HeapStats::newPass(name);               \
     68        pass;
    6869
    6970LinkageSpec::Spec linkage = LinkageSpec::Cforall;
     
    176177        signal( SIGABRT, sigAbortHandler );
    177178
     179        // std::cout << "main" << std::endl;
     180        // for ( int i = 0; i < argc; i += 1 ) {
     181        //      std::cout << '\t' << argv[i] << std::endl;
     182        // } // for
     183
    178184        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    179185        CodeGen::FixMain::setReplaceMain( !nomainp );
     
    234240                delete parseTree;
    235241                parseTree = nullptr;
    236                 collect( translationUnit );
    237242
    238243                if ( astp ) {
     
    242247
    243248                // add the assignment statement after the initialization of a type parameter
    244                 OPTPRINT( "validate" )
    245                 SymTab::validate( translationUnit, symtabp );
    246                 if ( symtabp ) return 0;
    247                 collect( translationUnit );
     249                PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
     250                if ( symtabp ) {
     251                        deleteAll( translationUnit );
     252                        return 0;
     253                } // if
    248254
    249255                if ( expraltp ) {
     
    258264                } // if
    259265
    260                 OPTPRINT( "mutate" )
    261                 ControlStruct::mutate( translationUnit );
    262                 OPTPRINT( "fixNames" )
    263                 CodeGen::fixNames( translationUnit );
    264                 OPTPRINT( "genInit" )
    265                 InitTweak::genInit( translationUnit );
    266                 OPTPRINT( "expandMemberTuples" );
    267                 Tuples::expandMemberTuples( translationUnit );
    268                 collect( translationUnit );
     266                PASS( "mutate", ControlStruct::mutate( translationUnit ) );
     267                PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
     268                PASS( "genInit", InitTweak::genInit( translationUnit ) );
     269                PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
    269270                if ( libcfap ) {
    270271                        // generate the bodies of cfa library functions
     
    274275                if ( declstatsp ) {
    275276                        CodeTools::printDeclStats( translationUnit );
     277                        deleteAll( translationUnit );
    276278                        return 0;
    277279                }
     
    284286                CodeTools::fillLocations( translationUnit );
    285287
    286                 OPTPRINT( "resolve" )
    287                 ResolvExpr::resolve( translationUnit );
    288                 collect( translationUnit );
     288                PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
    289289                if ( exprp ) {
    290290                        dump( translationUnit );
     
    293293
    294294                // fix ObjectDecl - replaces ConstructorInit nodes
    295                 OPTPRINT( "fixInit" )
    296                 InitTweak::fix( translationUnit, filename, libcfap || treep );
    297                 collect( translationUnit );
     295                PASS( "fixInit", InitTweak::fix( translationUnit, filename, libcfap || treep ) );
    298296                if ( ctorinitp ) {
    299297                        dump ( translationUnit );
     
    301299                } // if
    302300
    303                 OPTPRINT( "expandUniqueExpr" ); // xxx - is this the right place for this? want to expand ASAP so that subsequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
     301                PASS( "expandUniqueExpr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
    304302                Tuples::expandUniqueExpr( translationUnit );
    305303
    306                 OPTPRINT( "translateEHM" );
    307                 ControlStruct::translateEHM( translationUnit );
    308 
    309                 OPTPRINT( "generateWaitfor" );
    310                 Concurrency::generateWaitFor( translationUnit );
    311 
    312                 OPTPRINT( "convertSpecializations" ) // needs to happen before tuple types are expanded
    313                 GenPoly::convertSpecializations( translationUnit );
    314 
    315                 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this?
    316                 Tuples::expandTuples( translationUnit );
    317                 collect( translationUnit );
     304                PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) );
     305
     306                PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );
     307
     308                PASS( "convertSpecializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     309
     310                PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     311
    318312                if ( tuplep ) {
    319313                        dump( translationUnit );
     
    321315                }
    322316
    323                 OPTPRINT( "virtual expandCasts" ) // Must come after translateEHM
    324                 Virtual::expandCasts( translationUnit );
    325 
    326                 OPTPRINT("instantiateGenerics")
    327                 GenPoly::instantiateGeneric( translationUnit );
    328                 collect( translationUnit );
     317                PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     318
     319                PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
    329320                if ( genericsp ) {
    330321                        dump( translationUnit );
    331322                        return 0;
    332323                }
    333 
    334                 OPTPRINT( "convertLvalue" )
    335                 GenPoly::convertLvalue( translationUnit );
    336                 collect( translationUnit );
     324                PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
     325
     326
    337327                if ( bboxp ) {
    338328                        dump( translationUnit );
    339329                        return 0;
    340330                } // if
    341 
    342                 OPTPRINT( "box" )
    343                 GenPoly::box( translationUnit );
    344                 collect( translationUnit );
     331                PASS( "box", GenPoly::box( translationUnit ) );
     332
    345333                if ( bcodegenp ) {
    346334                        dump( translationUnit );
     
    353341
    354342                CodeTools::fillLocations( translationUnit );
    355                 OPTPRINT( "codegen" )
    356                 CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks );
     343                PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
    357344
    358345                CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
    359                 OPTPRINT( "end" )
    360 
    361346                if ( output != &cout ) {
    362347                        delete output;
     
    386371                } // if
    387372                return 1;
    388         } // try
    389 
     373        } catch(...) {
     374                std::exception_ptr eptr = std::current_exception();
     375                try {
     376                        if (eptr) {
     377                                std::rethrow_exception(eptr);
     378                        }
     379                        else {
     380                                std::cerr << "Exception Uncaught and Unkown" << std::endl;
     381                        }
     382                } catch(const std::exception& e) {
     383                        std::cerr << "Unaught Exception \"" << e.what() << "\"\n";
     384                }
     385                return 1;
     386        }// try
     387
     388        deleteAll( translationUnit );
     389        if(!libcfap && !treep) HeapStats::printStats();
    390390        return 0;
    391391} // main
     
    420420        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    421421
     422        bool Wsuppress = false, Werror = false;
    422423        int c;
    423         while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {
     424        while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
    424425                switch ( c ) {
    425426                  case Ast:
     
    457458                        yydebug = true;
    458459                        break;
    459                   case 'G':                   // dump AST after instantiate generics
     460                  case 'G':                                                                             // dump AST after instantiate generics
    460461                        genericsp = true;
    461462                        break;
     
    505506                  case 'v':                                                                             // dump AST after decl validation pass
    506507                        validp = true;
     508                        break;
     509                  case 'w':
     510                        Wsuppress = true;
     511                        break;
     512                  case 'W':
     513                        if ( strcmp( optarg, "all" ) == 0 ) {
     514                                SemanticWarning_EnableAll();
     515                        } else if ( strcmp( optarg, "error" ) == 0 ) {
     516                                Werror = true;
     517                        } else {
     518                                char * warning = optarg;
     519                                Severity s;
     520                                if ( strncmp( optarg, "no-", 3 ) == 0 ) {
     521                                        warning += 3;
     522                                        s = Severity::Suppress;
     523                                } else {
     524                                        s = Severity::Warn;
     525                                } // if
     526                                SemanticWarning_Set( warning, s );
     527                        } // if
    507528                        break;
    508529                  case 'y':                                                                             // dump AST on error
     
    526547                                assertf( false, "Unknown option: %s\n", argv[optind - 1] );
    527548                        } // if
    528                         #if __GNUC__ < 7
    529                         #else
     549                        #if defined(__GNUC__) && __GNUC__ >= 7
    530550                                __attribute__((fallthrough));
    531551                        #endif
     
    534554                } // switch
    535555        } // while
     556
     557        if ( Werror ) {
     558                SemanticWarning_WarningAsError();
     559        } // if
     560        if ( Wsuppress ) {
     561                SemanticWarning_SuppressAll();
     562        } // if
     563        // for ( const auto w : WarningFormats ) {
     564        //      cout << w.name << ' ' << (int)w.severity << endl;
     565        // } // for
    536566} // parse_cmdline
    537567
     
    572602                printAll( decls, out );
    573603        }
     604        deleteAll( translationUnit );
    574605} // dump
    575606
Note: See TracChangeset for help on using the changeset viewer.