当前位置:网站首页>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
边栏推荐
- 【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
- SystemVerilog学习-08-随机约束和线程控制
- Oracle sequence + trigger
- Fixed height of the first column in El table dynamic header rendering
- 地宮取寶(記憶化深搜)
- 浏览器端保存数据到本地文件
- Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
- Excel dynamic chart
- 连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
- excel动态图表
猜你喜欢

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

让田头村变甜头村的特色农产品是仙景芋还是白菜

端口扫描工具对企业有什么帮助?

PLA不粘贴在床上:6个简单的解决方案

Talking from mlperf: how to lead the next wave of AI accelerator

Movable mechanical wall clock

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

数据库问题,如何优化Oracle SQL查询语句更快,效率更高

DHT11 temperature and humidity sensor

【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全
随机推荐
SystemVerilog学习-08-随机约束和线程控制
Arcserver password reset (account cannot be reset)
C language beginner level - realize the minesweeping game
【企业数据安全】升级备份策略 保障企业数据安全
Oracle sequence + trigger
DEV XPO对比之XAF BO
Recueillir des trésors dans le palais souterrain (recherche de mémoire profonde)
【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
Timer based on LabVIEW
ManageEngine卓豪助您符合ISO 20000标准(四)
Preliminary level of C language -- selected good questions on niuke.com
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
jdbc-连接池
highmap gejson数据格式转换脚本
restframework-simpleJWT重写认证机制
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
uniapp树形层级选择器
Oracle create user + Role
SQL必会题之留存率
Tidb single machine simulation deployment production environment cluster (closed pit practice, personal test is effective)