cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_equality.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include <
util/byte_operators.h
>
10
#include <
util/invariant.h
>
11
#include <
util/std_expr.h
>
12
13
#include "
boolbv.h
"
14
15
literalt
boolbvt::convert_equality
(
const
equal_exprt
&expr)
16
{
17
const
bool
equality_types_match = expr.
lhs
().
type
() == expr.
rhs
().
type
();
18
DATA_INVARIANT_WITH_DIAGNOSTICS
(
19
equality_types_match,
20
"types of expressions on each side of equality should match"
,
21
irep_pretty_diagnosticst
{expr.
lhs
()},
22
irep_pretty_diagnosticst
{expr.
rhs
()});
23
24
// see if it is an unbounded array
25
if
(
is_unbounded_array
(expr.
lhs
().
type
()))
26
{
27
// flatten byte_update/byte_extract operators if needed
28
29
if
(
has_byte_operator
(expr))
30
{
31
return
record_array_equality
(
32
to_equal_expr
(
lower_byte_operators
(expr,
ns
)));
33
}
34
35
return
record_array_equality
(expr);
36
}
37
38
const
bvt
&lhs_bv =
convert_bv
(expr.
lhs
());
39
const
bvt
&rhs_bv =
convert_bv
(expr.
rhs
());
40
41
DATA_INVARIANT_WITH_DIAGNOSTICS
(
42
lhs_bv.size() == rhs_bv.size(),
43
"sizes of lhs and rhs bitvectors should match"
,
44
irep_pretty_diagnosticst
{expr.lhs()},
45
"lhs size: "
+ std::to_string(lhs_bv.size()),
46
irep_pretty_diagnosticst
{expr.rhs()},
47
"rhs size: "
+ std::to_string(rhs_bv.size()));
48
49
if
(lhs_bv.empty())
50
{
51
// An empty bit-vector comparison. It's not clear
52
// what this is meant to say.
53
return
prop
.new_variable();
54
}
55
56
return
bv_utils
.equal(lhs_bv, rhs_bv);
57
}
58
59
literalt
boolbvt::convert_verilog_case_equality
(
60
const
binary_relation_exprt
&expr)
61
{
62
// This is 4-valued comparison, i.e., z===z, x===x etc.
63
// The result is always Boolean.
64
65
DATA_INVARIANT_WITH_DIAGNOSTICS
(
66
expr.
lhs
().
type
() == expr.
rhs
().
type
(),
67
"lhs and rhs types should match in verilog_case_equality"
,
68
irep_pretty_diagnosticst
{expr.lhs()},
69
irep_pretty_diagnosticst
{expr.rhs()});
70
71
const
bvt
&lhs_bv =
convert_bv
(expr.
lhs
());
72
const
bvt
&rhs_bv =
convert_bv
(expr.
rhs
());
73
74
DATA_INVARIANT_WITH_DIAGNOSTICS
(
75
lhs_bv.size() == rhs_bv.size(),
76
"bitvector arguments to verilog_case_equality should have the same size"
,
77
irep_pretty_diagnosticst
{expr.lhs()},
78
"lhs size: "
+ std::to_string(lhs_bv.size()),
79
irep_pretty_diagnosticst
{expr.rhs()},
80
"rhs size: "
+ std::to_string(rhs_bv.size()));
81
82
if
(expr.
id
()==ID_verilog_case_inequality)
83
return
!
bv_utils
.equal(lhs_bv, rhs_bv);
84
else
85
return
bv_utils
.equal(lhs_bv, rhs_bv);
86
}
boolbv.h
has_byte_operator
bool has_byte_operator(const exprt &src)
Return true iff src or one of its operands contain a byte extract or byte update expression.
Definition
byte_operators.cpp:61
byte_operators.h
Expression classes for byte-level operators.
lower_byte_operators
exprt lower_byte_operators(const exprt &src, const namespacet &ns)
Rewrite an expression possibly containing byte-extract or -update expressions to more fundamental ope...
Definition
lower_byte_operators.cpp:2638
arrayst::ns
const namespacet & ns
Definition
arrays.h:63
arrayst::record_array_equality
literalt record_array_equality(const equal_exprt &expr)
Definition
arrays.cpp:55
binary_exprt::lhs
exprt & lhs()
Definition
std_expr.h:669
binary_exprt::rhs
exprt & rhs()
Definition
std_expr.h:679
binary_relation_exprt
A base class for relations, i.e., binary predicates whose two operands have the same type.
Definition
std_expr.h:774
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::is_unbounded_array
bool is_unbounded_array(const typet &type) const override
Definition
boolbv.cpp:543
boolbvt::convert_verilog_case_equality
virtual literalt convert_verilog_case_equality(const binary_relation_exprt &expr)
Definition
boolbv_equality.cpp:59
boolbvt::bv_utils
bv_utilst bv_utils
Definition
boolbv.h:121
boolbvt::convert_equality
virtual literalt convert_equality(const equal_exprt &expr)
Definition
boolbv_equality.cpp:15
equal_exprt
Equality.
Definition
std_expr.h:1329
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
irept::id
const irep_idt & id() const
Definition
irep.h:388
literalt
Definition
literal.h:26
prop_conv_solvert::prop
propt & prop
Definition
prop_conv_solver.h:130
bvt
std::vector< literalt > bvt
Definition
literal.h:201
invariant.h
DATA_INVARIANT_WITH_DIAGNOSTICS
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Definition
invariant.h:535
std_expr.h
API to expression classes.
to_equal_expr
const equal_exprt & to_equal_expr(const exprt &expr)
Cast an exprt to an equal_exprt.
Definition
std_expr.h:1365
irep_pretty_diagnosticst
Definition
irep.h:495
solvers
flattening
boolbv_equality.cpp
Generated by
1.17.0