Specman:在一个表达式中分配多个结构成员
嘿,
我扩展了一个现有的 specman 测试,其中出现了一些类似这样的代码:
struct dataset {
!register : int (bits:16);
... other members
}
...
data : list of dataset;
foo : dataset;
gen foo;
foo.register = 0xfe;
... assign other foo members ...
data.push(foo.copy());
有没有一种方法可以在一行中分配给结构体的成员?喜欢:
foo = { 0xff, ... };
Hy,
I expanding an existing specman test where some code like this appears:
struct dataset {
!register : int (bits:16);
... other members
}
...
data : list of dataset;
foo : dataset;
gen foo;
foo.register = 0xfe;
... assign other foo members ...
data.push(foo.copy());
is there a way to assign to the members of the struct in one line? like:
foo = { 0xff, ... };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我目前无法想出一种根据需要设置所有成员的直接方法,但是有一种方法可以初始化变量(我不确定它是否也适用于结构成员)。无论如何,类似下面的内容可能适合您:
您可以从specman提示符中使用
help new struct
找到有关new
的更多信息。希望有帮助!
I currently can't think of a direct way of setting all members as you want, but there is a way to initialize variables (I'm not sure if it works on struct members as well). Anyway something like the following may fit for you:
You can find more information about
new
withhelp new struct
from the specman prompt.Hope it helps!
按名称分配字段的简单优点是我一直认为有用、编码安全且可读的一种语言功能。
这就是我的做法:
我什至会这样做
data.push(new dataset with {.reg = 0xff; bar = 0x0;});
但如果您愿意,您可以提高可读性标志。警告:使用 unpack() 是完全正确的(参见罗斯的答案),但在我看来很容易出错。我建议验证(使用实际运行的代码)您选择使用 unpack() 的每个地方。
the simple beuty of assigning fields by name is one language feature i've always found usefull , safe to code and readable.
this is how i'd go about it:
i even do
data.push(new dataset with {.reg = 0xff; bar = 0x0;});
but you may raise the readablity flag if you want.warning: using unpack() is perfectly correct (see ross's answer), however error prone IMO. i recommend to verify (with code that actually runs) every place you opt to use unpack().
您可以直接使用 Specman 的
pack
和unpack
功能以及“物理字段”(这些实例成员以修饰符%
为前缀)。示例:
运行此命令时,它会打印:
在您的 Specman 文档中查找
packing, unpacking,Physical fields, Packing.low, Packing.high
。即使结构未映射到 DUT,您仍然可以使用物理字段。如果您的结构已经将物理字段用于其他目的,那么您需要为该结构寻求某种
set*
方法。You can directly use the
pack
andunpack
facility of Specman with "physical fields" ( those instance members prefixed with the modifier%
).Example:
When this run, it prints:
Look up
packing, unpacking, physical fields, packing.low, packing.high
in your Specman docs.You can still use physical fields even if the struct doesn't map to the DUT. If your struct is already using physical fields for some other purpose then you'll need to pursue some sort of
set*
method for that struct.