CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boolbv_cond.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "boolbv.h"
10
11#include <util/invariant.h>
12
14{
15 const exprt::operandst &operands=expr.operands();
16
17 std::size_t width=boolbv_width(expr.type());
18
19 bvt bv;
20
21 DATA_INVARIANT(operands.size() >= 2, "cond must have at least two operands");
22
24 operands.size() % 2 == 0, "number of cond operands must be even");
25
26 if(prop.has_set_to())
27 {
28 bool condition=true;
31
32 // make it free variables
33 bv = prop.new_variables(width);
34
35 for(const auto &operand : expr.operands())
36 {
37 if(condition)
38 {
41
43 }
44 else
45 {
46 const bvt &op = convert_bv(operand, bv.size());
47
49
51 }
52
53 condition=!condition;
54 }
55 }
56 else
57 {
58 bv.resize(width);
59
60 // functional version -- go backwards
61 for(std::size_t i=expr.operands().size(); i!=0; i-=2)
62 {
64 i >= 2,
65 "since the number of operands is even if i is nonzero it must be "
66 "greater than two");
67 const exprt &cond=expr.operands()[i-2];
68 const exprt &value=expr.operands()[i-1];
69
71
72 const bvt &op = convert_bv(value, bv.size());
73
74 for(std::size_t j = 0; j < bv.size(); j++)
75 bv[j] = prop.lselect(cond_literal, op[j], bv[j]);
76 }
77 }
78
79 return bv;
80}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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:39
virtual bvt convert_cond(const cond_exprt &)
bv_utilst bv_utils
Definition boolbv.h:118
virtual std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:103
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
this is a parametric version of an if-expression: it returns the value of the first case (using the o...
Definition std_expr.h:3477
Base class for all expressions.
Definition expr.h:56
std::vector< exprt > operandst
Definition expr.h:58
typet & type()
Return the type of the expression.
Definition expr.h:84
operandst & operands()
Definition expr.h:94
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
void l_set_to_true(literalt a)
Definition prop.h:52
virtual literalt land(literalt a, literalt b)=0
virtual literalt limplies(literalt a, literalt b)=0
virtual literalt lselect(literalt a, literalt b, literalt c)=0
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
Definition prop.cpp:30
virtual literalt lor(literalt a, literalt b)=0
virtual bool has_set_to() const
Definition prop.h:81
std::vector< literalt > bvt
Definition literal.h:201
literalt const_literal(bool value)
Definition literal.h:188
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423