-
Notifications
You must be signed in to change notification settings - Fork 156
Be more careful computing the size of an array Cluster. #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
r? @therealprof (rust-highfive has picked a reviewer for you, use r? to override) |
If you are right, this is big bug. Rustfmt and add changelog, please. |
rustfmt corrected, I hope, and brief changelog entry added. I'm not sure what your expectations around the latter are - let me know if you want a different amount of detail. |
Incidentally, I'm not entirely sure whether cluster_size_in_bits gets the size of a register array correct, in the case where the size does not match the dimIncrement (is that allowed?) |
Looks good, but we need to test it on different inputs first. |
In this case we need to add "_reserved" at the end of cluster block. |
Padding at the end of a cluster block is not implemented as far as I can see, looking at the code. register_or_cluster_block() adds padding between items but not at the end. My change to cluster_size_in_bits does assume that clusters get padded - without that I fear the change here will break on an array-of-clusters that gets rendered as a list of fields rather than a rust array. Another case that svd2rust doesn't handle correctly, as far as I can see, if the rust struct created for a cluster is |
https://doc.rust-lang.org/nomicon/repr-rust.html |
This wasn't broken on the first case I looked at, but then I dug further and found more cases, that were broken (differently!) in both current master and with the first rev of this PR. I have updateed But even better would be to move the padding inside the array element, which would remove the need for the However, this would also be a non-compatible change to the generate rust in some cases - because it will change when the array gets emitted as a rust array, and when it gets expanded. How big a deal is it if we make non-compatible changes to the generated rust? (The change on this PR also does this, but only for cases where the generated rust was previously incorrect, I believe.) |
I would want to see several different examples of generated code like: You add non-zero padding after last cluster. So they can be collected into array only if their increment equals to content size. I can be wrong, of course. Need examples. |
This corresponds to the first version of rust-embedded/svd2rust#519
This has the further fix mentioned in this comment: rust-embedded/svd2rust#519 (comment)
Ok. Can you rebase it on https://github.com/rust-embedded/svd2rust/tree/hex_reserved and I'll merge this patch. |
Add changelog entry.
* A cluster contains a cluster that ends with a cluster array. * The innermost cluster has a mismatch between the size of the element data and the array dim_increment.
Ok, I rebased on hex_reserved. (I also squashed the "clean up formatting commits at the same time). |
bors r+ |
- Option `-o`(`--output-path`) let you specify output directory path | ||
|
||
### Changed | ||
|
||
- `_rererved` fields in `RegisterBlock` now hexidemical usize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) My mistake
cluster_size_in_bits
was ignoring array information, leading to incorrect padding with nested clusters.I noticed this as incorrect padding on the three SARs in PASS0 on the Cypress cyt4bb. (The .svd for this requires registration on the Cypress website.)
It also shows up as incorrect padding on the TCPWM0 in the Cypress PSOC6_04 (svd at https://github.com/cypresssemiconductorco/psoc6pdl/blob/master/devices/svd/psoc6_04.svd)
E.g., for the PSOC TCPWM0, the diffs on the generated code from this change are:
Eyeballing the GRP, it has 8 * 128byte entries = 1024 bytes, and the correct padding is then 32768 - 1024 = 31744 bytes.