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