Changeset 34ed17b
- Timestamp:
- Jan 30, 2023, 4:30:37 PM (22 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 1c75ef8
- Parents:
- 77ca074
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Concurrency/Actors.cpp
r77ca074 r34ed17b 73 73 const StructDecl ** actorDecl; 74 74 const StructDecl ** msgDecl; 75 std::vector<FunctionDecl *> & forwardDecls; 75 76 76 77 void postvisit( const FunctionDecl * decl ) { 77 // return if not of the form receive( param1, param2 ) 78 if ( decl->name != "receive" || decl->params.size() != 2 ) return;78 // return if not of the form receive( param1, param2 ) or if it is a forward decl 79 if ( decl->name != "receive" || decl->params.size() != 2 || !decl->stmts ) return; 79 80 80 81 // the params should be references … … 193 194 194 195 // put it all together into the complete function decl from above 195 declsToAddAfter.push_back(new FunctionDecl(196 FunctionDecl * sendOperatorFunction = new FunctionDecl( 196 197 decl->location, 197 198 "?|?", … … 216 217 ) 217 218 }, 218 sendBody, // body219 nullptr, // body 219 220 { Storage::Static }, // storage 220 221 Linkage::Cforall, // linkage 221 222 {}, // attributes 222 223 { Function::Inline } 223 )); 224 ); 225 226 // forward decls to resolve use before decl problem for '|' routines 227 forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) ); 228 229 sendOperatorFunction->stmts = sendBody; 230 declsToAddAfter.push_back( sendOperatorFunction ); 224 231 } 225 232 } … … 227 234 public: 228 235 GenReceiveDecls( std::map<const StructDecl *, int> & actorStructDecls, std::map<const StructDecl *, int> & messageStructDecls, 229 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl ) 230 : actorStructDecls( actorStructDecls ), messageStructDecls( messageStructDecls ), requestDecl( requestDecl ), 231 allocationDecl( allocationDecl ), actorDecl(actorDecl), msgDecl(msgDecl) {} 236 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl, 237 std::vector<FunctionDecl *> & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), 238 requestDecl(requestDecl), allocationDecl(allocationDecl), actorDecl(actorDecl), msgDecl(msgDecl), forwardDecls(forwardDecls) {} 239 }; 240 241 struct GenFwdDecls : public ast::WithDeclsToAdd<> { 242 std::map<const StructDecl *, int> & actorStructDecls; 243 std::map<const StructDecl *, int> & messageStructDecls; 244 std::vector<FunctionDecl *> & forwardDecls; 245 bool done; 246 247 void postvisit( const FunctionDecl * decl ) { 248 if ( done ) return; 249 // return if not of the form receive( param1, param2 ) or if it is a forward decl 250 if ( decl->name != "receive" || decl->params.size() != 2 || !decl->stmts ) return; 251 252 // the params should be references 253 const ReferenceType * derivedActorRef = dynamic_cast<const ReferenceType *>(decl->params.at(0)->get_type()); 254 const ReferenceType * derivedMsgRef = dynamic_cast<const ReferenceType *>(decl->params.at(1)->get_type()); 255 if ( !derivedActorRef || !derivedMsgRef ) return; 256 257 // the references should be to struct instances 258 const StructInstType * arg1InstType = dynamic_cast<const StructInstType *>(derivedActorRef->base.get()); 259 const StructInstType * arg2InstType = dynamic_cast<const StructInstType *>(derivedMsgRef->base.get()); 260 if ( !arg1InstType || !arg2InstType ) return; 261 262 // If the struct instances are derived actor and message types then generate the message send routine 263 if ( actorStructDecls.count( arg1InstType->aggr() ) && messageStructDecls.count( arg2InstType->aggr() ) ) { 264 done = true; 265 for ( const auto & func : forwardDecls ) { 266 declsToAddBefore.push_back( func ); 267 } 268 } 269 } 270 271 public: 272 GenFwdDecls( std::map<const StructDecl *, int> & actorStructDecls, std::map<const StructDecl *, int> & messageStructDecls, 273 std::vector<FunctionDecl *> & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), 274 forwardDecls(forwardDecls), done(false) {} 232 275 }; 233 276 … … 236 279 std::map<const StructDecl *, int> actorStructDecls; 237 280 std::map<const StructDecl *, int> messageStructDecls; 238 239 // for setting through the passes 281 std::vector<FunctionDecl *> forwardDecls; 282 283 // for storing through the passes 284 // these are populated with various important struct decls 240 285 const StructDecl * requestDeclPtr = nullptr; 241 286 const EnumDecl * allocationDeclPtr = nullptr; … … 257 302 // it then generates the appropriate operator '|' send routines for the receive routines 258 303 Pass<GenReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl, 259 allocationDecl, actorDecl, msgDecl ); 304 allocationDecl, actorDecl, msgDecl, forwardDecls ); 305 306 // The third pass forward declares operator '|' send routines 307 Pass<GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls ); 260 308 } 261 309
Note: See TracChangeset
for help on using the changeset viewer.