1)
architecture a of t is
type arr is array (natural range <>) of std_logic_vector(N downto 0) ;
signal rr : arr(M downto 0) := (others => (others => '0')) ;
...
2) this doesn't work without a package because a port of array type has to be fully constrained (at least in VHDL 93, see later). An alternative is to use the std_logic_2D data type , declared in the lpm package as
type std_logic_2D is array (natural range<> , natural range <>) of std_logic ;
This you can use in your entity:
library lpm ;
use lpm.lpm_components.all ; -- or use lpm.lpm_components.std_logic_2D
entity t is
generic (
M : natural := 4 ;
N : natural := 2
) ;
port (
...
result : std_logic_2D(M - 1 downto 0 , N - 1 downto 0) ;
...
) ;
end entity t ;
If you have a utility package you include in your projects (I do) you could add the std_logic_2D declaration there in stead of relying on the lpm package
Slicing and assigning values is tedious though and you may have to write (quite a few) functions and procedures in your utility package to handle that all.
There is an alternative in VHDL 2008 that let's you define an array of unconstrained std_logic_vector:
type arr_slv is array (natural range <>) of std_logic_vector ;
You would again add this declaration in your utility package, which you could use like this :
use work.my_utility_package.all ;
entity t is
generic (
M : natural := 4 ;
N : natural := 2
) ;
port (
...
result : out arr_slv( M - 1 downto 0 )(N - 1 downto 0 ) ;
...
) ;
I'm not sure whether ModelSim handles that, Quartus II should as it did so already in version 10.0. Unfortunately I have to stick with the std_logic_2D as I have too much legacy source code to convert otherwise