cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_constraint_select_one.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
10
#include "
boolbv.h
"
11
12
bvt
boolbvt::convert_constraint_select_one
(
const
exprt
&expr)
13
{
14
const
exprt::operandst
&operands=expr.
operands
();
15
16
if
(expr.
id
()!=ID_constraint_select_one)
17
throw
"expected constraint_select_one expression"
;
18
19
if
(operands.empty())
20
throw
"constraint_select_one takes at least one operand"
;
21
22
if
(expr.
type
() !=
to_multi_ary_expr
(expr).op0().type())
23
throw
"constraint_select_one expects matching types"
;
24
25
bvt
bv;
26
27
if
(
prop
.has_set_to())
28
{
29
std::size_t width=
boolbv_width
(expr.
type
());
30
bv=
prop
.new_variables(width);
31
32
bvt
b;
33
b.reserve(expr.
operands
().size());
34
35
// add constraints
36
for
(
const
auto
&op : expr.
operands
())
37
{
38
bvt
it_bv =
convert_bv
(op);
39
40
if
(it_bv.size()!=bv.size())
41
throw
"constraint_select_one expects matching width"
;
42
43
b.push_back(
bv_utils
.equal(bv, it_bv));
44
}
45
46
prop
.lcnf(b);
47
}
48
else
49
{
50
std::size_t op_nr=0;
51
for
(
const
auto
&op : expr.
operands
())
52
{
53
const
bvt
&op_bv =
convert_bv
(op);
54
55
if
(op_nr==0)
56
bv=op_bv;
57
else
58
{
59
if
(op_bv.size()!=bv.size())
60
return
conversion_failed
(expr);
61
62
for
(std::size_t i=0; i<op_bv.size(); i++)
63
bv[i]=
prop
.lselect(
prop
.new_variable(), bv[i], op_bv[i]);
64
}
65
66
op_nr++;
67
}
68
}
69
70
return
bv;
71
}
boolbv.h
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition
boolbv.cpp:40
boolbvt::convert_constraint_select_one
virtual bvt convert_constraint_select_one(const exprt &expr)
Definition
boolbv_constraint_select_one.cpp:12
boolbvt::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
boolbvt::conversion_failed
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
Definition
boolbv.cpp:95
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition
boolbv.h:106
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::operandst
std::vector< exprt > operandst
Definition
expr.h:59
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
irept::id
const irep_idt & id() const
Definition
irep.h:388
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
bvt
std::vector< literalt > bvt
Definition
literal.h:201
to_multi_ary_expr
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
Definition
std_expr.h:981
solvers
flattening
boolbv_constraint_select_one.cpp
Generated by
1.17.0