Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Waituntil.cpp

    r1d66a91 rfc0996a  
    142142    UniqueName namer_target = "__clause_target_"s;
    143143    UniqueName namer_when = "__when_cond_"s;
    144     UniqueName namer_label = "__waituntil_label_"s;
    145144
    146145    string idxName = "__CFA_clause_idx_";
     
    174173    void addPredicates( const WaitUntilStmt * stmt, string & satName, string & runName );
    175174    void setUpClause( const WhenClause * clause, ClauseData * data, string & pCountName, CompoundStmt * body );
    176     CompoundStmt * genStatusCheckFor( const WaitUntilStmt * stmt, vector<ClauseData *> & clauseData, string & predName );
     175    ForStmt * genStatusCheckFor( const WaitUntilStmt * stmt, vector<ClauseData *> & clauseData, string & predName );
    177176    Expr * genSelectTraitCall( const WhenClause * clause, const ClauseData * data, string fnName );
    178177    CompoundStmt * genStmtBlock( const WhenClause * clause, const ClauseData * data );
    179178    Stmt * genElseClauseBranch( const WaitUntilStmt * stmt, string & runName, string & arrName, vector<ClauseData *> & clauseData );
    180     Stmt * genNoElseClauseBranch( const WaitUntilStmt * stmt, string & runName, string & arrName, string & pCountName, vector<ClauseData *> & clauseData );
     179    Stmt * genNoElseClauseBranch( const WaitUntilStmt * stmt, string & satName, string & runName, string & arrName, string & pCountName, vector<ClauseData *> & clauseData );
    181180    void genClauseInits( const WaitUntilStmt * stmt, vector<ClauseData *> & clauseData, CompoundStmt * body, string & statusName, string & elseWhenName );
    182181    Stmt * recursiveOrIfGen( const WaitUntilStmt * stmt, vector<ClauseData *> & data, vector<ClauseData*>::size_type idx, string & elseWhenName );
     
    627626    return new CompoundStmt( cLoc,
    628627        {
    629             new IfStmt( cLoc,
    630                 genSelectTraitCall( clause, data, "on_selected" ),
    631                 ast::deepCopy( clause->stmt )
    632             )
     628            new ExprStmt( cLoc,
     629                genSelectTraitCall( clause, data, "on_selected" )
     630            ),
     631            ast::deepCopy( clause->stmt )
    633632        }
    634633    );
     
    654653    }
    655654}*/
    656 CompoundStmt * GenerateWaitUntilCore::genStatusCheckFor( const WaitUntilStmt * stmt, vector<ClauseData *> & clauseData, string & predName ) {
     655ForStmt * GenerateWaitUntilCore::genStatusCheckFor( const WaitUntilStmt * stmt, vector<ClauseData *> & clauseData, string & predName ) {
    657656    CompoundStmt * ifBody = new CompoundStmt( stmt->location );
    658657    const CodeLocation & loc = stmt->location;
    659 
    660     string switchLabel = namer_label.newName();
    661658
    662659    /* generates:
     
    710707                                )
    711708                            ),
    712                             new BranchStmt( cLoc, BranchStmt::Kind::Break, Label( cLoc, switchLabel ) )
     709                            new BranchStmt( cLoc, BranchStmt::Kind::Break, Label( cLoc ) )
    713710                        }
    714711                    )
     
    722719        new SwitchStmt( loc,
    723720            new NameExpr( loc, idxName ),
    724             std::move( switchCases ),
    725             { Label( loc, switchLabel ) }
     721            std::move( switchCases )
    726722        )
    727723    );
     
    748744    );
    749745
    750     string forLabel = namer_label.newName();
    751 
    752     // we hoist init here so that this pass can happen after hoistdecls pass
    753     return new CompoundStmt( loc,
     746    return new ForStmt( loc,
    754747        {
    755748            new DeclStmt( loc,
     
    759752                    new SingleInit( loc, ConstantExpr::from_int( loc, 0 ) )
    760753                )
    761             ),
    762             new ForStmt( loc,
    763                 {},  // inits
    764                 new UntypedExpr ( loc,
    765                     new NameExpr( loc, "?<?" ),
    766                     {
    767                         new NameExpr( loc, idxName ),
    768                         ConstantExpr::from_int( loc, stmt->clauses.size() )
    769                     }
    770                 ),  // cond
    771                 new UntypedExpr ( loc,
    772                     new NameExpr( loc, "?++" ),
    773                     { new NameExpr( loc, idxName ) }
    774                 ),  // inc
    775                 new CompoundStmt( loc,
    776                     {
    777                         new IfStmt( loc,
    778                             new UntypedExpr ( loc,
    779                                 new NameExpr( loc, predName ),
    780                                 { new NameExpr( loc, clauseData.at(0)->statusName ) }
    781                             ),
    782                             new BranchStmt( loc, BranchStmt::Kind::Break, Label( loc, forLabel ) )
    783                         ),
    784                         ifSwitch
    785                     }
    786                 ),   // body
    787                 { Label( loc, forLabel ) }
    788             )
    789         }
     754            )
     755        },  // inits
     756        new UntypedExpr ( loc,
     757            new NameExpr( loc, "?<?" ),
     758            {
     759                new NameExpr( loc, idxName ),
     760                ConstantExpr::from_int( loc, stmt->clauses.size() )
     761            }
     762        ),  // cond
     763        new UntypedExpr ( loc,
     764            new NameExpr( loc, "?++" ),
     765            { new NameExpr( loc, idxName ) }
     766        ),  // inc
     767        new CompoundStmt( loc,
     768            {
     769                new IfStmt( loc,
     770                    new UntypedExpr ( loc,
     771                        new NameExpr( loc, predName ),
     772                        { new NameExpr( loc, clauseData.at(0)->statusName ) }
     773                    ),
     774                    new BranchStmt( loc, BranchStmt::Kind::Break, Label( loc ) )
     775                ),
     776                ifSwitch
     777            }
     778        )   // body
    790779    );
    791780}
     
    820809}
    821810
    822 Stmt * GenerateWaitUntilCore::genNoElseClauseBranch( const WaitUntilStmt * stmt, string & runName, string & arrName, string & pCountName, vector<ClauseData *> & clauseData ) {
     811Stmt * GenerateWaitUntilCore::genNoElseClauseBranch( const WaitUntilStmt * stmt, string & satName, string & runName, string & arrName, string & pCountName, vector<ClauseData *> & clauseData ) {
    823812    CompoundStmt * whileBody = new CompoundStmt( stmt->location );
    824813    const CodeLocation & loc = stmt->location;
     
    834823    );
    835824
    836     whileBody->push_back( genStatusCheckFor( stmt, clauseData, runName ) );
     825    whileBody->push_back( genStatusCheckFor( stmt, clauseData, satName ) );
    837826
    838827    return new CompoundStmt( loc,
    839828        {
    840829            new WhileDoStmt( loc,
    841                 genNotSatExpr( stmt, runName, arrName ),
     830                genNotSatExpr( stmt, satName, arrName ),
    842831                whileBody,  // body
    843832                {}          // no inits
    844             )
     833            ),
     834            genStatusCheckFor( stmt, clauseData, runName )
    845835        }
    846836    );
     
    866856                new ObjectDecl( cLoc,
    867857                    currClause->targetName,
    868                     new ReferenceType(
    869                         new TypeofType( new UntypedExpr( cLoc,
    870                             new NameExpr( cLoc, "__CFA_select_get_type" ),
    871                             { ast::deepCopy( stmt->clauses.at(i)->target ) }
    872                         ))
    873                     ),
     858                    new ReferenceType( new TypeofType( ast::deepCopy( stmt->clauses.at(i)->target ) ) ),
    874859                    new SingleInit( cLoc, ast::deepCopy( stmt->clauses.at(i)->target ) )
    875860                )
     
    12831268                new NameExpr( stmt->else_cond->location, elseWhenName ),
    12841269                genElseClauseBranch( stmt, runName, statusArrName, clauseData ),
    1285                 genNoElseClauseBranch( stmt, runName, statusArrName, pCountName, clauseData )
     1270                genNoElseClauseBranch( stmt, satName, runName, statusArrName, pCountName, clauseData )
    12861271            )
    12871272        );
    12881273    } else if ( !stmt->else_stmt ) { // normal gen
    1289         tryBody->push_back( genNoElseClauseBranch( stmt, runName, statusArrName, pCountName, clauseData ) );
     1274        tryBody->push_back( genNoElseClauseBranch( stmt, satName, runName, statusArrName, pCountName, clauseData ) );
    12901275    } else { // generate just else
    12911276        tryBody->push_back( genElseClauseBranch( stmt, runName, statusArrName, clauseData ) );
    12921277    }
    12931278
    1294     // Collection of unregister calls on resources to be put in finally clause
    1295     // for each clause:
    1296     // if ( !__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei ) ) { ... clausei stmt ... }
    1297     // OR if when( ... ) defined on resource
    1298     // if ( when_cond_i && (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei ) ) { ... clausei stmt ... }
    12991279    CompoundStmt * unregisters = new CompoundStmt( loc );
    1300 
    1301     Expr * statusExpr; // !__CFA_has_clause_run( clause_statuses[i] )
     1280    // generates for each clause:
     1281    // if ( !has_run( clause_statuses[i] ) )
     1282    // OR if when_cond defined
     1283    // if ( when_cond_i && !has_run( clause_statuses[i] ) )
     1284    // body of if is:
     1285    // { if (unregister_select(A, clause1) && on_selected(A, clause1)) clause1->stmt; } // this conditionally runs the block unregister_select returns true (needed by some primitives)
     1286    Expr * ifCond;
     1287    UntypedExpr * statusExpr; // !clause_statuses[i]
    13021288    for ( int i = 0; i < numClauses; i++ ) {
    13031289        const CodeLocation & cLoc = stmt->clauses.at(i)->location;
    13041290
    1305         // Generates: !__CFA_has_clause_run( clause_statuses[i] )
    13061291        statusExpr = new UntypedExpr ( cLoc,
    13071292            new NameExpr( cLoc, "!?" ),
     
    13151300            }
    13161301        );
    1317        
    1318         // Generates:
    1319         // (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
    1320         statusExpr = new LogicalExpr( cLoc,
    1321             new CastExpr( cLoc,
    1322                 statusExpr,
    1323                 new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
    1324             ),
    1325             new CastExpr( cLoc,
    1326                 genSelectTraitCall( stmt->clauses.at(i), clauseData.at(i), "unregister_select" ),
    1327                 new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
    1328             ),
    1329             LogicalFlag::AndExpr
    1330         );
    1331        
    1332         // if when cond defined generates:
    1333         // when_cond_i && (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
    1334         if ( stmt->clauses.at(i)->when_cond )
    1335             statusExpr = new LogicalExpr( cLoc,
     1302
     1303        if ( stmt->clauses.at(i)->when_cond ) {
     1304            // generates: if( when_cond_i && !has_run(clause_statuses[i]) )
     1305            ifCond = new LogicalExpr( cLoc,
    13361306                new CastExpr( cLoc,
    13371307                    new NameExpr( cLoc, clauseData.at(i)->whenName ),
     
    13441314                LogicalFlag::AndExpr
    13451315            );
    1346 
    1347         // generates:
    1348         // if ( statusExpr ) { ... clausei stmt ... }
     1316        } else // generates: if( !clause_statuses[i] )
     1317            ifCond = statusExpr;
     1318       
    13491319        unregisters->push_back(
    13501320            new IfStmt( cLoc,
    1351                 statusExpr,
     1321                ifCond,
    13521322                new CompoundStmt( cLoc,
    13531323                    {
    13541324                        new IfStmt( cLoc,
    1355                             genSelectTraitCall( stmt->clauses.at(i), clauseData.at(i), "on_selected" ),
    1356                             ast::deepCopy( stmt->clauses.at(i)->stmt )
     1325                            genSelectTraitCall( stmt->clauses.at(i), clauseData.at(i), "unregister_select" ),
     1326                            // ast::deepCopy( stmt->clauses.at(i)->stmt )
     1327                            genStmtBlock( stmt->clauses.at(i), clauseData.at(i) )
    13571328                        )
    13581329                    }
    13591330                )
    1360             )
    1361         );
    1362 
    1363         // // generates:
    1364         // // if ( statusExpr ) { ... clausei stmt ... }
    1365         // unregisters->push_back(
    1366         //     new IfStmt( cLoc,
    1367         //         statusExpr,
    1368         //         genStmtBlock( stmt->clauses.at(i), clauseData.at(i) )
    1369         //     )
    1370         // );
     1331               
     1332            )
     1333        );
    13711334    }
    13721335
Note: See TracChangeset for help on using the changeset viewer.