Digital Signal Processing Reference
In-Depth Information
2.9.11 Classes
In SV, as in C
, a class consists of data and methods. The methods are functions and tasks that
operate on the data in the class. SV supports key aspects of object-oriented programming (OOP),
including inheritance, encapsulation and polymorphism.
A class is declared with internal or external declared functions that operate on the data defined in
the class. The example below defines a class with an internal and external declared method:
รพรพ
class frame{
byte dst_addr;
bit [3:0] set_frame_type;
data_struct payload;
function byte get_src_addr ()
return src_addr;
endfunction
extern task assign_dst_addr_type (input byte addr, input bit[3:0] type);
endclass
task frame::assign_dst_addr(input byte addr, input bit [3:0] type);
dst_addr = addr;
frame_type = type;
endtask
The syntax only declares an object class of type frame . One or multiple instances of this class can
be created as follows:
frame first_frame = new;
A class constructor can also be used to initialize data as:
class frame
function new (input byte addr, input [3:0] type)
dst_addr = addr;
frame_type = type;
endfunction
.
.
endclass
// Set the dst and type of the frame
frame msg_frame = new(8 ' h00, MSG);
Another class can inherit data and methods of this class and adds newmethods and can change the
existing methods.
class warning_frame extends frame;
bit [2:0] warning_type;
function MSG_TYPE send_warning ();
return warning_type;
endfuction;
endclass
Search WWH ::




Custom Search