use crate::smt::{self, Pred, Var};
use core::ops::{Add, BitAnd, BitOr, BitXor, Mul, Not, Shl, Shr, Sub};
impl Add for Var {
type Output = Var;
fn add(self, rhs: Var) -> Var {
smt::add(self, rhs)
}
}
impl Sub for Var {
type Output = Var;
fn sub(self, rhs: Var) -> Var {
smt::sub(self, rhs)
}
}
impl Mul for Var {
type Output = Var;
fn mul(self, rhs: Var) -> Var {
smt::mul(self, rhs)
}
}
impl BitAnd for Var {
type Output = Var;
fn bitand(self, rhs: Var) -> Var {
smt::band(self, rhs)
}
}
impl BitOr for Var {
type Output = Var;
fn bitor(self, rhs: Var) -> Var {
smt::bor(self, rhs)
}
}
impl BitXor for Var {
type Output = Var;
fn bitxor(self, rhs: Var) -> Var {
smt::bxor(self, rhs)
}
}
impl Shl<u32> for Var {
type Output = Var;
fn shl(self, rhs: u32) -> Var {
smt::shl(self, rhs)
}
}
impl Shr<u32> for Var {
type Output = Var;
fn shr(self, rhs: u32) -> Var {
smt::lshr(self, rhs)
}
}
macro_rules! impl_word_literal_ops {
($($t:ty),*) => {$(
impl BitAnd<$t> for Var {
type Output = Var;
fn bitand(self, rhs: $t) -> Var {
smt::band(self, smt::word(rhs as u64, smt::bits(self)))
}
}
impl BitOr<$t> for Var {
type Output = Var;
fn bitor(self, rhs: $t) -> Var {
smt::bor(self, smt::word(rhs as u64, smt::bits(self)))
}
}
impl BitXor<$t> for Var {
type Output = Var;
fn bitxor(self, rhs: $t) -> Var {
smt::bxor(self, smt::word(rhs as u64, smt::bits(self)))
}
}
impl Add<$t> for Var {
type Output = Var;
fn add(self, rhs: $t) -> Var {
smt::add(self, smt::word(rhs as u64, smt::bits(self)))
}
}
impl Sub<$t> for Var {
type Output = Var;
fn sub(self, rhs: $t) -> Var {
smt::sub(self, smt::word(rhs as u64, smt::bits(self)))
}
}
impl Mul<$t> for Var {
type Output = Var;
fn mul(self, rhs: $t) -> Var {
smt::mul(self, smt::word(rhs as u64, smt::bits(self)))
}
}
)*};
}
impl_word_literal_ops!(u32, u64);
impl Not for Pred {
type Output = Pred;
fn not(self) -> Pred {
smt::not(self)
}
}
impl BitAnd for Pred {
type Output = Pred;
fn bitand(self, rhs: Pred) -> Pred {
smt::and(self, rhs)
}
}
impl BitOr for Pred {
type Output = Pred;
fn bitor(self, rhs: Pred) -> Pred {
smt::or(self, rhs)
}
}
impl BitXor for Pred {
type Output = Pred;
fn bitxor(self, rhs: Pred) -> Pred {
smt::xor(self, rhs)
}
}
impl Pred {
pub fn implies(self, other: Pred) -> Pred {
smt::implies(self, other)
}
pub fn iff(self, other: Pred) -> Pred {
smt::iff(self, other)
}
pub fn prove(self) -> smt::Verdict {
smt::prove(self)
}
pub fn find_model(self) -> smt::Verdict {
smt::find_model(self)
}
}
impl Var {
pub fn width(self) -> u8 {
smt::bits(self)
}
pub fn index(self) -> u32 {
smt::index(self)
}
pub fn eq(self, other: Var) -> Pred {
smt::eq(self, other)
}
pub fn eq_val(self, k: u64) -> Pred {
smt::eq_const(self, k)
}
pub fn ne(self, other: Var) -> Pred {
smt::not(smt::eq(self, other))
}
pub fn lt(self, other: Var) -> Pred {
smt::ult(self, other)
}
pub fn le(self, other: Var) -> Pred {
smt::ule(self, other)
}
pub fn ge(self, other: Var) -> Pred {
smt::ule(other, self)
}
pub fn gt(self, other: Var) -> Pred {
smt::ult(other, self)
}
pub fn lt_val(self, k: u64) -> Pred {
smt::ult_const(self, k)
}
pub fn le_val(self, k: u64) -> Pred {
smt::ule_const(self, k)
}
pub fn ge_val(self, k: u64) -> Pred {
smt::uge_const(self, k)
}
pub fn gt_val(self, k: u64) -> Pred {
smt::ugt_const(self, k)
}
}
pub fn forall(p: Pred) -> Pred {
p
}