Bin creation using functions

Hi,

Iam trying to create bins using a function just to avoid the repetition. But Iam getting error in below code

function bins_uint bin_creator(int size, int multiple);
    bins_uint local_arr;
    local_arr = new[size/multiple];
    foreach(local_arr[i]) begin
      local_arr[i] = i*multiple; 
    end
  endfunction

  covergroup cg with function sample(trans txn);
    efc_obw_cp : coverpoint txn.width { 
                   bins width[] = bin_creator(8,8);
                 }
  endgroup

The intention of above code is to generate multiples of 8, till 64(which is size). Iam trying to make bins 0,8,16,24,32…64. But iam getting an error. Could anyone please suggest me a better way to do it or why the error is popped up? This is not just for 8 multiple, I want to re-use for other multiples as well

Thanks

In reply to Anudeep J:

Please mention the error that you are getting.
Have you tried using queue instead of array?

In reply to mbhat:

In reply to Anudeep J:
Please mention the error that you are getting.
Have you tried using queue instead of array?

Please find the error below :
Error-[SE] Syntax error
Following verilog source has syntax error :
“/local_vol1_nobackup/coverage.sv”,
411: token is ‘(’
bins width = bin_creator(8,8);

In reply to Anudeep J:

In reply to mbhat:
Please find the error below :
Error-[SE] Syntax error
Following verilog source has syntax error :
“/local_vol1_nobackup/coverage.sv”,
411: token is ‘(’
bins width = bin_creator(8,8);

Check your simulator to see the SV LRM (2012 should support using queues and arrays) it is supporting, I believe I the support is to use s queue or array in the RHS of the bins expression, not a function (I could be wrong) , you could try something like this.

class some_cov
bit [7:0] my_bins[$];
bit [7:0] data;
covergroup m_cg;
        data_cp  :  coverpoint data 
        { 
            bins data_bins[] = my_bins;
        }
endgroup
 
function new (string _name = "", int size);
        int count
        this.name = _name; 
        repeat(size) begin
          my_bins.push_back((count++)*8);
        end
        m_cg = new();       
endfunction 

endclass