|
|
|
|
|
|
|
|
|
|
|
|
Introduction
|
|
|
SystemVerilog introduces an object-oriented class data abstraction. Classes allow objects to be dynamically created, deleted, assigned, and accessed via object handles. Object handles provide a safe pointer-like mechanism to the language. Classes offer inheritance and abstract type modeling, which brings the advantages of C function pointers with none of the type-safety problems, thus, bringing true polymorphism into Verilog. |
|
|
|
|
|
It is better one refreshed C++ basics, as most of it is picked from C++ with slight difference. |
|
|
|
|
|
A class is a type that includes data and subroutines (functions and tasks) that operate on that data. A class data is referred to as class properties, and its subroutines are called methods, both are members of the class. The class properties and methods, taken together, define the contents and capabilities of some kind of object. |
|
|
|
|
|
We will be seeing following in detail in new few pages |
|
|
|
|
|
- Objects
- Object members
- Constructors
- Static class members
- Assignments
- Inheritance and subclasses
- this and super
- Data hiding and encapsulation
- Constant class properties
- Abstract classes and virtual methods
- Class scope resolution operator ::
- Parameterized classes
|
|
|
|
|
|
Objects
|
|
|
A class defines a data type. An object is an instance of that class. 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. |
|
|
|
|
|
|
|
|
|
|
|
Object members
|
|
|
The data fields of an object can be used by qualifying class property names with an instance name. So any data field inside a Object is called object members |
|
|
|
|
|
Object Methods
|
|
|
Objects Methods are functions and tasks that operate on the Object members to do some meaning full function. They are accesses similar to object members. |
|
|
|
|
|
Example - Objects
|
|
|
|
|
|
1 program class_t;
2 class packet;
3 // members in class
4 integer size;
5 integer payload [];
6 integer i;
7 // Constructor
8 function new (integer size);
9 begin
10 this.size = size;
11 payload = new[size];
12 for (i=0; i < this.size; i ++) begin
13 payload[i] = $random;
14 end
15 end
16 endfunction
17 // Task in class (object method)
18 task print ();
19 begin
20 $write("Payload : ");
21 for (i=0; i < size; i ++) begin
22 $write("%x ",payload[i]);
23 end
24 $write("\n");
25 end
26 endtask
27 // Function in class (object method)
28 function integer get_size();
29 begin
30 get_size = this.size;
31 end
32 endfunction
33 endclass
34
35 packet pkt;
36
37 initial begin
38 pkt = new(5);
39 pkt.print();
40 $display ("Size of packet %0d",pkt.get_size());
41 end
42
43 endprogram
You could download file class_t.sv here
|
|
|
|
|
|
Simulation - Objects
|
|
|
|
|
|
Payload : 12153524 c0895e81 8484d609 b1f05663 06b97b0d
Size of packet 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|