tgingold-cern / cheby

GNU General Public License v3.0
7 stars 4 forks source link

Fix constants generation with same c_name between register and field #44

Closed lorenzschmid closed 2 months ago

lorenzschmid commented 2 months ago

Bug introduced in #43:

If there is a register containing a single field and both share the same name, both of their c_names will be equal. Hence, when the default separator _ is selected, pr_name() will return the same name for the register as well as for the field. Printing the address for the register and the field will therefore lead to the same constant printed twice.

E.g.

    - reg:
        name: foo_bar
        description: 'Foo Bar'
        width: 32
        access: rw
        children:
            - field:
                name: foo_bar
                description: 'Foo Bar'
                range: 31-0
    - reg:
        ...

will lead to the following VHDL constant generation (ADDR_REG_SET_FOO_BAR declared twice):

  constant ADDR_REG_SET_FOO_BAR : Natural := 16#c#;
  constant ADDR_REG_SET_FOO_BAR : Natural := 16#c#;
  constant REG_SET_FOO_BAR_OFFSET : Natural := 0;

Since before #43, the address constant was only printed for the register (but not for the field), the constant was previously printed only once.

This fix blocks the printing of the constant if a field and its register share the same c_name.

tgingold-cern commented 2 months ago

Maybe worth adding a test ?

lorenzschmid commented 2 months ago

Maybe worth adding a test ?

I agree but think that this should be done a bit more thoroughly than only compare to golden files. Hence, I opened #45 to tackle it at a later moment.