SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Object Oriented Programming
Procedural Approach
Focus is on procedures
All data is shared: no protection
More difficult to modify
Hard to manage complexity
Introduction to OOP
Object-oriented programming is a method of implementation
in which programs are organized as cooperative collections of
objects, each of which represents an instance of some class,
and whose classes are all members of one or more hierarchy
of classes united via inheritance relationships
Basic OOP
OOPs breaks a testbench into blocks that work together to
accomplish the verification goal
Why OOP?
• Highly abstract system level modelling
• Classes are intended for verification
• Classes are easily reused and extended
• Data security
• Classes are dynamic in nature
• Easy debugging, one class at a time
• Redundant code can be avoided by using inheritance
• Inheritance reduces time and cost
• Easy upgrading of system is possible using object oriented system
OOP cont..
 A class is a user-defined data type.
 Classes consist of data (called properties) and tasks and
functions to access the data (called methods).
 Classes are used in object-oriented programming.
 In SystemVerilog, classes support the following aspects of
object-orientation – encapsulation, data hiding, inheritance
and polymorphism
Class
Class Declaration
class register;
local bit[31:0] contents;
function void write(bit[31:0] d)
contents = d;
endfunction
function bit[31:0] read();
return contents;
endfunction
endclass
 Organized into groups with similar characteristics
• They are said to be related by a common characteristic
 Object-Oriented programming seeks to provide mechanisms
for modelling these relationships
Objects
 The world conceptually consists of objects
 Many objects can be said to be of the same type or class
•My bank account, your bank account, Bill Gates’ bank
account …
 We call the object type a class
 Instantiation
•An Object is instantiated from a Class
BankAccount myAccount; //creating a handle for
//the class BankAccount
myAccount = new ();//creating object
Objects as instances of Classes
 It is a pointer to an object.
 An oop handle is like the address of the object but is stored in a
pointer that only refer to one type.
Ex:
class Transaction;
logic addr,data;
endclass
initial begin
Transaction tr;
tr=new();
end
Variables..
Class Transaction
Variables
Memory
Handle
tr
What is Handle?
Class Example:
class register;
local bit[31:0] contents;
function void write(bit[31:0] d)
contents = d;
endfunction
function bit[31:0] read();
return contents;
endfunction
endclass
module top;
register r;
bit[31:0] d;
initial begin
r = new();
r.write(32’h00ff72a8);
d = r.read();
end
endmodule
 A class encapsulation is a process of hiding all internal details
of an object from out side world.
 Encapsulation is the ability to hide data and methods from out
side world and only expose data and methods that are required.
DATA
ENCAPSULATION
Class Encapsulation
 Advantage of encapsulation
• Protection
• Consistency
• Allows change
Encapsulation example:
class base;
local int i;
endclass
program main;
initial
begin
base b = new();
b.i = 123;
end
endprogram
Local variable error
Result:
 Polymorphism refers to the ability to assume different
forms. In OOP, it indicates a language’s ability to handle
objects differently based on their runtime type.
 When objects communicate with one another, we say that
they send and receive messages.
 The sending object only needs to be aware that the
receiving object can perform a particular behaviour.
Polymorphism
class A ;
virtual task disp ();
$display(" This is class A ");
endtask
endclass
class EA extends A ;
task disp ();
$display(" This is Extended class A ");
endtask
endclass
program main ;
EA my_ea;
A my_a;
initial
begin
my_a = new();
my_a.disp();
my_ea = new();
my_a = my_ea;
my_a.disp();
end
endprogram
RESULTS
This is class A
This is Extended class A
Example:
 Definition (Inheritance) Inheritance is the mechanism
which allows a class B to inherit properties of a class A.
 We say “ B inherits from A”.
 Objects of class B thus have access to attributes and
methods of class A without the need to redefine them.
 The following definition defines two terms with which we
are able to refer to participating classes when they use
inheritance.
INHERITANCE
 The idea of inheritance is simple but powerful:
 When you want to create a new class and there is already a class
that includes some of the code that you want, you can derive your
new class from the existing class.
 In doing this, you can reuse the fields and methods of the existing
class without having to write (and debug!) them yourself.
INHERITANCE (Cont...)
Example:
class parent;
task printf();
$display(" THIS IS PARENT CLASS ");
endtask
endclass
class subclass extends parent;
task printf();
$display(" THIS IS SUBCLASS ");
endtask
endclass
program main;
initial
begin
parent p;
subclass s;
p = new();
s = new();
p.printf();
s.printf();
end
endprogram
RESULTS
THIS IS PARENT CLASS A
THIS IS SUBCLASS
Why
SystemVerilog?
Why Not C++?
Why not C++?
C++ System Verilog
 Superset of Verilog
 RTL/Verification language
 Assertion language
 Constraint language
 Code coverage language
 No relation to
verilog
 Interface is required
to interact with Verilog
Comparison

Contenu connexe

Similaire à Introduction to Object Oriented Programming with SystemVerilog

Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialscesarmendez78
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Application package
Application packageApplication package
Application packageJAYAARC
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3Atif Khan
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingMH Abid
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01Zafor Iqbal
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .NetGreg Sohl
 

