I want to pass type as an argument in the function as shown below :
module tb;
function void check(type a = int);
a s;
$display(s);
endfunction
initial
begin
check(reg);
check(int);
end
endmodule
but this is not working…can someone say is there any way to pass type as an argument.
thankyou
In reply to sasi_8985:
You can wrap your function in a parameterized virtual class.
module tb;
virtual class C#(type a);
static function void check;
a s;
$display(s);
endfunction
initial
begin
C#(reg)::check;
C#(int)::check;
end
endmodule
This is explained in section 13.8 of the IEEE 1800-2017 LRM and some synthesis tools support this.
In reply to dave_59:
Hi dave, can you kindly explain me what is type reference and how ‘var’ and ‘nettype’ keyword works?
In reply to sasi_8985:
You need to explain where you saw these terms in relation to the discussion above.
In reply to dave_59:
Hi, in lrm 13.4 section there is a table in which type reference is mentioned under data type.
Page no 290. This is related to can functions input arguments be given using type operator
In reply to sasi_8985:
I believe you are looking at an older version of the LRM. The IEEE 1800-2017 is the current version. The type_reference has been removed because you can’t have nets as function arguments or return types.