如何在 VHDL(post-87;即 93、2008)中为函数调用编写别名?

How can I write an alias in VHDL (post-87; i.e. 93, 2008) for a function call?

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

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

'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.

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

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

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

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

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

别名实际上就是对具有相同参数的相同函数进行重命名(如@Matthew Taylor 所贴)。您无法更改签名,因此仍然必须使用与原始函数相同的参数调用别名。

您建议的是 wrapper/helper function/procedure,它使用本地作用域访问本地 signals/variables:

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;