systemverilog之OOP
what is oop
terminology
an example class
default methods for classes
static attibute
assigment and copying
inheritance
polymorphism
why oop?
1. helps in creating and maintaining large testbench:
You can creat complex data types and tie them together with
the routines that work with them
2.increases productivity:
You can creat testbenches and system-level models at a more
abstract level by calling a routine to perform an action rather than toggling bits
You can work with transactions rather than signals transitions
3.Allows the Testbench to be reused
OOP decouples the testbench from design details make it more rebust and easier
to maintain and reuse
How should the data and code be brought tegother?
transactions
OOP Basics:Terminology
Blueprint for a house ===> Class
A compelet house ====> Object
House Address ====> Handle
Turn on/off swithes =====> Methods
Light swithes ======> Properties
verilog VS OOP
Block definition module class
Block instance instance object
Block name instance name handle
Data Type reg & wire properties & variables
Executable Code behavioral blocks Methods:functions
(always / initial) and tasks
tasks / functions
communication ports or cross-module mailboxes/semaphores/calls
between blocks task calls ……..
OOP:Your First Class
略。。。
BusTran b; <—Declare a handle that points to an object of the type BusTran .When a handle is declared it is initialized to null
b= new();<- call the new function to construct the BusTran object.
when you call new you are allocating a new block of
memory to store variable for that object
1.new allocates space for ButTran
2.Initialize the variable to their default value( 0 for 2state
and x for 4-state variables)
3.Return the address where the object is stored
how gettint a handle on objects?
how deallocating a handle on objects?
BusTran b1,b2; <-----declare a handle
b1 = new(); <-----allocate bustran object
b2 = b1; <------
b1 = new(); <------allocate another buttran object
b2 = null; <-------deallocate the second bustran object
How do I create a variable shared by all objects of a class,but not make it global?
static variable
1.The static variable is associted with the class definition , not the instantiated object
2.It is often used to store meta-data,such as number of instances construncted
3.It is shared by all objects of that class
Using the id field can help keep track of transactions as flow through test
class routines : tasks and functions
Using one class inside another class
mainly use a handle to an object
using hierarchical syntax
done for reuse and controll complexity
copy:object copy
1.shallow copy ===> b2 = new()b1 copy的只是句柄,但b1 & b2 指向同一个空间
2.deep copy ====b2 = copy(b1) copy之后,b1 & b2有独立的空间
Inheritance
1.易于debug
2.在以前的基础进行代码扩展,而不是修改以前的代码.
super.parent_method/property
Inheritance chain
1.base class can hold extended class handle
2.extended class cannot hold base handle,this fails because the base object is missing properties(variable)
that only exist in the extended class,such as bad_src in the following example
$cast(badtr,tr) ===>必须badtr tr的类型一致
Abstract Classes and Virtual Methods
1.virtual class
2.polymorphism
the oop term for multiple routines sharing a common name is “polymorphism”
polymorphism is realized by virtual method
always declare routines inside a class as virtual so that they can be redefine
in an extended class.This applies to all tasks and functions ,except the new
function.which is called when the object is constructed, and there is no way to extend it
virtual fucntion在run时实现,compile并不关注 (有绑定的意思)
new在compile时实现
parameterized classes
It is often useful to define a generic class whose objects can be
instantiated to have different array sizes or data types
1.The normal verilog parameter machanism is used to parameterize the calss
class vector #(int size = 1)
bit [size-1:0] a;
endclass
2.Instance of this class can then be instantiated like modules or interfaces
vecor #(.size(2)) vtwo;
Initializing class properties (new)
How does systemverilog know which new function to call?
it does that by looking at the type of handle(有的概念根据句柄所指向的对象类型比如通过句柄调用method)
systemverilog之OOP的更多相关文章
- systemverilog(3)之Randomize
what to randomize? (1) primary input data <==one data (2)encapsulated input data <== muti grou ...
- SystemVerilog搭建APB_I2C IP 层次化验证平台
一.前言 近期疫情严重,身为社畜的我只能在家中继续钻研技术了.之前写过一篇关于搭建FIFO验证平台的博文,利用SV的OOP特性对FIFO进行初步验证,但有很多不足之处,比如结构不够规范.验证组件类不独 ...
- SystemVerilog基本语法总结(下)
2018年IC设计企业笔试题解析-(验证方向) 1.请简述:定宽数组,动态数组,关联数组,队列四种数据类型的各自特点.解析:(1)定宽数组:其宽度在声明的时候就指定了,故其宽度在编译时就确定了.(2) ...
- SystemVerilog基本语法总结(中)
Systemverilog 语法总结(中) 上一个博客分享了SV基本的概念,这一博客继续分享,等下一个博客分享一个公司的验证的笔试题目. l 事件 背景: Verilog中当一个线程在一个事件上发生阻 ...
- 【原创】SystemVerilog中的多态和虚方法
封装可以隐藏实现细节,使代码模块化,继承可以扩展已经存在的代码模块,目的都是为了代码重用.多态是为了实现接口的重用.在SystemVerilog中,子类和父类之间多个子程序使用同一个名字的现象称为Sy ...
- c#面向对象基础技能——学习笔记(二)基于OOP思想研究对象的【属性】
字段(成员变量): 字段只能从对象中访问实例字段,无法直接从类中访问(换言之,不创建实例就不能访问),可以理解为:字段一般用在内部数据交互使用,当需要为外部提供数据时,(要优先使用自动实现的属性而不是 ...
- 一个简单oop的changeTab
好多地方都会用到这样一个效果“点击tab切换内容页”,根据自己的想法实现了一下,写了个简单的插件.以前写代码都是标准的函数式编程,现在觉得面向对象编程看起来比较爽,并且更容易维护,于是就用oop的思想 ...
- Python OOP(面向对象编程)
一OOP的作用 在Python中,类是面向对象设计(OOP)的主要工具.通过使用类这种工具,OOP可以: 1.分解代码,最小化代码的冗余. 2.通过定制现有的代码,来编写新的程序,而不用在原处进行修改 ...
- OOP,WEB开发实用小技巧
偶然读到一篇博客,记录一下心得.这种设计对于新手来说一般是想不到的,它充分的发挥了OOP语言的特性,让代码专用而清爽.这是不是重构的思想呢? 我们在写业务层的时候,有很多方法是重复功能的,我们就可以使 ...
随机推荐
- icekingdom(2018.10.17)
一句话题意:给你一颗n个点的树,节点初始状态下都是白色,有q次修改,每次修改会把[li,ri]区间内的点染成黑色,并且问黑色点能形成几个联通块,然后会将所有点染回白色.(也就是说每次都只有[li,ri ...
- iPhone X的适配问题
//屏幕宽高 #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width #define SCREEN_HEIGHT [UIScreen ...
- jmeter常用的beanshell脚本
时间戳下载文件保存响应内容断言连接数据库解析jsonlist递归创建多级目录 常用内置变量调用cmd文件GUI小命令 时间戳import java.text.SimpleDateFormat;impo ...
- C# 基础之字段与属性
1.属性是字段的扩展 2.根据面向对象封装思想,字段最好设为private(私有),这样有利于防止客户端对字段的篡改,从而保证了成员的完整性 3.访问类中私有字段,C#提供了属性,用来对字段进行灵活的 ...
- Codeforces Round #542(Div. 2) B.Two Cakes
链接:https://codeforces.com/contest/1130/problem/B 题意: 给定n和 2 * n个数,表示i位置卖ai层蛋糕, 有两个人在1号,必须严格按照1-n的顺序买 ...
- POJ 1830 开关问题 高斯消元,自由变量个数
http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...
- Java微信公众平台开发(七)--多媒体消息回复之图片回复
之前我们在做消息回复的时候我们对回复的消息简单做了分类,前面也有讲述如何回复[普通消息类型消息],这里将讲述多媒体消息的回复方法,[多媒体消息]包含回复图片消息/回复语音消息/回复视频消息/回复音乐消 ...
- PHP知识点总结2
PHP5数据类型 String(字符串), Integer(整型), Float(浮点型), Boolean(布尔型), Array(数组), Object(对象), NULL(空值). 字符串 你可 ...
- bootstrap输入框组、导航和导航条
输入框组(input groups) 避免使用select 支持不好,使用输入框组 尺寸根据 input-group-lg input-group-sm来选择 <div class ...
- 【实用】Html5实现文件异步上传
1 简介 开发文件上传功能从来不是一件愉快的事,异步上传更是如此,使用过iframe和Flash的上传方案,也都感觉十分的别扭.本文简要简绍利用Html5的FormData实现文件的异步上传,还可以实 ...