Add "Rules" function on the end of "Subtype Indication"
The current (well, VHDL 2008 LRM I have access to) declares the subtype_indication
on p65 to be:
subtype_indication ::= [ resolution_indication ] type_mark [ constraint ]
Im proposing this is changed to
subtype_indication ::= [ resolution_indication ] type_mark [ constraint ] [rules_indication]
Where rules_indication
is a function call when an object is created using the specified subtype with the following signature:
function <rules> (o : <base_t>) return <base_t>;
where o
is the object declared
using my usual AXIS example (and also would be nice when paired with #79):
type axis_t is private record
tdata : std_logic_vector;
tkeep : std_logic_vector;
end record axis_t;
and a user could declare a "rules" function like this:
function axis_rules(o : axis_t) return axis_t is
begin
assert tdata'length rem 8 = 0 report "tdata length must be a multiple of 8 bits" severity ERROR;
assert tkeep'length = tdata'length/8 report "tkeep must have 1 bit per tdata byte" severity ERROR;
return o;
end function;
subtype axis_checked_t is axis_t axis_rules;
Then, as another interesting effect, you could override the initial value for a given subtype:
function axis_init(o : axis_t) return axis_t is
variable r : o'subtype := o;
begin
r.tkeep := (others => '0');
return r;
end function;
subtype axis_tkeep_init_t is axis_t axis_init;
and finally, if you remove the subtype restriction on protected types, you can give yourself a "constructor"
type p_t is private protected -- cannot create object directly
procedure init;
end prootected p_t;
function p_t_init(o : p_t) return p_t is
variable r : p_t;
begin
r.init;
return r;
end function;
subtype p_constructor_t is p_t p_t_init;
shared variable some_inited_object : p_constructor_t; -- will create the object and call the "init" constructor