Changeset 3830c84 for src/Concurrency


Ignore:
Timestamp:
Mar 14, 2023, 3:48:53 PM (22 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
8512a2f
Parents:
2ceb2bf
Message:

cleaned up actor pass and added virtual destructor pass

Location:
src/Concurrency
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Actors.cpp

    r2ceb2bf r3830c84  
    4545    // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass
    4646    void previsit( const StructDecl * decl ) {
    47         GuardValue(insideStruct);
    48         insideStruct = true;
    49         parentDecl = mutate( decl );
    50         if( decl->name == "actor" ) {
    51             if ( actorDecl ) actorStructDecls.insert( decl ); // skip inserting fwd decl
     47        if ( !decl->body ) return;
     48        if ( decl->name == "actor" ) {
     49            actorStructDecls.insert( decl ); // skip inserting fwd decl
    5250            *actorDecl = decl;
    53         }
    54         if( decl->name == "message" ) {
    55             if ( msgDecl ) messageStructDecls.insert( decl ); // skip inserting fwd decl
     51        } else if( decl->name == "message" ) {
     52            messageStructDecls.insert( decl ); // skip inserting fwd decl
    5653            *msgDecl = decl;
    57         }
    58         if( decl->name == "request" ) *requestDecl = decl;
     54        } else if( decl->name == "request" ) *requestDecl = decl;
     55        else {
     56            GuardValue(insideStruct);
     57            insideStruct = true;
     58            parentDecl = mutate( decl );
     59        }
    5960        }
    6061
     
    7071    }
    7172
    72     // this collects the valid actor and message struct decl pts
     73    // this collects the derived actor and message struct decl ptrs
    7374    void postvisit( const StructInstType * node ) {
    7475        if ( ! *actorDecl || ! *msgDecl ) return;
    7576        if ( insideStruct && !namedDecl ) {
    76             if ( node->aggr() == *actorDecl ) {
     77            auto actorIter = actorStructDecls.find( node->aggr() );   
     78            if ( actorIter != actorStructDecls.end() ) {
    7779                actorStructDecls.insert( parentDecl );
    78             } else if ( node->aggr() == *msgDecl ) {
     80                return;
     81            }
     82            auto messageIter = messageStructDecls.find( node->aggr() );
     83            if ( messageIter != messageStructDecls.end() ) {
    7984                messageStructDecls.insert( parentDecl );
    8085            }
     
    186191};
    187192
    188 struct GenReceiveDecls : public ast::WithDeclsToAdd<> {
     193// generates the definitions of send operators for actors
     194// collects data needed for next pass that does the circular defn resolution
     195//     for message send operators (via table above)
     196struct GenFuncsCreateTables : public ast::WithDeclsToAdd<> {
    189197    unordered_set<const StructDecl *> & actorStructDecls;
    190198    unordered_set<const StructDecl *>  & messageStructDecls;
     
    195203    FwdDeclTable & forwardDecls;
    196204
     205    // generates the operator for actor message sends
    197206        void postvisit( const FunctionDecl * decl ) {
    198207        // return if not of the form receive( param1, param2 ) or if it is a forward decl
     
    213222        auto messageIter = messageStructDecls.find( arg2InstType->aggr() );
    214223        if ( actorIter != actorStructDecls.end() && messageIter != messageStructDecls.end() ) {
    215 
    216             // check that we have found all the decls we need from <actor.hfa>
    217             if ( !*allocationDecl || !*requestDecl )
    218                 SemanticError( decl->location, "using actors requires a header, add #include <actor.hfa>\n" );
    219 
    220224            //////////////////////////////////////////////////////////////////////
    221225            // The following generates this send message operator routine for all receive(derived_actor &, derived_msg &) functions
     
    347351            // forward decls to resolve use before decl problem for '|' routines
    348352            forwardDecls.insertDecl( *actorIter, *messageIter , ast::deepCopy( sendOperatorFunction ) );
    349             // forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) );
    350353
    351354            sendOperatorFunction->stmts = sendBody;
     
    355358
    356359  public:
    357     GenReceiveDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     360    GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    358361        const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
    359362        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     
    361364};
    362365
    363 struct GenFwdDecls : public ast::WithDeclsToAdd<> {
     366
     367// separate pass is needed since this pass resolves circular defn issues
     368// generates the forward declarations of the send operator for actor routines
     369struct FwdDeclOperator : public ast::WithDeclsToAdd<> {
    364370    unordered_set<const StructDecl *> & actorStructDecls;
    365371    unordered_set<const StructDecl *>  & messageStructDecls;
    366372    FwdDeclTable & forwardDecls;
    367373
     374    // handles forward declaring the message operator
    368375    void postvisit( const StructDecl * decl ) {
    369376        list<FunctionDecl *> toAddAfter;
     
    392399
    393400  public:
    394     GenFwdDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    395         FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
    396         forwardDecls(forwardDecls) {}
     401    FwdDeclOperator( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     402        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), forwardDecls(forwardDecls) {}
    397403};
    398404
     
    420426    Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    421427        allocationDecl, actorDecl, msgDecl );
    422        
     428
     429    // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
     430    if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
     431        return;
     432
    423433    // second pass locates all receive() routines that overload the generic receive fn
    424434    // it then generates the appropriate operator '|' send routines for the receive routines
    425     Pass<GenReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     435    Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    426436        allocationDecl, actorDecl, msgDecl, forwardDecls );
    427437
    428438    // The third pass forward declares operator '|' send routines
    429     Pass<GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
     439    Pass<FwdDeclOperator>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
    430440}
    431441
  • src/Concurrency/Actors.hpp

    r2ceb2bf r3830c84  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Keywords.h -- Implement concurrency constructs from their keywords.
     7// Actors.hpp -- Implement concurrency constructs from their keywords.
    88//
    99// Author           : Colby Parsons
Note: See TracChangeset for help on using the changeset viewer.