fiz
fiz

Reputation: 934

Creating an unconstrained asymmetrical array of arrays

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:

Upvotes: 3

Views: 75

Answers (1)

fiz
fiz

Reputation: 934

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.

Upvotes: 1

Related Questions