Daniel,
Constraints themselves are treated as virtual methods, thus, a constraint in a derived class overrides a constrain (of the same name) in the base class hierarchy. The LRM is explicit about this:
An instance of class A constrains x to be less than zero whereas an instance of class B constrains x to be greater than zero. The extended class B overrides the definition of constraint c. In this sense, cons-traints are treated the same as virtual functions; therefore, casting an instance of B to an A does not change the constraint set.
Since an overridden constraint is no longer part of that particular object, there is only one valid semantic definition for constraint_mode when applied to a constraint: the constraint_mode applies only to the non-overridden constrains in the object. This means that in your example, both calls a.c3.constraint_mode() and b.c3.constraint_mode() (and for that matter a.constraint_mode or b.constraint_mode refer to the same constraint) : B::c3.
The output of your example should be:
5
<some random unconstrained number>
5
<some random unconstrained number>
Perhaps including such an example with this clarification in the LRM would be useful, but I don't believe any other interpretation is possible.
Arturo
From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Daniel Mlynek
Sent: Friday, April 16, 2010 12:12 AM
To: sv-ec@eda.org
Subject: [sv-ec] Constraint_mode virtuality
Thre are some ambiguites in LRM according to constrain_mode and inheritance:
1. LRM do not specifies if constraints_mode function is virtual or not.
2. LRM do not specifies if constraint_mode should turn-off constraints in whole class hierarchy or only in certain constraint
Example:
virtual class A;
rand int x,y;
constraint c3 { x==50; }
function void post_randomize;
$display(x);
endfunction
endclass
class B extends A;
constraint c3 { x==5; }
endclass
module top;
B b = new;
A a;
initial begin
a=b;
a.randomize();//it should randomize 5
a.c3.constraint_mode(0);
//there are 3 possibilities which one is correct
//B::c3 be turned off and A::c3 be valid
//B::c3 and A::c3 be turned off?
//A::c3 turned off B::c3 valid
a.randomize();
a.c3.constraint_mode(1);
b.randomize();
b.c3.constraint_mode(0);
//there are 2 possibilities which one is correct
//B::c3 be turned off and A::c3 be valid
//B::c3 and A::c3 be turned off?
b.randomize();
end
endmodule
Are above known issues?
DANiel
-- This message has been scanned for viruses and dangerous content by MailScanner<http://www.mailscanner.info/>, and is believed to be clean. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Fri Apr 16 10:54:53 2010
This archive was generated by hypermail 2.1.8 : Fri Apr 16 2010 - 10:54:58 PDT