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
use crate::il::*;
use std::fmt;
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Scalar {
name: String,
bits: usize,
ssa: Option<usize>,
}
impl Scalar {
pub fn new<S>(name: S, bits: usize) -> Scalar
where
S: Into<String>,
{
Scalar {
name: name.into(),
bits: bits,
ssa: None,
}
}
pub fn temp(index: u64, bits: usize) -> Self {
Self::new(format!("temp_0x{:X}", index), bits)
}
pub fn bits(&self) -> usize {
self.bits
}
pub fn name(&self) -> &str {
&self.name
}
pub fn ssa(&self) -> Option<usize> {
self.ssa.clone()
}
pub fn set_ssa(&mut self, ssa: Option<usize>) {
self.ssa = ssa;
}
pub fn identifier(&self) -> String {
let ssa = match self.ssa() {
Some(ssa) => format!(".{}", ssa),
None => String::default(),
};
format!("{}{}:{}", self.name, ssa, self.bits)
}
}
impl fmt::Display for Scalar {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.identifier())
}
}
impl Into<Expression> for Scalar {
fn into(self) -> Expression {
Expression::scalar(self)
}
}