【问题标题】:How can I write an alias in VHDL (post-87; i.e. 93, 2008) for a function call?如何在 VHDL(87 后;即 93、2008)中为函数调用编写别名?
【发布时间】:2018-12-17 11:18:24
【问题描述】:

我有一个函数调用来简化信号转换,否则会在整个源代码中重复。

现在,作为进一步的优化,我想使用别名使相当复杂的函数调用(两个参数几乎相同)更具可读性和更易于编写。

'87 之后的 VHDL 标准允许为非数据对象使用别名,例如子程序调用。在寻找解决方案时,我了解到函数需要签名作为别名声明的一部分。然而,我找不到帮助我为与 Synopsys VCS 一起使用的函数声明别名的文档。

function discard_elem (
  signal discard_vector : in std_ulogic_vector(63 downto 0);
  signal id             : in std_ulogic_vector(5 downto 0))
  return std_ulogic is
begin
  return discard_vector(to_integer(unsigned(id)));
end discard_elem;

alias discard_current_elem is 
  discard_elem(discard_vector_i, interface_i.id) [ return std_ulogic ];

VCS 报告以下错误,然后以分段错误退出:

Error-[ANL-ALIAS-BADSIGNAT] Bad signature in alias declaration
                                                                          ^
  No subprogram or enumeration literal matches the signature of the alias 
  declaration DISCARD_ELEM.
  Please verify that the signature matches the parameter and result type 
  profile of exactly one of the subprograms or enumeration literals.

是别名定义错误还是工具问题?

【问题讨论】:

  • IEEE Std 1076-2008 6.6.3 非对象别名“以下规则适用于非对象别名:,,,"b) 如果名称表示子程序(包括运算符)或枚举,则需要签名文字。在这种情况下,签名需要匹配(参见 4.5.3)名称所表示的子程序或枚举文字之一的参数和结果类型配置文件。” VCS 找不到带有签名类型标记的声明函数 discard_elem (4.5.3 签名)discard_vector_i 和 interface_i.id。子程序不是“非数据对象”(6.4 对象),它是命名实体(6.1)。

标签: function vhdl alias


【解决方案1】:

我认为您将别名与宏混淆(在 Verilog 和其他语言中)。您不能在别名中包含 actuals(函数参数)。所以,你可以这样做:

alias discard_current_elem is discard_elem[std_ulogic_vector, std_ulogic_vector return std_ulogic];

但我认为这不是你所希望的。

https://www.edaplayground.com/x/5QS_

【讨论】:

  • 感谢您的澄清。具有相同参数的另一个名称不是我想要的,真的。想让它更容易阅读。
【解决方案2】:

别名真的就是这样,重命名相同的函数,具有相同的参数(由@Matthew Taylor 发布)。您无法更改签名,因此仍必须使用与原始函数相同的参数调用别名。

您建议的是一个包装器/帮助器函数/过程,它使用本地范围来访问本地信号/变量:

signal discard_vector_i : std_ulogic_vector(63 downto 0);
signal interface_id     : some_record_type;

impure function discard_current_elem return std_ulogc is 
begin
  return discard_elem(discard_vector_i, interface_i.id); -- scope used to access these parameters
end function;

【讨论】:

  • 这就是我想要的,谢谢。在声明别名之前,我已经尝试过一个函数调用——虽然是默认的,pure。使用不纯函数,可以使用除输入参数以外的其他对象 (ics.uci.edu/~jmoorkan/vhdlref/function.html)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-03
相关资源
最近更新 更多