-
Notifications
You must be signed in to change notification settings - Fork 64
Handle overrides in element group derivation #293
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for the PR and sorry for the delay in reviewing! LGTM but I don't understand why the CI workflows haven't run and there doesn't seem to be the usual option to approve running them. Maybe if you run another force push it will run/allow approving to run? Otherwise all seems OK so we could merge through the merge queue which will run CI too. @burrbull / @Emilgardis ? |
|
Unfortunately the spec does not fully describe behavior during derive. I not sure about correctness of code neither before PR not after (I afraid that partial derive of dim group could cause tag conflicts). I need see real example what was working wrong and how it should work. |
@scootermon show this file, please. Or part of the file. |
| derived.dim_index = derived.dim_index.or_else(|| dim_index.clone()); | ||
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | ||
| derived.dim_array_index = derived.dim_array_index.or_else(|| dim_array_index.clone()); |
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.
| derived.dim_index = derived.dim_index.or_else(|| dim_index.clone()); | |
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | |
| derived.dim_array_index = derived.dim_array_index.or_else(|| dim_array_index.clone()); | |
| derived.dim_index = derived.dim_index.or_else(|| { | |
| dim_index | |
| .as_ref() | |
| .and_then(|di| (*dim == derived.dim).then(|| di.clone())) | |
| }); | |
| derived.dim_name = derived.dim_name.or_else(|| dim_name.clone()); | |
| derived.dim_array_index = derived.dim_array_index.or_else(|| { | |
| dim_array_index | |
| .as_ref() | |
| .and_then(|dai| (*dim == derived.dim).then(|| dai.clone())) | |
| }); |
We should derive dim_index only when same size.
@burrbull, unfortunately, I cannot share the file or significant portions from it. Here's a reduced version just to illustrate the pattern: <!-- CAN0 -->
<register>
<name>eRAM[%s]</name>
<description>Embedded RAM</description>
<size>32</size>
<access>read-write</access>
<dim>128</dim>
<dimIncrement>4</dimIncrement>
<!-- [Other elements omitted] -->
</register>
<!-- CAN1 (this one is complete!) -->
<register derivedFrom="CAN0.eRAM[%s]">
<name>eRAM[%s]</name>
<description>Embedded RAM</description>
<dim>64</dim>
<dimIncrement>4</dimIncrement>
</register>The CAN1 peripheral only has half the amount of "RAM" registers, but the fields are otherwise identical. |
|
Really strange that CI hasn't run. I agree with being hesitant to this change. Does the svd pass through svdconv? |
I think it's some weirdness with the CI not being approved in time. I rebased the PR so you should be able to approve the workflow run again. You can also see the run from the forked repo here: https://github.com/inomotech-foss/svd/actions/runs/20753031060 |
@Emilgardis I ran typedef struct { /*!< CAN0 Structure */
/* [SNIP] */
__IM uint32_t RESERVED4[11];
__IOM uint32_t CAN0_eRAM[128]; /*!< Embedded RAM */
__IM uint32_t RESERVED5[384];
/* [SNIP] */
} CAN0_Type;
typedef struct { /*!< CAN1 Structure */
/* [SNIP] */
__IM uint32_t RESERVED4[11];
__IOM uint32_t CAN1_eRAM[64]; /*!< Embedded RAM */
__IM uint32_t RESERVED5[448];
/* [SNIP] */
} CAN1_Type;So it definitely understands the I went ahead and crafted a minimal SVD file to reproduce this. You can find it along with the generated header file here: https://gist.github.com/scootermon/68828d5bc4f19b06dfb3a0b1e473d155 |
|
LGTM
|
I have an SVD file with two instances of a peripheral. The second peripheral contains the same registers, but instead of 128 it only has 64. The SVD file uses
derivedFromin the second peripheral to inherit these registers but overrides the<dim>element. To my surprise,svd2rustgenerated arrays with the same number of elements for both instances.Well, after following the trail I ended up here and the reason wasn't hard to find.
I saw #283 and the follow up #286, but there's little to no reasoning attached to these PRs.
Looking at the spec here I really don't see a reason why the fields from
dimElementGroupshouldn't also be overridden.The
derivedFromdescription readsI can't see a statement about the
dimElementGroupelements somehow being exempt.