4

I'm trying to create dynamically sized nested generate statements so non-firmware people can change the values of constants.

I want to create something like C++ vectors which at compile time will have a defined size and contain integer constants. For example I would like a 2D vector which looks like this :

a = < <1,2> , <1,3> , <3,4,5> >

So I can access it like so:

a[0,0] = 5
a[1,0] = 3
a[2,1] = 1

So far I have tried this:

type int_array is array (integer range<>) of integer;
type int_array_array is array (integer range<>, integer range<>) of integer;

constant nOuter : positive := 2;
constant nInner : int_array := (2 , 2 , 3);
constant vals : int_array_array(nOuter - 1 downto 0 , ???) := ( (1,2) , (1,3) , (3,4,5) );

I'm not entirely sure how this would be written or if this is even possible?

The idea being I could then create dynamically sized blocks like this:

nOuters: for i in 0 to nOuters -1 generate:
    nInners: for j in 0 to nInner(i) generate:
        nVals: for inner k in 0 to vals(i,j) -1 generate:
2
  • 1
    If you need this for synthesis it can't be done, as arrays have to be fixed at elaboration time. All sub-elements have to be the same size. Your options are to insert dummy values or store the rows in a record and use a function to "index" into it. If you only need this for simulation, though, it is possible to create arbitrary data structures using dynamically allocated access types, including heterogeneous arrays. Commented Feb 9, 2016 at 13:52
  • I understand they need to be fixed at elaboration time, but I guess there just isn't a way to make asymmetrical arrays. I'll just have to use dummy variables like in my answer below. Commented Feb 9, 2016 at 14:28

1 Answer 1

1

My crappy solution, I add another constant:

constant nMaxInner : positive := 3;

constant vals : int_array_array(nOuter - 1 downto 0 , nMaxInner - 1 downto 0) := ( (0,1,2) , (0,1,3) , (3,4,5) );

But this isn't elegant.

Sign up to request clarification or add additional context in comments.

Comments

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.