Skip to content
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

Rework: Enum typename considering name in enumeratedValues #627

Merged
merged 1 commit into from Jul 14, 2022

Conversation

luojia65
Copy link
Contributor

@luojia65 luojia65 commented Jul 10, 2022

Marked as draft: this pull request depends on #626, and should be merged after that pull request is merged. Ready for review as #626 is merged.

This pull request is a rework to #612; commits in this pull request only considers enumeration name other than writer structure and reader structure. Names to those two proxy structures are yet to be discussed.

svd2rust has a good mechanism to parse enumeratedValues into Rust enums. However, current code would pick name of the first field the enum resides, and use pub type to re-export it into other names.

SVD files provide name field in enumeratedValues, this commit make use of them to name the Rust enums it generated. After this commit, more information of SVD file is considered in output pac crate. Users may also discover a significant drop in amount of types, which will speed up rustdoc generation and crate compilation.

After this pull request is merged, we can discuss on how the read proxy and write proxy should be named as is mentioned in comment at #612.

Before this pull request:

图片

After this pull request:

图片

SVD file for this example:

        <register>
          <name>interrupt</name>
          <description>Interrupt enables, states and masks</description>
          <addressOffset>0x04</addressOffset>
          <resetValue>0x3f003f00</resetValue>
          <resetMask>0xffffffff</resetMask>
          <fields>
            <field>
              <name>fifo_error_enable</name>
              <description>Transmit or receive FIFO error interrupt enable</description>
              <lsb>29</lsb>
              <msb>29</msb>
              <writeConstraint>
                <useEnumeratedValues>true</useEnumeratedValues>
              </writeConstraint>
              <enumeratedValues>
                <name>InterruptEnable</name>
                <enumeratedValue>
                  <name>enable</name>
                  <description>Enable interrupt</description>
                  <value>1</value>
                </enumeratedValue>
                <enumeratedValue>
                  <name>disable</name>
                  <description>Disable interrupt</description>
                  <value>0</value>
                </enumeratedValue>
              </enumeratedValues>
            </field>
            <field>
              <name>arbitrate_lost_enable</name>
              <description>Arbitration lost interrupt enable</description>
              <lsb>28</lsb>
              <msb>28</msb>
              <writeConstraint>
                <useEnumeratedValues>true</useEnumeratedValues>
              </writeConstraint>
              <enumeratedValues derivedFrom="InterruptEnable" />
            </field>
<!-- ...... -->

@rust-highfive
Copy link

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 10, 2022
@luojia65 luojia65 force-pushed the enum-names branch 3 times, most recently from 541b2dc to 01e2bb2 Compare July 11, 2022 09:07
@luojia65 luojia65 marked this pull request as ready for review July 12, 2022 00:53
@luojia65 luojia65 requested a review from a team as a code owner July 12, 2022 00:53
burrbull added a commit that referenced this pull request Jul 12, 2022
burrbull added a commit that referenced this pull request Jul 12, 2022
burrbull added a commit that referenced this pull request Jul 12, 2022
burrbull added a commit that referenced this pull request Jul 12, 2022
@burrbull burrbull mentioned this pull request Jul 12, 2022
bors bot added a commit that referenced this pull request Jul 12, 2022
630: docs from #627 r=therealprof a=burrbull

Some non-breaking changes from #627

Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
@burrbull
Copy link
Member

rebase, please.
You can use last commit from https://github.com/rust-embedded/svd2rust/commits/enum-names2

@luojia65
Copy link
Contributor Author

luojia65 commented Jul 13, 2022

thanks, I'll rebase to adapt main branch changes.

This pull request is a rework to rust-embedded#612; it only considers enumeration name
other than writer structure and reader structure. Names to those two
proxy structures are yet to be discussed.

svd2rust has a good mechanism to parse enumeratedValues into Rust enums.
However, current code would pick name of the first field the enum resides,
and use `pub type` to re-export it into other names.

SVD files provide `name` field in enumeratedValues, this commit make use of
them to name the Rust enums it generated.
After this commit, more information of SVD file is considered in output pac crate.
Users may also discover a significant drop in amount of types, which will speed up
rustdoc generation and crate compilation.

This commit is tested on deriving enum from other peripherals and
registers, and it uses old convention of format! macro to match the
1.51.0 minimum supported Rust version.
@luojia65
Copy link
Contributor Author

@burrbull: Hello! I have rebased to master and pushed my commit.

@burrbull
Copy link
Member

@burrbull: Hello! I have rebased to master and pushed my commit.

Thanks. Could you also look at GD32 #628 ?
Possibly you have idea how to fix it.

@burrbull
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 14, 2022

Build succeeded:

@bors bors bot merged commit ce233c4 into rust-embedded:master Jul 14, 2022
@luojia65 luojia65 deleted the enum-names branch July 19, 2022 04:53
@burrbull burrbull mentioned this pull request Jul 25, 2022
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.

None yet

4 participants