CBMC
boolbv_map.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 "
boolbv_map.h
"
10
11
#include <
util/threeval.h
>
12
13
#include <
solvers/prop/prop.h
>
14
15
#ifdef DEBUG
16
#include <iostream>
17
#endif
18
19
std::string
boolbv_mapt::map_entryt::get_value
(
const
propt
&prop)
const
20
{
21
std::string result;
22
23
result.reserve(
literal_map
.size());
24
25
for
(
const
auto
&literal :
literal_map
)
26
{
27
const
tvt
value =
prop
.
l_get
(literal);
28
29
result += (value.
is_true
() ?
'1'
: (value.
is_false
() ?
'0'
:
'?'
));
30
}
31
32
return
result;
33
}
34
35
void
boolbv_mapt::show
(std::ostream &out)
const
36
{
37
for
(
const
auto
&pair :
mapping
)
38
out << pair.first <<
"="
<< pair.second.get_value(
prop
) <<
'\n'
;
39
}
40
41
const
bvt
&
boolbv_mapt::get_literals
(
42
const
irep_idt
&identifier,
43
const
typet
&type,
44
std::size_t width)
45
{
46
std::pair<mappingt::iterator, bool> result=
47
mapping
.insert(std::pair<irep_idt, map_entryt>(
48
identifier,
map_entryt
()));
49
50
map_entryt
&map_entry=result.first->second;
51
52
if
(result.second)
53
{
// actually inserted
54
map_entry.
type
=type;
55
map_entry.
literal_map
.reserve(width);
56
57
for
(std::size_t bit = 0; bit < width; ++bit)
58
{
59
map_entry.
literal_map
.push_back(
prop
.
new_variable
());
60
61
#ifdef DEBUG
62
std::cout <<
"NEW: "
<< identifier <<
":"
<< bit <<
"="
63
<< map_entry.
literal_map
.back() <<
'\n'
;
64
#endif
65
}
66
}
67
68
INVARIANT
(
69
map_entry.
literal_map
.size() == width,
70
"number of literals in the literal map shall equal the bitvector width"
);
71
72
return
map_entry.
literal_map
;
73
}
74
75
void
boolbv_mapt::set_literals
(
76
const
irep_idt
&identifier,
77
const
typet
&type,
78
const
bvt
&literals)
79
{
80
std::pair<mappingt::iterator, bool> result =
81
mapping
.insert(std::pair<irep_idt, map_entryt>(identifier,
map_entryt
()));
82
83
map_entryt
&map_entry = result.first->second;
84
85
if
(result.second)
86
{
// actually inserted
87
map_entry.
type
= type;
88
89
for
(
const
auto
&literal : literals)
90
{
91
INVARIANT
(
92
literal.is_constant() || literal.var_no() <
prop
.
no_variables
(),
93
"variable number of non-constant literals shall be within bounds"
);
94
}
95
96
map_entry.
literal_map
= literals;
97
}
98
else
99
{
100
for
(
auto
it = literals.begin(); it != literals.end(); ++it)
101
{
102
const
literalt
&literal = *it;
103
104
INVARIANT
(
105
literal.
is_constant
() || literal.
var_no
() <
prop
.
no_variables
(),
106
"variable number of non-constant literals shall be within bounds"
);
107
108
const
std::size_t bit = it - literals.begin();
109
110
INVARIANT
(
111
bit < map_entry.
literal_map
.size(),
"bit index shall be within bounds"
);
112
113
prop
.
set_equal
(map_entry.
literal_map
[bit], literal);
114
}
115
}
116
}
117
118
void
boolbv_mapt::erase_literals
(
119
const
irep_idt
&identifier,
120
const
typet
&)
121
{
122
mapping
.erase(identifier);
123
}
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition:
dstring.h:36
boolbv_mapt::erase_literals
void erase_literals(const irep_idt &identifier, const typet &type)
Definition:
boolbv_map.cpp:118
boolbv_mapt::map_entryt::get_value
std::string get_value(const propt &) const
Definition:
boolbv_map.cpp:19
typet
The type of an expression, extends irept.
Definition:
type.h:28
boolbv_mapt::prop
propt & prop
Definition:
boolbv_map.h:73
bvt
std::vector< literalt > bvt
Definition:
literal.h:201
threeval.h
boolbv_mapt::get_literals
const bvt & get_literals(const irep_idt &identifier, const typet &type, std::size_t width)
Definition:
boolbv_map.cpp:41
propt::set_equal
virtual void set_equal(literalt a, literalt b)
asserts a==b in the propositional formula
Definition:
prop.cpp:12
boolbv_mapt::map_entryt::literal_map
bvt literal_map
Definition:
boolbv_map.h:33
propt::new_variable
virtual literalt new_variable()=0
literalt::var_no
var_not var_no() const
Definition:
literal.h:83
propt::no_variables
virtual size_t no_variables() const =0
boolbv_mapt::map_entryt
Definition:
boolbv_map.h:29
boolbv_mapt::mapping
mappingt mapping
Definition:
boolbv_map.h:72
boolbv_mapt::show
void show(std::ostream &out) const
Definition:
boolbv_map.cpp:35
prop.h
tvt::is_false
bool is_false() const
Definition:
threeval.h:26
tvt
Definition:
threeval.h:19
boolbv_mapt::map_entryt::type
typet type
Definition:
boolbv_map.h:32
propt
TO_BE_DOCUMENTED.
Definition:
prop.h:22
propt::l_get
virtual tvt l_get(literalt a) const =0
literalt
Definition:
literal.h:25
literalt::is_constant
bool is_constant() const
Definition:
literal.h:166
boolbv_map.h
validation_modet::INVARIANT
@ INVARIANT
tvt::is_true
bool is_true() const
Definition:
threeval.h:25
boolbv_mapt::set_literals
void set_literals(const irep_idt &identifier, const typet &type, const bvt &literals)
Definition:
boolbv_map.cpp:75
src
solvers
flattening
boolbv_map.cpp
Generated by
1.8.17