[meta] Add new instruction predicates and the InstructionPredicateMap;

The latter helps deduplicating predicates during encodings and recipes
construction.
This commit is contained in:
Benjamin Bouvier
2019-06-24 16:56:00 +02:00
parent a3e459269e
commit 1e42aac41a
3 changed files with 349 additions and 20 deletions

View File

@@ -67,6 +67,20 @@ impl fmt::Display for InstructionFormat {
}
}
impl InstructionFormat {
pub fn imm_by_name(&self, name: &'static str) -> &FormatField {
self.imm_fields
.iter()
.find(|&field| field.member == name)
.unwrap_or_else(|| {
panic!(
"unexpected immediate field named {} in instruction format {}",
name, self.name
)
})
}
}
pub struct InstructionFormatBuilder {
name: &'static str,
num_value_operands: usize,
@@ -200,6 +214,14 @@ impl FormatRegistry {
.expect("unknown InstructionFormat; please define it in shared/formats.rs first")
}
pub fn by_name(&self, name: &str) -> InstructionFormatIndex {
self.map
.iter()
.find(|(_key, value)| value.name == name)
.unwrap_or_else(|| panic!("format with name '{}' doesn't exist", name))
.0
}
pub fn get(&self, index: InstructionFormatIndex) -> &InstructionFormat {
self.map.get(index).unwrap()
}