Skip to content

Commit 3790406

Browse files
committed
remove bv_pointerst::bv_pointers_widtht
There is no need for a pointer-aware bv_width class, as pointers are bitvector types (including a width) since 2016.
1 parent 3653c9b commit 3790406

File tree

2 files changed

+19
-62
lines changed

2 files changed

+19
-62
lines changed

src/solvers/flattening/bv_pointers.cpp

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,58 +68,33 @@ void bv_endianness_mapt::build_big_endian(const typet &src)
6868
endianness_mapt
6969
bv_pointerst::endianness_map(const typet &type, bool little_endian) const
7070
{
71-
return bv_endianness_mapt{type, little_endian, ns, bv_pointers_width};
71+
return bv_endianness_mapt{type, little_endian, ns, bv_width};
7272
}
7373

74-
std::size_t bv_pointerst::bv_pointers_widtht::
75-
operator()(const typet &type) const
76-
{
77-
if(type.id() != ID_pointer)
78-
return boolbv_widtht::operator()(type);
79-
80-
// check or update the cache, just like boolbv_widtht does
81-
std::pair<cachet::iterator, bool> cache_result =
82-
cache.insert(std::pair<typet, entryt>(type, entryt()));
83-
84-
if(cache_result.second)
85-
{
86-
std::size_t &total_width = cache_result.first->second.total_width;
87-
88-
total_width = get_address_width(to_pointer_type(type));
89-
DATA_INVARIANT(total_width > 0, "pointer width shall be greater than zero");
90-
}
91-
92-
return cache_result.first->second.total_width;
93-
}
94-
95-
std::size_t bv_pointerst::bv_pointers_widtht::get_object_width(
96-
const pointer_typet &type) const
74+
std::size_t bv_pointerst::get_object_width(const pointer_typet &) const
9775
{
9876
// not actually type-dependent for now
99-
(void)type;
10077
return config.bv_encoding.object_bits;
10178
}
10279

103-
std::size_t bv_pointerst::bv_pointers_widtht::get_offset_width(
104-
const pointer_typet &type) const
80+
std::size_t bv_pointerst::get_offset_width(const pointer_typet &type) const
10581
{
10682
const std::size_t pointer_width = type.get_width();
10783
const std::size_t object_width = get_object_width(type);
10884
PRECONDITION(pointer_width >= object_width);
10985
return pointer_width - object_width;
11086
}
11187

112-
std::size_t bv_pointerst::bv_pointers_widtht::get_address_width(
113-
const pointer_typet &type) const
88+
std::size_t bv_pointerst::get_address_width(const pointer_typet &type) const
11489
{
11590
return type.get_width();
11691
}
11792

