Hello
Can we override constraints of base class in extended class, by defining a new constraint with the same name in extended class.
In the code blow, there are two constraint in “base” class for variable “a” & “b”.
In “extended” class which is extended from base, I defined two more constraint which are in conflict with the constraint in base class. For variable “a” constraint I used the same name as in base class, and for “b” I used a different name.
When I randomized the extended class object, I expected randomization should fail for both the constraint in extended class. But the randomization only fail for the conflicting constraint with different name in base and extended class.
I am using Cadence IUS 8.2u12, is something specific to IUS. I want to keep my code generic.
Thanks in advance
- Rajkumar
module junk () ;
class base;
rand bit [15:0] a,b;
function new();
endfunction // new
constraint ct_a {a inside {[0:9]};}
constraint ct_b {b inside {[10:19]};}
endclass // base
class extended extends base;
function new();
endfunction // new
constraint ct_a {a inside {[10:19]};}
constraint ct_b_new {b inside {[0:9]};}
endclass // extended
initial begin
extended extended_obj;
extended_obj = new();
if(!extended_obj.randomize()) $display("Randomization Failed");
end
endmodule // junk