Refactor find_reg_for_field()

This commit is contained in:
Timo Kröger 2021-08-04 11:08:18 +02:00
parent c985c031d4
commit 37536695e1

View File

@ -121,27 +121,21 @@ fn find_reg_for_field<'c>(
reg_regex: &str, reg_regex: &str,
field_name: &str, field_name: &str,
) -> Option<(&'c str, &'c str)> { ) -> Option<(&'c str, &'c str)> {
rcc.fieldsets.iter().find_map(|(name, fieldset)| { let reg_regex = Regex::new(reg_regex).unwrap();
for (name, fieldset) in &rcc.fieldsets {
// Workaround for some families that prefix register aliases with C1_, which does // Workaround for some families that prefix register aliases with C1_, which does
// not help matching for clock name. // not help matching for clock name.
if name.starts_with("C1") || name.starts_with("C2") { if !name.starts_with("C1") && !name.starts_with("C2") && reg_regex.is_match(name) {
None for field in &fieldset.fields {
} else if Regex::new(reg_regex).unwrap().is_match(name) { if field_name == field.name {
fieldset return Some((name.as_str(), field.name.as_str()));
.fields }
.iter() }
.find_map(|field| {
if field_name == field.name {
return Some(field.name.as_str());
} else {
None
}
})
.map(|n| (name.as_str(), n))
} else {
None
} }
}) }
None
} }
fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) { fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) {