Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r4990812 rbd06384  
     1
    12//
    23// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     
    1011// Created On       : Fri May 15 23:12:02 2015
    1112// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon May  7 14:35:57 2018
    13 // Update Count     : 492
     13// Last Modified On : Tue Oct 31 12:22:40 2017
     14// Update Count     : 445
    1415//
    1516
     
    3435#include "CodeTools/DeclStats.h"            // for printDeclStats
    3536#include "CodeTools/TrackLoc.h"             // for fillLocations
     37#include "Common/PassVisitor.h"
    3638#include "Common/CompilerError.h"           // for CompilerError
    37 #include "Common/Heap.h"
    38 #include "Common/PassVisitor.h"
     39#include "Common/GC.h"                                          // for GC
    3940#include "Common/SemanticError.h"           // for SemanticError
    4041#include "Common/UnimplementedError.h"      // for UnimplementedError
     
    5758#include "SymTab/Validate.h"                // for validate
    5859#include "SynTree/Declaration.h"            // for Declaration
     60#include "SynTree/GcTracer.h"               // for GC << TranslationUnit
    5961#include "SynTree/Visitor.h"                // for acceptAll
    6062#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
     
    6365using namespace std;
    6466
    65 #define PASS(name, pass)                   \
    66         if ( errorp ) { cerr << name << endl; } \
    67         HeapStats::newPass(name);               \
    68         pass;
     67#define OPTPRINT(x) if ( errorp ) cerr << x << endl;
    6968
    7069LinkageSpec::Spec linkage = LinkageSpec::Cforall;
     
    177176        signal( SIGABRT, sigAbortHandler );
    178177
    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 
    184178        parse_cmdline( argc, argv, filename );                          // process command-line arguments
    185179        CodeGen::FixMain::setReplaceMain( !nomainp );
     
    240234                delete parseTree;
    241235                parseTree = nullptr;
     236                collect( translationUnit );
    242237
    243238                if ( astp ) {
     
    247242
    248243                // add the assignment statement after the initialization of a type parameter
    249                 PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
    250                 if ( symtabp ) {
    251                         deleteAll( translationUnit );
    252                         return 0;
    253                 } // if
     244                OPTPRINT( "validate" )
     245                SymTab::validate( translationUnit, symtabp );
     246                if ( symtabp ) return 0;
     247                collect( translationUnit );
    254248
    255249                if ( expraltp ) {
     
    264258                } // if
    265259
    266                 PASS( "mutate", ControlStruct::mutate( translationUnit ) );
    267                 PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
    268                 PASS( "genInit", InitTweak::genInit( translationUnit ) );
    269                 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
     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 );
    270269                if ( libcfap ) {
    271270                        // generate the bodies of cfa library functions
     
    275274                if ( declstatsp ) {
    276275                        CodeTools::printDeclStats( translationUnit );
    277                         deleteAll( translationUnit );
    278276                        return 0;
    279277                }
     
    286284                CodeTools::fillLocations( translationUnit );
    287285
    288                 PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
     286                OPTPRINT( "resolve" )
     287                ResolvExpr::resolve( translationUnit );
     288                collect( translationUnit );
    289289                if ( exprp ) {
    290290                        dump( translationUnit );
     
    293293
    294294                // fix ObjectDecl - replaces ConstructorInit nodes
    295                 PASS( "fixInit", InitTweak::fix( translationUnit, filename, libcfap || treep ) );
     295                OPTPRINT( "fixInit" )
     296                InitTweak::fix( translationUnit, filename, libcfap || treep );
     297                collect( translationUnit );
    296298                if ( ctorinitp ) {
    297299                        dump ( translationUnit );
     
    299301                } // if
    300302
    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
     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
    302304                Tuples::expandUniqueExpr( translationUnit );
    303305
    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 
     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 );
    312318                if ( tuplep ) {
    313319                        dump( translationUnit );
     
    315321                }
    316322
    317                 PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
    318 
    319                 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
     323                OPTPRINT( "virtual expandCasts" ) // Must come after translateEHM
     324                Virtual::expandCasts( translationUnit );
     325
     326                OPTPRINT("instantiateGenerics")
     327                GenPoly::instantiateGeneric( translationUnit );
     328                collect( translationUnit );
    320329                if ( genericsp ) {
    321330                        dump( translationUnit );
    322331                        return 0;
    323332                }
    324                 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
    325 
    326 
     333
     334                OPTPRINT( "convertLvalue" )
     335                GenPoly::convertLvalue( translationUnit );
     336                collect( translationUnit );
    327337                if ( bboxp ) {
    328338                        dump( translationUnit );
    329339                        return 0;
    330340                } // if
    331                 PASS( "box", GenPoly::box( translationUnit ) );
    332 
     341
     342                OPTPRINT( "box" )
     343                GenPoly::box( translationUnit );
     344                collect( translationUnit );
    333345                if ( bcodegenp ) {
    334346                        dump( translationUnit );
     
    341353
    342354                CodeTools::fillLocations( translationUnit );
    343                 PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
     355                OPTPRINT( "codegen" )
     356                CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks );
    344357
    345358                CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
     359                OPTPRINT( "end" )
     360
    346361                if ( output != &cout ) {
    347362                        delete output;
     
    371386                } // if
    372387                return 1;
    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();
     388        } // try
     389
    390390        return 0;
    391391} // main
     
    420420        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    421421
    422         bool Wsuppress = false, Werror = false;
    423422        int c;
    424         while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
     423        while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {
    425424                switch ( c ) {
    426425                  case Ast:
     
    458457                        yydebug = true;
    459458                        break;
    460                   case 'G':                                                                             // dump AST after instantiate generics
     459                  case 'G':                   // dump AST after instantiate generics
    461460                        genericsp = true;
    462461                        break;
     
    506505                  case 'v':                                                                             // dump AST after decl validation pass
    507506                        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
    528507                        break;
    529508                  case 'y':                                                                             // dump AST on error
     
    547526                                assertf( false, "Unknown option: %s\n", argv[optind - 1] );
    548527                        } // if
    549                         #if defined(__GNUC__) && __GNUC__ >= 7
     528                        #if __GNUC__ < 7
     529                        #else
    550530                                __attribute__((fallthrough));
    551531                        #endif
     
    554534                } // switch
    555535        } // 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
    566536} // parse_cmdline
    567537
     
    602572                printAll( decls, out );
    603573        }
    604         deleteAll( translationUnit );
    605574} // dump
    606575
Note: See TracChangeset for help on using the changeset viewer.