-
Notifications
You must be signed in to change notification settings - Fork 156
Put padding for cluster-arrays inside each individual array element, #531
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? @burrbull (rust-highfive has picked a reviewer for you, use r? to override) |
instead of breaking the array up into a list of items and adding padding between the items.
d6f4dc6
to
655e0a1
Compare
This is excellent change in theory. |
I hadn't thought of the case where some random other register was placed within the padding (Does SVD allow that? - I'm not particularly familiar with the specification). |
I'm afraid, the answer YES. |
I'll attempt to address this & only apply my change in cases where it is safe. Do you have a SVD you can point me at? (Or I can probably make one up). |
To get this right, seems to need a bit of re-arranging of the existing code, as currently we decide whether or not to split an array before sorting, making it harder to know whether or not another register falls into the padding.
@burrbull does that sound like a sensible plan to you? Or am I still missing some complexity. |
I'm thinking about 2-pass expanding of peripheral children. |
A much less elegant solution, but easier to implement, would be to add methods to do the array indexing on the containing cluster: |
This is a good temporary solution in the sense that we can deprecate it some time after we find better way and implement it. |
A slight variant on the |
Closing this pull-request. #534 has a different approach which doesn't fall foul of the problems discussed above. |
534: Emit more Cluster arrays as arrays instead of lists of elements. r=burrbull a=rcls (This obsoletes #531) Some Cluster arrays cannot be emitted as Rust (built-in) arrays due to padding between elements. Add a helper zero-sized type `ArrayProxy` that overloads `[]` to do pointer-arithmetic internally. I believe, although I'm not 100% confident, that I'm not breaking Rust safety, as follows: There is no way for (safe) code to create an `ArrayProxy`. Code that produces a (reference to) an `ArrayProxy` has to use `unsafe` somewhere. See rcls/svd2rust-example@b8645fe for any example of the difference this makes (or does not make): - STM32L051 and LPC408x get no change. - Cypress PSOC gets a significant difference. This uses const generics, so the new functionality requires the `--const_generic` command line optoin. Co-authored-by: Ralph Loader <[email protected]>
Currently, some SVD arrays get emitted as a sequence of numbered fields, instead of as a single rust array, due to padding between elements.
This change moves the padding into the array elements, allowing the SVD array to be emitted as a rust array. This makes the generated API more consistent and easier to use. (The downside is that the API changes are not backward compatible.)
Cypress PSOC and Traveo processors appear to be particularly effected with this, it looks like many others get no change. I made a git repo show the changes for three processors at rcls/svd2rust-example@08798fc