Skip to content

Allow scalar subtype declarations within composite subtype declarations

Currently, if I declare composite type, the types are fixed within the composite type declarations.

eg:

type pkt_t is (p0, p1, p2, p3, p4, p5, p6, p7);

type config_t is record
    pkt1 : pkt_t;
    pkt2 : pkt_t;
end record config_t;

now I can declare a subtype of pkt_t:

subtype test1_pkt_st is (p3 to p6);

But now I cannot apply this subtype to the config_t If I create an object of the test1_pkt_st , and assign it to an object of config_t, the subtype constraint is now lost.

variable test1_pkt    : test1_pkt_st;
variable test1_config : config_t;

test1_config.pkt1   := test1_pkt;   -- subtype constraints now lost.

Currently, the only way I can kind of get this working, is creating an entire new record type that uses the constrained subtype, and then doing a cast between the types as they are now similar types.

type test1_config_t is record
    pkt1 : test1_pkt_st;
    pkt2 : test1_pkt_st;
end record test1_config_t;

variable test1_config : test1_config_t;
variable config : config_t;

test1_config <= test1_config_t(config);

And the problem here is that any subprograms that use config_t are now unable to use the constraints defined for test1_config_t;

Proposal: Allow constraining of scalar types within a composite type declaration.

subtype test1_config_st is record
    pkt1 is (t3 to t6);
    pkt2 is (t1 to t3);
end record test1_config_st;


variable test1_config : test1_config_st;

-- or how about an array that autodetects meta values:
subtype slv_error_on_meta is std_logic_vector(open) ('0' to '1');
Edited by Richard Head
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information