0

I have the following function:

   function void foo_arr_bit (int seed, ref bit [*] mem, string  mem_name);
      for (int i=0; i< mem.size(); i++)
    mem[i] = my_randomize_int(seed, mem[i], mem_name);     
   endfunction: foo_arr_bit

I call the function by:

 foo_arr_bit(seed, data_bit, "data_bit"); 

Where data_bit can be: bit [1:0]/ bit [2:0]/ bit [3:0]/ bit [4:0]/ bit [5:0] etc...

When I try to compile I got the following error: near "[": syntax error, unexpected [ , expecting IDENTIFIER or TYPE_IDENTIFIER or NETTYPE_IDENTIFIER.

1 Answer 1

1

[*] is not the correct syntax for a dynamic array, use [].

Your array can only be dynamic in the unpacked dimension. So you cannot have bit [] mem_array, but must have bit mem_array[].

Finally a function using pass by reference cannot have a static lifetime. That is, it must be declared as automatic.

function automatic void foo_arr_bit (int seed, ref bit mem[], string  mem_name);
  for (int i=0; i< mem.size(); i++)
    mem[i] = my_randomize_int(seed, mem[i], mem_name);     
endfunction: foo_arr_bit

Edit: But even with these changes you face a bigger issue. Passing by reference demands very strict typing. There is no casting allowed so I expect there to be issues with type conversion.

Furthermore, passing by reference is not really necessary in your case. Use inout instead.

function automatic void foo_arr_bit (input int seed, string  mem_name, inout bit mem[]);
  for (int i=0; i< mem.size(); i++)
    mem[i] = my_randomize_int(seed, mem[i], mem_name);
endfunction: foo_arr_bit
Sign up to request clarification or add additional context in comments.

2 Comments

my input is packed array, not unpaked.
Systemverilog does not have dynamic packed arrays. Using a parameterizable class to encapsule your function could be a solution. More on that here: forums.accellera.org/topic/… Or just pass SIZE to the function and have a sufficiently large packed array.

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.