我可以定义一个不为边缘情况生成任何东西的 for..generate 吗?

Can I define a for..generate that doesn't generate anything for edge cases?

我可以定义一个从 0 到 -1 的 for..generate 不生成任何东西吗? BLOCK_WIDTH 是一个泛型,在某些边缘情况下可能为 0(这很好,我们只是不需要生成任何东西)。

Gen_Block: if BLOCK_WIDTH /= 0 generate -- Do I need this?
    Gen_Bits: for i in 0 to BLOCK_WIDTH - 1 generate
        -- Other stuff here.
    end generate;
end generate;

是否需要封闭的 if generate 语句?号

一个完整且可验证的最小示例:

entity foo is
end entity;

architecture fum of foo is
  constant BLOCK_WIDTH: natural := 0;

begin
  Gen_Bits: 
    for i in 0 to BLOCK_WIDTH - 1 generate
      -- Other stuff here.
    end generate;
end architecture;

这个分析、阐述和运行告诉我们它在句法和语义上都是合法的VHDL。

对于 BLOCK_WIDTH = 0 的情况,我们看到 for generate 语句条件的参数规范范围为 0 到 BLOCKWIDTH - 1(或 0 = 1 = -1)。

IEEE 标准 5.2 标量类型,5.2.1。一般,第 3 段:

A range specifies a subset of values of a scalar type. A range is said to be a null range if the specified subset is empty.

那么我们如何判断子集是否为空呢?

11.8 生成语句第 5 段:

The discrete range in the generate parameter specification of a for generate statement shall be a static discrete range; similarly, each condition in an if generate statement shall be a static expression.

那么在离散范围内会发生什么?

5.3.2 数组类型,5.3.2.1 第 2 段(摘录):

discrete_range ::= *discrete_*subtype_indication | range

5.2 标量类型,5.2.1 第 2 段(摘录):

range ::= 
    range_attribute_name
  | simple_expression direction 

simple_expression direction ::= to | downto

第 4 段:

The range L to R is called an ascending range; if L > R, then the range is a null range. The range L downto R is called a descending range; if L < R, then the range is a null range. L is called the left bound of the range, ...

第 7 段:

If a range constraint is used in a subtype indication, the type of the expressions (likewise, of the bounds of a range attribute) shall be the same as the base type of the type mark of the subtype indication. A range constraint is compatible with a subtype if each bound of the range belongs to the subtype or if the range constraint defines a null range. Otherwise, the range constraint is not compatible with the subtype.

(并且 i 范围的每个界限都与范围表达式的基本类型兼容,即整数)。

你猜怎么着?没有包含 for generate 语句的 if generate 语句的 VHDL 代码是合法的 VHDL,在整数值的子集中没有 i 的值可以导致任何包含的并发语句或声明的详细说明。

所以不,您不需要封闭的 if generate 语句。