uint32_t parser_r(char **tokens, struct Table *table){ uint32_t opcode = getValue(tokens[0],table)<<26; uint32_t reg1Opcode = (checkRegister(tokens[1])) ? getRegisterNumber(tokens[1]) <<21 : 0; uint32_t reg2Opcode = (checkRegister(tokens[2])) ? getRegisterNumber(tokens[2]) <<16 : 0; uint32_t reg3Opcode = (checkRegister(tokens[3])) ? getRegisterNumber(tokens[3]) <<11 : 0; return (opcode + reg1Opcode + reg2Opcode + reg3Opcode); }
int checkAllRegistersAreValid(char **regs) { while (*regs) { if (!checkRegister(*regs) || !checkIfNumber(*regs+1) || getRegisterNumber(*regs) <0 || getRegisterNumber(*regs) >= NUMBER_OF_REGISTERS) { return 0; } regs++; } return 1; }
/* Ensure a Condition is met */ bool Test::checkConditions(ppc::Interpreter::State &state, std::vector<Test::Condition> &conds) { for (auto &cond : conds) { switch (cond.type) { case ConditionType::SetRegister: if (cond.target.type != ValueType::Register) { return false; } if (!setRegister(state, cond.target.name, cond.value)) { throw new TestError(state, "Could not set register %s", cond.target.name.c_str()); } break; case ConditionType::CheckRegister: if (cond.target.type != ValueType::Register) { return false; } if (!checkRegister(state, cond.target.name, cond.value)) { throw new TestError(state, "Incorrect value in register %s", cond.target.name.c_str()); } break; case ConditionType::SetMemory: if (cond.target.type != ValueType::Address) { return false; } if (!setMemory(state, cond.target.value, cond.value)) { throw new TestError(state, "Could not set memory at 0x%X", translateAddress(cond.target.value)); } break; case ConditionType::CheckMemory: if (cond.target.type != ValueType::Address) { return false; } if (!checkMemory(state, cond.target.value, cond.value)) { throw new TestError(state, "Incorrect value at memory location 0x%X", translateAddress(cond.target.value)); } break; } } return true; }