/* * mm_checkheap - Check the heap for consistency * Checks the epilogue and prologue blocks for size and allocation bit. * Checks the 8-byte address alignment for each block in the free list. * Checks each free block to see if its next and previous pointers are * within heap bounds. * Checks the consistency of header and footer size and allocation bits * for each free block. */ void mm_checkheap(int verbose) { void *bp = heap_listp; //Points to the first block in the heap if (verbose) printf("Heap (%p):\n", heap_listp); /* If first block's header's size or allocation bit is wrong, * the prologue header is wrong */ if ((GET_SIZE(HDRP(heap_listp)) != MINIMUM) || !GET_ALLOC(HDRP(heap_listp))) printf("Bad prologue header\n"); checkBlock(heap_listp); // /* Print the stats of every free block in the free list */ for (bp = free_listp; GET_ALLOC(HDRP(bp))==0; bp = NEXT_FREEP(bp)) { if (verbose) printBlock(bp); checkBlock(bp); } /* Print the stats of the last block in the heap */ if (verbose) printBlock(bp); /* If last block's header's size or allocation bit is wrong, * the epilogue's header is wrong */ if ((GET_SIZE(HDRP(bp)) != 0) || !(GET_ALLOC(HDRP(bp)))) printf("Bad epilogue header\n"); }
bool check(const php::Func& f) { assert(checkParams(f)); assert(checkName(f.name)); for (DEBUG_ONLY auto& block : f.blocks) assert(checkBlock(*block)); /* * Some of these relationships may change as async/await * implementation progresses. Asserting them now so they are * revisited here if they aren't true anymore. */ if (f.isClosureBody) assert(!f.top); if (f.isPairGenerator) assert(f.isGenerator); if (f.isClosureBody) { assert(f.cls && f.cls->parentName && f.cls->parentName->isame(s_Closure.get())); } boost::dynamic_bitset<> seenId(f.nextBlockId); for (auto& block : f.blocks) { assert(checkBlock(*block)); // All blocks have unique ids in a given function; not necessarily // consecutive. assert(block->id < f.nextBlockId); assert(!seenId.test(block->id)); seenId.set(block->id); } assert(checkExnTree(f)); return true; }
const Vector2<int> Game::findPos(const Vector2<int> &startPos, const Vector2<int> &finishPos, Direction direction) { Vector2<int> result = startPos; Vector2<int> testPos = startPos; Vector2<int> distance = finishPos - testPos; while (testPos != finishPos){ if (distance.x < 0){ if (-distance.x <= distance.y) testPos.y += 1; else testPos.x -= 1; } else{ if (distance.x <= distance.y) testPos.y += 1; else testPos.x += 1; } if (checkBlock(testPos, direction)){ result = testPos; } else { break; } distance = finishPos - testPos; } return result; }
std::shared_ptr<inter::IfInstr> SemanticChecker::checkIfStatement(inter::ScopePrototype & scopePrototype, syntax::IfStatement & statement) { CHECK_FAIL(nullptr); std::shared_ptr<inter::IfInstr> obj = std::make_shared<inter::IfInstr>(); obj->condition = checkLogicalExpression(scopePrototype, *(statement._condition)); obj->trueBlock = checkBlock(scopePrototype, *(statement._trueBlock)); if (statement._falseBlock) { obj->falseBlock = checkBlock(scopePrototype, *(statement._falseBlock)); } return obj; }
/** * @brief Parses in the argument context for the given node. */ void NepParser::genCtxArg(Nepeta::Node &data) { while( notEof() ) { char ch = getCurRaw(); if( isSpace(ch) ) { iterCur(); } else if( checkIdentifier(ch) ) { genArgWord(data); } else if( checkString(ch) ) { genArgString(data); } else if( checkBlock(ch) ) { genArgBlock(data); } else if( isNewline(ch) || ch == ';' ) { iterCur(); return; } else if( ch == '\\' ) { iterCur(); helpSeekNewline(true); } else if( ch == '&' ) { genArgReference(data); } else { mScript.addError(Nepeta::ErrIllegalCharacter, std::string(1,ch), getCurLine(), getCurCol()); helpSeekNewline(false); break; } } }
bool sudokuSolver::fillColumn(int row,int column){ if(row==9){ return true; } else if(column==9){ if(fillColumn(row+1,0))return true; else return false; } else if(problem[row][column]==0){ for(int i=1;i<=9;i++){ ans[row][column]=i; for(int k=row;k<9;k++){ if(k==row){ for(int l=column+1;l<9;l++) ans[k][l]=problem[k][l]; } else{ for(int l=0;l<9;l++) ans[k][l]=problem[k][l]; } } if(checkColumn(row,column) && checkRow(row,column) && checkBlock(row,column)) if(fillColumn(row,column+1))return true; } return false; } else {if(fillColumn(row,column+1))return true;else return false;} }
int AI::eval() { int ret = 0; int retEat = 0; int max = -1000000000; if (verifWin() == _initTeam) return 1000000000; if (verifWin() == invertTeam(_initTeam)) return -1000000000; for (int y = 0; y != 19; y++) { for (int x = 0; x != 19; x++) { if (_mapRule[y][x] != FREE && _mapRule[y][x] != TRY) { retEat = verifEat(x, y); ret += howManyCoin(x, y); ret = ret + retEat; if (_type == DEF && _mapRule[y][x] == invertTeam(_initTeam)) ret += checkBlock(x, y); if (ret > max) max = ret; } } } return max; }
void searchInput(mafFileApi_t *mfa, char *fullname, unsigned long pos) { mafBlock_t *thisBlock = NULL; while ((thisBlock = maf_readBlock(mfa)) != NULL) { checkBlock(thisBlock, fullname, pos); maf_destroyMafBlockList(thisBlock); } }
Block& getBlock(int index) { Block& b = sgLevel.blocks[index]; checkBlock(b); return b; }
void SmushPlayer::handleFetch(Chunk &b) { debugC(DEBUG_SMUSH, "SmushPlayer::handleFetch()"); checkBlock(b, TYPE_FTCH, 6); if (_frameBuffer != NULL) { memcpy(_dst, _frameBuffer, _width * _height); } }
void TextModelLavaan::contentChangedHandler() { _changed = true; _content = toPlainText(); QTextBlock current = findBlockByNumber(_currentBlock); checkBlock(current); }
void processBody(mafFileApi_t *mfa, char *seq, uint32_t start, uint32_t stop) { mafBlock_t *thisBlock = NULL; bool printedHeader = false; while ((thisBlock = maf_readBlock(mfa)) != NULL) { checkBlock(thisBlock, seq, start, stop, &printedHeader); maf_destroyMafBlockList(thisBlock); } }
int Filesys::nextBlock(std::string file, int blockNumber) { if (checkBlock(file, blockNumber)) { // Block is in file. return fat[blockNumber]; } else { // Block not in file. throw std::invalid_argument("nextBlock error: block not in file."); return 0; } }
bool isValidSudoku(Board board) { Block block; std::vector<int> column; std::vector<int> row; bool isValidSize = true; bool isValidBlock = true; bool isValidRow = true; bool isValidColums = true; std::vector<bool> blockValidationResults; std::vector<bool> columnValidationResults; std::vector<bool> rowValidationResults; if (board.size() != 9) { return false; } for (int i = 0; i < 9; i++) { auto row = board[i]; isValidSize = isValidSize && (row.size() == 9); } if (!isValidSize) { return false; } for (unsigned int col = 0; col < BOARD_SIZE; col++) { for (unsigned int row = 0; row < BOARD_SIZE; row++) { if (!isValidValue(board[row][col])) return false; } } for (unsigned int i = 0; i < 9; i++) { block = getBlock(board, i); blockValidationResults.push_back(checkBlock(block)); } for (unsigned int i = 0; i < 9; i++) { column = getColumn(board, i); columnValidationResults.push_back(checkColumn(column)); } for (int j = 0; j < 9; j++) { row = getRow(board, j); rowValidationResults.push_back(checkRow(row)); } return checkResults(blockValidationResults, columnValidationResults, rowValidationResults); }
int Filesys::readBlock(std::string file, int blockNumber, std::string& buffer) { if (checkBlock(file, blockNumber)) { // Block is in file. getBlock(blockNumber, buffer); return 1; } else { // Block not in file. throw std::invalid_argument("Cannot read: block permission error."); return 0; } }
void SmushPlayer::handleSkip(Chunk &b) { checkBlock(b, TYPE_SKIP, 4); int32 code = b.getDword(); debugC(DEBUG_SMUSH, "SmushPlayer::handleSkip(%d)", code); if (code >= 0 && code < 37) _skipNext = _skips[code]; else _skipNext = true; }
int Filesys::writeBlock(std::string file, int blockNumber, std::string buffer) { if (checkBlock(file, blockNumber)) { // Block is in file. putBlock(blockNumber, buffer); fssynch(); return 1; } else { // Block not in file. throw std::invalid_argument("Cannot write: block permission error."); return 0; } }
bool sudokuSolver::validateProblem(){ for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ if(problem[i][j]==0)continue; else{ if(!(checkBlock(i,j)&&checkRow(i,j)&&checkColumn(i,j)))return false; } } } return true; }
void processBody(mafFileApi_t *mfa) { // walk the body of the maf file and process it, block by block. mafBlock_t *thisBlock = NULL; thisBlock = maf_readBlock(mfa); // unused maf_destroyMafBlockList(thisBlock); while((thisBlock = maf_readBlock(mfa)) != NULL) { correctSpeciesNames(thisBlock); checkBlock(thisBlock); maf_destroyMafBlockList(thisBlock); } }
void GameScene::onTouchEnded(Touch* touch, Event* event) { if (_touchBlock != nullptr){ _touchBlock->setPosition(getPosition(_touchBlock->_tagX,_touchBlock->_tagY)); _block[_touchBlock->_tagX][_touchBlock->_tagY] = _touchBlock; setTag(_touchBlock->_tagX,_touchBlock->_tagY,_touchBlock->_tag); } _touchBlock = nullptr; //_checkBlockWaiting = true; checkBlock(); }
std::shared_ptr<inter::WhileInstr> SemanticChecker::checkWhileStatement(inter::ScopePrototype & scopePrototype, syntax::WhileStatement & statement) { CHECK_FAIL(nullptr); std::shared_ptr<inter::WhileInstr> obj = std::make_shared<inter::WhileInstr>(); obj->_condition = checkLogicalExpression(scopePrototype, *(statement._condition)); obj->_block = checkBlock(scopePrototype, *(statement._block)); return obj; }
/* * Build the CFG, then the dominator tree, then use it to validate SSA. * 1. Each src must be defined by some other instruction, and each dst must * be defined by the current instruction. * 2. Each src must be defined earlier in the same block or in a dominator. * 3. Each dst must not be previously defined. * 4. Treat tmps defined by DefConst as always defined. * 5. Each predecessor of a reachable block must be reachable (deleted * blocks must not have out-edges to reachable blocks). * 6. The entry block must not have any predecessors. */ bool checkCfg(const IRUnit& unit) { auto const blocksIds = rpoSortCfgWithIds(unit); auto const& blocks = blocksIds.blocks; jit::hash_set<const Edge*> edges; // Entry block can't have predecessors. assert(unit.entry()->numPreds() == 0); // Check valid successor/predecessor edges. for (Block* b : blocks) { auto checkEdge = [&] (const Edge* e) { assert(e->from() == b); edges.insert(e); for (auto& p : e->to()->preds()) if (&p == e) return; assert(false); // did not find edge. }; checkBlock(b); if (auto *e = b->nextEdge()) checkEdge(e); if (auto *e = b->takenEdge()) checkEdge(e); } for (Block* b : blocks) { for (DEBUG_ONLY auto const &e : b->preds()) { assert(&e == e.inst()->takenEdge() || &e == e.inst()->nextEdge()); assert(e.to() == b); } } // visit dom tree in preorder, checking all tmps auto const children = findDomChildren(unit, blocksIds); StateVector<SSATmp, bool> defined0(unit, false); forPreorderDoms(blocks.front(), children, defined0, [] (Block* block, StateVector<SSATmp, bool>& defined) { for (IRInstruction& inst : *block) { for (DEBUG_ONLY SSATmp* src : inst.srcs()) { assert(src->inst() != &inst); assert_log(src->inst()->op() == DefConst || defined[src], [&]{ return folly::format( "src '{}' in '{}' came from '{}', which is not a " "DefConst and is not defined at this use site", src->toString(), inst.toString(), src->inst()->toString()).str(); }); } for (SSATmp& dst : inst.dsts()) { assert(dst.inst() == &inst && inst.op() != DefConst); assert(!defined[dst]); defined[dst] = true; } } }); return true; }
void AgiEngine::changePos(VtEntry *v) { int b, x, y; int dx[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 }; int dy[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; x = v->xPos; y = v->yPos; b = checkBlock(x, y); x += v->stepSize * dx[v->direction]; y += v->stepSize * dy[v->direction]; if (checkBlock(x, y) == b) { v->flags &= ~MOTION; } else { v->flags |= MOTION; v->direction = 0; if (isEgoView(v)) _game.vars[vEgoDir] = 0; } }
void processBody(mafFileApi_t *mfa, char *seq, char strand) { // walk the body of the maf file and process it, block by block. mafBlock_t *thisBlock = NULL; thisBlock = maf_readBlock(mfa); // header block, unused maf_destroyMafBlockList(thisBlock); printHeader(); while((thisBlock = maf_readBlock(mfa)) != NULL) { checkBlock(thisBlock, seq, strand); maf_mafBlock_print(thisBlock); maf_destroyMafBlockList(thisBlock); } }
void AgiEngine::changePos(ScreenObjEntry *screenObj) { bool insideBlock; int16 x, y; int dx[9] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 }; int dy[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; x = screenObj->xPos; y = screenObj->yPos; insideBlock = checkBlock(x, y); x += screenObj->stepSize * dx[screenObj->direction]; y += screenObj->stepSize * dy[screenObj->direction]; if (checkBlock(x, y) == insideBlock) { screenObj->flags &= ~fMotion; } else { screenObj->flags |= fMotion; screenObj->direction = 0; if (isEgoView(screenObj)) setVar(VM_VAR_EGO_DIRECTION, 0); } }
/* * Build the CFG, then the dominator tree, then use it to validate SSA. * 1. Each src must be defined by some other instruction, and each dst must * be defined by the current instruction. * 2. Each src must be defined earlier in the same block or in a dominator. * 3. Each dst must not be previously defined. * 4. Treat tmps defined by DefConst as always defined. * 5. Each predecessor of a reachable block must be reachable (deleted * blocks must not have out-edges to reachable blocks). * 6. The entry block must not have any predecessors. * 7. The entry block starts with a DefFP instruction. */ bool checkCfg(const IRUnit& unit) { auto const blocksIds = rpoSortCfgWithIds(unit); auto const& blocks = blocksIds.blocks; jit::hash_set<const Edge*> edges; // Entry block can't have predecessors. always_assert(unit.entry()->numPreds() == 0); // Entry block starts with DefFP always_assert(!unit.entry()->empty() && unit.entry()->begin()->op() == DefFP); // Check valid successor/predecessor edges. for (Block* b : blocks) { auto checkEdge = [&] (const Edge* e) { always_assert(e->from() == b); edges.insert(e); for (auto& p : e->to()->preds()) if (&p == e) return; always_assert(false); // did not find edge. }; checkBlock(b); if (auto *e = b->nextEdge()) checkEdge(e); if (auto *e = b->takenEdge()) checkEdge(e); } for (Block* b : blocks) { for (auto const &e : b->preds()) { always_assert(&e == e.inst()->takenEdge() || &e == e.inst()->nextEdge()); always_assert(e.to() == b); } } // Visit every instruction and make sure their sources are defined in a block // that dominates the block containing the instruction. auto const idoms = findDominators(unit, blocksIds); forEachInst(blocks, [&] (const IRInstruction* inst) { for (auto src : inst->srcs()) { if (src->inst()->is(DefConst)) continue; auto const dom = findDefiningBlock(src); always_assert_flog( dom && dominates(dom, inst->block(), idoms), "src '{}' in '{}' came from '{}', which is not a " "DefConst and is not defined at this use site", src->toString(), inst->toString(), src->inst()->toString() ); } }); return true; }
void processBody(mafFileApi_t *mfa, char *seq, uint64_t start, uint64_t stop, bool isSoft) { mafBlock_t *thisBlock = NULL; bool printedHeader = false; uint64_t blockNumber = 0; while ((thisBlock = maf_readBlock(mfa)) != NULL) { checkBlock(thisBlock, blockNumber, seq, start, stop, &printedHeader, isSoft); maf_destroyMafBlockList(thisBlock); ++blockNumber; } if (!printedHeader) { // this makes the output valid even when no data was output printHeader(); } }
void Game::areDelayHandleEvent(const SDL_Event &event) { if (event.type == SDL_KEYUP){ SDLKey sym = event.key.keysym.sym; if (sym == playerData->moveLeft){ dropStatus = NORMAL; } else if (sym == playerData->moveRight){ dropStatus = NORMAL; } } if (event.type == SDL_KEYDOWN){ SDLKey sym = event.key.keysym.sym; if (sym == playerData->moveLeft){ dropStatus = ARRLEFT; } else if (sym == playerData->moveRight){ dropStatus = ARRRIGHT; } else if (sym == playerData->rotateLeft){ direction = Direction( direction == 3? 0: direction + 1); } else if (sym == playerData->rotateRight){ direction = Direction( direction == 0? 3: direction - 1); } else if (sym == playerData->hardDrop){ pos = getLockPos(); ResourceData::sound->playChunk(Sound::HARDDROP); if (!checkBlock(pos, direction)){ gameOver(); } else{ fillMap(); gameStatus = START; } } else if (sym == playerData->hold){ if (holdStatus == PREPAREHOLD){ ResourceData::sound->playChunk(Sound::HOLD); holdStatus = HOLD; gameStatus = START; } else{ ResourceData::sound->playChunk(Sound::HOLDFAIL); } } } }
/** * Check the heap for consistency. * HELPER FUNCTION * @param - int verbose */ void mm_checkheap(int verbose){ void *bp = heap_listp; if (verbose) { printf("Heap (%p):\n", heap_listp); } if (((GET_HSIZE(heap_listp)) != BLKSIZE) || !GET_HALLOC(heap_listp)){ printf("Bad prologue header\n"); } checkBlock(heap_listp); for (bp = listp; GET_HALLOC(bp) == 0; bp = NEXT_PTR(bp)) { if (verbose){ printBlock(bp); } checkBlock(bp); } if ((GET_HSIZE(bp) != 0) || !(GET_HALLOC(bp))){ printf("Bad epilogue header\n"); } }
void Game::areDelayUpdate() { show->mapShow(mapData); show->ghostShow(getLockPos(), shape, direction); if (areDelayTimer->checkTimeOut()){ if (!checkBlock(pos, direction)){ gameOver(); } else{ if (normalDropCounter != NULL) normalDropCounter->reset(); gameStatus = DROP; } } }