将init_val模板应用于uint64_attr。

huangapple go评论88阅读模式
英文:

apply init_val template to the uint64_attr

问题

你好,

我想将init_val模板应用于我的模型中的多个属性,以通过sreset模板重置它们。

以下属性定义无法通过166基础编译,有任何建议吗?

attribute attr1[10] is (uint64_attr, init_val) {
    param init_val = 100;
}
英文:

​Hi all,

I want to apply the init_val template to several attributes in my model to reset them by sreset template.

Attribute definition below can't be compiled by 166 base, any suggestions?

attribute attr1[10] is (uint64_attr, init_val) {
    param init_val = 100;
}

答案1

得分: 2

init_val 是一个模板,旨在应用于寄存器或字段,而不是通用属性(此外,对于寄存器和字段,模板是由对象模板隐式提供的,不需要显式实例化它)。

也就是说,uint64_attr 也提供了一个可重写的 init_val 参数,但与 init_val 模板无关。因此,在你的情况下,只需移除 init_val 实例化即可使代码编译通过。

然而,这还不足以将属性与软重置机制连接起来。推荐的做法是在每个属性中实例化 soft_reset 模板,并重写 soft_reset 方法,使其调用 init。这应该使属性重新运行它们的初始化代码(如果你没有修改它,那么将它们的值设置为 init_val)。

英文:

init_val is a template meant to be applied on registers or fields, not generic attributes (in addition, for registers and fields the template is implicitly provided by the object template and there is no need to explicitly instantiate it)

That said, uint64_attr does provide you with an overrideable init_val parameter as well, just disconnected from the init_val template. So in your case just removing the init_val instantiation should make the code compile.

However, this will not be enough to tie the attributes into the soft reset mechanisms. The recommended way to do that would be to instantiate soft_reset template in each attribute, and override the soft_reset method and have it call into init. This should make the attributes re-run their init code (which, if you have not modified it, will set their values to init_val).

huangapple
  • 本文由 发表于 2023年7月3日 20:09:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76604598.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定