0

Say I have a custom record type:

type CustomRecord is record
    S : signed;
    V : std_logic;
end record;

We instantiate this by using

signal X : CustomRecord(S(21 downto 0))

which is fine. But then say I want another signal that depends on X's size, I would do

signal Y : CustomRecord(S(X.S'length downto 0))

How would I define a custom attribute for CustomRecord (e.g. 'length) so that the expression instead becomes something like:

signal Y : CustomRecord(S(X'depth downto 0))

All user-defined attributes I can find online are all hard-baked into the code.

When I try to define my own using

attribute depth : integer;
attribute depth of CustomRecord : type is CustomRecord.S'length;

I get "record type 'CustomRecord' cannot be selected", which I do more-or-less understand, but I don't know how to work around it.


Aside note: I know having the .S isn't that big of a deal, but in reality, X.S is an array of signed, so the expression is actually CustomRecord(S(X.S'length downto 0)(X.S(X.S'left)'length downto 0)) which I want to simplify to CustomRecord(S(X'width downto 0)(X'depth downto 0)). I've simplified it to just a signed for this example.

4
  • See e.g. IEEE Std 1076-2008 8.3 Selected names "or a selected name that is used to denote a record element, the suffix shall be a simple name denoting an element of a record object or value." A type name is neither an object nor named value while your first two signal declarations X or Y are valid prefixes. The predefined attribute 'length requires a prefix appropriate for an array object or a subtype defined by a constraint(16.2.3 Predefined attributes of arrays). You could instantiate a package with the type declaration element constraint derived from a generic. Consider providing a minimal reproducible example. Commented Aug 13, 2024 at 4:39
  • 1
    Why not use the 'subtype or 'element attributes? Posting a minimal reproducible example would help us help you. Commented Aug 13, 2024 at 5:23
  • 1
    OT: Wouldn't x'length downto 0 extend the new object by one? Commented Aug 13, 2024 at 6:14
  • x'length downto 0 would absolutely extend the new object by one, and that is very much intended. I'm looking to change the size of these new objects (either smaller or larger than the original), but 'subtype and 'element is definitely interesting and was something I wasn't aware of. Thank you. Commented Aug 14, 2024 at 5:26

1 Answer 1

1

Getting something the same size is easy:

signal Y : X'subtype ; 

This is why @Tricky suggested you to look at `subtype.

However, changing the size is tedious as you have found and needs to be looked by the VHDL working group (and you should join us).

What can we do about this for future revisions of VHDL is discussed here:
https://gitlab.com/IEEE-P1076/VHDL-Issues/-/issues

In particular issues that are indirectly related, but may be interesting are here:
https://gitlab.com/IEEE-P1076/VHDL-Issues/-/issues/83
https://gitlab.com/IEEE-P1076/VHDL-Issues/-/issues/81

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.