How to use constraint_mode to control one constraint in an override ovm_object

Hi,

I have such a scenario.

I define
class A extends ovm_object;
and there is one constraint c_A inside.

And then, I define
class B extends A;
and there is one new constraint c_B inside.

Now, I write a base_test, and construct
A_h = A :: type_id :: create(“A_h”, this);
then, I write a another test E_test extends base_test, and
set_type_override(“A”, B);

then, I do constraint control in E_test using
A_h.c_B.constraint_mode(0);

But it will report compilation error by VCS that “Could not find member c_B in class A_h”. (If I don’t do constraint_mode control, object A_h could randomize with B type)

anyone has idea about this. thanks

You can’t access any identifiers declared in an extended class from a base class variable. If E_test knows it will be accessing c_B from class B, it needs to do $cast(B_h, A_h) and then do B_h.c_B.constraint_mode(0);

In reply to dave_59:

Thanks Dave. It works.

In reply to sages:

Hi Dave,

I have another question.
Due to I have override the A type with B type, does this mean handler A_h could point to B type. If so, why A_h could not access members in B ?

In reply to sages:

Since you have overriden, the object would be of type B. That is correct.

But, the handle is of the type A. This would restrict the access to constraints in class A alone and not B.

If you are sure that all the time you would be using class B, then you can change the handle to B type itself. If not, then it does not make sense to switch off constraint in B, when the object is of A. This would cause some confusion in the tool implementation. Hence, they have made sure that, to access constraints the handle should be of the same type.

Hope this cleared some of your confusion.

In reply to Ashith:

Hi Ashith

I split your comment into 2 parts.

  1. But, the handle is of the type A. This would restrict the access to constraints in class A alone and not B.
    thanks for your clarification. I misunderstand the definition of member in object. Generally, if we use A_h = B_h, then A_h could access virtual function in B_h. Thus I think we could also access member c_B in B_h. I made a mistake here.

  2. then you can change the handle to B type itself
    I’m not sure the smart way to implement this. Because as a base_test, we need to have base configuration A as the object type. So, what do you mean to change the handle to B type itself ? I only now to cast A_h to B_h.

In reply to sages:

Yes Sages,
You are correct. I also believe casting is the best way. But another way of doing the same is - In base_test you can have object of type A (A_h) and in your local test create an object of type b (B_h), so that you can switch off the constraint using this handle. Post this you can assign the same handle to A_h.

  • Ashith

In reply to Ashith:

Yes, that’s what i did. i create another B_h, and casting A_h to B_h to switch off the constraint.