本文介绍了Specman:动态生成具有所有不同值的列表列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试生成具有所有不同值的uint(my_list_of_list)列表的即时列表(我有一个变量num_of_ms_in_each_g : list of uint,该列表将每个列表的长度保留在my_list_of_list之内):

I try to generate on-the-fly list of list of uint (my_list_of_list) with all different values (I have a variable num_of_ms_in_each_g : list of uint, that keeps lengths of every list inside my_list_of_list):

  var my_list_of_list : list of list of uint;
  gen my_list_of_list keeping {
     for each (g) using index (g_idx) in it {
        g.size() == num_of_ms_in_each_g[g_idx];
        for each (m) using index (m_idx) in g {
           // Error in the next line:
           m not in it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1];
           m not in it[g_idx][0..max(0, m_idx-1)];
        };
  };

代码算法的说明:生成以前尚未在uint(g)的任何列表中且未出现在先前索引的当前列表中的m(值)

Explanation for the code algorithm: generate m (the value) that was not yet in any list of uint (g) before, and does not appear in current list for previous indexes.

我收到编译错误:

  *** Error: 'm' is of type 'uint', while expecting type 'list of uint' or
'list of list of uint'.

您知道如何解决编译错误吗? (it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1] 是uint ..)或者另一种即时生成具有所有不同值的list of list of uint的方法吗?谢谢您的帮助.

Do you have any idea how to solve the compilation error? (it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1] is uint..) Or maybe another way to generate on-the-fly list of list of uint with all different values?Thank you for your help.

推荐答案

实际上,表达式it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1]的类型为list of list of uint.运算符list[from..to]生成一个子列表.在您的代码中,将其两次应用于it,它首先生成一个子列表,然后生成该子列表的子列表.

Actually, the expression it[0..g_idx-1][0..num_of_ms_in_each_g[g_idx]-1] is of type list of list of uint. The operator list[from..to] produces a sub list. In your code you apply it twice to it which first produces a sublist and then produces a sublist of the sublist.

代码中的第二个此类约束有效,因为it[g_idx]不会生成子列表,而是访问类型为list of uint的列表项,然后生成一个子列表.

The second such constraint in your code works, because it[g_idx] does not produce a sublist, but rather accesses a list item, which is of type list of uint and then produces a sublist.

要生成列表的所有不同列表,我将执行以下操作:

To produce an all different list of list I would do something like:

var my_list_of_list : list of list of uint;
for each (sz) in num_of_ms_in_each_g {
    var l : list of uint;
    gen l keeping {
        it.size() == sz;
        it.all_different(it);
        //  not it.has(it in my_list_of_list.flatten());
        // for better performance
        for each (itm) in it {
            itm not in my_list_of_list.flatten();
        };
    };
    my_list_of_list.add(l);
};

这篇关于Specman:动态生成具有所有不同值的列表列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:46