[meta] Try to use {prefix+number} when looking up a register by name;
This makes it possible to look up registers like r15 on x86.
This commit is contained in:
@@ -43,10 +43,26 @@ impl RegBank {
|
|||||||
// Try to match without the bank prefix.
|
// Try to match without the bank prefix.
|
||||||
assert!(name.starts_with(self.prefix));
|
assert!(name.starts_with(self.prefix));
|
||||||
let name_without_prefix = &name[self.prefix.len()..];
|
let name_without_prefix = &name[self.prefix.len()..];
|
||||||
self.names
|
if let Some(found) = self
|
||||||
|
.names
|
||||||
.iter()
|
.iter()
|
||||||
.position(|®_name| reg_name == name_without_prefix)
|
.position(|®_name| reg_name == name_without_prefix)
|
||||||
.expect(&format!("invalid register name {}", name))
|
{
|
||||||
|
found
|
||||||
|
} else {
|
||||||
|
// Ultimate try: try to parse a number and use this in the array, eg r15 on x86.
|
||||||
|
if let Ok(as_num) = name_without_prefix.parse::<u8>() {
|
||||||
|
assert!(
|
||||||
|
(as_num - self.first_unit) < self.units,
|
||||||
|
"trying to get {}, but bank only has {} registers!",
|
||||||
|
name,
|
||||||
|
self.units
|
||||||
|
);
|
||||||
|
(as_num - self.first_unit) as usize
|
||||||
|
} else {
|
||||||
|
panic!("invalid register name {}", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
self.first_unit + (unit as u8)
|
self.first_unit + (unit as u8)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user