I have code with nested template parameters:
class datatype#(parameter int W);
bit signed [W-1:0] s;
static const int c_W=W;
endclass
class data_packer#(type T, int W);
static function void pack(T in);
$display("data_packer: W equals %0d",W);
endfunction
endclass
class C#(type T, int Z);
T x;
function void f();
//data_packer#(T,T::c_W)::pack(x);
data_packer#(T,Z)::pack(x);
endfunction
endclass
...
C#(datatype#(20),20) myC=new;
myC.f();
This works but I need to pass the ‘20’ twice. So I wanted to do:
class datatype#(parameter int W);
bit signed [W-1:0] s;
static const int c_W=W;
endclass
class data_packer#(type T, int W);
static function void pack(T in);
$display("data_packer: W equals %0d",W);
endfunction
endclass
class C#(type T);
T x;
function void f();
data_packer#(T,T::c_W)::pack(x);
//data_packer#(T,Z)::pack(x);
endfunction
endclass
...
C#(datatype#(20)) myC=new;
myC.f();
I.e. replacing the Z parameter by the ‘extracted’ T::c_W.
This compiles fine, but doesn’t run. Is this not possible in SV or am I making a big mistake somewhere?