About type_id::create()

Hi all,

can somebody explain the meaning of the following statement,

scb = scoreboard::type_id::create("scb", this);

Here i have scoreboard class is derived from the ovm_component.
sometimes it is showing me error as type_id is not a class item when iam 
using the above statement.
what does type_id stands for?

Thank you,
mpurna.


type_id::create()
is a static method in the factory registration class
ovm_component_registry
/
ovm_object_registry
. When you create a class and want to register it with the factory, you add that type to your class.

class scoreboard extends ovm_scoreboard;

typedef ovm_component_registry #(scoreboard,"scoreboard") type_id;

This creates a specialization of the parametrized class ovm_component_registry that inside defines the static method create(). The two parameters are to register the class by type and by string name. So type_id is the specialized class that represents the factory registration. Not that since you only need to access the static methods of this class, there is no need to ever construct it, the typedef is sufficient.

The macro `ovm_component_utils(scoreboard) generates this typedef for you. So if scoreboard::type_id does not exist, you either need to add the typedef, or add the macro.

Dave Rich

1 Like

Hi Dave,

I have forgot to insert the macro.
Its working fine when i have inserted the macro(`ovm_component_utils).
But when i tried it with the typedef it is giving the following error.....

Error:

const static string type_name = scoreboard;
A declared type is not a legal rvalue in this context.

    How this can be solved?

Thank you,
mpurna.

Not sure if you have called the macro with proper arguments (one with class type and one with class name as string). In case you are passing correctly, may be you can dig into the macro and see how it is getting expanded wrongly.

It should have been declared as
const static string type_name = ā€œscoreboardā€;

instead of
const static string type_name = scoreboard;

Hi all,

 I have written a small code snippet. what i expect from it is just to run with out having any errors.
 It is simulating fine when i have used the macro which is commented in the code.
 But it is showing error when iam running it by placing the typedef statement.
module top;

    `include "ovm.svh"

     class scoreboard extends ovm_component;

          // `ovm_component_utils(scoreboard)
          typedef ovm_component_registry #(scoreboard, "scoreboard") type_id;
 
          function void new(input string name = "scoreboard",
                                        input ovm_component parent = null);
                  super.new(name, parent);
          endfunction

     endclass : scoreboard

     scoreboard scb;

     initial begin
          //scb = new();
          scb = scoreboard::type_id::create("scoreboard", this);
     end

endmodule

Error:

 typedef class scoreboard;
 The class specified in the typedef is never declared.

How this can be solved?

Thank you in advance,
mpurna.

A couple of problems with your code:

  1. You forgot to import ovm_pkg
  2. The constructor should have no return type - void
  3. ā€˜thisā€™ is not valid outside of a non-static method.

Here is the example that works for me

module top;
import ovm_pkg::*;
     class scoreboard extends ovm_component;

          // `ovm_component_utils(scoreboard)
          typedef ovm_component_registry #(scoreboard, "scoreboard") type_id;

          function new(input string name = "scoreboard",
                                        input ovm_component parent = null);
                  super.new(name, parent);
          endfunction

     endclass : scoreboard

     scoreboard scb;

     initial begin
          //scb = new();
          scb = scoreboard::type_id::create("scoreboard", null);
     end

endmodule

Dave

Hi Dave,

      Thank you for mentioning the errors.

A couple of problems with your code:

  1. You forgot to import ovm_pkg
  2. The constructor should have no return type - void
  3. ā€˜thisā€™ is not valid outside of a non-static method.

Dave

Thanks & Regards,
mpurna.

Hi Dave & puneet,

 Thanks a lot for your response.

 I have solved the two things which i have asked earlier.     
 Iam running it with cadence tool.
 It is giving the above mentioned errors when i used the ***-svpp*** option.
 when i have removed the option they are working fine.
 Do you guys have any idea why the ***-svpp*** option is generating such errors?

Thank you,
mpurna.

Yes, I do have an idea, but I doubt everyone would find it as humorous as I do. You will have to ask someone at Cadence.

Hi Dave,

 i think cadence people may see the post & they might answer this question.

Thank you,
mpurna.

Hi mpurna.

SVPP is a pre-processor that was used in the bad old days when Incisive didnā€™t have built-in support for parameterised classes.
Since Incisive 9.2 came out (about a year ago), the SVPP switch is redundant.
Not only that, its use is strongly discouraged, because SVPP has a number of limitations (itā€™s just a basic pre-processor after all).

Please try Incisive 9.2 and do not use SVPP.

Dave, thereā€™s not much point in the pot calling the kettle black; Cadence people could share a lot of stories about SV problems in other vendorsā€™ tools too! :p

Dave, thereā€™s not much point in the pot calling the kettle black; Cadence people could share a lot of stories about SV problems in other vendorsā€™ tools too! :p

Iā€™ve worked at Cadence and Synopsys for many years - I know all the stories.

The funny part, I thought, was being asked to explain why a competitors product behaves the way it does.

What I know is that earlier version of cadence was not having support for the parametrized classes and some other constructs, so they did this workaround. because the svpp directory is created where we run the simulation.

ā€¦i have solved my error through this ideaā€¦


type_id::create()
is a static method in the factory registration class
ovm_component_registry
/
ovm_object_registry
. When you create a class and want to register it with the factory, you add that type to your class.

class scoreboard extends ovm_scoreboard;
typedef ovm_component_registry #(scoreboard,"scoreboard") type_id;

This creates a specialization of the parametrized class ovm_component_registry that inside defines the static method create(). The two parameters are to register the class by type and by string name. So type_id is the specialized class that represents the factory registration. Not that since you only need to access the static methods of this class, there is no need to ever construct it, the typedef is sufficient.
The macro `ovm_component_utils(scoreboard) generates this typedef for you. So if scoreboard::type_id does not exist, you either need to add the typedef, or add the macro.
Dave Rich

In reply to dave_59:

In which case will we do the following:
class scoreboard extends uvm_component

What is the difference of the following 2 methods?

class scoreboard extends uvm_component
class scoreboard extends uvm_scoreboard