Hi
I need help in Oveririding The parameter inside the class.
class basic;
parameter int My_var=1;
endclass
module basic;
//import abc#(My_var=2)::*;
//import abc::*;
initial begin
//abc::My_var=2;
basic1#(.My_var(2)) bas;
bas=new();
//defparam bas.My_var=2;
$display("My_var=%d",bas.My_var);
end
endmodule
How we do this,I want to understand the real use of parameter inside class.
Thanks
Bharath
Barath,
Please use code tags to format your code.
Parameters cannot be procedurally overridden. Parameters are compile time constants that can be used in the definition of other types. The compiler requires that certain expressions be compile time constants so it can either generate the code to simulate it, or synthesize it into hardware. You can only override a class parameter in the declaration of a class variable or in the declaration of another class type using a typedef.
package abc;
class basic #(int My_var); // It is preferable to put parameters in the class header
bit [My_var:0] member; // type of member is determined at compile time
endclass
endpackage : abc
module top; // You should not reuse the same name to represent different things
abc::basic #(.My_var(2)) bas1;
abc::basic #(.My_var(8)) bas2;
initial begin
bas1=new();
bas2=new();
$display("bas1.member=%b",bas1.member); // displays 3-bits
$display("bas2.member=%b",bas2.member); // displays 9-bits
end
endmodule : top
You may want to read my DVcon paper about parameterized classes.
In reply to dave_59:
Thanks Dave,
Then these parameters used when we want something to be fixed at compile time.
While instantiating the class or module only we can override these members.
Thanks
Bharath
In reply to bharath123:
Hello Dave,
Please see below snippet of code where i want to override the parameter declared inside the package.
I need help how can we do it?
////////////////////////////////////////////////////////////////////////////////////////////
package abc;
parameter int My_var=1;
function par_override(int local_val)
My_var=local_val;
// $display(“local_cal=%d”,local_val);
endfunction
endpackage
module basic1;
initial begin
abc::par_override(2);
//$display("My_var=%d ",abc::My_var);
end
endmodule:basic1
Thanks
Bharath
In reply to bharath123:
You can’t override parameters in a package. You can only override parameters when instantiating a parameterized thing like a class, module, or interface.