Uvm_component parent handle cannot be passed into static method inside virtual class

Hi all,

I am trying to create a generic method which could be utilized in the creation of any amount of any agent. Basically, my approach is to implement virtual parameterized class with static method targeted to create process. The problem is that it seems I can’t pass parent component handle to that implemented create method.

Here is an example case. Inside example_env, I am trying to create six instances of example_agent. m_example_agent is an dynamic array holding handles for those six occurrences of example_agent. Parent uvm_component handle is tried to pass to support_class via this since uvm_component’s create() method requires it.

class example_env extends uvm_env;
  example_agent m_example_agent[];
  function virtual void build_phase(uvm_phase phase);
    m_example_agent = support_class#(example_agent, this)::create_child(6);
  endfunction: build_phase 
endclass: example_env

support_class is declared as a virtual class and it has a static method called create_child as follows:

virtual class support_class #(type T = int, uvm_component parent);
  typedef T return_type_array[];

  static function return_type_array create_child(int number);
    string str;
    create_child = new[number];

    for (int i = 0; i < number; i++) begin
      create_child[i] = T::type_id::create({"agent_x", str.itoa(i)}, parent);
  endfunction: create_child
endclass: support_class

Simulator doesn’t accept that but instead it says “Class specialization parameter must be constant…” once ::create_child(6) is called. If I give a default value of null for parent parameter, it seems working.

Do I have any possibility to pass parent uvm_component handle to my create_child() method? Or do you have any other implementations in your mind? I wouldn’t like to throw this to the waste bin.

Sorry for the typos in the example code already in advance. Thanks for your help!


In reply to Vaino:
Why do you want the parent to be a parameter of your class? Just pass it as the second argument to your create_child class.

In reply to dave_59:

Actually, I don’t know. I just started to wonder why the heck I tried to pass parent handle via class parameterization. Thanks for your insightful comment.

But, I am still wondering whether it is good programming practice or not to set the size of the returned dynamic array by the new constructor inside the method such in my create_child() function (create_child = new[number])?

In reply to Vaino:

I’m wondering what your objective is with your implementation. Is there some theoretical interest or do you have a practical application. For a certain test the number of agents should be fixed or do you want to restructure your testbench when running a test?

In reply to chr_sue:

I have a practical application behind that, but opening it in more detail isn’t relevant. But, based on my studies, the implementation works now fairly well. So, I think I have no more questions on that.