本文整理汇总了C++中bvt::size方法的典型用法代码示例。如果您正苦于以下问题:C++ bvt::size方法的具体用法?C++ bvt::size怎么用?C++ bvt::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bvt
的用法示例。
在下文中一共展示了bvt::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
literalt smt1_propt::lxor(const bvt &bv)
{
if(bv.size()==0) return const_literal(false);
if(bv.size()==1) return bv[0];
out << std::endl;
literalt l=new_variable();
out << ":assumption ; lxor" << std::endl;
out << " (iff " << smt1_literal(l) << " (xor";
forall_literals(it, bv)
out << " " << smt1_literal(*it);
out << "))" << std::endl;
return l;
}
示例2: extension
bvt bv_utilst::extension(
const bvt &bv,
std::size_t new_size,
representationt rep)
{
std::size_t old_size=bv.size();
bvt result=bv;
result.resize(new_size);
assert(old_size!=0);
literalt extend_with=
(rep==SIGNED && !bv.empty())?bv[old_size-1]:
const_literal(false);
for(std::size_t i=old_size; i<new_size; i++)
result[i]=extend_with;
return result;
}
示例3: convert_update
void boolbvt::convert_update(const exprt &expr, bvt &bv)
{
const exprt::operandst &ops=expr.operands();
if(ops.size()!=3)
throw "update takes at three operands";
std::size_t width=boolbv_width(expr.type());
if(width==0)
return conversion_failed(expr, bv);
bv=convert_bv(ops[0]);
if(bv.size()!=width)
throw "update: unexpected operand 0 width";
// start the recursion
convert_update_rec(
expr.op1().operands(), 0, expr.type(), 0, expr.op2(), bv);
}
示例4: assert
bool z3_propt::process_clause(const bvt &bv, bvt &dest)
{
dest.clear();
// empty clause! this is UNSAT
if(bv.empty()) return false;
std::set<literalt> s;
dest.reserve(bv.size());
for(bvt::const_iterator it=bv.begin();
it!=bv.end();
it++)
{
literalt l=*it;
// we never use index 0
assert(l.var_no()!=0);
if(l.is_true())
return true; // clause satisfied
if(l.is_false())
continue;
if(l.var_no()>=_no_variables)
std::cout << "l.var_no()=" << l.var_no() << " _no_variables=" << _no_variables << std::endl;
assert(l.var_no()<_no_variables);
// prevent duplicate literals
if(s.insert(l).second)
dest.push_back(l);
if(s.find(lnot(l))!=s.end())
return true; // clause satisfied
}
return false;
}
示例5: if
void smt1_propt::lcnf(const bvt &bv)
{
out << std::endl;
out << ":assumption ; lcnf" << std::endl;
out << " ";
if(bv.empty())
out << "false ; the empty clause";
else if(bv.size()==1)
out << smt1_literal(bv.front());
else
{
out << "(or";
for(bvt::const_iterator it=bv.begin(); it!=bv.end(); it++)
out << " " << smt1_literal(*it);
out << ")";
}
out << std::endl;
}
示例6: write_dimacs_clause
static void write_dimacs_clause(
const bvt &clause,
std::ostream &out,
bool break_lines)
{
// The DIMACS CNF format allows line breaks in clauses:
// "Each clauses is terminated by the value 0. Unlike many formats
// that represent the end of a clause by a new-line character,
// this format allows clauses to be on multiple lines."
// Some historic solvers (zchaff e.g.) have silently swallowed
// literals in clauses that exceed some fixed buffer size.
// However, the SAT competition format does not allow line
// breaks in clauses, so we offer both options.
for(size_t j=0; j<clause.size(); j++)
{
out << clause[j].dimacs() << " ";
// newline to avoid overflow in sat checkers
if((j&15)==0 && j!=0 && break_lines) out << "\n";
}
out << "0" << "\n";
}
示例7: convert_union
void boolbvt::convert_union(const exprt &expr, bvt &bv)
{
unsigned width=boolbv_width(expr.type());
if(width==0)
return conversion_failed(expr, bv);
if(expr.operands().size()!=1)
throw "union expects one argument";
const bvt &op_bv=convert_bv(expr.op0());
if(width<op_bv.size())
throw "union: unexpected operand op width";
bv.resize(width);
for(unsigned i=0; i<op_bv.size(); i++)
bv[i]=op_bv[i];
// pad with nondets
for(unsigned i=op_bv.size(); i<bv.size(); i++)
bv[i]=prop.new_variable();
}
示例8: overflow_sub
literalt bv_utilst::overflow_sub(
const bvt &op0, const bvt &op1, representationt rep)
{
if(rep==SIGNED)
{
// We special-case x-INT_MIN, which is >=0 if
// x is negative, always representable, and
// thus not an overflow.
literalt op1_is_int_min=is_int_min(op1);
literalt op0_is_negative=op0[op0.size()-1];
return
prop.lselect(op1_is_int_min,
!op0_is_negative,
overflow_add(op0, negate(op1), SIGNED));
}
else if(rep==UNSIGNED)
{
// overflow is simply _negated_ carry-out
return !carry_out(op0, inverted(op1), const_literal(true));
}
else
assert(false);
}
示例9: get_value
mp_integer boolbvt::get_value(
const bvt &bv,
unsigned offset,
unsigned width)
{
mp_integer value=0;
mp_integer weight=1;
for(unsigned bit_nr=offset; bit_nr<offset+width; bit_nr++)
{
assert(bit_nr<bv.size());
switch(prop.l_get(bv[bit_nr]).get_value())
{
case tvt::TV_FALSE: break;
case tvt::TV_TRUE: value+=weight; break;
case tvt::TV_UNKNOWN: break;
default: assert(false);
}
weight*=2;
}
return value;
}
示例10: convert_add_sub
void boolbvt::convert_add_sub(const exprt &expr, bvt &bv)
{
const typet &type=ns.follow(expr.type());
if(type.id()!=ID_unsignedbv &&
type.id()!=ID_signedbv &&
type.id()!=ID_fixedbv &&
type.id()!=ID_floatbv &&
type.id()!=ID_range &&
type.id()!=ID_vector)
return conversion_failed(expr, bv);
unsigned width=boolbv_width(type);
if(width==0)
return conversion_failed(expr, bv);
const exprt::operandst &operands=expr.operands();
if(operands.size()==0)
throw "operand "+expr.id_string()+" takes at least one operand";
const exprt &op0=expr.op0();
if(op0.type()!=type)
{
std::cerr << expr.pretty() << std::endl;
throw "add/sub with mixed types";
}
convert_bv(op0, bv);
if(bv.size()!=width)
throw "convert_add_sub: unexpected operand 0 width";
bool subtract=(expr.id()==ID_minus ||
expr.id()=="no-overflow-minus");
bool no_overflow=(expr.id()=="no-overflow-plus" ||
expr.id()=="no-overflow-minus");
typet arithmetic_type=
(type.id()==ID_vector)?ns.follow(type.subtype()):type;
bv_utilst::representationt rep=
(arithmetic_type.id()==ID_signedbv ||
arithmetic_type.id()==ID_fixedbv)?bv_utilst::SIGNED:
bv_utilst::UNSIGNED;
for(exprt::operandst::const_iterator
it=operands.begin()+1;
it!=operands.end(); it++)
{
if(it->type()!=type)
{
std::cerr << expr.pretty() << std::endl;
throw "add/sub with mixed types";
}
bvt op;
convert_bv(*it, op);
if(op.size()!=width)
throw "convert_add_sub: unexpected operand width";
if(type.id()==ID_vector)
{
const typet &subtype=ns.follow(type.subtype());
unsigned sub_width=boolbv_width(subtype);
if(sub_width==0 || width%sub_width!=0)
throw "convert_add_sub: unexpected vector operand width";
unsigned size=width/sub_width;
bv.resize(width);
for(unsigned i=0; i<size; i++)
{
bvt tmp_op;
tmp_op.resize(sub_width);
for(unsigned j=0; j<tmp_op.size(); j++)
{
assert(i*sub_width+j<op.size());
tmp_op[j]=op[i*sub_width+j];
}
bvt tmp_result;
tmp_result.resize(sub_width);
for(unsigned j=0; j<tmp_result.size(); j++)
{
assert(i*sub_width+j<bv.size());
tmp_result[j]=bv[i*sub_width+j];
}
if(type.subtype().id()==ID_floatbv)
{
#ifdef HAVE_FLOATBV
//.........这里部分代码省略.........
示例11: type_conversion
bool boolbvt::type_conversion(
const typet &src_type, const bvt &src,
const typet &dest_type, bvt &dest)
{
bvtypet dest_bvtype=get_bvtype(dest_type);
bvtypet src_bvtype=get_bvtype(src_type);
if(src_bvtype==IS_C_BIT_FIELD)
return type_conversion(
c_bit_field_replacement_type(to_c_bit_field_type(src_type), ns), src, dest_type, dest);
if(dest_bvtype==IS_C_BIT_FIELD)
return type_conversion(
src_type, src, c_bit_field_replacement_type(to_c_bit_field_type(dest_type), ns), dest);
std::size_t src_width=src.size();
std::size_t dest_width=boolbv_width(dest_type);
if(dest_width==0 || src_width==0)
return true;
dest.clear();
dest.reserve(dest_width);
if(dest_type.id()==ID_complex)
{
if(src_type==dest_type.subtype())
{
forall_literals(it, src)
dest.push_back(*it);
// pad with zeros
for(std::size_t i=src.size(); i<dest_width; i++)
dest.push_back(const_literal(false));
return false;
}
else if(src_type.id()==ID_complex)
{
// recursively do both halfs
bvt lower, upper, lower_res, upper_res;
lower.assign(src.begin(), src.begin()+src.size()/2);
upper.assign(src.begin()+src.size()/2, src.end());
type_conversion(ns.follow(src_type.subtype()), lower, ns.follow(dest_type.subtype()), lower_res);
type_conversion(ns.follow(src_type.subtype()), upper, ns.follow(dest_type.subtype()), upper_res);
assert(lower_res.size()+upper_res.size()==dest_width);
dest=lower_res;
dest.insert(dest.end(), upper_res.begin(), upper_res.end());
return false;
}
}
if(src_type.id()==ID_complex)
{
assert(dest_type.id()!=ID_complex);
if(dest_type.id()==ID_signedbv ||
dest_type.id()==ID_unsignedbv ||
dest_type.id()==ID_floatbv ||
dest_type.id()==ID_fixedbv ||
dest_type.id()==ID_c_enum ||
dest_type.id()==ID_c_enum_tag ||
dest_type.id()==ID_bool)
{
// A cast from complex x to real T
// is (T) __real__ x.
bvt tmp_src(src);
tmp_src.resize(src.size()/2); // cut off imag part
return type_conversion(src_type.subtype(), tmp_src, dest_type, dest);
}
}
switch(dest_bvtype)
{
case IS_RANGE:
if(src_bvtype==IS_UNSIGNED ||
src_bvtype==IS_SIGNED ||
src_bvtype==IS_C_BOOL)
{
mp_integer dest_from=to_range_type(dest_type).get_from();
if(dest_from==0)
{
// do zero extension
dest.resize(dest_width);
for(std::size_t i=0; i<dest.size(); i++)
dest[i]=(i<src.size()?src[i]:const_literal(false));
return false;
}
}
else if(src_bvtype==IS_RANGE) // range to range
{
mp_integer src_from=to_range_type(src_type).get_from();
mp_integer dest_from=to_range_type(dest_type).get_from();
if(dest_from==src_from)
{
// do zero extension, if needed
dest=bv_utils.zero_extension(src, dest_width);
return false;
//.........这里部分代码省略.........
示例12: convert_unary_minus
void boolbvt::convert_unary_minus(const exprt &expr, bvt &bv)
{
const typet &type=ns.follow(expr.type());
unsigned width=boolbv_width(type);
if(width==0)
return conversion_failed(expr, bv);
const exprt::operandst &operands=expr.operands();
if(operands.size()!=1)
throw "unary minus takes one operand";
const exprt &op0=expr.op0();
const bvt &op_bv=convert_bv(op0);
bvtypet bvtype=get_bvtype(type);
bvtypet op_bvtype=get_bvtype(op0.type());
unsigned op_width=op_bv.size();
bool no_overflow=(expr.id()=="no-overflow-unary-minus");
if(op_width==0 || op_width!=width)
return conversion_failed(expr, bv);
if(bvtype==IS_UNKNOWN &&
(type.id()==ID_vector || type.id()==ID_complex))
{
const typet &subtype=ns.follow(type.subtype());
unsigned sub_width=boolbv_width(subtype);
if(sub_width==0 || width%sub_width!=0)
throw "unary-: unexpected vector operand width";
unsigned size=width/sub_width;
bv.resize(width);
for(unsigned i=0; i<size; i++)
{
bvt tmp_op;
tmp_op.resize(sub_width);
for(unsigned j=0; j<tmp_op.size(); j++)
{
assert(i*sub_width+j<op_bv.size());
tmp_op[j]=op_bv[i*sub_width+j];
}
bvt tmp_result;
if(type.subtype().id()==ID_floatbv)
{
float_utilst float_utils(prop);
float_utils.spec=to_floatbv_type(subtype);
tmp_result=float_utils.negate(tmp_op);
}
else
tmp_result=bv_utils.negate(tmp_op);
assert(tmp_result.size()==sub_width);
for(unsigned j=0; j<tmp_result.size(); j++)
{
assert(i*sub_width+j<bv.size());
bv[i*sub_width+j]=tmp_result[j];
}
}
return;
}
else if(bvtype==IS_FIXED && op_bvtype==IS_FIXED)
{
if(no_overflow)
bv=bv_utils.negate_no_overflow(op_bv);
else
bv=bv_utils.negate(op_bv);
return;
}
else if(bvtype==IS_FLOAT && op_bvtype==IS_FLOAT)
{
assert(!no_overflow);
float_utilst float_utils(prop);
float_utils.spec=to_floatbv_type(expr.type());
bv=float_utils.negate(op_bv);
return;
}
else if((op_bvtype==IS_SIGNED || op_bvtype==IS_UNSIGNED) &&
(bvtype==IS_SIGNED || bvtype==IS_UNSIGNED))
{
if(no_overflow)
prop.l_set_to(bv_utils.overflow_negate(op_bv), false);
if(no_overflow)
bv=bv_utils.negate_no_overflow(op_bv);
else
bv=bv_utils.negate(op_bv);
//.........这里部分代码省略.........
示例13: convert_constraint_select_one
void boolbvt::convert_constraint_select_one(const exprt &expr, bvt &bv)
{
const exprt::operandst &operands=expr.operands();
if(expr.id()!="constraint_select_one")
throw "expected constraint_select_one expression";
if(operands.size()<2)
throw "constraint_select_one takes at least two operands";
if(expr.type()!=expr.op0().type())
throw "constraint_select_one expects matching types";
if(prop.has_set_to())
{
std::vector<bvt> op_bv;
op_bv.reserve(expr.operands().size());
forall_operands(it, expr)
op_bv.push_back(convert_bv(*it));
bv=op_bv[0];
// add constraints
bvt equal_bv;
equal_bv.resize(bv.size());
bvt b;
b.reserve(op_bv.size()-1);
for(unsigned i=1; i<op_bv.size(); i++)
{
if(op_bv[i].size()!=bv.size())
throw "constraint_select_one expects matching width";
for(unsigned j=0; j<bv.size(); j++)
equal_bv[j]=prop.lequal(bv[j], op_bv[i][j]);
b.push_back(prop.land(equal_bv));
}
prop.l_set_to_true(prop.lor(b));
}
else
{
unsigned op_nr=0;
forall_operands(it, expr)
{
const bvt &op_bv=convert_bv(*it);
if(op_nr==0)
bv=op_bv;
else
{
if(op_bv.size()!=bv.size())
return conversion_failed(expr, bv);
for(unsigned i=0; i<op_bv.size(); i++)
bv[i]=prop.lselect(prop.new_variable(), bv[i], op_bv[i]);
}
op_nr++;
}
}
}
示例14: convert_case
void boolbvt::convert_case(const exprt &expr, bvt &bv)
{
const std::vector<exprt> &operands=expr.operands();
unsigned width=boolbv_width(expr.type());
if(width==0)
return conversion_failed(expr, bv);
bv.resize(width);
// make it free variables
Forall_literals(it, bv)
*it=prop.new_variable();
if(operands.size()<3)
throw "case takes at least three operands";
if((operands.size()%2)!=1)
throw "number of case operands must be odd";
enum { FIRST, COMPARE, VALUE } what=FIRST;
bvt compare_bv;
literalt previous_compare=const_literal(false);
literalt compare_literal=const_literal(false);
forall_operands(it, expr)
{
bvt op=convert_bv(*it);
switch(what)
{
case FIRST:
compare_bv.swap(op);
what=COMPARE;
break;
case COMPARE:
if(compare_bv.size()!=op.size())
{
std::cerr << "compare operand: " << compare_bv.size()
<< std::endl
<< "operand: " << op.size() << std::endl
<< it->pretty()
<< std::endl;
throw "size of compare operand does not match";
}
compare_literal=bv_utils.equal(compare_bv, op);
compare_literal=prop.land(prop.lnot(previous_compare),
compare_literal);
previous_compare=prop.lor(previous_compare, compare_literal);
what=VALUE;
break;
case VALUE:
if(bv.size()!=op.size())
{
std::cerr << "result size: " << bv.size()
<< std::endl
<< "operand: " << op.size() << std::endl
<< it->pretty()
<< std::endl;
throw "size of value operand does not match";
}
{
literalt value_literal=bv_utils.equal(bv, op);
prop.l_set_to_true(
prop.limplies(compare_literal, value_literal));
}
what=COMPARE;
break;
default:
assert(false);
}
}
示例15: convert_floatbv_op
void boolbvt::convert_floatbv_op(const exprt &expr, bvt &bv)
{
const exprt::operandst &operands=expr.operands();
if(operands.size()!=3)
throw "operator "+expr.id_string()+" takes three operands";
const exprt &op0=expr.op0(); // first operand
const exprt &op1=expr.op1(); // second operand
const exprt &op2=expr.op2(); // rounding mode
bvt bv0=convert_bv(op0);
bvt bv1=convert_bv(op1);
bvt bv2=convert_bv(op2);
const typet &type=ns.follow(expr.type());
if(op0.type()!=type || op1.type()!=type)
{
std::cerr << expr.pretty() << std::endl;
throw "float op with mixed types";
}
float_utilst float_utils(prop);
float_utils.set_rounding_mode(bv2);
if(type.id()==ID_floatbv)
{
float_utils.spec=to_floatbv_type(expr.type());
if(expr.id()==ID_floatbv_plus)
bv=float_utils.add_sub(bv0, bv1, false);
else if(expr.id()==ID_floatbv_minus)
bv=float_utils.add_sub(bv0, bv1, true);
else if(expr.id()==ID_floatbv_mult)
bv=float_utils.mul(bv0, bv1);
else if(expr.id()==ID_floatbv_div)
bv=float_utils.div(bv0, bv1);
else if(expr.id()==ID_floatbv_rem)
bv=float_utils.rem(bv0, bv1);
else
assert(false);
}
else if(type.id()==ID_vector || type.id()==ID_complex)
{
const typet &subtype=ns.follow(type.subtype());
if(subtype.id()==ID_floatbv)
{
float_utils.spec=to_floatbv_type(subtype);
std::size_t width=boolbv_width(type);
std::size_t sub_width=boolbv_width(subtype);
if(sub_width==0 || width%sub_width!=0)
throw "convert_floatbv_op: unexpected vector operand width";
std::size_t size=width/sub_width;
bv.resize(width);
for(std::size_t i=0; i<size; i++)
{
bvt tmp_bv0, tmp_bv1, tmp_bv;
tmp_bv0.assign(bv0.begin()+i*sub_width, bv0.begin()+(i+1)*sub_width);
tmp_bv1.assign(bv1.begin()+i*sub_width, bv1.begin()+(i+1)*sub_width);
if(expr.id()==ID_floatbv_plus)
tmp_bv=float_utils.add_sub(tmp_bv0, tmp_bv1, false);
else if(expr.id()==ID_floatbv_minus)
tmp_bv=float_utils.add_sub(tmp_bv0, tmp_bv1, true);
else if(expr.id()==ID_floatbv_mult)
tmp_bv=float_utils.mul(tmp_bv0, tmp_bv1);
else if(expr.id()==ID_floatbv_div)
tmp_bv=float_utils.div(tmp_bv0, tmp_bv1);
else
assert(false);
assert(tmp_bv.size()==sub_width);
assert(i*sub_width+sub_width-1<bv.size());
std::copy(tmp_bv.begin(), tmp_bv.end(), bv.begin()+i*sub_width);
}
}
else
return conversion_failed(expr, bv);
}
else
return conversion_failed(expr, bv);
}