[英]Specman e: Is there a way to know how many values there is in an enumerated type?
I need to know how many values there is in an enumerated type in my verification environment. 我需要知道我的验证环境中的枚举类型中有多少个值。 Eg:
例如:
type my_type: [a, b, c, d];
I there a way to check on the fly that there 4 different values in the my_type
? 我有一种方法可以即时检查
my_type
是否存在4个不同的值?
Thank you for your help 谢谢您的帮助
There's an all_values(...)
pseudo-routine that returns all possible values of a scalar type. 有一个
all_values(...)
伪例程,该例程返回标量类型的所有可能值。 You can use this to get the number of enum
literals: 您可以使用它来获取
enum
文字的数量:
assert all_values(my_type).size() == 4;
Besides what Tudor suggested, another way is to use set_of_values()
pseudo-routine that returns a set
(rather than a list) of all values: 除了Tudor提出的建议之外,另一种方法是使用
set_of_values()
伪例程,该例程返回所有值的set
(而不是列表):
set_of_values(my_type).uint_size()
In a way, using set_of_values()
is better because all_values()
creates a new list, which usually consumes more memory than a set. 在某种程度上,使用
set_of_values()
更好,因为all_values()
创建一个新列表,该列表通常比集合消耗更多的内存。 uint_size()
returns the size of the set as uint
. uint_size()
将集合的大小返回为uint
。 There is also size()
but it returns int(bits: *)
, so it's good enough to use uint_size()
in this case, because there can never be more than MAX_UINT
items in an enumerated type. 还有
size()
但它返回int(bits: *)
,因此在这种情况下使用uint_size()
足够了,因为枚举类型中最多不能有MAX_UINT
项目。
also - set_of_values() return 'set', which you can inquire for the type smallest/largest value, and its range. 还-set_of_values()返回'set',您可以查询该类型的最小/最大值及其范围。
For example: 例如:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.