Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Abstract class in system verilog

Status
Not open for further replies.

srish

Newbie level 6
Joined
Dec 13, 2011
Messages
14
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,375
Why we need Abstract class in our Testbench.........what is advantage of using it.......normally in its child class we declare the functions or tasks with full functionality then why to create a abstract class???
 

The abstract class represent a contract that must be fulfilled (implemented) before it can be used. This way, you can have code with class variables of the abstract type assigned with handles to extended class objects, and that code does not need to know anything about the extended classes. "Abstract" means the class has no use as an object by itself, and SystemVerilog makes it a compiler error if you try to construct an abstract object.

Read my DVCon paper attached to **broken link removed** for an application of abstract classes.
 

Hi Dave,
I referred to **broken link removed** thread.....
may be my understanding is not enough but let me ask you one of my basic doubt ........see you have virtual/abstract class UART_BFM in UART_pkg and one virtual method in it setNbits().....and then in its child class U_TX you define setNbits() completely.....now my doubt is when you are giving full method definition in child class then what is the use of declaring it in abstract class........."why to have a abstract class with virtual methods when you are going to define them in your child class anyway" ...............Is it like a sort of TEMPLATE .........a template on which you will modify according to your needs............PLZ REPLY.....THANKS....
The abstract class represent a contract that must be fulfilled (implemented) before it can be used. This way, you can have code with class variables of the abstract type assigned with handles to extended class objects, and that code does not need to know anything about the extended classes. "Abstract" means the class has no use as an object by itself, and SystemVerilog makes it a compiler error if you try to construct an abstract object.

Read my DVCon paper attached to **broken link removed** for an application of abstract classes.
 

If you look at the class uart_driver, it declares a variable of the abstract class type

uart_bfm_c bfm_h;

The uart_driver class has the method
Code:
task does_something(); 
	 bfm_h.setBitPeriod(5);
	 bfm_h.setNBits(8);
	 repeat(10)
	   bfm_h.send($random);
      endtask
It does not know anything about the child class, but bfm_h must contain a handle to an object that is not an abstract class. The object must be an extension of uart_bfm_c that implements those pure virtual methods. So uart_driver has been written to be independent of any extensions to uart_bfm_c, but can safely call any method that was defined in the abstract class.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top