sv class中的一些基本用法 |
您所在的位置:网站首页 › sv枚举类型约束 › sv class中的一些基本用法 |
1. static; a. 直接声明一个static变量,每次调用时,都会保持上次的值; 注意static的值,刚开始的时候必须要进行初始化; b. static function; static function声明后,其返回值就是static的,同时这个function也是会申请一段空间,不会释放,所以该function的调用,可以时实例化后再调用,也可以是静态调用; Packet::get_pkt_ctr(); // Static call using :: operator; pkt[5].get_pkt_ctr(); // Normal call using instanc static function中,不能调用function外部的automatic的变量或者方法,因为生命周期不同; static function内部的变量,可以声明成automatic的; 2. pure virtual methods A virtual method in an abstract class may be declared as a prototype without providing an implementation. This is called a pure virtual method and shall be indicated with the keyword pure together with not providing a method body virtual class BasePacket; pure virtual function integer send(bit[31:0] data); // No implementation endclass class EtherPacket extends BasePacket; virtual function integer send(bit[31:0] data); // body of the function ... endfunction endclass 3. interface class;参考环境即可; interface class PutImp#(type PUT_T = logic); pure virtual function void put(PUT_T a); endclass interface class GetImp#(type GET_T = logic); pure virtual function GET_T get(); endclass class MyQueue #(type T = logic, int DEPTH = 1); T PipeQueue[$:DEPTH-1]; virtual function void deleteQ(); PipeQueue.delete(); endfunction endclass class Fifo #(type T = logic, int DEPTH = 1) extends MyQueue#(T, DEPTH) implements PutImp#(T), GetImp#(T); virtual function void put(T a); PipeQueue.push_back(a); endfunction virtual function T get(); get = PipeQueue.pop_front(); endfunction endclass |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |