Changes in / [70f97c8:1ae3ac46]


Ignore:
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/channel.hfa

    r70f97c8 r1ae3ac46  
    340340    unlock( mutex_lock );
    341341
    342     // only return true when not special OR case and status is SAT
    343     return !node.park_counter ? false : *node.clause_status == __SELECT_SAT;
     342    // only return true when not special OR case, not exceptional calse and status is SAT
     343    return ( node.extra == 0p || !node.park_counter ) ? false : *node.clause_status == __SELECT_SAT;
    344344}
    345345
  • src/Concurrency/Waituntil.cpp

    r70f97c8 r1ae3ac46  
    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 );
     
    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}
     
    881870                        new BasicType( BasicType::Kind::Bool ),
    882871                        new SingleInit( cLoc, ast::deepCopy( stmt->clauses.at(i)->when_cond ) )
    883                     )
    884                 )
    885             );
    886         else // we reuse the when_cond bools later during unregister so init to false if initially unused
    887             body->push_back(
    888                 new DeclStmt( cLoc,
    889                     new ObjectDecl( cLoc,
    890                         currClause->whenName,
    891                         new BasicType( BasicType::Kind::Bool ),
    892                         new SingleInit( cLoc, ConstantExpr::from_bool( cLoc, false ) )
    893872                    )
    894873                )
     
    12981277    }
    12991278
    1300     // Collection of unregister calls on resources to be put in finally clause
    1301     // for each clause:
    1302     // when_cond_i = (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
    1303     // OR if when( ... ) defined on resource
    1304     // if ( when_cond_i )
    1305     //   when_cond_i =  (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
    13061279    CompoundStmt * unregisters = new CompoundStmt( loc );
    1307 
    1308     // Collection of optional statement executions following finally clause
    1309     // for each clause:
    1310     // if ( when_cond_i ) clausei->stmt;
    1311     // when_cond_i is repurposed in the finally to store if any statements need to be run after unregisters
    1312     // the statements need to be run outside a finally clause since they may contain non-local transfers
    1313     CompoundStmt * unregisterStmts = new CompoundStmt( loc );
    1314 
    1315     UntypedExpr * statusExpr; // !__CFA_has_clause_run( clause_statuses[i] )
    1316     ExprStmt * assignStmt; // when_cond_i = (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
     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]
    13171288    for ( int i = 0; i < numClauses; i++ ) {
    13181289        const CodeLocation & cLoc = stmt->clauses.at(i)->location;
    13191290
    1320         // Generates: !__CFA_has_clause_run( clause_statuses[i] )
    13211291        statusExpr = new UntypedExpr ( cLoc,
    13221292            new NameExpr( cLoc, "!?" ),
     
    13301300            }
    13311301        );
     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,
     1306                new CastExpr( cLoc,
     1307                    new NameExpr( cLoc, clauseData.at(i)->whenName ),
     1308                    new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
     1309                ),
     1310                new CastExpr( cLoc,
     1311                    statusExpr,
     1312                    new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
     1313                ),
     1314                LogicalFlag::AndExpr
     1315            );
     1316        } else // generates: if( !clause_statuses[i] )
     1317            ifCond = statusExpr;
    13321318       
    1333         // Generates:
    1334         // when_cond_i = (!__CFA_has_clause_run( clause_statuses[i] )) && unregister_select( ... , clausei );
    1335         assignStmt = new ExprStmt( cLoc,
    1336             UntypedExpr::createAssign( cLoc,
    1337                 new NameExpr( cLoc, clauseData.at(i)->whenName ),
    1338                 new LogicalExpr( cLoc,
    1339                     new CastExpr( cLoc,
    1340                         statusExpr,
    1341                         new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
    1342                     ),
    1343                     new CastExpr( cLoc,
    1344                         genSelectTraitCall( stmt->clauses.at(i), clauseData.at(i), "unregister_select" ),
    1345                         new BasicType( BasicType::Kind::Bool ), GeneratedFlag::ExplicitCast
    1346                     ),
    1347                     LogicalFlag::AndExpr
     1319        unregisters->push_back(
     1320            new IfStmt( cLoc,
     1321                ifCond,
     1322                new CompoundStmt( cLoc,
     1323                    {
     1324                        new IfStmt( cLoc,
     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) )
     1328                        )
     1329                    }
    13481330                )
    1349             )
    1350         );
    1351 
    1352         if ( stmt->clauses.at(i)->when_cond ) // if ( when_cond_i ) assignStmt
    1353             unregisters->push_back(
    1354                 new IfStmt( cLoc,
    1355                     new NameExpr( cLoc, clauseData.at(i)->whenName ),
    1356                     new CompoundStmt( cLoc, { assignStmt } )
    1357                 )
    1358             );
    1359         else
    1360             unregisters->push_back( assignStmt );
    1361 
    1362         unregisterStmts->push_back(
    1363             new IfStmt( cLoc,
    1364                 new NameExpr( cLoc, clauseData.at(i)->whenName ),
    1365                 genStmtBlock( stmt->clauses.at(i), clauseData.at(i) )
     1331               
    13661332            )
    13671333        );
     
    13761342        )
    13771343    );
    1378 
    1379     body->push_back( unregisterStmts );
    1380    
    13811344
    13821345    for ( ClauseData * datum : clauseData )
  • src/main.cc

    r70f97c8 r1ae3ac46  
    343343                PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit );
    344344                PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit );
     345        PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit  );
    345346                PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit );
    346347
     
    369370                PASS( "Translate Throws", ControlStruct::translateThrows, transUnit );
    370371                PASS( "Fix Labels", ControlStruct::fixLabels, transUnit );
    371         PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit  );
    372372                PASS( "Fix Names", CodeGen::fixNames, transUnit );
    373373                PASS( "Gen Init", InitTweak::genInit, transUnit );
Note: See TracChangeset for help on using the changeset viewer.