1 / 19

System Verilog Object Oriented Programming and Classes

IEP on Design Verification and Hardware Security NIT, Rourkela. System Verilog Object Oriented Programming and Classes. OUTLINE. Classes “this” keyword Constructors Class Assignment Shallow Copy and Deep Copy Inheritance Polymorphism Overriding Class members “super” keyword Casting

burl
Download Presentation

System Verilog Object Oriented Programming and Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IEP on Design Verification and Hardware Security NIT, Rourkela System Verilog Object Oriented Programming and Classes

  2. OUTLINE • Classes • “this” keyword • Constructors • Class Assignment • Shallow Copy and Deep Copy • Inheritance • Polymorphism • Overriding Class members • “super” keyword • Casting • Data hiding and Encapsulation • Virtual methods and Extern methods

  3. Introduction to Classes • A class is a user-defined data type that includes data (class properties), functions and tasks that operate on data. • An object is used by first declaring a variable of that class type (that holds an object handle) and then creating an object of that class (using the new function) and assigning it to the variable. source: - www.verificationguide.com

  4. Class Constructors • The new function is called as class constructor. • On calling the new method it allocates the memory and returns the address to the class handle. • Constructors should be function and not a task. • Constructors does not return values. • Constructors like any other function take input parameters. • There can be only one constructor per class. source: - www.verificationguide.com

  5. “this” keyword • “this” keyword is used to refer to class properties. • “this” keyword is used to unambiguously refer to class properties or methods of the current instance. source: - www.verificationguide.com

  6. Static Class members • Static class members : - Class members can be created with the keyword static. class members with the keyword static are called as static class members. The class can have static properties and static methods (functions and tasks). • Static Properties: - The class can have multiple instances, each instance of the class will be having its own copy of variables. Sometimes only one version of a variable is required to be shared by all instances. These class properties are created using the keyword static. • A static method can access only static properties of the class and access to the non-static properties is illegal and lead to a compilation error. source: - www.verificationguide.com

  7. Class Assignment • Object will be created only after doing new to an class handle, • packet   pkt_1;pkt_1  = new();packet   pkt_2;pkt_2  = pkt_1; • In the above piece of code, an object is created only for pkt_1, pkt_2 is just a handle to the packet. • pkt_1 is assigned to the pkt_2. So only one object has been created, pkt_1 and pkt_2 are two handles both are pointing to the same object • As both the handles are pointing to the same object any changes made with respect to pkt_1 will reflect on pkt_2.

  8. System Verilog Inheritance • Inheritance is an OOP concept that allows the user to create classes that are built upon existing classes. • Inheritance is about inheriting base class members to the extended class. • The new class will be with new properties and methods along with having access to all the properties and methods of the original class. source: - www.verificationguide.com

  9. Overriding Class members • Base class or parent class properties and methods can be overridden in the child class . • Defining the class properties and methods with the same name as parent class in the child class will override the class members. source: - www.verificationguide.com

  10. “Super” Keyword • When class  members are overridden in the derived class, it is necessary to use the super keyword to access members of a parent class. • With super keyword, it is allowed to access the class members of parent class which is only one level up. source: - www.verificationguide.com

  11. Data hiding and encapsulation • Data hiding and Encapsulation: The technique of hiding the data within the class and making it available only through the methods (i.e., by the methods of the class) is known as encapsulation.  • Access Control:Access control rules that restrict the members of a class from being used outside the class. • This is achieved by prefixing the class members with the keywords: local and keyword. source: - www.verificationguide.com

  12. Extern Functions • The definition of the method written outside the body of the class then the method is called an external method. • External functions need to declare the method (Function/Task) with an extern keyword. • The extern qualifier indicates that the body of the method (its implementation) is to be found outside the class declaration. source: - www.verificationguide.com

  13. SV Interface source: - www.verificationguide.com

  14. SV Interfaces source: - www.verificationguide.com

  15. Ones Counter source: - www.testbench.in

  16. Ones Counter_TestBench source: - www.testbench.in

  17. Ones Counter_TestBench source: - www.testbench.in

  18. Ones Counter_TestBench source: - www.testbench.in

  19. Thank You

More Related