Changeset b110bcc for src/Concurrency/Actors.cpp
- Timestamp:
- Apr 21, 2023, 5:36:12 PM (2 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Actors.cpp
r2ed94a9 rb110bcc 45 45 // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass 46 46 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 } 53 60 } 54 61 … … 64 71 } 65 72 66 // this collects the valid actor and message struct decl pts73 // this collects the derived actor and message struct decl ptrs 67 74 void postvisit( const StructInstType * node ) { 68 75 if ( ! *actorDecl || ! *msgDecl ) return; 69 76 if ( insideStruct && !namedDecl ) { 70 if ( node->aggr() == *actorDecl ) { 77 auto actorIter = actorStructDecls.find( node->aggr() ); 78 if ( actorIter != actorStructDecls.end() ) { 71 79 actorStructDecls.insert( parentDecl ); 72 } else if ( node->aggr() == *msgDecl ) { 80 return; 81 } 82 auto messageIter = messageStructDecls.find( node->aggr() ); 83 if ( messageIter != messageStructDecls.end() ) { 73 84 messageStructDecls.insert( parentDecl ); 74 85 } … … 180 191 }; 181 192 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) 196 struct GenFuncsCreateTables : public ast::WithDeclsToAdd<> { 185 197 unordered_set<const StructDecl *> & actorStructDecls; 186 198 unordered_set<const StructDecl *> & messageStructDecls; … … 191 203 FwdDeclTable & forwardDecls; 192 204 205 // generates the operator for actor message sends 193 206 void postvisit( const FunctionDecl * decl ) { 194 207 // return if not of the form receive( param1, param2 ) or if it is a forward decl … … 209 222 auto messageIter = messageStructDecls.find( arg2InstType->aggr() ); 210 223 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 216 224 ////////////////////////////////////////////////////////////////////// 217 225 // The following generates this send message operator routine for all receive(derived_actor &, derived_msg &) functions 218 226 /* 219 227 static inline derived_actor & ?|?( derived_actor & receiver, derived_msg & msg ) { 220 request * new_req = alloc();228 request new_req; 221 229 Allocation (*my_work_fn)( derived_actor &, derived_msg & ) = receive; 222 230 __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 ); 225 233 return receiver; 226 234 } 227 */ // C_TODO: update this with new no alloc version235 */ 228 236 CompoundStmt * sendBody = new CompoundStmt( decl->location ); 229 237 230 #if __ALLOC231 // 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 #else242 238 // Generates: request new_req; 243 239 sendBody->push_back( new DeclStmt( … … 249 245 ) 250 246 )); 251 #endif252 247 253 248 // Function type is: Allocation (*)( derived_actor &, derived_msg & ) … … 268 263 )); 269 264 270 // Function type is: Allocation (*)( actor &, mess sage & )265 // Function type is: Allocation (*)( actor &, message & ) 271 266 FunctionType * genericReceive = new FunctionType(); 272 267 genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) ); … … 274 269 genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) ); 275 270 276 // Generates: Allocation (*fn)( actor &, mess sage & ) = (Allocation (*)( actor &, messsage & ))my_work_fn;271 // Generates: Allocation (*fn)( actor &, message & ) = (Allocation (*)( actor &, message & ))my_work_fn; 277 272 // More readable synonymous code: 278 273 // typedef Allocation (*__receive_fn)(actor &, message &); … … 290 285 )); 291 286 292 #if __ALLOC293 // 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 #else323 287 // Generates: new_req{ &receiver, &msg, fn }; 324 288 sendBody->push_back( new ExprStmt( … … 350 314 ) 351 315 )); 352 #endif353 316 354 317 // Generates: return receiver; … … 358 321 FunctionDecl * sendOperatorFunction = new FunctionDecl( 359 322 decl->location, 360 "? |?",323 "?<<?", 361 324 {}, // forall 362 325 { … … 388 351 // forward decls to resolve use before decl problem for '|' routines 389 352 forwardDecls.insertDecl( *actorIter, *messageIter , ast::deepCopy( sendOperatorFunction ) ); 390 // forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) );391 353 392 354 sendOperatorFunction->stmts = sendBody; … … 396 358 397 359 public: 398 Gen ReceiveDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,360 GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls, 399 361 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl, 400 362 FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), … … 402 364 }; 403 365 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 369 struct FwdDeclOperator : public ast::WithDeclsToAdd<> { 405 370 unordered_set<const StructDecl *> & actorStructDecls; 406 371 unordered_set<const StructDecl *> & messageStructDecls; 407 372 FwdDeclTable & forwardDecls; 408 373 374 // handles forward declaring the message operator 409 375 void postvisit( const StructDecl * decl ) { 410 376 list<FunctionDecl *> toAddAfter; … … 433 399 434 400 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) {} 438 403 }; 439 404 … … 461 426 Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl, 462 427 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 464 433 // second pass locates all receive() routines that overload the generic receive fn 465 434 // it then generates the appropriate operator '|' send routines for the receive routines 466 Pass<Gen ReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,435 Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl, 467 436 allocationDecl, actorDecl, msgDecl, forwardDecls ); 468 437 469 438 // The third pass forward declares operator '|' send routines 470 Pass< GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );439 Pass<FwdDeclOperator>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls ); 471 440 } 472 441
Note:
See TracChangeset
for help on using the changeset viewer.