Fix enumeratedValues derivedFrom lookup across sibling fields - #116
Open
RREE wants to merge 1 commit into
Open
Conversation
Read_Field only searched the current field's own (still empty at that point) Enums vector for a derivedFrom match on <enumeratedValues>, never the sibling fields already parsed in the same register. Per the CMSIS-SVD schema, a named enumeratedValues can be shared across fields via derivedFrom, so this raised Constraint_Error on any SVD using that pattern. Espressif's esp32.svd hits this: the RTC watchdog's WDT_STG2/1/0 fields each reference the enumeratedValues named "WDT_STG3" defined on their sibling WDT_STG3 field. Now the lookup also scans Vec (the register's already-parsed fields), so it finds enums defined on siblings, not just ones already appended to the current field.
Author
|
This is a fix for issue #98 . I generated the fix with the help of Claude Pro, if AI generated code is an issue for you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Read_Fieldinsrc/descriptors-field.adbonly searched the current field's ownEnumsvector when resolving aderivedFromattribute on a nested<enumeratedValues>element. That vector is still empty the first time a field'senumeratedValuesis parsed, so aderivedFrompointing at a namedenumeratedValuesdefined on a sibling field (a valid CMSIS-SVD construct) could never be found, andRead_EnumerateraisedConstraint_Error.Reproduction
Espressif's
esp32.svdtriggers this on the RTC watchdog config register: theWDT_STG3field defines a namedenumeratedValues(OFF/INTERRUPT/RESET/RESET_SYS), and the sibling fieldsWDT_STG2,WDT_STG1,WDT_STG0each reuse it via<enumeratedValues derivedFrom="WDT_STG3"/>:Fix
Read_Fieldalready receivesVec, the register's already-parsed sibling fields (used for field-levelderivedFrom), but never passed it into theenumeratedValues-level lookup. This change builds the lookup vector from the current field's own enums plus every sibling field's enums before callingRead_Enumerate, so aderivedFromreference can resolve to a named enum defined anywhere in the register, not just within the same field.Test plan
alr buildsucceedsbin/svd2ada -o /tmp --base-types-package=Interfaces esp32.svdcompletes (previously crashed) and generatesESP32.RTC_CNTL/ESP32.TIMGetc.esp32c3.svdandesp32s3.svd(same watchdog pattern) also generate cleanlyWDT_STG3gets its own enum typeWDTCONFIG0_WDT_STG3 := (OFF, INTERRUPT, RESET, RESET_SYS), andWDT_STG2/WDT_STG1/WDT_STG0correctly share that same enum type in the generated.ads