【问题标题】:Element not found for associative array index in constraint在约束中找不到关联数组索引的元素
【发布时间】:2021-05-19 01:47:36
【问题描述】:

我正在尝试随机化关联数组的内容,但遇到了错误:

在约束中找不到关联数组索引的元素

如何初始化这些索引,然后随机化它们的值?

module top;

class TFoo;

typedef struct {
                rand byte element_id;
                rand byte length;
                rand byte body_val[int];
               } mgmt_info_ele;

rand mgmt_info_ele   tspec; 

constraint tspec_1                                //Constraints for tspec
   {
      tspec.element_id == 8'd13;
      tspec.length == 'd55;
      //tspec.body_val.num() == tspec.length;      
      {tspec.body_val[1][0],tspec.body_val[0][7]} inside {[1:3]};
      tspec.body_val[1][7:6] inside {0, 1, 3};
      tspec.body_val[2][7:1] == 7'b0;
   }
endclass

TFoo f = new;
int status;

initial begin
    for(int i = 0; i < 1000; i++) begin
        $display("i=%0d: %s", i, f.get_randstate());
                $display("NUM Return value = %0d", f.tspec.body_val.num());      
        status = f.randomize();
        $display(status);
        assert(status) else $fatal;
    end
end

endmodule

【问题讨论】:

    标签: system-verilog questasim


    【解决方案1】:

    调用randomize 无法修改关联数组或其任何索引键的大小。关联数组的索引不一定是连续的。这就是为什么人们有时称它们为 sparse 数组。也许您应该改用动态数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-18
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多