# Mimic object constructor in VHDL

I am writing IPbus Transaction Verification Model for UVVM and I have encountered some problem. I know potential solution, but I don't like it and I am not sure if it can be handled better in some different way.

Here is some code snippet that is necessary to introduce the problem.

  type t_ipbus_tranaction_header is
record
protocol_version : natural range 0 to 2**4  - 1;
transaction_id   : natural range 0 to 2**12 - 1;
words            : natural range 0 to 2**8  - 1;
type_id          : t_ipbus_transaction_type_id;
info_code        : t_ipbus_transaction_info_code;
end record;

-- Overload t_slv_array in order to enable unconstrained array in record.
type t_slv_array is array (natural range <>) of std_logic_vector(31 downto 0);

type t_ipbus_transaction is
record
bodyy  : t_slv_array;
end record;

function ipbus_transaction (
protocol_version : natural;
transaction_id   : natural;
words            : natural;
type_id          : t_ipbus_transaction_type_id;
info_code        : t_ipbus_transaction_info_code;
bodyy            : t_slv_array
) return t_ipbus_transaction is
variable trans : t_ipbus_transaction(bodyy(bodyy'length-1 downto 0));
begin
assert protocol_version = 2 report "Wrong IPbus protocol version." severity failure;

trans.bodyy                   := bodyy;

return trans;
end function;

) return t_ipbus_transaction is
variable aux : t_slv_array(0 downto 0);
begin
end function;


Now, I would like to define signal or variable in the testbench in the following way:

signal transaction : t_ipbus_transaction := ipbus_read_transaction(1, (others => '0'));


However this returns following error in the GHDL:

tb/ipbus_tvm_tb.vhd:40:12:error: declaration of signal "transaction" with unconstrained record type "t_ipbus_transaction" is not allowed
tb/ipbus_tvm_tb.vhd:40:12:error: (even with a default value)


I am not sure if it is because of lack of the support in the VHDL standard or in GHDL.

I have also tried the following definition:

signal transaction : t_ipbus_transaction := new ipbus_read_transaction(1, (others => '0'));


This returns error:

tb/ipbus_tvm_tb.vhd:41:53:error: a type mark must denote a type or a subtype
tb/ipbus_tvm_tb.vhd:41:53:error: (type mark denotes function "ipbus_read_transaction")


So it is not supported by the VHDL standard.

I am aware that the problem can be easily solved by the following definition:

signal transaction : t_ipbus_transaction(bodyy(0 downto 0)) := ipbus_read_transaction(1, (others => '0'));


However, this approach has few drawbacks for me. Namely:

1. User has to type redundant information.
2. User has to know transaction body length in advance.
3. User has to have greater knowledge about the protocol itself.

So, this is the VHDL language issue I am facing right now.

I realize already in this moment, that there also will be problem with returning response transaction in the procedure via output argument, where length of the transaction body is also unknown.

I would like to ask you for advice, if my object oriented approach to model the IPbus transaction with variable body length is implementable in the VHDL language.

Of the scant information I can find, the only thing that comes close to addressing your question is this post on VHDLGuru where the author points out that you can't even use a generic to set the size of the array, so that doesn't bode well for the dynamic approach you're targeting. (The author does propose using a package to help solve the problem, but that's probably not helpful for your purposes.)
If this is just a simulation model, why not just declare bodyy to be an array of fixed size (i.e. the maximum size you would ever require)? You would of course need another variable to track the actual message size, but that could be easily defined using your approach. The only downside to this approach is that your simulation could slow down for super-huge messages, but if you're trying to simulate super-huge messages then you have a problem no matter what approach you take...
• On the other hand, I'm sure. signal transaction : t_ipbus_transaction := ... provides no subtype indication constraint. IEEE Std 1076-2008 5.3.2.2 Index constraints and discrete ranges "The index range for each index of an array object or array subelement of a composite object is determined as follows: a) For a variable or signal declared by an object declaration, the subtype indication of the corresponding object declaration shall define a fully constrained subtype (and thereby, the index range for each index of the array object or subelement)." Shall has mandatory weight (1.3.1). – user8352 Mar 15 at 1:14