Ignore:
Timestamp:
Apr 21, 2023, 5:36:12 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, master
Children:
28f8f15, 6e4c44d
Parents:
2ed94a9 (diff), 699a97d (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Actors.cpp

    r2ed94a9 rb110bcc  
    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" ) *actorDecl = decl;
    51         if( decl->name == "message" ) *msgDecl = decl;
    52         if( decl->name == "request" ) *requestDecl = decl;
     47        if ( !decl->body ) return;
     48        if ( decl->name == "actor" ) {
     49            actorStructDecls.insert( decl ); // skip inserting fwd decl
     50            *actorDecl = decl;
     51        } else if( decl->name == "message" ) {
     52            messageStructDecls.insert( decl ); // skip inserting fwd decl
     53            *msgDecl = decl;
     54        } else if( decl->name == "request" ) *requestDecl = decl;
     55        else {
     56            GuardValue(insideStruct);
     57            insideStruct = true;
     58            parentDecl = mutate( decl );
     59        }
    5360        }
    5461
     
    6471    }
    6572
    66     // this collects the valid actor and message struct decl pts
     73    // this collects the derived actor and message struct decl ptrs
    6774    void postvisit( const StructInstType * node ) {
    6875        if ( ! *actorDecl || ! *msgDecl ) return;
    6976        if ( insideStruct && !namedDecl ) {
    70             if ( node->aggr() == *actorDecl ) {
     77            auto actorIter = actorStructDecls.find( node->aggr() );   
     78            if ( actorIter != actorStructDecls.end() ) {
    7179                actorStructDecls.insert( parentDecl );
    72             } else if ( node->aggr() == *msgDecl ) {
     80                return;
     81            }
     82            auto messageIter = messageStructDecls.find( node->aggr() );
     83            if ( messageIter != messageStructDecls.end() ) {
    7384                messageStructDecls.insert( parentDecl );
    7485            }
     
    180191};
    181192
    182 #define __ALLOC 0 // C_TODO: complete swap to no-alloc version
    183 
    184 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<> {
    185197    unordered_set<const StructDecl *> & actorStructDecls;
    186198    unordered_set<const StructDecl *>  & messageStructDecls;
     
    191203    FwdDeclTable & forwardDecls;
    192204
     205    // generates the operator for actor message sends
    193206        void postvisit( const FunctionDecl * decl ) {
    194207        // return if not of the form receive( param1, param2 ) or if it is a forward decl
     
    209222        auto messageIter = messageStructDecls.find( arg2InstType->aggr() );
    210223        if ( actorIter != actorStructDecls.end() && messageIter != messageStructDecls.end() ) {
    211 
    212             // check that we have found all the decls we need from <actor.hfa>
    213             if ( !*allocationDecl || !*requestDecl )
    214                 SemanticError( decl->location, "using actors requires a header, add #include <actor.hfa>\n" );
    215 
    216224            //////////////////////////////////////////////////////////////////////
    217225            // The following generates this send message operator routine for all receive(derived_actor &, derived_msg &) functions
    218226            /*
    219227                static inline derived_actor & ?|?( derived_actor & receiver, derived_msg & msg ) {
    220                     request * new_req = alloc();
     228                    request new_req;
    221229                    Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive;
    222230                    __receive_fn fn = (__receive_fn)my_work_fn;
    223                     (*new_req){ &receiver, &msg, fn };
    224                     send( receiver, *new_req );
     231                    new_req{ &receiver, &msg, fn };
     232                    send( receiver, new_req );
    225233                    return receiver;
    226234                }
    227             */ // C_TODO: update this with new no alloc version
     235            */
    228236            CompoundStmt * sendBody = new CompoundStmt( decl->location );
    229237
    230             #if __ALLOC
    231             // Generates: request * new_req = alloc();
    232             sendBody->push_back( new DeclStmt(
    233                 decl->location,
    234                 new ObjectDecl(
    235                     decl->location,
    236                     "new_req",
    237                     new PointerType( new StructInstType( *requestDecl ) ),
    238                     new SingleInit( decl->location, new UntypedExpr( decl->location, new NameExpr( decl->location, "alloc" ), {} ) )
    239                 )
    240             ));
    241             #else
    242238            // Generates: request new_req;
    243239            sendBody->push_back( new DeclStmt(
     
    249245                )
    250246            ));
    251             #endif
    252247           
    253248            // Function type is: Allocation (*)( derived_actor &, derived_msg & )
     
    268263            ));
    269264
    270             // Function type is: Allocation (*)( actor &, messsage & )
     265            // Function type is: Allocation (*)( actor &, message & )
    271266            FunctionType * genericReceive = new FunctionType();
    272267            genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) );
     
    274269            genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
    275270
    276             // Generates: Allocation (*fn)( actor &, messsage & ) = (Allocation (*)( actor &, messsage & ))my_work_fn;
     271            // Generates: Allocation (*fn)( actor &, message & ) = (Allocation (*)( actor &, message & ))my_work_fn;
    277272            // More readable synonymous code:
    278273            //     typedef Allocation (*__receive_fn)(actor &, message &);
     
    290285            ));
    291286
    292             #if __ALLOC
    293             // Generates: (*new_req){ &receiver, &msg, fn };
    294             sendBody->push_back( new ExprStmt(
    295                 decl->location,
    296                                 new UntypedExpr (
    297                     decl->location,
    298                                         new NameExpr( decl->location, "?{}" ),
    299                                         {
    300                                                 new UntypedExpr( decl->location, new NameExpr( decl->location, "*?" ), {  new NameExpr( decl->location, "new_req" ) } ),
    301                         new AddressExpr( new NameExpr( decl->location, "receiver" ) ),
    302                         new AddressExpr( new NameExpr( decl->location, "msg" ) ),
    303                         new NameExpr( decl->location, "fn" )
    304                                         }
    305                                 )
    306                         ));
    307 
    308             // Generates: send( receiver, *new_req );
    309             sendBody->push_back( new ExprStmt(
    310                 decl->location,
    311                                 new UntypedExpr (
    312                     decl->location,
    313                                         new NameExpr( decl->location, "send" ),
    314                                         {
    315                                                 {
    316                             new NameExpr( decl->location, "receiver" ),
    317                             new UntypedExpr( decl->location, new NameExpr( decl->location, "*?" ), {  new NameExpr( decl->location, "new_req" ) } )
    318                         }
    319                                         }
    320                                 )
    321                         ));
    322             #else
    323287            // Generates: new_req{ &receiver, &msg, fn };
    324288            sendBody->push_back( new ExprStmt(
     
    350314                                )
    351315                        ));
    352             #endif
    353316           
    354317            // Generates: return receiver;
     
    358321            FunctionDecl * sendOperatorFunction = new FunctionDecl(
    359322                decl->location,
    360                 "?|?",
     323                "?<<?",
    361324                {},                     // forall
    362325                {
     
    388351            // forward decls to resolve use before decl problem for '|' routines
    389352            forwardDecls.insertDecl( *actorIter, *messageIter , ast::deepCopy( sendOperatorFunction ) );
    390             // forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) );
    391353
    392354            sendOperatorFunction->stmts = sendBody;
     
    396358
    397359  public:
    398     GenReceiveDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     360    GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    399361        const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
    400362        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     
    402364};
    403365
    404 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<> {
    405370    unordered_set<const StructDecl *> & actorStructDecls;
    406371    unordered_set<const StructDecl *>  & messageStructDecls;
    407372    FwdDeclTable & forwardDecls;
    408373
     374    // handles forward declaring the message operator
    409375    void postvisit( const StructDecl * decl ) {
    410376        list<FunctionDecl *> toAddAfter;
     
    433399
    434400  public:
    435     GenFwdDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    436         FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
    437         forwardDecls(forwardDecls) {}
     401    FwdDeclOperator( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     402        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), forwardDecls(forwardDecls) {}
    438403};
    439404
     
    461426    Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    462427        allocationDecl, actorDecl, msgDecl );
    463        
     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
    464433    // second pass locates all receive() routines that overload the generic receive fn
    465434    // it then generates the appropriate operator '|' send routines for the receive routines
    466     Pass<GenReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     435    Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    467436        allocationDecl, actorDecl, msgDecl, forwardDecls );
    468437
    469438    // The third pass forward declares operator '|' send routines
    470     Pass<GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
     439    Pass<FwdDeclOperator>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
    471440}
    472441
Note: See TracChangeset for help on using the changeset viewer.