SV中的蓝图模式

SV中的蓝图模式

根据给定的事务去建立一个新的事务(给定的事务的对象即被称为蓝图)

//使用了蓝图模式的发生器类
class Generator;
   mailbox gen2drv;
   Transaction blueprint;//蓝图为事务类的一个对象

   function new(input mailbox gen2drv)
      this.gen2drv=gen2drv;
      buleprint=new();
   endfunction

   task run;
      Transaction tr;
      forever begin
          assert(buleprint.randomize);
          tr=buleprint.copy();//**将蓝图对象复制过来**
          gen2drv.put(tr);
      end
   endtask
endclass   
//事务基类
class Transaction;
   rand bit[31:0]src,dst,data[8];
   bit[31:0]crc;

   virtual function void calc_crc;
       crc=src^dst^data.xor;
   endfunction

   virtual function void display(input string prefix="");
   $dsiplay("%sTr:src=%h,dst=%h,crc=%h",prefix,src,dst,crc);
   endfunction
endclass

使用蓝图模式,将会允许你改变发生器类的行为而无需改变代码

//一个简单的测试平台
program automatic test;
    Enviroment env;
        env=new();
        env.build();     //创建
        env.run();       //运行
        env.warp_up()    //收尾
    end
endprogram
//该代码中省略了基本的Transaction类、Generator类和Enviroment类,其中蓝图为Transaction类的一个对象

如果要对测试平台中的事务类进行扩展为注入错误的实物类(而蓝图对象在第一段代码中的Generator类中实例化)

program automatic test;
    Enviroment env;
        env=new();
        env.build();     //创建

        begin
           BdaTr=new();
           env.gen.buleprint=bad     //使用bad对象来取代蓝图!
        end
        
        env.run();       //运行
        env.warp_up()    //收尾
    end
endprogram
  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值