当前位置:网站首页>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
边栏推荐
猜你喜欢

excel可视化

TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)

ArcServer密码重置(账号不可以重置)

68 cesium code datasource loading czml

【文件系统】如何在ubi之上运行squashfs

让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村

SystemVerilog学习-10-验证量化和覆盖率

Infinite horizontal marble game
![Pit of kotlin bit operation (bytes[i] and 0xff error)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
Pit of kotlin bit operation (bytes[i] and 0xff error)

ONEFLOW source code parsing: automatic inference of operator signature
随机推荐
【自动化运维】自动化运维平台有什么用
SystemVerilog学习-07-类的继承和包的使用
PLA not pasted on the bed: 6 simple solutions
srpingboot security demo
让田头村变甜头村的特色农产品是仙景芋还是白菜
MySQL怎么存储emoji?
Distributed lock implementation
Thesis learning record essay multi label lift
SOE空间分析服务器 MySQL以及PostGres的地理空间库PostGIS防注入攻击
局域网监控软件有哪些功能
ABP 学习解决方案中的项目以及依赖关系
数据库er图组成要素
C language beginner level - realize the minesweeping game
【ManageEngine】终端管理系统,助力华盛证券数字化转型
Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project
68 Cesium代码datasource加载czml
【ManageEngine卓豪】用统一终端管理助“欧力士集团”数字化转型
让厦门灌口镇田头村变“甜头”村的特色农产品之一是
PLA不粘貼在床上:6個簡單的解决方案
FPGA - 7系列 FPGA内部结构之Clocking -02- 时钟布线资源