Skip to content

Fix enumeratedValues derivedFrom lookup across sibling fields - #116

Open
RREE wants to merge 1 commit into
AdaCore:masterfrom
RREE:fix/enumeratedvalues-derivedfrom-sibling-field
Open

Fix enumeratedValues derivedFrom lookup across sibling fields#116
RREE wants to merge 1 commit into
AdaCore:masterfrom
RREE:fix/enumeratedvalues-derivedfrom-sibling-field

Conversation

@RREE

@RREE RREE commented Aug 21, 2026

Copy link
Copy Markdown

Summary

Read_Field in src/descriptors-field.adb only searched the current field's own Enums vector when resolving a derivedFrom attribute on a nested <enumeratedValues> element. That vector is still empty the first time a field's enumeratedValues is parsed, so a derivedFrom pointing at a named enumeratedValues defined on a sibling field (a valid CMSIS-SVD construct) could never be found, and Read_Enumerate raised Constraint_Error.

Reproduction

Espressif's esp32.svd triggers this on the RTC watchdog config register: the WDT_STG3 field defines a named enumeratedValues (OFF/INTERRUPT/RESET/RESET_SYS), and the sibling fields WDT_STG2, WDT_STG1, WDT_STG0 each reuse it via <enumeratedValues derivedFrom="WDT_STG3"/>:

$ bin/svd2ada -o /tmp --base-types-package=Interfaces esp32.svd
...
raised CONSTRAINT_ERROR : enumerate 'derivedFrom' is not known: WDT_STG3

Fix

Read_Field already receives Vec, the register's already-parsed sibling fields (used for field-level derivedFrom), but never passed it into the enumeratedValues-level lookup. This change builds the lookup vector from the current field's own enums plus every sibling field's enums before calling Read_Enumerate, so a derivedFrom reference can resolve to a named enum defined anywhere in the register, not just within the same field.

Test plan

  • alr build succeeds
  • bin/svd2ada -o /tmp --base-types-package=Interfaces esp32.svd completes (previously crashed) and generates ESP32.RTC_CNTL/ESP32.TIMG etc.
  • Verified esp32c3.svd and esp32s3.svd (same watchdog pattern) also generate cleanly
  • Confirmed generated output: WDT_STG3 gets its own enum type WDTCONFIG0_WDT_STG3 := (OFF, INTERRUPT, RESET, RESET_SYS), and WDT_STG2/WDT_STG1/WDT_STG0 correctly share that same enum type in the generated .ads

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.
@CLAassistant

CLAassistant commented Aug 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RREE

RREE commented Aug 21, 2026

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants