I am trying to figure out what is a valid arg. to randomize() method .
// Code I
class Main ;
rand bit [1:0] b [2] ;
endclass
Main m ;
initial begin
m = new() ;
if ( m.randomize( b[1] ) ) // legal ??
$display("Success with %p",m);
else
$display("Fails");
end
I Observe Compilation Error with call to randomize() .
[Q1] Is element of unpacked not considered valid ?
// Code II
class A;
rand bit [1:0] a ;
endclass
class B extends A;
rand bit [1:0] a; // Overridden property . Obj of B will have 2 properties named 'a' !!
endclass
B b1;
initial begin
b1 = new();
if ( b1.randomize( super.a ) ) // Legal ??
$display("Success with %p ",b1 );
end
[Q2] Some simulators allow this whereas others flash compilation error .
Is super.overridden_property Legal based on LRM ?
As you have already seen, some tools accept it, other tools don’t.
The built-in randomize is a peculiar construct in that its actual arguments are looked at from the perspective of the object it it is being called on, which is the same as how the with clause works, so I would expect it to be considered already inside the context of randomize method. But the LRM is not very clear on exactly what the arguments to the randomize method could be, just that they are variable names.
// Code 3
class Base ;
rand bit [1:0] a ;
constraint aa { a == 0 ; }
endclass
class Ext1 extends Base;
rand bit [1:0] a;
constraint bb { a == 1 ; }
endclass
class Ext2 extends Ext1;
rand bit [1:0] a;
constraint cc { a == 2 ; }
// Override gparent Constraint aa
constraint aa { Base::a == 2 ; }
// Override parent Constraint bb
constraint bb { Ext1::a == 2 ; }
endclass
Ext2 e2;
initial begin
e2 = new();
if ( e2.randomize() )
$display("Success with %p ",e2 );
end
O/P is :: Success with ‘{super:’{super:'{a:'h2}, a:'h2}, a:'h2}
Class Scope resolution operator helps to unambiguously refer to correct variable even though none are static
However if I try to constraint via in-line Constraint ::
// Code 4
class Base ;
rand bit [1:0] a ;
constraint aa { a > 0 ; }
endclass
class Ext1 extends Base;
rand bit [1:0] a;
constraint bb { a > 1 ; }
endclass
class Ext2 extends Ext1;
rand bit [1:0] a;
constraint cc { a == 2 ; }
endclass
Ext2 e2;
initial begin
e2 = new();
// TO_DO :: Below in-line Constraint throws Compilation Error !!
// Why does the Class Scope Resolution Operator work in Constraint Override but doesn't work within in-line Constraint
if ( e2.randomize() with { Ext1::a == 2 ; Base::a == 2 ; } ) // Valid ??
$display("Success with %p ",e2 );
end
**Since unrestricted Constraint block searches for variables in Class Object Scope first ,
shouldn’t this be considered a Valid Syntax ( even though these are non-static variables ) ??
**
You are dealing with such poor programming practices that tools have probably never exercised those features. Please contact your tool vendor to report the problem.