On Wednesday, November 26, 2014 6:21:16 AM UTC-5, Allan Herriman wrote:
> Hi,
>
> I'm trying to do something equivalent to the following:
>
> generic g : boolean;
> ...
> constant c : some_type := expression1 when g else expression2;
>
<snip>
>
> Q3: If not, how do we go about fixing this?
>
>
Write a function that takes as input the condition and the two expressions and returns the result. I called mine 'sel' (since 'select' is already a reserved keyword). Overload it for all of the basic types that you would use for an expression as well as for std_ulogic and boolean for the condition. Works just fine for any version VHDL.
function sel(Cond: BOOLEAN; If_True, If_False: integer) return integer;
function sel(Cond: BOOLEAN; If_True, If_False: real) return real;
function sel(Cond: BOOLEAN; If_True, If_False: time) return time;
function sel(Cond: BOOLEAN; If_True, If_False: BOOLEAN) return BOOLEAN;
function sel(Cond: BOOLEAN; If_True, If_False: arr_integer) return arr_integer;
function sel(Cond: BOOLEAN; If_True, If_False: arr_natural) return arr_natural;
function sel(Cond: BOOLEAN; If_True, If_False: arr_real) return arr_real;
function sel(Cond: BOOLEAN; If_True, If_False: arr_time) return arr_time;
function sel(Cond: BOOLEAN; If_True, If_False: std_ulogic) return std_ulogic;
function sel(Cond: BOOLEAN; If_True, If_False: std_ulogic_vector) return std_ulogic_vector;
function sel(Cond: BOOLEAN; If_True, If_False: std_logic_vector) return std_logic_vector;
function sel(Cond: BOOLEAN; If_True, If_False: signed) return signed;
function sel(Cond: BOOLEAN; If_True, If_False: unsigned) return unsigned;
function sel(Cond: BOOLEAN; If_True, If_False: STRING) return STRING;
function sel(Cond: BOOLEAN; If_True, If_False: Character) return Character;
Then the usage is simply:
constant c : some_type := sel(g, expression1, expression2);
Or for the more wordy
constant c : some_type := sel(Cond => g, If_True => expression1, If_False => expression2);
Kevin Jennings