Vhdl 重载子程序中的函数,但它有;已定义“已定义”;
我正在尝试编译子程序包,但出现以下错误: **错误:C:/Users/kmgryte/Downloads/subprog_pck.vhd(16):(vcom-1295)函数“奇偶校验”已在此区域中定义。 **====>先前的“奇偶校验”声明位于C:/Users/kmgryte/Downloads/subprog_pck.vhd(12)。 **错误:C:/Users/kmgryte/Downloads/subprog_pck.vhd(20):VHDL编译器正在退出 这样的重载在我的主程序中起作用,我在在线子程序中找不到任何重载的好例子Vhdl 重载子程序中的函数,但它有;已定义“已定义”;,vhdl,overloading,pack,questasim,Vhdl,Overloading,Pack,Questasim,我正在尝试编译子程序包,但出现以下错误: **错误:C:/Users/kmgryte/Downloads/subprog_pck.vhd(16):(vcom-1295)函数“奇偶校验”已在此区域中定义。 **====>先前的“奇偶校验”声明位于C:/Users/kmgryte/Downloads/subprog_pck.vhd(12)。 **错误:C:/Users/kmgryte/Downloads/subprog_pck.vhd(20):VHDL编译器正在退出 这样的重载在我的主程序中起作用,
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
package subprog_pck is
procedure parity;
procedure parity(
in1 : in std_logic_vector(15 downto 0);
in2 : in std_logic_vector(15 downto 0);
par : out std_logic);
function parity return std_logic;
function parity(
indata : in std_logic_vector(15 downto 0)) return std_logic;
impure function parity return std_logic;
impure function parity(
indata : in unsigned(15 downto 0)) return std_logic;
end package subprog_pck;
package body subprog_pck is
procedure parity(
in1 : in std_logic_vector(15 downto 0);
in2 : in std_logic_vector(15 downto 0);
par : out std_logic) is
begin
variable parity1, parity2 : std_logic:=0;
if (rst_n = '0') then
parity1 := '0';
parity2 := '0';
par <= '0';
elsif rising_edge(mclk) then
parity1 := '0';
for i in in1'range loop
if in1(i) = '1' then
parity1 := not parity1;
end if;
end loop;
parity2 := '0';
for j in in2'range loop
parity2 := parity2 xor in2(j);
end loop;
par <= parity1 xor parity2;
end if;
end parity;
function parity(indata : in std_logic_vector(15 downto 0)) return std_logic is
variable parity_var : std_logic := '0';
begin
for i in indata'range loop
if (indata(i) = '1') then
parity_var := not parity_var;
end if;
end loop;
return parity_var;
end function parity;
function parity(indata : in unsigned(15 downto 0))
return std_logic is
variable parity_var : std_logic := '0';
begin
for j in indata'range loop
parity_var := parity_var xor indata(j);
end loop;
return parity_var;
end function parity;
end package body subprog_pck;
使用IEEE.std_logic_1164.all;
使用ieee.numeric_std.all;
包子包pck为
程序奇偶性;
程序奇偶性(
in1:in标准逻辑向量(15到0);
in2:in标准逻辑向量(15到0);
PAR:输出STDYLogic;
函数奇偶返回标准逻辑;
函数奇偶性(
indata:在标准逻辑向量(15到0)中返回标准逻辑;
不纯函数奇偶返回标准逻辑;
不纯函数奇偶性(
indata:在无符号(15到0)中返回标准_逻辑;
端包子包pck;
包体子包pck为
程序奇偶性(
in1:in标准逻辑向量(15到0);
in2:in标准逻辑向量(15到0);
PAR:输出STDYLogic)
开始
变量parity1、parity2:std_逻辑=0;
如果(rst_n='0'),则
parity1:=“0”;
parity2:=“0”;
PAR 函数重载只发生在具有不同参数列表的相同函数名时。使用不纯不会使另一个函数过载。所以有两种版本的奇偶校验,不接受输入,输出std_逻辑。因此出现了编译错误
您还没有在包正文中提供此版本的奇偶校验。包中还有其他错误,在上下文子句中缺少库子句(库ieee;
)。过程parity
在begin
之后有一个变量声明,parity1和parity2的初始值为0(一个数字文本),在par中没有关于rst\u n
或mclk
的声明