Consider the following VHDL record:
type big_record_t is record
field_a : unsigned(15 downto 0);
field_b : unsigned(23 downto 0);
end record;
Is it possible to get attributes on the record fields without instantiating the record itself? eg
signal ex : unsigned(big_record_t.field_a'range);
modelsim reports the following error:
(vcom-1260) Type mark (big_record_t) cannot be prefix of selected name.
I know that getting the attribute of a instantiated signal is possible but for this specific situation I want to get the type attributes from the type itself.
You cannot use the 'range
attribute on a type †, which is what you are trying to do in your code. If you were to do something like this:
signal big_record_instance : big_record_t;
signal ex : unsigned(big_record_instance.field_a'range);
It should work, because you are now trying to get the range of an instance, not a type.
An alternative if you don't have an instance might be to have your width based on constants in the same package that your record type is defined, something like this:
constant field_a_width : integer := 16;
type big_record_t is record
field_a : std_logic_vector(field_a_width-1 downto 0);
field_b : std_logic_vector(23 downto 0);
end record;
signal ex : std_logic_vector(field_a_width-1 downto 0);
Or perhaps
constant field_a_width : integer := 16;
subtype field_a_type is std_logic_vector(field_a_width-1 downto 0);
type big_record_t is record
field_a : field_a_type;
field_b : std_logic_vector(23 downto 0);
end record;
signal ex : field_a_type;
† see exception in comments