Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r9e23b446 r09f34a84  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  7 13:29:00 2022
    13 // Update Count     : 674
     12// Last Modified On : Thu Sep 15 13:58:00 2022
     13// Update Count     : 678
    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
    4240#include "CodeTools/TrackLoc.h"             // for fillLocations
    4341#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
     
    4543#include "Common/DeclStats.hpp"             // for printDeclStats
    4644#include "Common/ResolvProtoDump.hpp"       // for dumpAsResolverProto
    47 #include "Common/Stats.h"
    48 #include "Common/PassVisitor.h"
    49 #include "Common/SemanticError.h"           // for SemanticError
     45#include "Common/Stats.h"                   // for Stats
    5046#include "Common/UnimplementedError.h"      // for UnimplementedError
    5147#include "Common/utility.h"                 // for deleteAll, filter, printAll
     
    5349#include "Concurrency/Waitfor.h"            // for generateWaitfor
    5450#include "ControlStruct/ExceptDecl.h"       // for translateExcept
    55 #include "ControlStruct/ExceptTranslate.h"  // for translateEHM
     51#include "ControlStruct/ExceptTranslate.h"  // for translateThrows, translat...
    5652#include "ControlStruct/FixLabels.hpp"      // for fixLabels
    5753#include "ControlStruct/HoistControlDecls.hpp" //  hoistControlDecls
    58 #include "ControlStruct/Mutate.h"           // for mutate
    5954#include "GenPoly/Box.h"                    // for box
    6055#include "GenPoly/InstantiateGeneric.h"     // for instantiateGeneric
     
    6661#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    6762#include "Parser/TypedefTable.h"            // for TypedefTable
    68 #include "ResolvExpr/AlternativePrinter.h"  // for AlternativePrinter
    6963#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
    7064#include "ResolvExpr/Resolver.h"            // for resolve
    71 #include "SymTab/Validate.h"                // for validate
    72 #include "SymTab/ValidateType.h"            // for linkReferenceToTypes
    7365#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    7466#include "SynTree/Declaration.h"            // for Declaration
    75 #include "SynTree/Visitor.h"                // for acceptAll
    7667#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    7768#include "Validate/Autogen.hpp"             // for autogenerateRoutines
    7869#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
    7970#include "Validate/EliminateTypedef.hpp"    // for eliminateTypedef
     71#include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers
    8072#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
    8173#include "Validate/FixQualifiedTypes.hpp"   // for fixQualifiedTypes
     74#include "Validate/FixReturnTypes.hpp"      // for fixReturnTypes
    8275#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
    8376#include "Validate/GenericParameter.hpp"    // for fillGenericParameters, tr...
    8477#include "Validate/HoistStruct.hpp"         // for hoistStruct
     78#include "Validate/HoistTypeDecls.hpp"      // for hoistTypeDecls
    8579#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
    8680#include "Validate/LabelAddressFixer.hpp"   // for fixLabelAddresses
     81#include "Validate/LinkReferenceToTypes.hpp" // for linkReferenceToTypes
     82#include "Validate/ReplaceTypedef.hpp"      // for replaceTypedef
    8783#include "Validate/ReturnCheck.hpp"         // for checkReturnStatements
     84#include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign
    8885#include "Virtual/ExpandCasts.h"            // for expandCasts
    8986
     
    324321                Stats::Time::StopBlock();
    325322
    326                 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) );
     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");
     326                }
     327                auto transUnit = convert( std::move( translationUnit ) );
     328
     329                forceFillCodeLocations( transUnit );
     330
     331                PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) );
    327332                if ( exdeclp ) {
    328                         dump( translationUnit );
    329                         return EXIT_SUCCESS;
    330                 } // if
    331 
    332                 // add the assignment statement after the initialization of a type parameter
    333                 PASS( "Validate-A", SymTab::validate_A( translationUnit ) );
    334 
    335                 // Must happen before auto-gen, because it uses the sized flag.
    336                 PASS( "Link Reference To Types", SymTab::linkReferenceToTypes( translationUnit ) );
    337 
    338                 CodeTools::fillLocations( translationUnit );
    339 
    340                 if( useNewAST ) {
    341                         CodeTools::fillLocations( translationUnit );
    342 
    343                         if (Stats::Counters::enabled) {
    344                                 ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New");
    345                                 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New");
    346                         }
    347                         auto transUnit = convert( move( translationUnit ) );
    348 
    349                         forceFillCodeLocations( transUnit );
    350 
    351                         // Must happen after Link References To Types,
    352                         // because aggregate members are accessed.
    353                         PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) );
    354 
    355                         PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) );
    356                         PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) );
    357 
    358                         // Check as early as possible. Can't happen before
    359                         // LinkReferenceToType, observed failing when attempted
    360                         // before eliminateTypedef
    361                         PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) );
    362 
    363                         PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) );
    364                         PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) );
    365 
    366                         // Must happen before Autogen.
    367                         PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) );
    368 
    369                         PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) );
    370 
    371                         // Must be after implement concurrent keywords; because uniqueIds
    372                         //   must be set on declaration before resolution.
    373                         // Must happen before autogen routines are added.
    374                         PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) );
    375 
    376                         // Must happen before autogen routines are added.
    377                         PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) );
    378 
    379                         // Must be after enum and pointer decay.
    380                         // Must be before compound literals.
    381                         PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) );
    382 
    383                         PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) );
    384                         PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) );
    385                         PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) );
    386                         PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) );
    387                         PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) );
    388                         PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) );
    389 
    390                         if ( symtabp ) {
    391                                 return EXIT_SUCCESS;
    392                         } // if
    393 
    394                         if ( expraltp ) {
    395                                 ResolvExpr::printCandidates( transUnit );
    396                                 return EXIT_SUCCESS;
    397                         } // if
    398 
    399                         if ( validp ) {
    400                                 dump( move( transUnit ) );
    401                                 return EXIT_SUCCESS;
    402                         } // if
    403 
    404                         PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) );
    405                         PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) );
    406                         PASS( "Fix Names", CodeGen::fixNames( transUnit ) );
    407                         PASS( "Gen Init", InitTweak::genInit( transUnit ) );
    408                         PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) );
    409 
    410                         if ( libcfap ) {
    411                                 // Generate the bodies of cfa library functions.
    412                                 LibCfa::makeLibCfa( transUnit );
    413                         } // if
    414 
    415                         if ( declstatsp ) {
    416                                 printDeclStats( transUnit );
    417                                 return EXIT_SUCCESS;
    418                         } // if
    419 
    420                         if ( bresolvep ) {
    421                                 dump( move( transUnit ) );
    422                                 return EXIT_SUCCESS;
    423                         } // if
    424 
    425                         if ( resolvprotop ) {
    426                                 dumpAsResolverProto( transUnit );
    427                                 return EXIT_SUCCESS;
    428                         } // if
    429 
    430                         PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
    431                         if ( exprp ) {
    432                                 dump( move( transUnit ) );
    433                                 return EXIT_SUCCESS;
    434                         } // if
    435 
    436                         forceFillCodeLocations( transUnit );
    437 
    438                         PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary()));
    439 
    440                         // fix ObjectDecl - replaces ConstructorInit nodes
    441                         if ( ctorinitp ) {
    442                                 dump( move( transUnit ) );
    443                                 return EXIT_SUCCESS;
    444                         } // if
    445 
    446                         // Currently not working due to unresolved issues with UniqueExpr
    447                         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
    448 
    449                         PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
    450                         PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
    451                         PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) ); // needs to happen before tuple types are expanded
    452 
    453 
    454                         translationUnit = convert( move( transUnit ) );
    455                 } else {
    456                         PASS( "Validate-B", SymTab::validate_B( translationUnit ) );
    457                         PASS( "Validate-C", SymTab::validate_C( translationUnit ) );
    458                         PASS( "Validate-D", SymTab::validate_D( translationUnit ) );
    459                         PASS( "Validate-E", SymTab::validate_E( translationUnit ) );
    460                         PASS( "Validate-F", SymTab::validate_F( translationUnit ) );
    461 
    462                         if ( symtabp ) {
    463                                 deleteAll( translationUnit );
    464                                 return EXIT_SUCCESS;
    465                         } // if
    466 
    467                         if ( expraltp ) {
    468                                 PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
    469                                 acceptAll( translationUnit, printer );
    470                                 return EXIT_SUCCESS;
    471                         } // if
    472 
    473                         if ( validp ) {
    474                                 dump( translationUnit );
    475                                 return EXIT_SUCCESS;
    476                         } // if
    477 
    478                         PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
    479                         PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
    480                         PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
    481                         PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
    482                         PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
    483 
    484                         if ( libcfap ) {
    485                                 // Generate the bodies of cfa library functions.
    486                                 LibCfa::makeLibCfa( translationUnit );
    487                         } // if
    488 
    489                         if ( declstatsp ) {
    490                                 CodeTools::printDeclStats( translationUnit );
    491                                 deleteAll( translationUnit );
    492                                 return EXIT_SUCCESS;
    493                         } // if
    494 
    495                         if ( bresolvep ) {
    496                                 dump( translationUnit );
    497                                 return EXIT_SUCCESS;
    498                         } // if
    499 
    500                         CodeTools::fillLocations( translationUnit );
    501 
    502                         if ( resolvprotop ) {
    503                                 CodeTools::dumpAsResolvProto( translationUnit );
    504                                 return EXIT_SUCCESS;
    505                         } // if
    506 
    507                         PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    508                         if ( exprp ) {
    509                                 dump( translationUnit );
    510                                 return EXIT_SUCCESS;
    511                         }
    512 
    513                         PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    514 
    515                         // fix ObjectDecl - replaces ConstructorInit nodes
    516                         if ( ctorinitp ) {
    517                                 dump ( translationUnit );
    518                                 return EXIT_SUCCESS;
    519                         } // if
    520 
    521                         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
    522                         PASS( "Translate Tries", ControlStruct::translateTries( translationUnit ) );
    523                         PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) );
    524                         PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    525 
     333                        dump( std::move( transUnit ) );
     334                        return EXIT_SUCCESS;
    526335                }
    527336
    528 
    529                 // PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    530 
    531                 PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     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 ) );
    532436
    533437                if ( tuplep ) {
    534                         dump( translationUnit );
    535                         return EXIT_SUCCESS;
    536                 } // if
    537 
    538                 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
    539 
    540                 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
     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
    541449                if ( genericsp ) {
    542450                        dump( translationUnit );
     
    621529
    622530
    623 static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:";
     531static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:";
    624532
    625533enum { PreludeDir = 128 };
     
    635543        { "prototypes", no_argument, nullptr, 'p' },
    636544        { "deterministic-out", no_argument, nullptr, 'd' },
    637         { "old-ast", no_argument, nullptr, 'O'},
    638         { "new-ast", no_argument, nullptr, 'A'},
    639545        { "print", required_argument, nullptr, 'P' },
    640546        { "prelude-dir", required_argument, nullptr, PreludeDir },
     
    658564        "do not generate prelude prototypes => prelude not printed", // -p
    659565        "only print deterministic output",                  // -d
    660         "Use the old-ast",                                                                      // -O
    661         "Use the new-ast",                                                                      // -A
    662566        "print",                                                                                        // -P
    663567        "<directory> prelude directory for debug/nodebug",      // no flag
     
    768672                        deterministic_output = true;
    769673                        break;
    770                   case 'O':                                     // don't print non-deterministic output
    771                         useNewAST = false;
    772                         break;
    773                   case 'A':                                     // don't print non-deterministic output
    774                         useNewAST = true;
    775                         break;
    776674                  case 'P':                                                                             // print options
    777675                        for ( int i = 0;; i += 1 ) {
     
    890788
    891789static void dump( ast::TranslationUnit && transUnit, ostream & out ) {
    892         std::list< Declaration * > translationUnit = convert( move( transUnit ) );
     790        std::list< Declaration * > translationUnit = convert( std::move( transUnit ) );
    893791        dump( translationUnit, out );
    894792}
Note: See TracChangeset for help on using the changeset viewer.