Skip to content

Commit

Permalink
value: add new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed May 20, 2024
1 parent 10b38eb commit ad33e6b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ impl<V: BitVecValue> PartialEq<V> for ValueOwned {
}
}

impl Eq for ValueOwned {}

impl<V: BitVecValue> std::ops::Add<&V> for &ValueOwned {
type Output = ValueOwned;

Expand Down Expand Up @@ -295,6 +297,7 @@ pub trait BitVecValue {

/// Returns the value as a 64-bit unsigned integer iff the width is 64-bit or less.
fn to_u64(&self) -> Option<u64> {
// TODO: allow conversion of bit-vectors over 64 bits if the value can fit into 64 bits
if self.width() <= 64 {
if self.width() == 0 {
Some(0)
Expand All @@ -310,6 +313,7 @@ pub trait BitVecValue {

/// Returns the value as a 64-bit signed integer iff the width is 64-bit or less.
fn to_i64(&self) -> Option<i64> {
// TODO: allow conversion of bit-vectors over 64 bits if the value can fit into 64 bits
if self.width() <= 64 {
if self.width() == 0 {
Some(0)
Expand All @@ -327,6 +331,10 @@ pub trait BitVecValue {
}
}

fn is_zero(&self) -> bool {
self.words().iter().all(|w| *w == 0)
}

declare_arith_bin_fn!(add);
declare_arith_bin_fn!(sub);
declare_arith_bin_fn!(shift_left);
Expand Down

0 comments on commit ad33e6b

Please sign in to comment.