[vhdl-200x] Iterating across a Record Type

From: Daniel Kho <daniel.kho@tauhop.com>
Date: Wed Jun 04 2014 - 21:14:42 PDT
Hi friends,
I know this question has been asked before in some forums, but I feel it
hasn't been adequately answered. My intent is to loop across all elements
of a record type, similar to how we could do it with an array:

for i in vect'range loop
end loop;

where "vect" is an array vector of naturals for example.

The question is, if I had a record type with several sub-elements, how
would I be able to iterate across all the sub-elements? For example, assume
we have a record:

type rec is record
    b:std_ulogic_vector(15 downto 0);
    c:signed(7 downto 0);
end record rec;

I prefer to not have to write out all the sub-elements individually:
function resolve(r:rec) return rec is begin
    if is_x(r.a) then ... end if;
    if is_x(r.b) then ... end if;
    if is_x(r.c) then ... end if;
end function resolve;

Currently, I feel having an option for iterating across record structures
will be very useful especially when writing resolution functions, but I
believe this usefulness can be applied to many other scenarios as well.
Another application I can think of which makes having such a feature
useful, is to apply them for initializers.

Some languages (e.g. scripting languages) have something like "child" or
"next" keywords which we can use to access neighbouring elements of a
structure. I was thinking of having something like this for VHDL:

function resolve(r:rec) return rec is begin
    for i in r'range loop    -- okay, 'range only works for arrays now,
                                   -- but you get the idea.
        if is_x(r.child(i)) then ... end if;
    end loop;
end function resolve;

Of course, "child" may as well be some other keyword, e.g. "element", or
picked from a suitable existing VHDL keyword.

Best regards,

This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed Jun 4 21:15:58 2014

This archive was generated by hypermail 2.1.8 : Wed Jun 04 2014 - 21:16:33 PDT