示例#1
0
__uint Z3Result::getUintValue(void) const {
  __uint result = 0;

  if (!this->expr.is_int())
    throw std::runtime_error("getUintValue: The ast is not a numerical value");

  #if defined(__x86_64__) || defined(_M_X64)
  Z3_get_numeral_uint64(this->context, this->expr, &result);
  #endif
  #if defined(__i386) || defined(_M_IX86)
  Z3_get_numeral_uint(this->context, this->expr, &result);
  #endif

  return result;
}
示例#2
0
void Z3BaseSolverImpl::extractModel(const std::vector<const Array*> &objects,
        std::vector<std::vector<unsigned char> > &values) {
    z3::model model = solver_.get_model();

#if 0 // TODO: Turn into proper debug logging
    std::stringstream model_ss;
    model_ss << solver_ << '\n';
    model_ss << model; model_ss.flush();
    errs() << "[Z3][Debug] Model: " << '\n' << model_ss.str() << '\n';
#endif

    values.reserve(objects.size());
    for (std::vector<const Array*>::const_iterator it = objects.begin(),
            ie = objects.end(); it != ie; ++it) {
        const Array *array = *it;
        std::vector<unsigned char> data;

#if 0 // TODO: Turn into proper debug logging
        errs() << "[Z3][Debug] Array name: " << array->name << '\n';
#endif

        data.reserve(array->size);
        for (unsigned offset = 0; offset < array->size; ++offset) {
            z3::expr value_ast = model.eval(
                    builder_->getInitialRead(array, offset), true);
            unsigned value_num;

#if 0 // TODO: Turn into proper debug logging
            std::stringstream ss;
            ss << builder_->getInitialRead(array, offset) << " // " << value_ast; ss.flush();
            errs() << "[Z3][Debug] Initial read eval: " << ss.str() << '\n';
#endif

            Z3_bool conv_result = Z3_get_numeral_uint(context_, value_ast,
                    &value_num);
            assert(conv_result == Z3_TRUE && "Could not convert value");
            assert(value_num < (1 << 8*sizeof(unsigned char))
                    && "Invalid model value");

            data.push_back((unsigned char)value_num);
        }
        values.push_back(data);
    }
}