Search code examples
vhdlvivadoghdl

return unconstrained array in vhdl


what's the best way to return an unconstrained vector in vhdl?

function func(selector : natural) return std_logic_vector is
begin
    case selector is
        when 3 => return std_logic_vector("11");
        when 4 => return std_logic_vector("101");
        when others => return std_logic_vector("0");
    end case;
end function;

In this case i get string literal cannot be a type conversion operand, so it doesn't work. The signal selector is generic, so it don't have to be synthesizeable.


Solution

  • You can't do this. The return value from your function will need to be associated with something when it is called and that something will have to be of a fixed width. In other words, you'll have to say thing like:

    s <= func(n);
    

    and s will have a fixed width, so all the return values from your function will have to have the same width.