3

In VHDL, is there a way to have a dynamically sized array for simulation?

I would like to use it as a list, i.e., the testbench repeatedly appends values to the end, and then iterates over the list. The length of the array is not statically known.

2
  • 3
    Yes. The easiest way is to determine the length at runtime, refer to the array via an access type (pointer) and allocate it with new. If it needs to continually grow, you will need to reallocate,copy atd free the old one. Commented Aug 3, 2015 at 13:54
  • 1
    But note that you can't create signals this way - only variables. Commented Aug 3, 2015 at 16:45

1 Answer 1

3

The array utility of VUnit (https://github.com/VUnit/vunit/tree/master/vunit/vhdl/array) provides the functionality you're looking for. It provides a protected type array_t which has a method append that does the dynamic sizing. Here is some code from the testbench for this utility (https://github.com/VUnit/vunit/blob/master/vunit/vhdl/array/test/tb_array.vhd) that exemplifies the append method

variable arr : array_t;
...
arr.init;
...
arr.append(11);
check_equal(arr.length, 1);
check_equal(arr.get(0), 11);

arr.append(7);
check_equal(arr.length, 2);
check_equal(arr.get(1), 7);
Sign up to request clarification or add additional context in comments.

1 Comment

Update: This type is now called integer_array_t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.