You can't override randomize
A customer asked me whether a class's randomize method could be overridden. I said I didn't know - I will find out. As is often the case, to find out I wrote a few lines of code on EDA Playground. EDA Playground is great for that, because it's always on. You don't have to queue for licences, wait for EDA tools to start, create new files, fire up editors...
So, I wrote this:
module override_randomize;
class C;
rand int i;
endclass
class E extends C;
rand int another_i;
function bit randomize;
return super.randomize;
endfunction
function new;
super.new;
endfunction
endclass
initial begin
C c = new;
E e = new;
void'(c.randomize); $display(c.i);
void'(e.randomize); $display(e.another_i);
end
endmodule
https://www.edaplayground.com/x/2G8z
and found out that the randomize method can't be overridden:
ERROR VCP2949 "The randomize() is a predefined method in class and cannot be overridden." "testbench.sv" 12 28
So, I wrote this:
module override_randomize;
class C;
rand int i;
endclass
class E extends C;
rand int another_i;
function bit randomize;
return super.randomize;
endfunction
function new;
super.new;
endfunction
endclass
initial begin
C c = new;
E e = new;
void'(c.randomize); $display(c.i);
void'(e.randomize); $display(e.another_i);
end
endmodule
https://www.edaplayground.com/x/2G8z
and found out that the randomize method can't be overridden:
ERROR VCP2949 "The randomize() is a predefined method in class and cannot be overridden." "testbench.sv" 12 28
Comments
Post a Comment