systemverilog constraint 里数组如何分配空间

正确示例如下:
环境中有两个master, 所以设置大小为2的静态数组。

module  test_random;
  class randmize_master_base; 
    rand bit[31:0] addr;
    rand bit[ 7:0] size;
    rand bit[ 1:0] op;    
  endclass

  class randmize_master;
    rand randize_master_base r_master[2];
    function new();
        r_master[0] = new();
        r_master[1] = new();
    endfunction
    constraint master_rand{
        foreach(r_master[i]){
            if(i==0) {r_master[i].addr inside{[10,100]};
                      r_master[i].size inside{1,2,4};
                      r_master[i].op   inside{0,1};}
            else     {r_master[i].addr inside{[1150,1190]};
                      r_master[i].size inside{2,4,8};
                      r_master[i].op == 1;}                    
        }
                
    }
  endclass
  initial begin
      randmize_master rand_master;
      rand_master = new();
      rand_master.randomize();
      foreach(rand_master.r_master[i])begin
          $display($time,"addr[%h]=%h, size[%h]=%h, op[%h]=%h", i, rand_master.r_master[i].addr,
                    i, rand_master.r_master[i].size,  i, rand_master.r_master[i].op)
      end
  end
endmodule

上述new函数如果添加 r_master=new(); 会报错
Class constructor “new()” cannot be in used with static array.

因为静态数组不需要分配空间

上述new函数如果为空, 会报错
Error-[CNST-NPE] Constraint null pointer error test_random.sv, 29 Accessing null pointer r_master[0] in constraints. Please make sure variable r_master[0] is allocated.

Error-[NOA] Null object access test_random.sv, 31 The object at dereference depth 1 is being used before it was constructed/allocated. Please make sure that the object is allocated before using it.
因为没有为静态数组的元素分配空间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值