Specman e:有没有办法知道枚举类型中有多少个值?

Specman e: Is there a way to know how many values there is in an enumerated type?

我需要知道在我的验证环境中枚举类型有多少个值。例如:

type my_type: [a, b, c, d];

我有办法即时检查 my_type?

中是否有 4 个不同的值

感谢您的帮助

有一个 all_values(...) 伪例程 returns 标量类型的所有可能值。您可以使用它来获取 enum 文字的数量:

assert all_values(my_type).size() == 4;

除了 Tudor 的建议之外,另一种方法是使用 set_of_values() 伪例程,即 returns 所有值的 set(而不是列表):

set_of_values(my_type).uint_size()

在某种程度上,使用 set_of_values() 更好,因为 all_values() 创建一个新列表,它通常比集合消耗更多内存。 uint_size() returns 集的大小为uint。还有 size() 但它是 returns int(bits: *),所以在这种情况下使用 uint_size() 就足够了,因为永远不会超过 MAX_UINT 项枚举类型。

还有-set_of_values()return'set',可以查询类型smallest/largest的值,以及范围。

例如:

 var x := set_of_values(my_type).uint_max();

 keep y ==  set_of_values(my_type).uint_max().as_a(my_type).as_a(my_type);

 print set_of_values(my_type).uint_min().as_a(my_type);