VHDL 检查字符串是否为空

VHDL check if string is empty

不敢相信我为此提出了一个新的 SO 问题。

我有一个这样的 VHDL 实体:

entity dpram is
    generic(
        DWIDTH  : integer;
        AWIDTH  : integer;
        INIT_FILE : string
    );
    port (
        clk     : in  std_logic;
        we      : in  std_logic;
        a       : in  std_logic_vector(AWIDTH - 1 downto 0);
        d_i     : in  std_logic_vector(DWIDTH - 1 downto 0);
        d_o     : out std_logic_vector(DWIDTH - 1 downto 0);

        dpra    : in  std_logic_vector(AWIDTH - 1 downto 0);
        dpo     : out std_logic_vector(DWIDTH - 1 downto 0)
    );

end dpram;

在架构中,我想检查INIT_FILE是否为空。我该怎么做?

您可以使用'长度属性:

if INIT_FILE'length = 0 then....

或将其与空字符串进行比较:

if INIT_FILE = "" then

注意 - 目前泛型没有默认值,因此实例化此模块的用户必须明确地将其连接到空字符串,这可能让人觉得很奇怪。对于空默认值:

INIT_FILE : string := ""