Get interface type from parameter

Is there a way to get the type of interface that is being passed in as a parameter? I believe using $typename will not work since the interface is not virtual.

I want to achieve something like this:


interface my_interface # (
  parameter some_other_interfaces = default_if
) (
  ...
  some_other_interfaces   m_if
)

  if($type(m_if) == "first_interface")
    ...
  else if ($type(m_if) == "second_interface")
    ...

  ...
endinterface

I also believe that SV doesn’t support introspection so that’s out of the question. It’s effectively trying to have some kind of function like get_type_name() in UVM for a UVM class object

In reply to jimmyhuang0904:

You cannot parameterize an interface, it is not a datatype. However, SystemVerilog provides a generic interface that assumes the kind of interface the port gets connected to. You can use a parameter inside the connected interface to select.

interface my_interface ( interface m_if ); // generic interface

...  if(my_if.name) == "first_interface")
    ...
  else if (m_if.name) == "second_interface")
    ...
 endinterface
interface first_interface;
  parameter string name = "first_interface";
  ...
endinterface
interface second_interface;
  parameter string name = "second_interface";
  ...
endinterface

module top;

   first_interface i1();
   second_interface i2();

   my_interface m1(i1);
   my_interface m2(i2);

endmodule

In reply to dave_59:

do you mean that you cannot parameterized interface with specific types? As far as I know, you can parameterize interfaces based on this example:

https://www.doulos.com/knowhow/sysverilog/uvm/easier_uvm_guidelines/parameterized_interface/

They have an example that looks like :


interface clkndata_if #(parameter AW = 1, DW = 1);
  ...
  bit [AW-1:0] addr;
  bit [DW-1:0] data;
  // Other variables, wires, and parameters
...

I’ve seen code that looks like:


interface some_if #(parameter type some_struct_t = default_struct_t)
(
  input wire clk,
  input wire rst_n
)
...

In reply to jimmyhuang0904:

Yes, you can parameterize the types used inside the interface/module, but not an interface port itself, which is what you seemed to be doing with the m_if port in your first example.