CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boolbv_case.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 PRECONDITION(expr.id() == ID_case);
16
17 const std::vector<exprt> &operands=expr.operands();
18
19 std::size_t width=boolbv_width(expr.type());
20
21 // make it free variables
22 bvt bv = prop.new_variables(width);
23
25 operands.size() >= 3, "case should have at least three operands");
26
28 operands.size() % 2 == 1, "number of case operands should be odd");
29
30 enum { FIRST, COMPARE, VALUE } what=FIRST;
34
35 for(const auto &operand : expr.operands())
36 {
38
39 switch(what)
40 {
41 case FIRST:
42 compare_bv.swap(op);
43 what=COMPARE;
44 break;
45
46 case COMPARE:
48 compare_bv.size() == op.size(),
49 std::string("size of compare operand does not match:\n") +
50 "compare operand: " + std::to_string(compare_bv.size()) +
51 "\noperand: " + std::to_string(op.size()) + '\n' + operand.pretty());
52
55
57
58 what=VALUE;
59 break;
60
61 case VALUE:
63 bv.size() == op.size(),
64 std::string("size of value operand does not match:\n") +
65 "result size: " + std::to_string(bv.size()) +
66 "\noperand: " + std::to_string(op.size()) + '\n' + operand.pretty());
67
68 {
70
73 }
74
75 what=COMPARE;
76 break;
77
78 default:
80 }
81 }
82
83 return bv;
84}
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
bv_utilst bv_utils
Definition boolbv.h:118
virtual std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:103
virtual bvt convert_case(const exprt &expr)
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
Base class for all expressions.
Definition expr.h:56
typet & type()
Return the type of the expression.
Definition expr.h:84
operandst & operands()
Definition expr.h:94
const irep_idt & id() const
Definition irep.h:388
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 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
std::vector< literalt > bvt
Definition literal.h:201
literalt const_literal(bool value)
Definition literal.h:188
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
#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 PRECONDITION(CONDITION)
Definition invariant.h:463