CBMC
boolbv_onehot.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
literalt
boolbvt::convert_onehot
(
const
unary_exprt
&expr)
13
{
14
PRECONDITION
(expr.
id
() == ID_onehot || expr.
id
() == ID_onehot0);
15
16
bvt
op=
convert_bv
(expr.
op
());
17
18
literalt
one_seen=
const_literal
(
false
);
19
literalt
more_than_one_seen=
const_literal
(
false
);
20
21
for
(bvt::const_iterator it=op.begin(); it!=op.end(); it++)
22
{
23
more_than_one_seen=
24
prop
.
lor
(more_than_one_seen,
prop
.
land
(*it, one_seen));
25
one_seen=
prop
.
lor
(*it, one_seen);
26
}
27
28
if
(expr.
id
()==ID_onehot)
29
return
prop
.
land
(one_seen, !more_than_one_seen);
30
else
31
{
32
INVARIANT
(
33
expr.
id
() == ID_onehot0,
34
"should be a onehot0 expression as other onehot expression kind has been "
35
"handled in other branch"
);
36
return
!more_than_one_seen;
37
}
38
}
bvt
std::vector< literalt > bvt
Definition:
literal.h:201
unary_exprt
Generic base class for unary expressions.
Definition:
std_expr.h:313
boolbvt::convert_onehot
virtual literalt convert_onehot(const unary_exprt &expr)
Definition:
boolbv_onehot.cpp:12
propt::lor
virtual literalt lor(literalt a, literalt b)=0
propt::land
virtual literalt land(literalt a, literalt b)=0
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition:
boolbv.cpp:39
PRECONDITION
#define PRECONDITION(CONDITION)
Definition:
invariant.h:463
const_literal
literalt const_literal(bool value)
Definition:
literal.h:188
irept::id
const irep_idt & id() const
Definition:
irep.h:396
unary_exprt::op
const exprt & op() const
Definition:
std_expr.h:326
literalt
Definition:
literal.h:25
boolbv.h
validation_modet::INVARIANT
@ INVARIANT
prop_conv_solvert::prop
propt & prop
Definition:
prop_conv_solver.h:130
src
solvers
flattening
boolbv_onehot.cpp
Generated by
1.8.17