Similaire à Introduction to Object Oriented Programming with SystemVerilog (20)

Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
java part 1 computer science.pptx
java part 1 computer science.pptxjava part 1 computer science.pptx
java part 1 computer science.pptx
 
Application package
Application packageApplication package
Application package
 
Oops
OopsOops
Oops
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
oopusingc.pptx
oopusingc.pptxoopusingc.pptx
oopusingc.pptx
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 
python.pptx
python.pptxpython.pptx
python.pptx
 
My c++
My c++My c++
My c++
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 

Dernier

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Dernier (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Introduction to Object Oriented Programming with SystemVerilog

  • 2. Procedural Approach Focus is on procedures All data is shared: no protection More difficult to modify Hard to manage complexity
  • 3. Introduction to OOP Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects, each of which represents an instance of some class, and whose classes are all members of one or more hierarchy of classes united via inheritance relationships
  • 4. Basic OOP OOPs breaks a testbench into blocks that work together to accomplish the verification goal
  • 5. Why OOP? • Highly abstract system level modelling • Classes are intended for verification • Classes are easily reused and extended • Data security • Classes are dynamic in nature • Easy debugging, one class at a time • Redundant code can be avoided by using inheritance • Inheritance reduces time and cost • Easy upgrading of system is possible using object oriented system OOP cont..
  • 6.  A class is a user-defined data type.  Classes consist of data (called properties) and tasks and functions to access the data (called methods).  Classes are used in object-oriented programming.  In SystemVerilog, classes support the following aspects of object-orientation – encapsulation, data hiding, inheritance and polymorphism Class
  • 7. Class Declaration class register; local bit[31:0] contents; function void write(bit[31:0] d) contents = d; endfunction function bit[31:0] read(); return contents; endfunction endclass
  • 8.  Organized into groups with similar characteristics • They are said to be related by a common characteristic  Object-Oriented programming seeks to provide mechanisms for modelling these relationships Objects
  • 9.  The world conceptually consists of objects  Many objects can be said to be of the same type or class •My bank account, your bank account, Bill Gates’ bank account …  We call the object type a class  Instantiation •An Object is instantiated from a Class BankAccount myAccount; //creating a handle for //the class BankAccount myAccount = new ();//creating object Objects as instances of Classes
  • 10.  It is a pointer to an object.  An oop handle is like the address of the object but is stored in a pointer that only refer to one type. Ex: class Transaction; logic addr,data; endclass initial begin Transaction tr; tr=new(); end Variables.. Class Transaction Variables Memory Handle tr What is Handle?
  • 11. Class Example: class register; local bit[31:0] contents; function void write(bit[31:0] d) contents = d; endfunction function bit[31:0] read(); return contents; endfunction endclass module top; register r; bit[31:0] d; initial begin r = new(); r.write(32’h00ff72a8); d = r.read(); end endmodule
  • 12.  A class encapsulation is a process of hiding all internal details of an object from out side world.  Encapsulation is the ability to hide data and methods from out side world and only expose data and methods that are required. DATA ENCAPSULATION Class Encapsulation  Advantage of encapsulation • Protection • Consistency • Allows change
  • 13. Encapsulation example: class base; local int i; endclass program main; initial begin base b = new(); b.i = 123; end endprogram Local variable error Result:
  • 14.  Polymorphism refers to the ability to assume different forms. In OOP, it indicates a language’s ability to handle objects differently based on their runtime type.  When objects communicate with one another, we say that they send and receive messages.  The sending object only needs to be aware that the receiving object can perform a particular behaviour. Polymorphism
  • 15. class A ; virtual task disp (); $display(" This is class A "); endtask endclass class EA extends A ; task disp (); $display(" This is Extended class A "); endtask endclass program main ; EA my_ea; A my_a; initial begin my_a = new(); my_a.disp(); my_ea = new(); my_a = my_ea; my_a.disp(); end endprogram RESULTS This is class A This is Extended class A Example:
  • 16.  Definition (Inheritance) Inheritance is the mechanism which allows a class B to inherit properties of a class A.  We say “ B inherits from A”.  Objects of class B thus have access to attributes and methods of class A without the need to redefine them.  The following definition defines two terms with which we are able to refer to participating classes when they use inheritance. INHERITANCE
  • 17.  The idea of inheritance is simple but powerful:  When you want to create a new class and there is already a class that includes some of the code that you want, you can derive your new class from the existing class.  In doing this, you can reuse the fields and methods of the existing class without having to write (and debug!) them yourself. INHERITANCE (Cont...)
  • 18. Example: class parent; task printf(); $display(" THIS IS PARENT CLASS "); endtask endclass class subclass extends parent; task printf(); $display(" THIS IS SUBCLASS "); endtask endclass program main; initial begin parent p; subclass s; p = new(); s = new(); p.printf(); s.printf(); end endprogram RESULTS THIS IS PARENT CLASS A THIS IS SUBCLASS
  • 20. C++ System Verilog  Superset of Verilog  RTL/Verification language  Assertion language  Constraint language  Code coverage language  No relation to verilog  Interface is required to interact with Verilog Comparison