Skip to content

Commit ed47f6d

Browse files
authored
Merge pull request #8350 from diffblue/bv_typet-helpers
add two helpers for bv_typet
2 parents f33d8ea + 977b3ee commit ed47f6d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/util/bitvector_types.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ Author: Daniel Kroening, kroening@kroening.com
1616
#include "std_expr.h"
1717
#include "string2int.h"
1818

19+
constant_exprt bv_typet::all_zeros_expr() const
20+
{
21+
return constant_exprt{
22+
make_bvrep(get_width(), [](std::size_t) { return false; }), *this};
23+
}
24+
25+
constant_exprt bv_typet::all_ones_expr() const
26+
{
27+
return constant_exprt{
28+
make_bvrep(get_width(), [](std::size_t) { return true; }), *this};
29+
}
30+
1931
std::size_t fixedbv_typet::get_integer_bits() const
2032
{
2133
const irep_idt integer_bits = get(ID_integer_bits);

src/util/bitvector_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class bv_typet : public bitvector_typet
6060
DATA_CHECK(
6161
vm, !type.get(ID_width).empty(), "bitvector type must have width");
6262
}
63+
64+
// helpers to create common constants
65+
constant_exprt all_zeros_expr() const;
66+
constant_exprt all_ones_expr() const;
6367
};
6468

6569
/// Check whether a reference to a typet is a \ref bv_typet.

src/util/lower_byte_operators.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static exprt unpack_array_vector(
579579
numeric_cast_v<std::size_t>(std::min(
580580
*offset_bytes - (*offset_bytes % el_bytes),
581581
*num_elements * el_bytes)),
582-
from_integer(0, bv_typet{bits_per_byte}));
582+
bv_typet{bits_per_byte}.all_zeros_expr());
583583
}
584584
}
585585

@@ -791,7 +791,7 @@ static array_exprt unpack_struct(
791791
byte_operands.resize(
792792
byte_operands.size() +
793793
numeric_cast_v<std::size_t>(*component_bits / bits_per_byte),
794-
from_integer(0, bv_typet{bits_per_byte}));
794+
bv_typet{bits_per_byte}.all_zeros_expr());
795795
}
796796
else
797797
{
@@ -2417,7 +2417,7 @@ static exprt lower_byte_update(
24172417
if(bit_width > type_bits)
24182418
{
24192419
val_before = concatenation_exprt{
2420-
from_integer(0, bv_typet{bit_width - type_bits}),
2420+
bv_typet{bit_width - type_bits}.all_zeros_expr(),
24212421
val_before,
24222422
bv_typet{bit_width}};
24232423

@@ -2492,7 +2492,7 @@ static exprt lower_byte_update(
24922492
if(bit_width > update_size_bits)
24932493
{
24942494
zero_extended = concatenation_exprt{
2495-
from_integer(0, bv_typet{bit_width - update_size_bits}),
2495+
bv_typet{bit_width - update_size_bits}.all_zeros_expr(),
24962496
value,
24972497
bv_typet{bit_width}};
24982498

0 commit comments

Comments
 (0)