DirtyManager::DirtyManager(const BlockCollection& coll) : _coll(coll), bot(coll.count()), _top(coll.count()) { bot.may().empty(); bot.must().fill(); _top.may().fill(); _top.must().empty(); }
void processColl(WorkSpace *ws, const BlockCollection& coll) { // resolve the problem Problem prob(coll); DefaultListener<Problem> listener(ws, prob); DefaultFixPoint<DefaultListener<Problem> > fp(listener); util::HalfAbsInt<DefaultFixPoint<DefaultListener<Problem> > > hai(fp, *ws); hai.solve(); // put the results for(CFGCollection::Iterator cfg(otawa::INVOLVED_CFGS(ws)); cfg; cfg++) for(CFG::BBIterator bb(cfg); bb; bb++) (*DIRTY(bb))[coll.cacheSet()] = *listener.results[cfg->number()][bb->number()]; }
void CATBuilder::processLBlockSet(WorkSpace *ws, const BlockCollection& coll, const hard::Cache *cache) { if(coll.count() == 0) return; // prepare problem int line = coll.cacheSet(); MUSTPERS prob(&coll, ws, cache); MUSTPERS::Domain dom = prob.bottom(); acs_stack_t empty_stack; if(logFor(LOG_FUN)) log << "\tSET " << line << io::endl; const CFGCollection *cfgs = INVOLVED_CFGS(ws); ASSERT(cfgs); for(int i = 0; i < cfgs->count(); i++) { if(logFor(LOG_BB)) log << "\t\tCFG " << cfgs->get(i) << io::endl; for(CFG::BBIterator bb(cfgs->get(i)); bb; bb++) { if(logFor(LOG_BB)) log << "\t\t\t" << *bb << io::endl; // get the input domain acs_table_t *ins = MUST_ACS(bb); prob.setMust(dom, *ins->get(line)); acs_table_t *pers = PERS_ACS(bb); bool has_pers = pers; if(!has_pers) prob.emptyPers(dom); else { acs_stack_t *stack; acs_stack_table_t *stack_table = LEVEL_PERS_ACS(bb); if(stack_table) stack = &stack_table->item(line); else stack = &empty_stack; prob.setPers(dom, *pers->get(line), *stack); } // explore the adresses Pair<int, BlockAccess *> ab = DATA_BLOCKS(bb); for(int j = 0; j < ab.fst; j++) { BlockAccess& b = ab.snd[j]; if(b.kind() != BlockAccess::BLOCK) { CATEGORY(b) = cache::NOT_CLASSIFIED; prob.ageAll(dom); } else if(b.block().set() == line) { // initialization bool done = false; CATEGORY(b) = cache::NOT_CLASSIFIED; ACS *may = 0; if(MAY_ACS(bb) != 0) may = MAY_ACS(bb)->get(line); // in MUST ? if(dom.getMust().contains(b.block().index())) CATEGORY(b) = cache::ALWAYS_HIT; // persistent ? else if(has_pers) { // find the initial header BasicBlock *header; if (LOOP_HEADER(bb)) header = bb; else header = ENCLOSING_LOOP_HEADER(bb); // look in the different levels for(int k = dom.getPers().length() - 1; k >= 0 && header; k--) { if(dom.getPers().isPersistent(b.block().index(), k)) { CATEGORY(b) = cache::FIRST_MISS; CATEGORY_HEADER(b) = header; done = true; break; } header = ENCLOSING_LOOP_HEADER(header); } } // out of MAY ? if(!done && may && !may->contains(b.block().index())) CATEGORY(b) = cache::ALWAYS_MISS; // update state prob.inject(dom, b.block().index()); } } } } }
void Game_Main() { HDC hdc = GetDC(g_hwnd); RECT rect; Ball* ball = NULL; static Archnoid::USHORT birthRate = 0; // white out the playing bounds GetClientRect(g_hwnd,&rect); FillRect(g_hdcBuffer,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH)); // draw the playing bounds SelectObject( g_hdcBuffer, GetStockObject( WHITE_BRUSH ) ); Rectangle(g_hdcBuffer, g_gameArea.GetWestWall(), g_gameArea.GetNorthWall(), g_gameArea.GetEastWall(), g_gameArea.GetSouthWall()); //g_blockCollection.RandomMoveAll(); //g_blockCollection.RandomGravitateToCenterAll(); // HAUKAP - which ball to gravitate to? g_blockCollection.RandomGravitateToPointAll( g_balls.GetFirstBall()->GetCntrX(), g_balls.GetFirstBall()->GetCntrY() ); if( ++birthRate >= GamePlayDefaults::RESPAWN_RATE ) { birthRate = 0; g_blockCollection.NewGenerations(); } ball = g_balls.GetFirstBall(); while( ball ) { ball->Move(); // did ball go out of bounds? CollisionType collision = g_gameArea.OutOfBounds(*ball); if( !collision ) { // did ball collide with one of the blocks? collision = g_blockCollection.IsCollision(*ball); } if( collision ) { ball->UnMove(); if( VERTICAL_COLLISION(collision) ) ball->ResolveCollision(Vertical); else if( HORIZONTAL_COLLISION(collision) ) ball->ResolveCollision(Horizontal); } ball = g_balls.GetNextBall(); } // draw the blocks SelectObject( g_hdcBuffer, GetStockObject( LTGRAY_BRUSH ) ); const Block* block = g_blockCollection.GetFirstBlock(); while( block ) { switch(BlockDefaults::SHAPE) { case ShapeCircle: Ellipse(g_hdcBuffer, block->GetX(), block->GetY(), block->GetX() + block->GetWidth(), block->GetY() + block->GetHeight()); break; case ShapeRect: Rectangle(g_hdcBuffer,block->GetX(),block->GetY(), block->GetX()+block->GetWidth(), block->GetY()+block->GetHeight()); break; default: assert(!"invalid shape"); } block = g_blockCollection.GetNextBlock(); } // draw the ball SelectObject( g_hdcBuffer, GetStockObject( BLACK_BRUSH ) ); ball = g_balls.GetFirstBall(); while( ball ) { Ellipse( g_hdcBuffer, ball->GetULX(), ball->GetULY(), ball->GetLRX(), ball->GetLRY()); ball = g_balls.GetNextBall(); } // draw debug/info text const char escMsg[] = "Hit any key to exit"; TextOut(g_hdcBuffer,5,5,escMsg, (int)strlen(escMsg)); char buf[256]; std::string buf1( "Blocks: " ); buf1 += _itoa_s( g_blockCollection.GetNumBlocks(), buf, 10); TextOut(g_hdcBuffer,5,20,buf1.c_str(), (int)buf1.size()); Archnoid::USHORT y = 40; Archnoid::USHORT i = 1; ball = g_balls.GetFirstBall(); while( ball ) { sprintf_s( buf, "Ball[%d] [x:%d y:%d sp:%f vX:%f vY:%f]", i, ball->GetCntrX(), ball->GetCntrY(), ball->GetSpeed(), ball->GetVectX(), ball->GetVectY() ); TextOut(g_hdcBuffer, 5, y, buf, (int)strlen(buf) ); ball = g_balls.GetNextBall(); y += 15; ++i; } // copy the game area over to the main hdc BitBlt(hdc,0,0,g_gameArea.GetEastWall(),g_gameArea.GetSouthWall(), g_hdcBuffer,0,0,SRCCOPY); ReleaseDC(g_hwnd,hdc); Sleep(GamePlayDefaults::SLEEPTIME); }