I am trying to use a function defined in a virtual class of a package to determine a parameter and I have run into an issue. Is there an elegant way to do this?. Here’s a snippet of code that causes the issue - the compiler complains of that a non-static class member cannot be accessed via the class scope resolution operator but I am not sure how I could resolve this.
package test_pkg;
virtual class const_func #(parameter ARRAY_SIZE = 8);
function automatic int num_sel
(
input logic [(ARRAY_SIZE-1):0] sel
);
int num;
num = 0;
for(int i = 0; i < ARRAY_SIZE; ++i)
if (sel[i])
num = num + 1;
return(num);
endfunction: num_sel
endclass: const_func
endpackage
module test
#(
parameter int NUM_WORDS = 32,
parameter logic [(NUM_WORDS-1):0] SM_WORD_SEL = 'h55555555,
parameter int SEL_NUM_WORDS = test_pkg::const_func#(.ARRAY_SIZE(NUM_WORDS))::num_sel(SM_WORD_SEL)
)
( input clk,
input rst_n,
input [(SEL_NUM_WORDS-1):0] sel,
output out
);
endmodule