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
use crate::data_structures::WritableBase;
use crate::{RealRegUniverse, Reg, Writable};
pub trait PrettyPrint {
fn show_rru(&self, maybe_reg_universe: Option<&RealRegUniverse>) -> String;
}
pub trait PrettyPrintSized: PrettyPrint {
fn show_rru_sized(&self, maybe_reg_universe: Option<&RealRegUniverse>, _size: u8) -> String {
self.show_rru(maybe_reg_universe)
}
}
impl PrettyPrint for Reg {
fn show_rru(&self, maybe_reg_universe: Option<&RealRegUniverse>) -> String {
if self.is_real() {
if let Some(rru) = maybe_reg_universe {
let reg_ix = self.get_index();
assert!(
reg_ix < rru.regs.len(),
"unknown real register with index {:?}",
reg_ix
);
return rru.regs[reg_ix].1.to_string();
}
}
format!("%{:?}", self)
}
}
impl<R: PrettyPrint + WritableBase> PrettyPrint for Writable<R> {
fn show_rru(&self, maybe_reg_universe: Option<&RealRegUniverse>) -> String {
self.to_reg().show_rru(maybe_reg_universe)
}
}
impl<R: PrettyPrintSized + WritableBase> PrettyPrintSized for Writable<R> {
fn show_rru_sized(&self, maybe_reg_universe: Option<&RealRegUniverse>, size: u8) -> String {
self.to_reg().show_rru_sized(maybe_reg_universe, size)
}
}