Skip to content

add two helpers for bv_typet #8350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/util/bitvector_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
#include "std_expr.h"
#include "string2int.h"

constant_exprt bv_typet::all_zeros_expr() const
{
return constant_exprt{
make_bvrep(get_width(), [](std::size_t) { return false; }), *this};
}

constant_exprt bv_typet::all_ones_expr() const

Check warning on line 25 in src/util/bitvector_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/bitvector_types.cpp#L25

Added line #L25 was not covered by tests
{
return constant_exprt{
make_bvrep(get_width(), [](std::size_t) { return true; }), *this};

Check warning on line 28 in src/util/bitvector_types.cpp

View check run for this annotation

Codecov / codecov/patch

src/util/bitvector_types.cpp#L27-L28

Added lines #L27 - L28 were not covered by tests
}

std::size_t fixedbv_typet::get_integer_bits() const
{
const irep_idt integer_bits = get(ID_integer_bits);
Expand Down
4 changes: 4 additions & 0 deletions src/util/bitvector_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class bv_typet : public bitvector_typet
DATA_CHECK(
vm, !type.get(ID_width).empty(), "bitvector type must have width");
}

// helpers to create common constants
constant_exprt all_zeros_expr() const;
constant_exprt all_ones_expr() const;
};

/// Check whether a reference to a typet is a \ref bv_typet.
Expand Down
8 changes: 4 additions & 4 deletions src/util/lower_byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static exprt unpack_array_vector(
numeric_cast_v<std::size_t>(std::min(
*offset_bytes - (*offset_bytes % el_bytes),
*num_elements * el_bytes)),
from_integer(0, bv_typet{bits_per_byte}));
bv_typet{bits_per_byte}.all_zeros_expr());
}
}

Expand Down Expand Up @@ -791,7 +791,7 @@ static array_exprt unpack_struct(
byte_operands.resize(
byte_operands.size() +
numeric_cast_v<std::size_t>(*component_bits / bits_per_byte),
from_integer(0, bv_typet{bits_per_byte}));
bv_typet{bits_per_byte}.all_zeros_expr());
}
else
{
Expand Down Expand Up @@ -2417,7 +2417,7 @@ static exprt lower_byte_update(
if(bit_width > type_bits)
{
val_before = concatenation_exprt{
from_integer(0, bv_typet{bit_width - type_bits}),
bv_typet{bit_width - type_bits}.all_zeros_expr(),
val_before,
bv_typet{bit_width}};

Expand Down Expand Up @@ -2492,7 +2492,7 @@ static exprt lower_byte_update(
if(bit_width > update_size_bits)
{
zero_extended = concatenation_exprt{
from_integer(0, bv_typet{bit_width - update_size_bits}),
bv_typet{bit_width - update_size_bits}.all_zeros_expr(),
value,
bv_typet{bit_width}};

Expand Down
Loading