use error::*;
use executor::eval;
use il;
use std::fmt::Debug;
pub trait Value: Clone + Debug + Eq + PartialEq {
fn constant(constant: il::Constant) -> Self;
fn bits(&self) -> usize;
fn shl(&self, bits: usize) -> Result<Self>;
fn shr(&self, bits: usize) -> Result<Self>;
fn trun(&self, bits: usize) -> Result<Self>;
fn zext(&self, bits: usize) -> Result<Self>;
fn or(&self, other: &Self) -> Result<Self>;
}
impl Value for il::Constant {
fn constant(constant: il::Constant) -> Self {
constant
}
fn bits(&self) -> usize {
self.bits()
}
fn shl(&self, bits: usize) -> Result<Self> {
eval(&il::Expression::shl(self.clone().into(), il::expr_const(bits as u64, self.bits()))?)
}
fn shr(&self, bits: usize) -> Result<Self> {
eval(&il::Expression::shr(self.clone().into(), il::expr_const(bits as u64, self.bits()))?)
}
fn trun(&self, bits: usize) -> Result<Self> {
eval(&il::Expression::trun(bits, self.clone().into())?)
}
fn zext(&self, bits: usize) -> Result<Self> {
eval(&il::Expression::zext(bits, self.clone().into())?)
}
fn or(&self, other: &Self) -> Result<Self> {
eval(&il::Expression::or(self.clone().into(), other.clone().into())?)
}
}