Localparam access to virtual interfaces compared to classes

Hi,

considering a class “A” definition like below, I can access localparam FOO value directly from the class using the syntax “A::FOO” without (or prior to) instantiating class A.


class A;
  localparam int FOO = 3;
endclass : A

Now considering an interface definition “B” like below, is there an equivalent syntax to access localparam BAR directly from the virtual-interface definition prior to getting a reference (as virtual interface) to an instance of that interface?


interface B;
  localparam int BAR = 7;
endinterface : B

The usage model I have in mind is as follows: a driver class is parameterized by the virtual interface type it drives and get other interface parameters directly from the virtual interface type prior to get the reference to an actual virtual interface to define size or type of some of its variables or variable arrays. This is to avoid having interface parameter to be pass as parameters of the driver class while they are already part of the interface definition which is itself passed as parameter type of the driver.


class my_driver_generic #(type MY_INTERFACE) extends uvm_driver;
  int fields[MY_INTERFACE::BAR]; // what would be a correct syntax here???
endclass : my_driver_generic

typedef my_driver_generic#(B) my_driver_for_B;

Jordan

In reply to jordan.chicheportiche:

This is one of the big problems with virtual interfaces, especially when it comes to parameterized interfaces. An interface is not a data type like a class. You can only access parameters with a handle to an actual interface instance.

In reply to dave_59:
Thank you very much for your quick answer. This was my feeling but needed a confirmation from an expert.
Would you have then a proposition to avoid duplicating the parameter information between the driver and interface while still having access to them in the constructor function of the driver at a time where no handle to virtual interface has yet been provided to the driver?
Please not that in my example I used a localparam but it is in fact I’m more interested in parameter of a parameterized interface.

rgds,
Jordan

In reply to jordan.chicheportiche:

You may want to search the DVCon.org archives for papers dealing with parameterized interfaces.

Some alternatives are

  1. Use a parameterized struct to represent a set of parameter values, and use a single parameter to override both the driver class and interface parameters. This works well when all the parameters are numeric values, but it becomes a pain if you want to override just a few parameter values.
  2. You can use a parameterized class type just for its parameters instead of a struct. Then the class parameters can contain type parameters, and you can override a few parameters by extending the class.
  3. Avoid the use of virtual interfaces. Abstract classes can be used instead, and they also can be used to decouple the interface parameters from the parameters that your driver/monitor needs to see.

You will need to check your downstream tools to make sure they support any of these alternative, especially if the interfaces need to be synthesized.

In reply to dave_59:

Thank you for your answer