Skip to content

Conversation

@gkelly
Copy link
Contributor

@gkelly gkelly commented May 10, 2020

Enforce register size, reset, and mask value agreement. If the provided
reset value or mask extend past the register size, or the provided reset
value would conflict with the mask, then fail parsing.


I saw that there are some tests from CMSIS that are disabled because of constraint violations due to a check like this. There are also a couple of ATSAMD51 tests (at least) that will fail because of this that are currently enabled.

@gkelly gkelly requested a review from a team as a code owner May 10, 2020 21:25
@gkelly gkelly force-pushed the reset-value-size branch from 4812089 to 6e626a7 Compare May 10, 2020 21:30
src/error.rs Outdated
}

pub(crate) fn check_reset_value(
size: &Option<u32>,
Copy link
Contributor

Choose a reason for hiding this comment

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

&Option<u32>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it's getting stored on RegisterProperties, so I figured I'd just take a reference. I can switch to non-ref if you think it's more ergonomic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do think a reference to an Option of a primitive type is a weird and unergonomic choice, yes. Not sure how much efforts it would be to change that but I certainly would prefer less ampersands in new code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, just pushed with references switched to plain Option<u32>s.

@gkelly gkelly force-pushed the reset-value-size branch from 6e626a7 to 88ef814 Compare May 10, 2020 22:39
@burrbull
Copy link
Member

Maybe it makes sense to add cargo feature something like without-checks to be possible to compile with disabled checks like check_name, this one and some other. This could be useful for tests.
cc @therealprof

@gkelly
Copy link
Contributor Author

gkelly commented May 11, 2020

Maybe it makes sense to add cargo feature something like without-checks to be possible to compile with disabled checks like check_name, this one and some other. This could be useful for tests.
cc @therealprof

I feel like svd-parser is already opinionated about correctness: name checking, enum variant validation. If svd-parser allows unchecked/unconstrained values to pass to consumers then it puts the burden on validation there, and so every consumer would just enable it...

burrbull
burrbull previously approved these changes May 12, 2020
@burrbull
Copy link
Member

Resolve conflicts, please.

Enforce register size, reset, and mask value agreement. If the provided
reset value or mask extend past the register size, or the provided reset
value would conflict with the mask, then fail parsing.
@gkelly
Copy link
Contributor Author

gkelly commented May 12, 2020

Resolve conflicts, please.

Done. Thank you for the reviews!

burrbull
burrbull previously approved these changes May 12, 2020
@burrbull
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request May 12, 2020
120: Enforce register value constraints r=burrbull a=gkelly

Enforce register size, reset, and mask value agreement. If the provided
reset value or mask extend past the register size, or the provided reset
value would conflict with the mask, then fail parsing.

---

I saw that there are some tests from CMSIS that are disabled because of constraint violations due to a check like this. There are also a couple of ATSAMD51 tests (at least) that will fail because of this that are currently enabled.

Co-authored-by: Garret Kelly <[email protected]>
@bors
Copy link
Contributor

bors bot commented May 12, 2020

Build failed:

@burrbull
Copy link
Member

Add use core::u32

and fix svd::registerproperties::tests::decode_encode example.

@gkelly
Copy link
Contributor Author

gkelly commented May 12, 2020

Add use core::u32

Done.

and fix svd::registerproperties::tests::decode_encode example.

Done. Apologies, I wasn't building with --features=untested!

@burrbull
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented May 12, 2020

Build succeeded:

@bors bors bot merged commit 4d384c5 into rust-embedded:master May 12, 2020
@gkelly gkelly deleted the reset-value-size branch May 12, 2020 14:26
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.

3 participants