Skip to content

Emit more Cluster arrays as arrays instead of lists of elements. - #534

Merged
bors[bot] merged 2 commits into
rust-embedded:masterfrom
rcls:array-proxy
Jul 21, 2021
Merged

Emit more Cluster arrays as arrays instead of lists of elements.#534
bors[bot] merged 2 commits into
rust-embedded:masterfrom
rcls:array-proxy

Conversation

@rcls

@rcls rcls commented Jul 19, 2021

Copy link
Copy Markdown
Contributor

(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.

Add ArrayProxy for handling Cluster arrays that would be emitted as a
rust array except for the need for padding between elements.
@rust-highfive

Copy link
Copy Markdown

r? @ryankurte

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Jul 19, 2021
@burrbull

burrbull commented Jul 19, 2021

Copy link
Copy Markdown
Member

One obvious issue with the current code: It uses const-generics, and does not build with the current minimum supported Rust version (1.40.0). Marking as draft until at least that is fixed.

svd2rust has --const_generic option that could be uses in your situation also.

Make the usage of ArrayProxy dependent on the const_generics config
option.
Comment thread src/generate/array_proxy.rs
@rcls

rcls commented Jul 20, 2021

Copy link
Copy Markdown
Contributor Author

svd2rust has --const_generic option that could be uses in your situation also.

Thanks. The changes updated to rely on that option.

@rcls
rcls marked this pull request as ready for review July 20, 2021 08:26
@rcls
rcls requested a review from a team as a code owner July 20, 2021 08:26
@burrbull

Copy link
Copy Markdown
Member

bors r+

@bors
bors Bot merged commit ead1f51 into rust-embedded:master Jul 21, 2021
@rcls
rcls deleted the array-proxy branch July 27, 2021 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants