UVM工厂机制(component和object)

本文档展示了如何在SystemVerilog中注册和使用UVM组件(comp1)和对象(ob1)。通过`uvm_component_utils`和`uvm_object_utils`宏进行注册,然后利用UVM工厂进行实例化,如`comp1::type_id::create`和`ob1::type_id::create`,这使得对象可以根据类型动态创建。

1.注册uvm_component类

class comp1 extends uvm_component;  //继承
    `uvm_component_utils(comp1)   //注册
    
    function new(string name = "comp1", uvm_component parent = null)  //创建new函数
        super.new(name,parent); //继承父类new函数
        $display($sformatf("%s is created",name));
    endfunction
    
    function void build_phase(uvm_phase phase);
        super.build_phase(phase);
    endfunction
endclass

2.注册uvm_object类

class  ob1 extends uvm_object;
    `uvm_object_utils(ob1);

    function new(string name = "ob1")
        super.new(name);
        $display($sformatf(%s is created,name));
    endfunction

endclass

3.创建-create

comp1 c1 c2;
ob1 o1 o2;

initial begin
    c1 = new("c1");  //sv创建
    o1 = new("o1");  //sv创建

    c2 = comp1::type_id::create("c2",null);  //uvm工厂创建
    o2 = ob1::type_id::create("o2");  //uvm工厂创建
end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值