Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r09f34a84 rb507dcd  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Sep 15 13:58:00 2022
    13 // Update Count     : 678
     12// Last Modified On : Mon Jul 18 11:08:00 2022
     13// Update Count     : 676
    1414//
    1515
     
    3838#include "CodeGen/Generate.h"               // for generate
    3939#include "CodeGen/LinkOnce.h"               // for translateLinkOnce
     40#include "CodeTools/DeclStats.h"            // for printDeclStats
     41#include "CodeTools/ResolvProtoDump.h"      // for dumpAsResolvProto
    4042#include "CodeTools/TrackLoc.h"             // for fillLocations
    4143#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
     
    4345#include "Common/DeclStats.hpp"             // for printDeclStats
    4446#include "Common/ResolvProtoDump.hpp"       // for dumpAsResolverProto
    45 #include "Common/Stats.h"                   // for Stats
     47#include "Common/Stats.h"
     48#include "Common/PassVisitor.h"
     49#include "Common/SemanticError.h"           // for SemanticError
    4650#include "Common/UnimplementedError.h"      // for UnimplementedError
    4751#include "Common/utility.h"                 // for deleteAll, filter, printAll
     
    4953#include "Concurrency/Waitfor.h"            // for generateWaitfor
    5054#include "ControlStruct/ExceptDecl.h"       // for translateExcept
    51 #include "ControlStruct/ExceptTranslate.h"  // for translateThrows, translat...
     55#include "ControlStruct/ExceptTranslate.h"  // for translateEHM
    5256#include "ControlStruct/FixLabels.hpp"      // for fixLabels
    5357#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
     58#include "ControlStruct/Mutate.h"           // for mutate
    5459#include "GenPoly/Box.h"                    // for box
    5560#include "GenPoly/InstantiateGeneric.h"     // for instantiateGeneric
     
    6166#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    6267#include "Parser/TypedefTable.h"            // for TypedefTable
     68#include "ResolvExpr/AlternativePrinter.h"  // for AlternativePrinter
    6369#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
    6470#include "ResolvExpr/Resolver.h"            // for resolve
     71#include "SymTab/Validate.h"                // for validate
     72#include "SymTab/ValidateType.h"            // for linkReferenceToTypes
    6573#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    6674#include "SynTree/Declaration.h"            // for Declaration
     75#include "SynTree/Visitor.h"                // for acceptAll
    6776#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    6877#include "Validate/Autogen.hpp"             // for autogenerateRoutines
     
    321330                Stats::Time::StopBlock();
    322331
    323                 if (Stats::Counters::enabled) {
    324                         ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New");
    325                         ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New");
     332                if( useNewAST ) {
     333                        if (Stats::Counters::enabled) {
     334                                ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New");
     335                                ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New");
     336                        }
     337                        auto transUnit = convert( move( translationUnit ) );
     338
     339                        forceFillCodeLocations( transUnit );
     340
     341                        PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) );
     342                        if ( exdeclp ) {
     343                                dump( move( transUnit ) );
     344                                return EXIT_SUCCESS;
     345                        }
     346
     347                        PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) );
     348                        PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) );
     349                        // Hoist Type Decls pulls some declarations out of contexts where
     350                        // locations are not tracked. Perhaps they should be, but for now
     351                        // the full fill solves it.
     352                        forceFillCodeLocations( transUnit );
     353
     354                        PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) );
     355                        PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) );
     356                        PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) );
     357
     358                        PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) );
     359
     360                        PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) );
     361                        PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) );
     362                        PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) );
     363                        PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) );
     364                        PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) );
     365                        PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) );
     366                        PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) );
     367                        PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) );
     368                        PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) );
     369                        PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) );
     370
     371                        PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) );
     372
     373                        PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) );
     374                        PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) );
     375                        PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) );
     376                        PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) );
     377                        PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) );
     378                        PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) );
     379
     380                        if ( symtabp ) {
     381                                return EXIT_SUCCESS;
     382                        } // if
     383
     384                        if ( expraltp ) {
     385                                ResolvExpr::printCandidates( transUnit );
     386                                return EXIT_SUCCESS;
     387                        } // if
     388
     389                        if ( validp ) {
     390                                dump( move( transUnit ) );
     391                                return EXIT_SUCCESS;
     392                        } // if
     393
     394                        PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) );
     395                        PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) );
     396                        PASS( "Fix Names", CodeGen::fixNames( transUnit ) );
     397                        PASS( "Gen Init", InitTweak::genInit( transUnit ) );
     398                        PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) );
     399
     400                        if ( libcfap ) {
     401                                // Generate the bodies of cfa library functions.
     402                                LibCfa::makeLibCfa( transUnit );
     403                        } // if
     404
     405                        if ( declstatsp ) {
     406                                printDeclStats( transUnit );
     407                                return EXIT_SUCCESS;
     408                        } // if
     409
     410                        if ( bresolvep ) {
     411                                dump( move( transUnit ) );
     412                                return EXIT_SUCCESS;
     413                        } // if
     414
     415                        if ( resolvprotop ) {
     416                                dumpAsResolverProto( transUnit );
     417                                return EXIT_SUCCESS;
     418                        } // if
     419
     420                        PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
     421                        if ( exprp ) {
     422                                dump( move( transUnit ) );
     423                                return EXIT_SUCCESS;
     424                        } // if
     425
     426                        forceFillCodeLocations( transUnit );
     427
     428                        PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary()));
     429
     430                        // fix ObjectDecl - replaces ConstructorInit nodes
     431                        if ( ctorinitp ) {
     432                                dump( move( transUnit ) );
     433                                return EXIT_SUCCESS;
     434                        } // if
     435
     436                        // Currently not working due to unresolved issues with UniqueExpr
     437                        PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // 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
     438
     439                        PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
     440                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
     441
     442                        // Needs to happen before tuple types are expanded.
     443                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) );
     444
     445                        PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) );
     446
     447                        translationUnit = convert( move( transUnit ) );
     448                } else {
     449                        PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) );
     450                        if ( exdeclp ) {
     451                                dump( translationUnit );
     452                                return EXIT_SUCCESS;
     453                        } // if
     454
     455                        // add the assignment statement after the initialization of a type parameter
     456                        PASS( "Validate", SymTab::validate( translationUnit ) );
     457
     458                        if ( symtabp ) {
     459                                deleteAll( translationUnit );
     460                                return EXIT_SUCCESS;
     461                        } // if
     462
     463                        if ( expraltp ) {
     464                                PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
     465                                acceptAll( translationUnit, printer );
     466                                return EXIT_SUCCESS;
     467                        } // if
     468
     469                        if ( validp ) {
     470                                dump( translationUnit );
     471                                return EXIT_SUCCESS;
     472                        } // if
     473
     474                        PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
     475                        PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
     476                        PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
     477                        PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
     478                        PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
     479
     480                        if ( libcfap ) {
     481                                // Generate the bodies of cfa library functions.
     482                                LibCfa::makeLibCfa( translationUnit );
     483                        } // if
     484
     485                        if ( declstatsp ) {
     486                                CodeTools::printDeclStats( translationUnit );
     487                                deleteAll( translationUnit );
     488                                return EXIT_SUCCESS;
     489                        } // if
     490
     491                        if ( bresolvep ) {
     492                                dump( translationUnit );
     493                                return EXIT_SUCCESS;
     494                        } // if
     495
     496                        CodeTools::fillLocations( translationUnit );
     497
     498                        if ( resolvprotop ) {
     499                                CodeTools::dumpAsResolvProto( translationUnit );
     500                                return EXIT_SUCCESS;
     501                        } // if
     502
     503                        PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
     504                        if ( exprp ) {
     505                                dump( translationUnit );
     506                                return EXIT_SUCCESS;
     507                        }
     508
     509                        PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
     510
     511                        // fix ObjectDecl - replaces ConstructorInit nodes
     512                        if ( ctorinitp ) {
     513                                dump ( translationUnit );
     514                                return EXIT_SUCCESS;
     515                        } // if
     516
     517                        PASS( "Expand Unique Expr", 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
     518                        PASS( "Translate Tries", ControlStruct::translateTries( translationUnit ) );
     519                        PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) );
     520                        PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     521                        PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
    326522                }
    327                 auto transUnit = convert( std::move( translationUnit ) );
    328 
    329                 forceFillCodeLocations( transUnit );
    330 
    331                 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) );
    332                 if ( exdeclp ) {
    333                         dump( std::move( transUnit ) );
     523
     524                if ( tuplep ) {
     525                        dump( translationUnit );
    334526                        return EXIT_SUCCESS;
    335                 }
    336 
    337                 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) );
    338                 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) );
    339                 // Hoist Type Decls pulls some declarations out of contexts where
    340                 // locations are not tracked. Perhaps they should be, but for now
    341                 // the full fill solves it.
    342                 forceFillCodeLocations( transUnit );
    343 
    344                 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) );
    345                 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) );
    346                 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) );
    347 
    348                 PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) );
    349 
    350                 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) );
    351                 PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) );
    352                 PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) );
    353                 PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) );
    354                 PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) );
    355                 PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) );
    356                 PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) );
    357                 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) );
    358                 PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) );
    359                 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) );
    360 
    361                 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) );
    362 
    363                 PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) );
    364                 PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) );
    365                 PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) );
    366                 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) );
    367                 PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) );
    368                 PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) );
    369 
    370                 if ( symtabp ) {
    371                         return EXIT_SUCCESS;
    372                 } // if
    373 
    374                 if ( expraltp ) {
    375                         ResolvExpr::printCandidates( transUnit );
    376                         return EXIT_SUCCESS;
    377                 } // if
    378 
    379                 if ( validp ) {
    380                         dump( std::move( transUnit ) );
    381                         return EXIT_SUCCESS;
    382                 } // if
    383 
    384                 PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) );
    385                 PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) );
    386                 PASS( "Fix Names", CodeGen::fixNames( transUnit ) );
    387                 PASS( "Gen Init", InitTweak::genInit( transUnit ) );
    388                 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) );
    389 
    390                 if ( libcfap ) {
    391                         // Generate the bodies of cfa library functions.
    392                         LibCfa::makeLibCfa( transUnit );
    393                 } // if
    394 
    395                 if ( declstatsp ) {
    396                         printDeclStats( transUnit );
    397                         return EXIT_SUCCESS;
    398                 } // if
    399 
    400                 if ( bresolvep ) {
    401                         dump( std::move( transUnit ) );
    402                         return EXIT_SUCCESS;
    403                 } // if
    404 
    405                 if ( resolvprotop ) {
    406                         dumpAsResolverProto( transUnit );
    407                         return EXIT_SUCCESS;
    408                 } // if
    409 
    410                 PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
    411                 if ( exprp ) {
    412                         dump( std::move( transUnit ) );
    413                         return EXIT_SUCCESS;
    414                 } // if
    415 
    416                 forceFillCodeLocations( transUnit );
    417 
    418                 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary()));
    419 
    420                 // fix ObjectDecl - replaces ConstructorInit nodes
    421                 if ( ctorinitp ) {
    422                         dump( std::move( transUnit ) );
    423                         return EXIT_SUCCESS;
    424                 } // if
    425 
    426                 // Currently not working due to unresolved issues with UniqueExpr
    427                 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // 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
    428 
    429                 PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
    430                 PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
    431 
    432                 // Needs to happen before tuple types are expanded.
    433                 PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) );
    434 
    435                 PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) );
    436 
    437                 if ( tuplep ) {
    438                         dump( std::move( transUnit ) );
    439                         return EXIT_SUCCESS;
    440                 } // if
    441 
    442                 // Must come after Translate Tries.
    443                 PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) );
    444 
    445                 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( transUnit ) );
    446 
    447                 translationUnit = convert( std::move( transUnit ) );
    448 
     527                } // if
     528
     529                PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     530
     531                PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
    449532                if ( genericsp ) {
    450533                        dump( translationUnit );
     
    529612
    530613
    531 static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:";
     614static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:";
    532615
    533616enum { PreludeDir = 128 };
     
    543626        { "prototypes", no_argument, nullptr, 'p' },
    544627        { "deterministic-out", no_argument, nullptr, 'd' },
     628        { "old-ast", no_argument, nullptr, 'O'},
     629        { "new-ast", no_argument, nullptr, 'A'},
    545630        { "print", required_argument, nullptr, 'P' },
    546631        { "prelude-dir", required_argument, nullptr, PreludeDir },
     
    564649        "do not generate prelude prototypes => prelude not printed", // -p
    565650        "only print deterministic output",                  // -d
     651        "Use the old-ast",                                                                      // -O
     652        "Use the new-ast",                                                                      // -A
    566653        "print",                                                                                        // -P
    567654        "<directory> prelude directory for debug/nodebug",      // no flag
     
    672759                        deterministic_output = true;
    673760                        break;
     761                  case 'O':                                     // don't print non-deterministic output
     762                        useNewAST = false;
     763                        break;
     764                  case 'A':                                     // don't print non-deterministic output
     765                        useNewAST = true;
     766                        break;
    674767                  case 'P':                                                                             // print options
    675768                        for ( int i = 0;; i += 1 ) {
     
    788881
    789882static void dump( ast::TranslationUnit && transUnit, ostream & out ) {
    790         std::list< Declaration * > translationUnit = convert( std::move( transUnit ) );
     883        std::list< Declaration * > translationUnit = convert( move( transUnit ) );
    791884        dump( translationUnit, out );
    792885}
Note: See TracChangeset for help on using the changeset viewer.