【验证小bai】randomize中的this.指的是哪个this呢

为啥小白是标题中的禁止词呢,有点摸不着头脑啊。

今天一精神小伙突然发现一个问题,简化讲就是在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中。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尼德兰的喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值