SystemVrilog randomize with时变量同名的问题
时间:12-12
整理:3721RD
点击:
如下,如果A和B里面有的field是同名的,randomize with的时候怎么才能把A的值传进去呢?
class A;
int id;
SeqType B;
task body();
B = new();
B.randomize() with {B.id = id}; //can't work, "this.id" also doesn't work
endtask
endclass
class A;
int id;
SeqType B;
task body();
B = new();
B.randomize() with {B.id = id}; //can't work, "this.id" also doesn't work
endtask
endclass
没有别的解决方案么?这个问题太烦人了。。。
方法2,问AE有没有新版的tool能解决这个问题
(看错题目了,不好意思)
with {B.id = id};
id和}中间得加个分号吧;
随手一写。。。语法对了也不work的,不信你试试
分开写在有的情况下可以。
但是有的变量要加在constraint里的就麻烦点。特别是同时被A变量约束又要约束变量B
B.randomize() with {B.id == id};
constrain里面用==
class seqtype;
rand int id;
endclass
class a;
int id = 5;
seqtype b;
task body();
b = new();
b.randomize() with {id == local::id;};
endtask
endclass
program test;
a ia;
initial begin
ia = new();
ia.body();
end
endprogram
上面的代码没问题。