VHDL - 为什么不允许在生成循环中使用变量
VHDL - Why are you not allowed to use variables in generate loops
我知道,变量只允许在进程中使用,但为什么不允许在生成循环中使用它们。
合成这样的结构没有问题,因为它们之前已经被评估过。
如果没有这个限制,代码的可读性会更高。
lbl1: for i in data_out'range generate
lbl2a: component comp_a
port map(
clk => clk,
out => out(0)(i)
in_a => data_in(i*w + offset to i*w + w + offset));
lbl2b: component comp_b
port map(
clk => clk,
out => out(1)(i)
in_b => data_in(i*w + offset to i*w + w + offset));
.
.
.
lbl2n: component comp_n
port map(
clk => clk,
out => out(n)(i)
in_n => data_in(i*w + offset to i*w + w + offset));
end generate lbl1;
或者直接写
lbl1: for i in data_out'range generate
variable lower : integer := i*w + offset;
variable upper : integer := i*w + w + offset;
lbl2a: component comp_a
port map(
clk => clk,
out => out(0)(i)
in_a => data_in(lower to upper));
lbl2b: component comp_b
port map(
clk => clk,
out => out(1)(i)
in_b => data_in(lower to upper));
.
.
.
lbl2n: component comp_n
port map(
clk => clk,
out => out(n)(i)
in_n => data_in(lower to upper));
end generate lbl1;
该代码并非来自任何示例,它随时可能会失败,但我想您明白我的意思了。它会更容易阅读和维护。生成的变量可能会超出生成过程之外的范围。
所以有什么原因不允许这样做,还是它只是以前 vhdl 标准的历史产物?
如果你想声明一些东西,它需要在一个声明区域中。 generate
语句有点特殊,因为它不需要 begin
;你可以(像你一样)使用:
GenerateLoop : for i in data_out'range generate
-- Code here
end generate;
如果您想将事物声明为循环的一部分,您必须有一个声明区域,它与生成语句一起看起来像这样:
GenerateLoop : for i in data_out'range generate
-- Declarative region
begin
-- Code here
end generate;
您应该能够在此声明区域中声明事物。请注意,您将需要使用信号或常数(看起来常数更合适)而不是变量。
我知道,变量只允许在进程中使用,但为什么不允许在生成循环中使用它们。 合成这样的结构没有问题,因为它们之前已经被评估过。
如果没有这个限制,代码的可读性会更高。
lbl1: for i in data_out'range generate
lbl2a: component comp_a
port map(
clk => clk,
out => out(0)(i)
in_a => data_in(i*w + offset to i*w + w + offset));
lbl2b: component comp_b
port map(
clk => clk,
out => out(1)(i)
in_b => data_in(i*w + offset to i*w + w + offset));
.
.
.
lbl2n: component comp_n
port map(
clk => clk,
out => out(n)(i)
in_n => data_in(i*w + offset to i*w + w + offset));
end generate lbl1;
或者直接写
lbl1: for i in data_out'range generate
variable lower : integer := i*w + offset;
variable upper : integer := i*w + w + offset;
lbl2a: component comp_a
port map(
clk => clk,
out => out(0)(i)
in_a => data_in(lower to upper));
lbl2b: component comp_b
port map(
clk => clk,
out => out(1)(i)
in_b => data_in(lower to upper));
.
.
.
lbl2n: component comp_n
port map(
clk => clk,
out => out(n)(i)
in_n => data_in(lower to upper));
end generate lbl1;
该代码并非来自任何示例,它随时可能会失败,但我想您明白我的意思了。它会更容易阅读和维护。生成的变量可能会超出生成过程之外的范围。
所以有什么原因不允许这样做,还是它只是以前 vhdl 标准的历史产物?
如果你想声明一些东西,它需要在一个声明区域中。 generate
语句有点特殊,因为它不需要 begin
;你可以(像你一样)使用:
GenerateLoop : for i in data_out'range generate
-- Code here
end generate;
如果您想将事物声明为循环的一部分,您必须有一个声明区域,它与生成语句一起看起来像这样:
GenerateLoop : for i in data_out'range generate
-- Declarative region
begin
-- Code here
end generate;
您应该能够在此声明区域中声明事物。请注意,您将需要使用信号或常数(看起来常数更合适)而不是变量。