CBMC
Loading...
Searching...
No Matches
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 <util/invariant.h>
10#include <util/std_expr.h>
11
12#include "boolbv.h"
13
15{
16 const std::vector<exprt> &operands=expr.operands();
17
18 std::size_t width=boolbv_width(expr.type());
19
20 // make it free variables
21 bvt bv = prop.new_variables(width);
22
24 operands.size() >= 3, "case should have at least three operands");
25
27 operands.size() % 2 == 1, "number of case operands should be odd");
28
29 enum { FIRST, COMPARE, VALUE } what=FIRST;
33
34 for(const auto &operand : expr.operands())
35 {
37
38 switch(what)
39 {
40 case FIRST:
41 compare_bv.swap(op);
42 what=COMPARE;
43 break;
44
45 case COMPARE:
47 compare_bv.size() == op.size(),
48 std::string("size of compare operand does not match:\n") +
49 "compare operand: " + std::to_string(compare_bv.size()) +
50 "\noperand: " + std::to_string(op.size()) + '\n' + operand.pretty());
51
54
56
57 what=VALUE;
58 break;
59
60 case VALUE:
62 bv.size() == op.size(),
63 std::string("size of value operand does not match:\n") +
64 "result size: " + std::to_string(bv.size()) +
65 "\noperand: " + std::to_string(op.size()) + '\n' + operand.pretty());
66
67 {
69
72 }
73
74 what=COMPARE;
75 break;
76
77 default:
79 }
80 }
81
82 return bv;
83}
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_case(const case_exprt &)
bv_utilst bv_utils
Definition boolbv.h:119
virtual std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:104
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
Case expression: evaluates to the value corresponding to the first matching case.
Definition std_expr.h:3612
typet & type()
Return the type of the expression.
Definition expr.h:85
operandst & operands()
Definition expr.h:95
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
API to expression classes.