当前位置:网站首页>SystemVerilog learning-06-class encapsulation
SystemVerilog learning-06-class encapsulation
2022-07-01 06:13:00 【Vuko-wxh】
Class overview
Object oriented programming (object oriented programing,OOP), The core idea is to combine data with relevant methods ( Also called subroutine , That is, some data processing task or function) Encapsulate into a class (class). such , Users can build test platforms at a higher level of abstraction . Users can build test platforms and system level models at a more abstract level , Execute by calling a function — One action rather than simply changing the level of the signal . In a validation environment , Include stimulator、monitor、checker As well as other verification components, you can follow OOP The way to build .
For example, a packet , May be defined as a class , Class can contain instructions 、 Address 、 queue ID、 Members such as timestamps and data .packet This class can initialize the data in it , Set command , Read the status of this class and check the queue ID.
every last packet The data members of concrete objects instantiated by classes may be different , However packet Class as an abstract type to describe these data , Define the corresponding data members and the methods of operating these data members .
OOP The term
- class (class) : Contains member variables and member methods , Basic building blocks that contain variables and subroutines .Verilog Corresponding to this is the module (mod-ule).
- object (object): Instance of class after instantiation . stay Verilog in , You need to instantiate a module to use it .
- Handle (handle)︰ Pointer to object . stay Verilog in , You reference signals and methods outside the module through the instance name . One OOP A handle is like the address of an object , But it is stored in a pointer that can only point to a single data type .
- Prototype (prototype): The declarative part of the program , Include program name 、 Return a list of types and parameters . The body of the program contains the execution code .
Building functions
SV Don't like C++ Language also requires complex means of storage space development and destruction , Instead, it uses things like Java— Means of automatic development and recycling of sample space . therefore SV When defining a class , Just define the build function (constructor) , Without defining a destructor (destructor) .
When a class is defined , You need to define the build function , If not defined , The system will automatically help define an empty build function ( There are no formal parameters , The function body is also empty ). Objects are created , You need to declare first and then instantiate , At the same time .
class Packet;
integer comnand ;
function new ();
command = IDLE ;
endfunction
endclass
Packet p = new ;
Static members
Class members ( Variable / Method ) The default is dynamic (automatic) Life cycle , That is, the variables and methods of each object will open up a new space for it . If multiple objects want to share a member ( Variable / Method ), Then you can add keywords static.
Multiple objects can therefore share the same member variable or method . When accessing this member , There is no need to instantiate objects .
class Packet ;
static integer fileID = $fopen( "data" , "r" ) ;
...
endclass
Packet p;
c = $fgetc( p.fileID ) ; //OR Packet: : fileID
Member methods can also be declared static . Static methods cannot access non static members ( Variable / Method ), Otherwise, there will be compilation errors .
this usage
this It is used to specify the member of the object where the index is currently located ( Variable / Parameters / Method ).this Can only be used in non static members of a class 、 Used in constraint and override groups .this The use of can specify the scope of the pointed variable .
class Demo ;
integer x;
function new (integer x);
this.x = x;
endfunction
endclass
Assignment and copy
Declaring variables and creating objects are two processes , It can also be done in one step .
Packet p1;
p1 = new ;
If you will p1 Assign to another variable p2, Then there is still only one object , Only the handle to this object has p1 and p2.
This means p1 and p2 Represents two different objects . Creating p2 Object time , Will be taken from p1 Copy its member variables, such as integer、string And handles, etc , This copy method is called shallow copy (shallow copy) .
Packet p1;
Packet p2;
pl = new ;
p2 = new pl ;
Data hiding and encapsulation
Class members ( Variable / Method ) By default , That is, the of public attributes . This means that the member can be accessed both for the class itself and outside .
For commercial development , The provider of the class will restrict the external access of some class members , Then hide more details of class members . This approach also makes the external access interface of the class more compact , Reduce the maintenance workload of classes , It also makes the class easy to modify with l Older versions remain compatible . The way of data hiding makes the test and maintenance of classes easier .
If you use local, Only this class can access this member , and Neither subclasses nor externals can access .
If you use protected, It means that this class and its subclasses can access this member , and External inaccessible .
reference
- Verification of West circuit department PPT
边栏推荐
- 基于LabVIEW的计时器
- three.js小结
- 1034 Head of a Gang
- Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project
- Primary application case of Excel DuPont analyzer
- 浏览器端保存数据到本地文件
- Essay learning record essay multi label Global
- Flink practice -- multi stream merge
- Oracle create user + Role
- Talking from mlperf: how to lead the next wave of AI accelerator
猜你喜欢

Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432

【网络安全工具】USB控制软件有什么用

【ManageEngine】如何实现网络自动化运维

MongoDB:一、MongoDB是什么?MongoDB的优缺点

linux 关闭redis 进程 systemd+

Transformer le village de tiantou en un village de betteraves sucrières

2022 年面向初学者的 10 大免费 3D 建模软件

Understanding of C manualresetevent class

3D printer threading: five simple solutions

SystemVerilog学习-08-随机约束和线程控制
随机推荐
Servlet
c# Xml帮助类
Highmap gejson data format conversion script
ArcServer密码重置(账号不可以重置)
Pychart configuring jupyter
QT write custom control - self drawn battery
ABP 学习解决方案中的项目以及依赖关系
PLA not pasted on the bed: 6 simple solutions
Kubedm builds kubenetes cluster (Personal Learning version)
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
Elements of database ER diagram
Top 10 Free 3D modeling software for beginners in 2022
Oracle sequence + trigger
srpingboot security demo
【ManageEngine】终端管理系统,助力华盛证券数字化转型
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
Linux closes the redis process SYSTEMd+
Pit of kotlin bit operation (bytes[i] and 0xff error)
restframework-simpleJWT重写认证机制
SOE空间分析服务器 MySQL以及PostGres的地理空间库PostGIS防注入攻击