Changeset 90152a4 for src/main.cc


Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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 cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rf9feab8 r90152a4  
    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 : Wed Jun  6 15:51:47 2018
     13// Update Count     : 498
    1514//
    1615
     
    2928#include <string>                           // for char_traits, operator<<
    3029
     30#include "CompilationState.h"
    3131#include "../config.h"                      // for CFA_LIBDIR
    3232#include "CodeGen/FixMain.h"                // for FixMain
     
    3535#include "CodeTools/DeclStats.h"            // for printDeclStats
    3636#include "CodeTools/TrackLoc.h"             // for fillLocations
     37#include "Common/CompilerError.h"           // for CompilerError
     38#include "Common/Heap.h"
    3739#include "Common/PassVisitor.h"
    38 #include "Common/CompilerError.h"           // for CompilerError
    3940#include "Common/SemanticError.h"           // for SemanticError
    4041#include "Common/UnimplementedError.h"      // for UnimplementedError
     
    6364using namespace std;
    6465
    65 #define OPTPRINT(x) if ( errorp ) cerr << x << endl;
    66 
     66#define PASS(name, pass)                   \
     67        if ( errorp ) { cerr << name << endl; } \
     68        HeapStats::newPass(name);               \
     69        pass;
    6770
    6871LinkageSpec::Spec linkage = LinkageSpec::Cforall;
     
    7073DeclarationNode * parseTree = nullptr;                                  // program parse tree
    7174
    72 extern int yydebug;                                                                             // set for -g flag (Grammar)
    73 bool
    74         astp = false,
    75         bresolvep = false,
    76         bboxp = false,
    77         bcodegenp = false,
    78         ctorinitp = false,
    79         declstatsp = false,
    80         exprp = false,
    81         expraltp = false,
    82         libcfap = false,
    83         nopreludep = false,
    84         noprotop = false,
    85         nomainp = false,
    86         parsep = false,
    87         resolvep = false,                                                                       // used in AlternativeFinder
    88         symtabp = false,
    89         treep = false,
    90         tuplep = false,
    91         validp = false,
    92         errorp = false,
    93         codegenp = false,
    94         prettycodegenp = false,
    95         linemarks = false;
     75std::string PreludeDirector = "";
    9676
    9777static void parse_cmdline( int argc, char *argv[], const char *& filename );
     
    154134                 << "." << endl;
    155135        backtrace( 2 );                                                                         // skip first 2 stack frames
    156         exit( EXIT_FAILURE );
     136        //_exit( EXIT_FAILURE );
     137        abort();
    157138} // sigSegvBusHandler
    158139
     
    173154        signal( SIGBUS, sigSegvBusHandler );
    174155        signal( SIGABRT, sigAbortHandler );
     156
     157        // std::cout << "main" << std::endl;
     158        // for ( int i = 0; i < argc; i += 1 ) {
     159        //      std::cout << '\t' << argv[i] << std::endl;
     160        // } // for
    175161
    176162        parse_cmdline( argc, argv, filename );                          // process command-line arguments
     
    198184                        // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
    199185
     186                        assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." );
     187
    200188                        // Read to gcc builtins, if not generating the cfa library
    201                         FILE * gcc_builtins = fopen( libcfap | treep ? "../prelude/gcc-builtins.cf" : CFA_LIBDIR "/gcc-builtins.cf", "r" );
     189                        FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" );
    202190                        assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
    203191                        parse( gcc_builtins, LinkageSpec::Compiler );
    204192
    205193                        // read the extra prelude in, if not generating the cfa library
    206                         FILE * extras = fopen( libcfap | treep ? "../prelude/extras.cf" : CFA_LIBDIR "/extras.cf", "r" );
     194                        FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" );
    207195                        assertf( extras, "cannot open extras.cf\n" );
    208196                        parse( extras, LinkageSpec::BuiltinC );
     
    210198                        if ( ! libcfap ) {
    211199                                // read the prelude in, if not generating the cfa library
    212                                 FILE * prelude = fopen( treep ? "../prelude/prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" );
     200                                FILE * prelude = fopen( (PreludeDirector + "/prelude.cf").c_str(), "r" );
    213201                                assertf( prelude, "cannot open prelude.cf\n" );
    214202                                parse( prelude, LinkageSpec::Intrinsic );
    215203
    216204                                // Read to cfa builtins, if not generating the cfa library
    217                                 FILE * builtins = fopen( libcfap | treep ? "../prelude/builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
     205                                FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" );
    218206                                assertf( builtins, "cannot open builtins.cf\n" );
    219207                                parse( builtins, LinkageSpec::BuiltinCFA );
     
    238226                } // if
    239227
     228                // Temporary: fill locations after parsing so that every node has a location, for early error messages.
     229                // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution
     230                // works okay for now.
     231                CodeTools::fillLocations( translationUnit );
     232
    240233                // add the assignment statement after the initialization of a type parameter
    241                 OPTPRINT( "validate" )
    242                 SymTab::validate( translationUnit, symtabp );
     234                PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
    243235                if ( symtabp ) {
    244236                        deleteAll( translationUnit );
     
    257249                } // if
    258250
    259                 OPTPRINT( "mutate" )
    260                 ControlStruct::mutate( translationUnit );
    261                 OPTPRINT( "fixNames" )
    262                 CodeGen::fixNames( translationUnit );
    263                 OPTPRINT( "genInit" )
    264                 InitTweak::genInit( translationUnit );
    265                 OPTPRINT( "expandMemberTuples" );
    266                 Tuples::expandMemberTuples( translationUnit );
     251                PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) );
     252                PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
     253                PASS( "genInit", InitTweak::genInit( translationUnit ) );
     254                PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
    267255                if ( libcfap ) {
    268256                        // generate the bodies of cfa library functions
     
    281269                } // if
    282270
    283                 OPTPRINT( "resolve" )
    284                 ResolvExpr::resolve( translationUnit );
     271                CodeTools::fillLocations( translationUnit );
     272
     273                PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
    285274                if ( exprp ) {
    286275                        dump( translationUnit );
     
    289278
    290279                // fix ObjectDecl - replaces ConstructorInit nodes
    291                 OPTPRINT( "fixInit" )
    292                 InitTweak::fix( translationUnit, filename, libcfap || treep );
     280                PASS( "fixInit", InitTweak::fix( translationUnit, buildingLibrary() ) );
    293281                if ( ctorinitp ) {
    294282                        dump ( translationUnit );
     
    296284                } // if
    297285
    298                 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
    299                 Tuples::expandUniqueExpr( translationUnit );
    300 
    301                 OPTPRINT( "translateEHM" );
    302                 ControlStruct::translateEHM( translationUnit );
    303 
    304                 OPTPRINT( "generateWaitfor" );
    305                 Concurrency::generateWaitFor( translationUnit );
    306 
    307                 OPTPRINT( "convertSpecializations" ) // needs to happen before tuple types are expanded
    308                 GenPoly::convertSpecializations( translationUnit );
    309 
    310                 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this?
    311                 Tuples::expandTuples( translationUnit );
     286                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
     287
     288                PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) );
     289
     290                PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );
     291
     292                PASS( "convertSpecializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     293
     294                PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     295
    312296                if ( tuplep ) {
    313297                        dump( translationUnit );
     
    315299                }
    316300
    317                 OPTPRINT( "virtual expandCasts" ) // Must come after translateEHM
    318                 Virtual::expandCasts( translationUnit );
    319 
    320                 OPTPRINT("instantiateGenerics")
    321                 GenPoly::instantiateGeneric( translationUnit );
    322                 OPTPRINT( "convertLvalue" )
    323                 GenPoly::convertLvalue( translationUnit );
     301                PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     302
     303                PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
     304                if ( genericsp ) {
     305                        dump( translationUnit );
     306                        return 0;
     307                }
     308                PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
     309
    324310
    325311                if ( bboxp ) {
     
    327313                        return 0;
    328314                } // if
    329                 OPTPRINT( "box" )
    330                 GenPoly::box( translationUnit );
     315                PASS( "box", GenPoly::box( translationUnit ) );
    331316
    332317                if ( bcodegenp ) {
     
    340325
    341326                CodeTools::fillLocations( translationUnit );
    342                 CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks );
    343 
    344                 CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
    345 
     327                PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
     328
     329                CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() );
    346330                if ( output != &cout ) {
    347331                        delete output;
    348332                } // if
    349         } catch ( SemanticError &e ) {
     333        } catch ( SemanticErrorException &e ) {
    350334                if ( errorp ) {
    351335                        cerr << "---AST at error:---" << endl;
     
    353337                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
    354338                } // if
    355                 e.print( cerr );
     339                e.print();
    356340                if ( output != &cout ) {
    357341                        delete output;
     
    371355                } // if
    372356                return 1;
    373         } // try
     357        } catch(...) {
     358                std::exception_ptr eptr = std::current_exception();
     359                try {
     360                        if (eptr) {
     361                                std::rethrow_exception(eptr);
     362                        }
     363                        else {
     364                                std::cerr << "Exception Uncaught and Unkown" << std::endl;
     365                        }
     366                } catch(const std::exception& e) {
     367                        std::cerr << "Unaught Exception \"" << e.what() << "\"\n";
     368                }
     369                return 1;
     370        }// try
    374371
    375372        deleteAll( translationUnit );
     373        if(!libcfap && !treep) HeapStats::printStats();
    376374        return 0;
    377375} // main
    378376
    379377void parse_cmdline( int argc, char * argv[], const char *& filename ) {
    380         enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, };
     378        enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, PreludeDir, Prototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, };
    381379
    382380        static struct option long_opts[] = {
     
    394392                { "no-preamble", no_argument, 0, Nopreamble },
    395393                { "parse", no_argument, 0, Parse },
     394                { "prelude-dir", required_argument, 0, PreludeDir },
    396395                { "no-prototypes", no_argument, 0, Prototypes },
    397396                { "resolver", no_argument, 0, Resolver },
     
    406405        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    407406
     407        bool Wsuppress = false, Werror = false;
    408408        int c;
    409         while ( (c = getopt_long( argc, argv, "abBcCdefglLmnNpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {
     409        while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
    410410                switch ( c ) {
    411411                  case Ast:
     
    443443                        yydebug = true;
    444444                        break;
     445                  case 'G':                                                                             // dump AST after instantiate generics
     446                        genericsp = true;
     447                        break;
    445448                  case LibCFA:
    446449                  case 'l':                                                                             // generate libcfa.c
     
    463466                        noprotop = true;
    464467                        break;
     468                  case PreludeDir:
     469                        PreludeDirector = optarg;
     470                        break;
    465471                  case 'm':                                                                             // don't replace the main
    466472                        nomainp = true;
     
    488494                  case 'v':                                                                             // dump AST after decl validation pass
    489495                        validp = true;
     496                        break;
     497                  case 'w':
     498                        Wsuppress = true;
     499                        break;
     500                  case 'W':
     501                        if ( strcmp( optarg, "all" ) == 0 ) {
     502                                SemanticWarning_EnableAll();
     503                        } else if ( strcmp( optarg, "error" ) == 0 ) {
     504                                Werror = true;
     505                        } else {
     506                                char * warning = optarg;
     507                                Severity s;
     508                                if ( strncmp( optarg, "no-", 3 ) == 0 ) {
     509                                        warning += 3;
     510                                        s = Severity::Suppress;
     511                                } else {
     512                                        s = Severity::Warn;
     513                                } // if
     514                                SemanticWarning_Set( warning, s );
     515                        } // if
    490516                        break;
    491517                  case 'y':                                                                             // dump AST on error
     
    509535                                assertf( false, "Unknown option: %s\n", argv[optind - 1] );
    510536                        } // if
    511                         #if __GNUC__ < 7
    512                         #else
     537                        #if defined(__GNUC__) && __GNUC__ >= 7
    513538                                __attribute__((fallthrough));
    514539                        #endif
     
    517542                } // switch
    518543        } // while
     544
     545        if ( Werror ) {
     546                SemanticWarning_WarningAsError();
     547        } // if
     548        if ( Wsuppress ) {
     549                SemanticWarning_SuppressAll();
     550        } // if
     551        // for ( const auto w : WarningFormats ) {
     552        //      cout << w.name << ' ' << (int)w.severity << endl;
     553        // } // for
    519554} // parse_cmdline
    520555
     
    527562        yyin = input;
    528563        yylineno = 1;
    529         typedefTable.enterScope();
    530564        int parseStatus = yyparse();
    531565
Note: See TracChangeset for help on using the changeset viewer.