Specman / e约束(每次输入)迭代

时间:2018-10-08 18:17:04

标签: aop verification specman e

我是否可以在约束中仅迭代e中列表的一部分。 例如,此代码将遍历整个layer_l列表:

<'

struct layer_s {
  a : int;
    keep soft a == 3;
};

struct layer_gen_s {
  n_layers : int;
    keep soft n_layers == 8;
  layer_l  : list of layer_s;
    keep layer_l.size() == read_only(n_layers);
};

extend sys {
  layer_gen : layer_gen_s;     

  run() is also {
    messagef(LOW, "n_layers = %0d", layer_gen.n_layers);
    for each in layer_gen.layer_l{
      messagef(LOW, "layer[%2d]: a = %0d", index, it.a);
    };
  };
};

-- this will go through all layer_l
extend layer_gen_s {    
  keep for each (layer) using index (i) in layer_l {
    layer.a == 7;
  };
};

但是,我只想迭代每个项目,例如2个项目。我尝试了下面的代码,但没有用:

-- this produces an error
extend layer_gen_s {    
  keep for each (layer) using index (i) in [layer_l.all(index < 2)] {
    layer.a == 7;
  };
};

我也不想使用暗示,所以这不是我想要的:

-- not what I want, I want to specify directly in iterated list
extend layer_gen_s {    
  keep for each (layer) using index (i) in layer_l {
    (i < 2) => {
      layer.a == 7;
    };
  };
};

1 个答案:

答案 0 :(得分:1)

使用列表切片运算符也不起作用,因为path约束中的for..each仅限于简单的path(例如,列表变量)。以下内容也不起作用:

keep for each (layer) using index (i) in layer_l[0..2] {
  //...
};

这是Specman的限制。

要强制循环子列表,您唯一的选择是将该子列表创建为单独的变量:

layer_subl: list of layer_s;
keep layer_subl.size() == 3;
keep for each (layer) using index (i) in layer_subl {
  layer == layer_l[i];
};

现在,您只能循环使用for..each约束内的前三个元素:

keep for each (layer) in layer_subl {
  layer.a == 7;
};

这避免在约束内部使用蕴涵。这是否值得您决定。另外请注意,列表将包含相同对象(这很好)。没有创建额外的struct对象。

像这样创建子列表是工具本身可以处理的样板代码。这将使代码更加简洁和可读。您可以联系您的供应商并请求此功能。