11893
bvt bv_pointerst::object_literals(const bvt &bv, const pointer_typet &type)
11994
const
12095
{
121-
const std::size_t offset_width = bv_pointers_width.get_offset_width(type);
122-
const std::size_t object_width = bv_pointers_width.get_object_width(type);
96+
const std::size_t offset_width = get_offset_width(type);
97+
const std::size_t object_width = get_object_width(type);
12398
PRECONDITION(bv.size() >= offset_width + object_width);
12499

125100
return bvt(
@@ -129,7 +104,7 @@ bvt bv_pointerst::object_literals(const bvt &bv, const pointer_typet &type)
129104
bvt bv_pointerst::offset_literals(const bvt &bv, const pointer_typet &type)
130105
const
131106
{
132-
const std::size_t offset_width = bv_pointers_width.get_offset_width(type);
107+
const std::size_t offset_width = get_offset_width(type);
133108
PRECONDITION(bv.size() >= offset_width);
134109

135110
return bvt(bv.begin(), bv.begin() + offset_width);
@@ -166,8 +141,7 @@ literalt bv_pointerst::convert_rest(const exprt &expr)
166141
bvt invalid_bv = object_literals(
167142
encode(pointer_logic.get_invalid_object(), type), type);
168143

169-
const std::size_t object_bits =
170-
bv_pointers_width.get_object_width(type);
144+
const std::size_t object_bits = get_object_width(type);
171145

172146
bvt equal_invalid_bv;
173147
equal_invalid_bv.reserve(object_bits);
@@ -240,8 +214,7 @@ bv_pointerst::bv_pointerst(
240214
message_handlert &message_handler,
241215
bool get_array_constraints)
242216
: boolbvt(_ns, _prop, message_handler, get_array_constraints),
243-
pointer_logic(_ns),
244-
bv_pointers_width(_ns)
217+
pointer_logic(_ns)
245218
{
246219
}
247220

@@ -490,7 +463,7 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
490463
count == 1,
491464
"there should be exactly one pointer-type operand in a pointer-type sum");
492465

493-
const std::size_t offset_bits = bv_pointers_width.get_offset_width(type);
466+
const std::size_t offset_bits = get_offset_width(type);
494467
bvt sum = bv_utils.build_constant(0, offset_bits);
495468

496469
forall_operands(it, plus_expr)
@@ -845,8 +818,8 @@ exprt bv_pointerst::bv_get_rec(
845818

846819
bvt bv_pointerst::encode(std::size_t addr, const pointer_typet &type) const
847820
{
848-
const std::size_t offset_bits = bv_pointers_width.get_offset_width(type);
849-
const std::size_t object_bits = bv_pointers_width.get_object_width(type);
821+
const std::size_t offset_bits = get_offset_width(type);
822+
const std::size_t object_bits = get_object_width(type);
850823

851824
bvt zero_offset(offset_bits, const_literal(false));
852825

@@ -864,7 +837,7 @@ bvt bv_pointerst::offset_arithmetic(
864837
const bvt &bv,
865838
const mp_integer &x)
866839
{
867-
const std::size_t offset_bits = bv_pointers_width.get_offset_width(type);
840+
const std::size_t offset_bits = get_offset_width(type);
868841

869842
return offset_arithmetic(
870843
type, bv, 1, bv_utils.build_constant(x, offset_bits));
@@ -882,7 +855,7 @@ bvt bv_pointerst::offset_arithmetic(
882855
index.type().id()==ID_signedbv?bv_utilst::representationt::SIGNED:
883856
bv_utilst::representationt::UNSIGNED;
884857

885-
const std::size_t offset_bits = bv_pointers_width.get_offset_width(type);
858+
const std::size_t offset_bits = get_offset_width(type);
886859
bv_index=bv_utils.extension(bv_index, offset_bits, rep);
887860

888861
return offset_arithmetic(type, bv, factor, bv_index);
@@ -904,7 +877,7 @@ bvt bv_pointerst::offset_arithmetic(
904877
bv_index = bv_utils.signed_multiplier(index, bv_factor);
905878
}
906879

907-
const std::size_t offset_bits = bv_pointers_width.get_offset_width(type);
880+
const std::size_t offset_bits = get_offset_width(type);
908881
bv_index = bv_utils.sign_extension(bv_index, offset_bits);
909882

910883
bvt offset_bv = offset_literals(bv, type);
@@ -919,7 +892,7 @@ bvt bv_pointerst::add_addr(const exprt &expr)
919892
std::size_t a=pointer_logic.add_object(expr);
920893

921894
const pointer_typet type = pointer_type(expr.type());
922-
const std::size_t object_bits = bv_pointers_width.get_object_width(type);
895+
const std::size_t object_bits = get_object_width(type);
923896
const std::size_t max_objects=std::size_t(1)<<object_bits;
924897

925898
if(a==max_objects)

src/solvers/flattening/bv_pointers.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,15 @@ class bv_pointerst:public boolbvt
2626

2727
void finish_eager_conversion() override;
2828

29-
std::size_t boolbv_width(const typet &type) const override
30-
{
31-
return bv_pointers_width(type);
32-
}
33-
3429
endianness_mapt
3530
endianness_map(const typet &type, bool little_endian) const override;
3631

3732
protected:
3833
pointer_logict pointer_logic;
3934

40-
class bv_pointers_widtht : public boolbv_widtht
41-
{
42-
public:
43-
explicit bv_pointers_widtht(const namespacet &_ns) : boolbv_widtht(_ns)
44-
{
45-
}
46-
47-
std::size_t operator()(const typet &type) const override;
48-
49-
std::size_t get_object_width(const pointer_typet &type) const;
50-
std::size_t get_offset_width(const pointer_typet &type) const;
51-
std::size_t get_address_width(const pointer_typet &type) const;
52-
};
53-
bv_pointers_widtht bv_pointers_width;
35+
std::size_t get_object_width(const pointer_typet &type) const;
36+
std::size_t get_offset_width(const pointer_typet &type) const;
37+
std::size_t get_address_width(const pointer_typet &type) const;
5438

5539
// NOLINTNEXTLINE(readability/identifiers)
5640
typedef boolbvt SUB;

0 commit comments

Comments
 (0)