Skip to content

Permit duplicate "reserved" fields.#93

Open
inferiorhumanorgans wants to merge 1 commit intoembassy-rs:mainfrom
inferiorhumanorgans:iho/duplicate-reserved-fields
Open

Permit duplicate "reserved" fields.#93
inferiorhumanorgans wants to merge 1 commit intoembassy-rs:mainfrom
inferiorhumanorgans:iho/duplicate-reserved-fields

Conversation

@inferiorhumanorgans
Copy link

Renesas uses multiple fields named Reserved within the same register in a few different places in e.g. the RA4M1 SVD. This would preserve the existing behavior of forbidding duplicate field names except where it appears to be deliberate.

Alternatively should duplicate field names be allowed and then deduplicated in the sanitize transform?

Renesas uses multiple fields named `Reserved` within the same register
in a few different places in e.g. the RA4M1 SVD.  This would preserve
the existing behavior of forbidding duplicate field names except where
it appears to be deliberate.

Alternatively should duplicate field names be allowed and then
deduplicated in the sanitize transform?
@Wassasin
Copy link
Contributor

Wassasin commented Feb 27, 2026

I think duplicate field names automagically transforming to fields with a number suffix is fine. Emitting an error seems redundant. Chiptool generally does not require to fix the SVD itself. Rather we fix the defs afterwards in transforms. Hence the SVD parser should be maximally generous.

I would say remove the "eserved" section and its good. Currently your PR does it both in sanitize and in the conversion. Only the latter would be sufficient.

Comment on lines +31 to +34
for (_, fieldset) in ir.fieldsets.iter_mut() {
rename_duplicate_fields(fieldset);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanitize is superfluous if also done during the parsing.

Comment on lines +100 to +112
fn rename_duplicate_fields(fieldset: &mut crate::ir::FieldSet) {
use std::collections::BTreeMap;

let mut name_counts: BTreeMap<String, usize> = BTreeMap::new();

for f in fieldset.fields.iter_mut() {
let count = name_counts.entry(f.name.clone()).or_insert(0);
*count += 1;
if *count > 1 {
f.name = format!("{}_{count:x}", f.name);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is then redundant.

field_name_counts.entry(field_name.clone()).or_insert(0);
*field_name_count += 1;
if *field_name_count > 1 {
if field_name.contains("eserved") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this for any field, no need for the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants