-- Automatically generated by WhishList - https://gitlab.cern.ch/msilvaol/wishlist
-- Package name: {{ name.lower() }}_pkg
-- Description : {{ description }}

library ieee;
use ieee.std_logic_1164.all;

package {{ name.lower() }}_pkg is

-- register data types
{# Iterating through registers #}
{%- for register in registers %}
    {%- set names = get_node_names(register, direction=None) %}
subtype {{ names['type_name'] }} is {{ names['vector'] }};
    {#- Checking if there is an array associated to it #}
    {%- if names['array'] %}
type {{ names['array_name'] }} is {{ names['array'] }};
    {%- endif %}
{%- endfor %}

{#- Iterating status and control registers #}
{% for permission,direction in (('r','status'),('rw','control')) %}
-- {{ direction }} hierarchy data types
    {#- Iterating through hierarchies #}
    {%- for hierarchy in hierarchies %}
        {#- Checking if there are descendants with the required permission value #}
        {% if attr_in_family(hierarchy,'permission',permission) %}
            {%- set parent_names = get_node_names(hierarchy, direction) %}
{#- Opening the record declaration #}
type {{ parent_names['type_name'] }} is record
            {#- Iterate thorugh each child of an hierarchical node #}
            {%- for child in hierarchy.children %}
                {#- Checking if itself or descendants have the required permission value #}
                {%- if attr_in_family(child,'permission',permission) %}
                    {%- set child_names = get_node_names(child, direction) %}
    {#- Adding member to record with type depending on both children and length attributes of the child #}
    {{ child.name.lower() }} : {{ child_names['member_name'] }};
                {%- endif %}
            {%- endfor %}
{#- Closing the record declaration #}
end record {{ parent_names['type_name'] }};
            {#- Checking if there is an array associated to this record #}
            {%- if parent_names['array'] %}
type {{ parent_names['array_name'] }} is {{ parent_names['array'] }};
            {%- endif %}
        {%- endif %}
    {%- endfor %}
{% endfor %}

end package {{ name.lower() }}_pkg;

