我正在使用自定义类型来定义一个两位对数组(长度为2的std_logic_vector)。 分配多个对时,这很好用,但是对于单个对,GHDL和Vivado都抛出错误。
代码:
library ieee;
use ieee.std_logic_1164.all;
entity test is
end entity;
architecture RTL of test is
type bit_pairs is array(natural range<>) of std_logic_vector(1 downto 0);
-- This works fine
constant test_vector0 : bit_pairs(1 downto 0) := ("11", "00");
-- This doesn't
constant test_vector1 : bit_pairs(0 downto 0) := ("11");
-- This also doesn't
constant test_vector2 : bit_pairs(0 downto 0) := std_logic_vector'("11");
-- This works, though seems like workaround / hack, not a real solution
constant test_vector3 : bit_pairs(0 downto 0) := (others => "11");
-- [Update - see comments] This works as well
constant test_vector4 : bit_pairs(0 downto 0) := (0 => "11");
begin
end RTL;
GHDL抛出此错误:
test2.vhd:15:55:error: can't match string literal with type the anonymous array subtype defined at test2.vhd:15:38
对于我的用例,有必要将常量声明为向量,因此在我只需要一个两位元素的情况下,我不能只使用常规的std_logic_vector(1降至0)。
尽管我能够弄清代码示例中包含的解决方法,但我更希望使用一种“黑客”式的解决方案。