【发布时间】:2018-09-28 07:05:14
【问题描述】:
我正在尝试制作一个使用泛型类型的组件。在这个组件中,我希望能够使用以前为这些类型定义的函数。考虑以下示例:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package generic_type_pkg is
function increment(x: unsigned) return unsigned;
function increment(x: signed) return signed;
end package;
package body generic_type_pkg is
function increment(x: unsigned) return unsigned is
begin
return x + 1;
end function increment;
function increment(x: signed) return signed is
begin
return x + 1;
end function increment;
end;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library common;
use common.generic_type_pkg.all;
entity generic_type is
generic(
type type_t
);
port(
clk : in std_logic;
din : in type_t;
dout : out type_t
);
end;
architecture rtl of generic_type is
begin
process(clk)
begin
if rising_edge(clk) then
dout <= increment(din);
end if;
end process;
end;
我使用下面的代码来实例化这个组件:
i_generic_type: entity common.generic_type(rtl)
generic map(
type_t => unsigned
)
port map(
clk => clk,
din => din,
dout => dout
);
如果我用 questasim 编译它,我会收到以下错误:
** 错误:*/generic_type.vhd(52): (vcom-1600) 子程序“增量”没有可行的条目。可见的子程序有: (显式)generic_type_pkg.increment[UNSIGNED return UNSIGNED] at */generic_type.vhd(6) (显式)generic_type_pkg.increment[SIGNED return SIGNED] at ***/generic_type.vhd(8)
VHDL-2008 Just the new stuff 书指出我需要为实体提供通用函数。通过将function increment ( x: type_t) return type_t 添加到泛型中,我能够解决编译错误。我对此不满意,因为这意味着我需要将要使用的每个函数传递给该组件(例如递增、递减、乘法、移位……)。这将很快变得无法维护。
有没有办法在编译顶级组件时解决这些通用函数?
【问题讨论】:
-
No。参见 IEEE 标准 1076-2008。 type_t 的子类型(6.5.3 接口类型声明)直到关联(6.5.7)才知道。如果没有在通用映射方面(6.5.7.2、14.3.3.3)提供子类型(这里有符号或无符号),则不知道基类型类(5.1、标量、复合、访问、文件、受保护)和 type_t 的基类型.如果没有这些,则在分析期间无法识别函数增量签名 (4.5.3)(4.5、12.5、4.10)。
-
generic_type_pkg.vhdl:24:18:error: no function declarations for operator "+"。 (如果你尝试定义它,你会发现类型类是未知的,type_t 的元素类型是什么?)