SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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)
 

Último

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 

Último (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 

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