// Call, Assert, Branch void Executor::ExecuteInst1(Instruction *i, Value *val) { assert(i && "Expecting an instruction!"); assert(val && "Expecting a value!"); assert(status==START && "Wrong status for Executor (!=START)!"); ExprPtr expr = NULL; switch (i->getOpcode()) { case Instruction::GetElementPtr: //executeGep(i); if (!DisabledSymbolicExe) { expr = PathEncoder->encode(cast<GetElementPtrInst>(i)); } break; case Instruction::Store: executeStore(i, val); if (!DisabledSymbolicExe) { expr = PathEncoder->encode(cast<StoreInst>(i)); } break; case Instruction::Load: executeLoad(i, val); if (!DisabledSymbolicExe) { expr = PathEncoder->encode(cast<LoadInst>(i), PathFormula); } break; case Instruction::PHI: executePhi(i); if (!DisabledSymbolicExe) { expr = PathEncoder->encode(cast<PHINode>(i), LastExecutedBB); } break; case Instruction::Br: { ConstantInt *CI = dyn_cast<ConstantInt>(val); assert(CI && "Unsupported value!"); const bool cond = CI->getSExtValue(); executeBranch(i, cond); } break; // TODO case Instruction::Call: executeCall(i, 0, 0); break; default: assert("test-executor"); } if (expr && !DisabledSymbolicExeCurRun) { expr->setHard(); PathFormula->add(expr); } }
void CPU::step() { ++m_cycles; if (m_skipCycles-- > 1) return; m_skipCycles = 0; int psw = f_N << 7 | f_V << 6 | 1 << 5 | f_D << 3 | f_I << 2 | f_Z << 1 | f_C; LOG_CPU << std::hex << std::setfill('0') << std::uppercase << std::setw(4) << +r_PC << " " << std::setw(2) << +m_bus.read(r_PC) << " " << "A:" << std::setw(2) << +r_A << " " << "X:" << std::setw(2) << +r_X << " " << "Y:" << std::setw(2) << +r_Y << " " << "P:" << std::setw(2) << psw << " " << "SP:" << std::setw(2) << +r_SP << /*std::endl;*/" " << "CYC:" << std::setw(3) << std::setfill(' ') << std::dec << ((m_cycles - 1) * 3) % 341 << std::endl; Byte opcode = m_bus.read(r_PC++); auto CycleLength = OperationCycles[opcode]; //Using short-circuit evaluation, call the other function only if the first failed //ExecuteImplied must be called first and ExecuteBranch must be before ExecuteType0 if (CycleLength && (executeImplied(opcode) || executeBranch(opcode) || executeType1(opcode) || executeType2(opcode) || executeType0(opcode))) { m_skipCycles += CycleLength; //m_cycles %= 340; //compatibility with Nintendulator log //m_skipCycles = 0; //for TESTING } else { LOG(Error) << "Unrecognized opcode: " << std::hex << +opcode << std::endl; } }