`ifndef GENERATOR `define GENERATOR class generator; mailbox gen2drv; function new (mailbox gen2drv_new); if(gen2drv_new == null)begin $display("%0t -> generator : ERROR -> gen2drv is null",$time); $finish; end else this.gen2drv = gen2drv_new; endfunction task run(int num_tr = 200); transaction tr; //random repeat(num_tr)begin tr = new(); assert(tr.randomize()); $display("%0t -> generator : tr is %s",$time,tr.convert2string_in()); gen2drv.put(tr); end //constraint operand with 'h00 or 'hff repeat(num_tr)begin tr = new(); assert(tr.randomize() with {A inside {'h0,'hff}; B inside {'h0,'hff};}); $display("%0t -> generator : tr is %s",$time,tr.convert2string_in()); gen2drv.put(tr); end endtask endclass `endif
generator模块负责打包transaction事务,之后由driver模块负责发送给DUT。
这里使用到了断言,并且是立即断言,没有使用到并行断言