process all elements of (unknown) records

Discussion in 'VHDL' started by Duke Scarring, Nov 5, 2008.

  1. 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
    Duke Scarring, Nov 5, 2008
    #1
    1. Advertising

  2. Duke Scarring

    KJ Guest

    "Duke Scarring" <> wrote in message
    news:49116366$0$30236$-online.net...
    > 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.
    >


    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
    KJ, Nov 5, 2008
    #2
    1. Advertising

  3. Duke Scarring

    Guest

    On Nov 5, 4:11 am, Duke Scarring <> wrote:
    > 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
    , Nov 5, 2008
    #3
  4. Duke Scarring

    Tricky Guest

    On 5 Nov, 09:11, Duke Scarring <> wrote:
    > 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).
    Tricky, Nov 5, 2008
    #4
  5. Duke Scarring

    elizas

    Joined:
    Jan 27, 2010
    Messages:
    27
    Location:
    India
    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
    elizas, May 6, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Airig
    Replies:
    0
    Views:
    765
    Luke Airig
    Dec 31, 2003
  2. Gerald Aichholzer
    Replies:
    2
    Views:
    2,471
    Gerald Aichholzer
    Jun 27, 2006
  3. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    448
    Ray at
    May 10, 2004
  4. Replies:
    3
    Views:
    637
    Anthony Jones
    Nov 2, 2006
  5. Vincent Arnoux
    Replies:
    1
    Views:
    226
    Arnaud Bergeron
    Aug 11, 2006
Loading...

Share This Page