Partial assignment to signal of record type when setting initial value

781 Views Asked by At

Is it possible to do partial assignment to a record type on initialization?
Something like:

type t_foo is record
    a : integer;
    b : std_logic;
end record;

signal bar : t_foo := (b => '0');

In case of a normal signal assignment I could do:

bar.b <= '1';

This is however not possible when initializing a signal or constant. To me it looks like all record members must be assigned when setting the initial value or none at all.
There is probably a workaround possible using functions, but is there a simpler/better/native way?

1

There are 1 best solutions below

6
andrsmllr On

Since it is possible to have default values for function parameters, one possible workaround to achieve a "partial initialization" can be the use of a init function:

type t_foo is record
    a : integer;
    b : std_logic;
end record;

function init_t_foo(a : integer := 83423; b : std_logic := 'Z') return t_foo is
    variable ifoo : t_foo;
begin
    ifoo.a := a;
    ifoo.b := b;
    return ifoo;
end function init_t_foo;

constant bar : t_foo := init_t_foo(b => '1');

When calling the function only those parameters which should have non-default values are supplied, the other parameters will remain unchanged.

EDIT: fixed variable assignment.