GHDL 找不到包中定义的函数

问题描述 投票:0回答:1

使用 GHDL-4.0.0 我想编译一个 VHDL 实体,该实体引用在单独的 VHDL 包文件中定义的函数。 我收到编译错误

error: no declaration for function_name

这是可复制的来源:

common.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;

package common is
    function Bmax_calc(Bin : natural; R : natural; N : natural; M : natural) return natural;
end package;

package body common is
    function Bmax_calc(Bin : natural; R : natural; N : natural; M : natural) return natural is
        constant a : real := real(R*M);
        constant b : real := log2(a);
        constant c : real := real(real(N) * b);
    begin
        return natural(c) + Bin;
    end function;
end package body;

mydesign.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;

entity mydesign is
    generic (
        Bin : natural := 24;
        R : natural := 8;
        N : natural := 3;
        M : natural := 1
    );
    port (
        clk : in std_logic;
        data_i : in signed(Bin - 1 downto 0);
        data_o : out signed(Bin - 1 downto 0)
    );
end mydesign;

architecture arch of mydesign is
    constant Bmax : integer := Bmax_calc(Bin, R, N, M);
    subtype regsize is signed(Bmax - 1 downto 0);
    signal int_r, int_out : regsize := (others => '0');
begin
    process(clk)
    begin
        if (rising_edge(clk)) then
            data_o <= data_i;
        end if;
    end process;
end arch;

build.sh

#!/usr/bin/bash
mkdir build
cd build
ghdl -a ../common.vhd
ghdl -a --ieee=synopsys ../mydesign.vhd
ghdl -e mydesign

控制台输出

../mydesign.vhd:22:36:error: no declaration for "bmax_calc"
        constant Bmax : integer := Bmax_calc(Bin, R, N, M);
                                   ^

我必须在编译时显式指定包吗? GHDL 不支持引用包中的函数吗? 或者还有什么问题?

vhdl ghdl
1个回答
2
投票

在声明

mydesign
实体之前,您需要“使用”您的包,以使包内容在设计单元中可见:

use work.common.all

或者您需要直接引用它:

constant Bmax : integer := work.common.Bmax_calc(Bin, R, N, M);
© www.soinside.com 2019 - 2024. All rights reserved.