1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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())?)
}
}
impl Value for il::Expression {
fn constant(constant: il::Constant) -> Self {
il::Expression::constant(constant)
}
fn bits(&self) -> usize {
self.bits()
}
fn shl(&self, bits: usize) -> Result<Self> {
il::Expression::shl(self.clone(), il::expr_const(bits as u64, self.bits()))
}
fn shr(&self, bits: usize) -> Result<Self> {
il::Expression::shr(self.clone(), il::expr_const(bits as u64, self.bits()))
}
fn trun(&self, bits: usize) -> Result<Self> {
il::Expression::trun(bits, self.clone())
}
fn zext(&self, bits: usize) -> Result<Self> {
il::Expression::zext(bits, self.clone())
}
fn or(&self, other: &Self) -> Result<Self> {
il::Expression::or(self.clone(), other.clone())
}
}