process all elements of (unknown) records

D

Duke Scarring

Hi folks,

I want process all elements of an unknown vhdl record. The following way
did'nt work with vhdl:

--
type r_t is record
a : std_logic;
b : bit_vector(3 downto 0);
i : integer;
end record;

dont_go: process
variable v : r_t;
begin
for i in v'range loop
do_something( v.i );
end loop;
end process;
--

With this way it works, but if I enhance my record, I also have to
enhance the process:

--
is_ok: process
variable v : r_t;
begin
do_something( v.a);
do_something( v.b);
do_something( v.i);
end process;
--

Maybe anyone has an suggestion how to handle such thing sophisticated
and flexible.

Thanks,
Duke
 
K

KJ

Duke Scarring said:
Hi folks,

I want process all elements of an unknown vhdl record. The following way
did'nt work with vhdl:

--
type r_t is record
a : std_logic;
b : bit_vector(3 downto 0);
i : integer;
end record;

dont_go: process
variable v : r_t;
begin
for i in v'range loop
do_something( v.i );
end loop;
end process;
--

With this way it works, but if I enhance my record, I also have to enhance
the process:

--
is_ok: process
variable v : r_t;
begin
do_something( v.a);
do_something( v.b);
do_something( v.i);
end process;

There is no way to do what you're proposing with records.

One alternative would be to arrange things as a multi-dimensional array of
some basic type. The problem there is that every element would have to be
of a size that works for all. In your example record with a std_logic, a
bit_vector(3 downto 0) and an integer, you would have to size it big enough
to handle the 32 bits of an integer. In reality though, this method really
doesn't have much appeal, because even though you've solved a method for
storing the record data that you'd like to store, in order to use the data
in a meaningful fashion you'd still have to convert the individual elements
back into the data types that are meaningful for you before you'd use them
(i.e. std_logic, a bit_vector(3 downto 0) and an integer).

Although the idea of being able to iterate through record elements has some
appeal, most of the time it is not really needed. In the example you
posted, you state "but if I enhance my record, I also have to enhance the
process" but that's not really true. If the process is doing what you want
it to do then it would not need any changes just because you added an
element to the record. The places where this would be useful though are
ones that inherently do something with every element of the record (for
example, a function/procedure that returns a string for display or writing
to a file that dumps the contents of the record for logging). But such a
function/procedure should be defined in the same package where the record is
defined. All of this should be located fairly close together in the same
file

package my_pkg is
type r_t is record
a : std_logic;
b : bit_vector(3 downto 0);
i : integer;
end record;
function Printme(x: r_t) return string;
end package my_pkg;
package body my_pkg is
function Printme(x: r_t) return string is
begin
....
end function Printme;
end package body my_pkg;

Kevin Jennings
 
K

kennheinrich

Hi folks,

I want process all elements of an unknown vhdl record. The following way
did'nt work with vhdl:

--
type r_t is record
   a : std_logic;
   b : bit_vector(3 downto 0);
   i : integer;
end record;

dont_go: process
   variable v : r_t;
begin
   for i in v'range loop
     do_something( v.i );
   end loop;
end process;
--

With this way it works, but if I enhance my record, I also have to
enhance the process:

--
is_ok: process
   variable v : r_t;
begin
   do_something( v.a);
   do_something( v.b);
   do_something( v.i);
end process;
--

Maybe anyone has an suggestion how to handle such thing sophisticated
and flexible.

Thanks,
Duke

I have wanted the same thing on many occasions, but so far (unless
VHDL-2008 adds something neat) this capability is missing in VHDL.
Part of the reason is that there are all sorts of typechecking
complexities that would arise (need to do run-time *type* checking and
have type-polymorphic variables, instead of merely run-time *subtype*
checking). Dynamic types and type polymorphism are not part of the
VHDL philosophy from what I've seen. This is not necessarily a bad
thing, though.

Your first form doesn't work because, while "range" is a type of
iterator (which is what you want), it's a scalar iterator whose exact
type has to be known (and hence stay fixed) before the loop executes.

If you want this kind of outside-the-language capability you'll
probably need to use a preprocessor or hack up a tool to build
procedure & package definitions for you from some sort of prototype.

- Kenn
 
T

Tricky

Hi folks,

I want process all elements of an unknown vhdl record. The following way
did'nt work with vhdl:

--
type r_t is record
   a : std_logic;
   b : bit_vector(3 downto 0);
   i : integer;
end record;

dont_go: process
   variable v : r_t;
begin
   for i in v'range loop
     do_something( v.i );
   end loop;
end process;
--

With this way it works, but if I enhance my record, I also have to
enhance the process:

--
is_ok: process
   variable v : r_t;
begin
   do_something( v.a);
   do_something( v.b);
   do_something( v.i);
end process;
--

Maybe anyone has an suggestion how to handle such thing sophisticated
and flexible.

Thanks,
Duke

I dont really see the time saving benefit? You would still have to
handle each element differently unless they are all the same type, and
you wanted to do the same thing with every element. So for example, if
do_something was a procedure or a funtion, you'd still have to write
an explicit function that handled the new element in an appropriate
way. But the problem with the "dont_go" process, is that you'd have a
load of functions with the same name but all an overloaded version
with the same name. I dont think this would read very well in most
code. Id rather have the function/procedure named appropriatly for
what its actually doing. (this applies if its not a function or
procedure).
 
Joined
Jan 27, 2010
Messages
27
Reaction score
0
Think before you loop records

We can modify/update the record data of a form by looping through its records. So, we are generally following the below code to do the same.





// loop through the records


var count = 1;

var maxCount = controller.getMaxRecordIndex();

for(var count=1; count<=maxCount; count++) {

// select the record

controller.setSelectedIndex(count);

/* Do any operations with the

selected record */

}

For more information
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Range of records 3
Assignment of records 8
simulating records 0
Detecting edges of array elements 3
Illegal sequential statement (VHDL) 0
Records in vhdl 6
assigning different elements of array 5
erreur VHDL 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top