当有多个选择时,聚合具有本地静态选择的要求。 (确定表达式值的代码是在分析时构建的。)
IEEE Std 1076-2008 9.3.3.3 数组聚合第 6 段:
除了与单个选择others的最终元素关联外,数组聚合的其余元素关联(如果有)应全部为位置或全部命名。数组聚合的命名关联允许有一个不是局部静态的选择,或者同样是一个空范围的选择,只有当聚合包括单个元素关联并且这个元素关联有一个选择时。如果适用的索引约束是本地静态的,则其他选择是本地静态的。
可以在细化时通过函数调用(表达式,9.3.4 函数调用)提供常量的值表达式(6.4.2.2 常量声明)或变量或信号的初始表达式(14.4.2.5 对象声明) )。该函数可能是不纯的(4. 子程序和包,4.1 通用,9.4.3 全局静态主,注 2)。
构造一个Minimal, Complete, and Verifiable example 可以证明这一点:
library ieee;
use ieee.std_logic_1164.all;
ravenwater_mcve is
generic (NBITS: natural := 42);
end entity;
architecture foo of ravenwater_mcve is
impure function leftbit return std_logic_vector is
variable retv: std_logic_vector (NBITS - 1 downto 0) :=
(others => '0');
begin
retv(retv'LEFT) := '1';
return retv;
end function;
constant NaR: std_logic_vector(NBITS - 1 downto 0) := leftbit;
-- (NBITS - 1 => '1', others => '0');
begin
end architecture;
MCVe 分析、阐述和模拟。
您可以添加一个过程来确定值表达式是否正确:
RESULT:
process
begin
report "NaR = " & to_string(NaR);
wait;
end process;
如果使用 -2008 之前的 VHDL 标准修订版,请提供 to_string 函数:
function to_string (inp: std_logic_vector) return string is
variable image_str: string (1 to inp'length);
alias input_str: std_logic_vector (1 to inp'length) is inp;
begin
for i in input_str'range loop
image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
end loop;
return image_str;
end function;
这会产生:
ghdl -r ravenwater_mcve
ravenwater_mcve.vhdl:33:9:@0ms:(报告说明):NaR = 100000000000000000000000000000000000000000
(也许我应该为通用常量使用较小的默认值。)
您也可以将泛型的值作为参数传递给纯函数。