Skip to content

Commit ebce6fb

Browse files
bors[bot]steelman
andauthored
Merge #666
666: Mark bits() as safe if a register has no reserved bits r=burrbull a=steelman If a register has no fields but its write constraints allow full range of values to be written, then mark bits() as safe. Co-authored-by: Łukasz Stelmach <[email protected]>
2 parents c5bbc3c + 583fc04 commit ebce6fb

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Update `clap` to 4.0, use `irx-config` instead of `clap_conf`
1111
- Add #[must_use] to prevent hanging field writers
1212
- remove explicit deref in `generic.rs` since it's done by auto-deref
13+
- Make writing raw bits to a whole register safe if the SVD indicates
14+
so through the <WriteConstraint> element (see [v0.7.1] too).
1315

1416
## [v0.26.0] - 2022-10-07
1517

src/generate/register.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,16 @@ pub fn render_register_mod(
264264
// the writer can be safe if:
265265
// * there is a single field that covers the entire register
266266
// * that field can represent all values
267-
let can_write_safe = match register
268-
.fields
269-
.as_ref()
270-
.and_then(|fields| fields.iter().next())
271-
.and_then(|field| field.write_constraint)
272-
{
273-
Some(WriteConstraint::Range(range)) => {
274-
range.min == 0 && range.max == u64::MAX >> (64 - rsize)
275-
}
276-
_ => false,
277-
};
267+
// * the write constraints of the register allow full range of values
268+
let can_write_safe = !unsafety(
269+
register
270+
.fields
271+
.as_ref()
272+
.and_then(|fields| fields.first())
273+
.and_then(|field| field.write_constraint)
274+
.as_ref(),
275+
rsize,
276+
) || !unsafety(register.write_constraint.as_ref(), rsize);
278277

279278
if can_write_safe {
280279
mod_items.extend(quote! {

0 commit comments

Comments
 (0)