-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclass_static.sv
More file actions
executable file
·51 lines (44 loc) · 922 Bytes
/
class_static.sv
File metadata and controls
executable file
·51 lines (44 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
`define PRINT task print (); \
begin \
$write("%s -> Size is %0d\n",this.name, this.size); \
end \
endtask
program class_static;
// Class with constructor, with no parameter
class A;
// Make size as static
static integer size;
string name;
// Constructor
function new (string name);
begin
this.name = name;
this.size = 0;
end
endfunction
// Increment size task
task inc_size();
begin
//this.size ++; // both are ok
size ++;
$write("%s -> size is incremented\n",this.name);
end
endtask
// Task in class (object method)
`PRINT
endclass
A a,b,c;
initial begin
a = new("A");
b = new("B");
c = new("C");
a.inc_size();
a.print();
b.print();
c.print();
c.inc_size();
a.print();
b.print();
c.print();
end
endprogram