为啥小白是标题中的禁止词呢,有点摸不着头脑啊。
今天一精神小伙突然发现一个问题,简化讲就是在seq中对某一transaction进行randomize时,this的含义竟然指的不是这个seq中的值,而是transaction中的值!
示意代码如下:
class my_transaction extends uvm_sequence_item; rand bit [8-1:0] data; rand bit par_err; bit [8 -1:0] test_value = 8'hFF; endclass class sanity_case_seq extends my_sequence; extern function new(string name = "sanity_case_seq"); extern virtual task body(); bit [8 -1:0] test_value = 8'hAA; `uvm_object_utils(sanity_case_seq) endclass: sanity_case_seq function sanity_case_seq::new(string name = "sanity_case_seq"); super.new(name); endfunction: new task sanity_case_seq::body(); bit [8 -1:0] test_value = 8'hBB; repeat(1) begin `uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == this.test_value;}) end #100; endtask: body
其中,
`uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == this.test_value;})
这个this.test_value指的是哪个值呢?没错,指的是class my_transaction中的test_value = 8'hFF,看下波形也能知道:
我当时大感惊奇,这this难道不是应该指的seq里的量么?后来下班路上我才想明白,这不就是相当于我在class my_transaction里做约束吗?my_transaction里constraint中的this一定是指的本身内部的值,这里也一定是呀!
这实验做得就有一点没有意义了哈哈哈
当然了,如果transaction内没有this.test_value这个值,那么此时会取哪个值呢?答案是会取class sanity_case_seq中的bit [8 -1:0] test_value = 8'hAA,如波形:
当然,此时VCS会给你告警,告诉你是他往外扩大了范围去找的:
Warning-[ETLIIC] Extended this/super lookup ../tc/sanity_case.sv, 21 "\this .test_value" A member 'test_value' is not found in the randomized object. It is present in the class of the method containing the randomize-with call.In inline constraints, this/super refers to the object being randomized. VCS supports an extended lookup in the class of the method, where randomize call is present, for backwards compatibility. This may be removed in the future. If you intend to access the this/super of the containing method in a portable way, you may want to create a local object aliased to this/super. To promote this warning to error, use '-error=ETLIIC'.
那么要怎么取到body()函数中的bit [8 -1:0] test_value = 8'hBB呢?需要把this去掉:
`uvm_do_with(my_tr, {my_tr.par_err == 0; my_tr.data == test_value;})
此时就是取值函数内的值:
还有一点,就是如果transaction和seq类内都没有这个值,只在function内有的话,VCS是会报error的,this必须是类内的变量,不能只在function中。